Sunday, June 28, 2009

click-once deployment, xenocode postbuild
> (http://www.xenocode.com/products/postbuild-for-net/) and tortoise svn
> to start with.

Tuesday, May 05, 2009

        protected void Button1_Click(object sender, EventArgs e)

        {

            string executePath = System.Configuration.ConfigurationSettings.AppSettings["executePath"];

            ExecuteCommandSync(executePath);

 

            string resultfilePath = System.Configuration.ConfigurationSettings.AppSettings["filePath"];

 

            this.Label1.Text = System.IO.File.ReadAllText(resultfilePath);

 

        }

        public void ExecuteCommandSync(string executePath)

        {

            try

            {

                System.Diagnostics.Process p = new System.Diagnostics.Process(); // Redirect the output stream of the child process.

                p.StartInfo.UseShellExecute = false;

                p.StartInfo.RedirectStandardOutput = true;

                p.StartInfo.FileName = executePath;

                p.Start(); // Do not wait for the child process to exit before // reading to the end of its redirected stream. // p.WaitForExit(); // Read the output stream first and then wait. string output = p.StandardOutput.ReadToEnd(); p.WaitForExit();

                p.WaitForExit();

            }

            catch (Exception ex)

            {

                System.Diagnostics.Debug.WriteLine(ex.ToString());

            }

 

        }

Tuesday, April 07, 2009

Mission:  From C#, P/Invoke C++ with callbacks to C#

//-----------------------------------------------------------------------

// inside unmanaged C# code

//-----------------------------------------------------------------------

//-----------------------------------------------------------------------

//delegates - define a signatures for unmanaged c++ code to call

//-----------------------------------------------------------------------

public delegate void MessageReceivedDelegate(

   int param1,

   string messageString,

   int param3,

   int param4,

   int param5);

 

 

public delegate void ExceptionParsedDelegate(

  string exceptionMessage);

 

//-----------------------------------------------------------------------

// P/invoke mapping with pointers to delegated methods

//-----------------------------------------------------------------------

[DllImport("my.dll"

   , CallingConvention = CallingConvention.StdCall)]

public static extern void an_unmanaged_function(

   string aa,

    int bb,

    string cc,

    string dd,

    int ee,

    int ff,

    MessageReceivedDelegate call,

    ExceptionParsedDelegate exception);

 

 

//-----------------------------------------------------------------------

// perform P/invoke

//-----------------------------------------------------------------------

an_unmanaged_function(  

aa

,bb

,cc

,dd

,ee

,ff

,new MessageReceivedDelegate(OnMessageReceived)

,new ExceptionParsedDelegate(OnExceptionReceived));

 

//-----------------------------------------------------------------------

// delegated methods (called inside unmanaged c++ code)

//-----------------------------------------------------------------------

public void OnExceptionReceived(

   string exceptionMessage)

{

 

    //handle exceptionMessage

}

protected void OnMessageParsed(myMessage theMesssage)

{

    //handle theMesssage

}

 

//-----------------------------------------------------------------------

// inside unmanaged c++ code ("my.dll")

//-----------------------------------------------------------------------

 

//define c++ delegate signatures

 

typedef void (__stdcall *callbackDelegatePointer)(

       int param1,

       char message[2100],

       int param3,

       int param4,

       int param5);

typedef void (__stdcall *exceptionDelegatePointer)(

       char* exceptionMessage);

 

//allow p/invoke by delcaring method “extern "C"”

extern "C" __declspec(dllexport)

void __stdcall an_unmanaged_function(

       char *aa,

       int   bb,

       char *cc,

       char *dd,

       int   ee,

       int   ff,

       callbackDelegatePointer onMessageReceived,

       exceptionDelegatePointer onException)

 

//call delegates

onMessageReceived(param1, message, param3, param4, param5);

             

onException("Hello Exception");

 

 

 

 

Mission:  Show elapsed time on a WinfForm in C#

thanks to Mahesh Chand

original article:  http://www.c-sharpcorner.com/UploadFile/mahesh/WorkingwithTimerControlinCSharp11302005054911AM/WorkingwithTimerControlinCSharp.aspx

1) add stop & start buttons and a timer control on a web form

2) put code behind the buttons (below), that consumes the StopWatch class (below)

    public partial class Form1 : Form
    {
        static void Main()
        {
            Application.Run(new Form1());
        }
        public Form1()
        {
            InitializeComponent();
        }

        StopWatch stopWatch = new StopWatch();

        private void btnStart_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
            stopWatch.Start();
        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            stopWatch.Stop();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            lblElapsedTime.Text = stopWatch.GetElapsedTimeString();
        }
    }

    public class StopWatch
    {

        private DateTime startTime;
        private DateTime stopTime;
        private DateTime currentTime;
        private bool running = false;


        public void Start()
        {
            this.startTime = DateTime.Now;
            this.running = true;
        }


        public void Stop()
        {
            this.stopTime = DateTime.Now;
            this.running = false;
        }


        // elaspsed time in milliseconds
        public string GetElapsedTimeString()
        {
            TimeSpan interval;

            if (!running)
                return ""; //interval = DateTime.Now - startTime;
            else
            {
                this.currentTime = DateTime.Now;
                interval = currentTime - startTime;
            }

            int days = interval.Days;
            double hours = interval.Hours;
            double mins = interval.Minutes;
            double secs = interval.Seconds;
            string x = "";
            if (days != 0)
            {
                x += days.ToString() + ":";
            }
            if (hours != 0)
            {
                x += hours.ToString("00") + ":";
            }
            x += mins.ToString("00") + ":";
            x += secs.ToString("00");

            return x;
        }
        public double GetElapsedMilliseconds()
        {
            TimeSpan interval;

            if (running)
                interval = DateTime.Now - startTime;
            else
                interval = stopTime - startTime;

            return interval.TotalMilliseconds;
        }


        // elaspsed time in seconds
        public double GetElapsedTimeSecs()
        {
            TimeSpan interval;

            if (running)
                interval = DateTime.Now - startTime;
            else
                interval = stopTime - startTime;

            return interval.TotalSeconds;
        }
    }

Wednesday, February 18, 2009

 
As .Net Developers we often need to change web.config/app.config settings.  We also need to share web.config/app.config without clobbering each others settings via Visual Source Safe (VSS).
 
There are two kinds of config changes.
 
1.      Changes that you do not want other developers to inherit
a.      Connection string changes or settings values
                                                                                        i.    that do not change the config structure
                                                                                       ii.    that need to vary between developers
 
·         You should:
1.      Point to each config files with Windows Explorer
2.      Uncheck the ReadOnly propery check box to make the file Readable
3.      proceed with your Visual Studio changes to each config files
(OBSERVE that the file will not show as “checked out” from VSS)
4.      be careful when you get the latest of everyting from VSS that you do not overwrite your config files changes
 
2.      New Connection strings or new settings
                                            i.    that do change the config structure
                                           ii.    that every developer needs in their version of config
 
·         for each config file(s) You should:
·     select each config file(s) in Visual Studio Project Explorer
·         right Mouse click -> Get Latest Version
·         overwriting your Readable config file
·         proceed with your Visual Studio changes to config file
·         save the config file
·         test your config file
·         checkin config file
·     email everyone to get latest VSS config structure changes!
 

Tuesday, February 03, 2009

Enabling classic ASP pages on Windows server 2003 with IIS 6.0

Problem:  we want to run a classic ASP page in the middle of our ASP.NET project

from Carl Morita
-  original article:  http://www.dovetailsoftware.com/resources/solutions/100.aspx

IIS 6.0 might have classic asp pages disabled
- (classic asp pages are disabled by default)

Open up ‘Manage Your Server’ console
via Start -> Control Panel -> Administrative Tools -> Manage Your Server

Then click on ‘Application Server’ -> ‘Manage this application server’

Go to IIS Manager

Double-click on your computer

Go to Web Service Extensions

A list will appear on the right. Select ‘active server pages’

Press the ‘Allow’ button

Monday, January 26, 2009

Carl     973-214-9330
Gene     917-450-4004
Jonathan 973-342-2763
Rodney   973-746-2143

Monday, March 2 you can work at home

unless you prefer to go to the office.
 
If you need to contact me,
Use Yahoo Messenger.
Use my home phone 973-746-2143 (my cell does not work well from my home).
Use my home email Rodney.Vinyard@gmail.com .

Thursday, January 01, 2009

Topic: Grow a VMware virtual bootable hard disk (vmdk)

 

 

I followed this article:  http://vmprofessional.com/index.php?content=2k3resize

 

Before you begin, make sure that you do not have an active snapshot on the VM, extending a virtual disk with a snapshot will cause corruption

Extend the boot volume of Windows Server 2003 Virtual Machine
To start, I have a Windows Server 2003 Virtual Machine that has a 5.3G disk allocated to it, I need to expand this disk to 10G.


Step 1: Power off the virtual machine that holds the boot volume that you want to extend.

Step 2: Make a backup copy of your virutal disk, this is optional but if you mess up don't call me unless you're willing to pay.

Step 3: From the service console, increase the size of the .dsk or .vmdk virtual disk file. This can also be accomplished through the Virtual Infrastructure Client if you are using VirtualCenter 2.x+.

[root@esx-test local]# ls -lah test.vmdk

-rw-------    1 root     root         5.4G Jul 18 13:57 test.vmdk

Extend the virtual disk with vmware-vdiskmanager.exe. The input to the -X switch is the size that you want the disk file to be not the size you want to extend the disk file by.

[root@esx-test local]# vmware-vdiskmanager.exe –d "C:\VideoBank\VMs\2003 Server - 02 WebXpress.NET + VS2005\Windows Server 2003 Standard Edition.vmdk"

 

 

 

 

Using out-of-box VMware dos utility as follows produces error

 

 

DiskName or some other argument missing

 

So then I

1.       downloaded and installed the “Petruska family” VMware DiskManager GUI tool

2.       http://petruska.stardock.net/Software/VMware.html (moved to http://vmxbuilder.com/ )

3.       the tool worked just fine J

 

 

 

 

View the new size of test.vmdk

[root@esx-test local]# ls -lah test.vmdk

-rw-------    1 root     root          10G Jul 18 13:57 test.vmdk

Step 4: For this step you will need an additional Virtual Machine running Windows Server 2003. Power off the second Virtual Machine, and add the disk from the first Virtual Machine to it through the mui.

In the Virtual Machine Settings window, click on the Add… button at the bottom

When you click the Add button, use the Browse button to point to the VMDK file for the first VM, and add the VMDK file.

 

 

 

Power up the second Virtual Machine and verify that the imported disk has unallocated space on it.

From the run menu type "diskpart.exe" to enter the command line utility to resize disk partitions in Windows Server 2003.

The command list volume will show you all the available volumes. Select your volume as shown below. select volume 1 corresponds to the "D" volume that I want to extend. Finally extend the volume with the extend command.


If all goes well, the partition will be immediately exnteded under the Disk Management snap in.


Step 5: Shut down the second Virtual Machine and remove the disk from the second Virtual Machine. Power on the first Virtual Machine and check out your new space.

 

 

 

 

 

Monday, December 01, 2008

To Use VS 2005 Web Deployment Projects
1.       install VS 2005 Web Deployment Project add-in at "setup" link below
 
2.       In File Name Box - "*.*" -> Click Open Button
3.       Select an available .wdproj file
Other links:
 

Saturday, November 08, 2008

Get email addressees of all users from all mails in Outlook Folder

Original Article:

http://msmvps.com/blogs/omar/archive/2006/08/09/get-email-address-of-all-users-from-all-mails-in-outlook-folder.aspx

Sometimes you want to send some important notice to everyone who has ever mailed you. Let's say you have a folder named "Friends" in Outlook where you store all the emails from your friends. Now you want to get all of their email addresses (from the folder, not from the email bodies). Pretty difficult work if you have thousands of such mails. Here's an easy way.

  • Select the folder in Outlook and press ALT+F11. It will open Visual Basic Editor.
  • Double click on ThisOutlookSession from the Project tree.
  • Set a reference to Microsoft Scripting Dictionary

  • Paste the following function:

 Hit F5 and it will run for a while. Then press Ctrl+G. You will see the email addresses in the "Immediate Window".    

Copy the whole string and you have all the email addresses from all the emails in the selected Outlook folder. There will be no duplicate address in the list.

Sub GetALLEmailAddresses()

Dim objFolder As MAPIFolder
Dim strEmail As String
Dim strEmails As String
''' Requires reference to Microsoft Scripting Runtime
Dim dic As New Dictionary
Dim objItem As Object

''Set objFolder = Application.ActiveExplorer.Selection
Set objFolder = Application.GetNamespace("Mapi").PickFolder

For Each objItem In objFolder.Items
   
   If objItem.Class = olMail Then
   
       strEmail = objItem.SenderEmailAddress

       If Not dic.Exists(strEmail) Then

           strEmails = strEmails + strEmail + vbCrLf

           dic.Add strEmail, ""

       End If

   End If
   
Next

Debug.Print strEmails

End Sub

 

Thursday, October 23, 2008

simulate: “file Streams into Memory, then JOIN the data in Memory, via LINQ to Objects”
 
I wrote up a quick little WinForms project in VS2008 with .NET Framework 3.5,
 
 
 
 
 
Code overview: 
 
1.    On Form_Load,
a.    create a List of People into DataDridView and in Memory
b.    create a List of Jobs into DataDridView and in Memory
c.    create a List of JobIds into ComboBox
2.    On ComboBox_SelectedIndexChanged,
a.    Perform LINQ to Objects query: “Select from People JOINED to Jobs by JobId”
b.    Show query result in list box
 
You can probably do this with nHibernate too.
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace FascetLINQtoObjects
{
    publicpartialclassForm1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        //-----------------------------------------------------
        //Form Scope (To hold & share LINQ Objects' state) -
        //-----------------------------------------------------
        List<Person> people = newList<Person>();
        List<Job> jobs = newList<Job>();
        bool _loaded = false;
       
        privatevoid Form1_Load(object sender, EventArgs e)
        {
            //-----------------------------------------------------
            //Form Load Load LINQ Objects' state
            //Simulate Fascet Client data streaming into Fascet Winform
            //-----------------------------------------------------
            people.Add(newPerson("Gerald", DateTime.Parse("1/2/2003"), 3));
            people.Add(newPerson("Linda", DateTime.Parse("2/2/2002"), 1));
            people.Add(newPerson("Sarah", DateTime.Parse("4/2/2002"), 1));
            people.Add(newPerson("Bill", DateTime.Parse("4/5/2006"), 2));
 
 
            jobs.Add(newJob(1, "Developer", "Microsoft", "West"));
            jobs.Add(newJob(2, "Developer", "Microsoft", "East"));
            jobs.Add(newJob(3, "Technical Account Representative", "Microsoft", "Central"));
           
            //-----------------------------------------------------
            //Bind to Jobs DataGridView
            //-----------------------------------------------------
            dgPeople.DataSource = people;
            this.dgJobs.DataSource = jobs;
 
            //-----------------------------------------------------
            //Bind to Jobs comboBox
            //-----------------------------------------------------
            this.cboJob.DataSource = jobs;
            this.cboJob.ValueMember = "ID";
            this.cboJob.DisplayMember = "ID";
 
            //-----------------------------------------------------
            //ShowPersonJob
            //-----------------------------------------------------
            int jobId = int.Parse(cboJob.SelectedValue.ToString());
            ShowPersonJob(jobId);
 
            _loaded = true;
 
        }
        privatevoid ShowPersonJob(int jobId)
        {
            //-----------------------------------------------------
            //query joined LINQ objects
            //-----------------------------------------------------
            var result = from p in people
                         from j in jobs
                         where p.JobID == j.ID
                         && j.ID == jobId
                         selectnew
                         {
                             p.Name,
                             j.Company,
                             j.Title
                         };
 
            //-----------------------------------------------------
            //display query result
            //-----------------------------------------------------
            this.listBox1.DataSource = result.ToList();
        }
 
        privatevoid cboJob_SelectedIndexChanged(object sender, EventArgs e)
        {
            //-----------------------------------------------------
            //ShowPersonJob
            //-----------------------------------------------------
            if (_loaded)
            {
                //-----------------------------------------------------
                //
                //-----------------------------------------------------
                int jobId = int.Parse(cboJob.SelectedValue.ToString());
                ShowPersonJob(jobId);
            }
        }
   
    }
}
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace FascetLINQtoObjects
{
    classPerson
    {
        string _name = "";
        publicstring Name
        {
            get { return _name; }
            set { _name = value; }
        }
        DateTime? _Birthday;
        publicDateTime? Birthday
        {
            get { return _Birthday; }
            set { _Birthday = value; }
        }
        int _jobID = 0;
        publicint JobID
        {
            get { return _jobID; }
            set { _jobID = value; }
        }
        public Person(string name, DateTime birthday, int jobID)
        {
            this._name = name;
            this._Birthday = birthday;
            this._jobID = jobID;
 
        }
    }
}
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace FascetLINQtoObjects
{
    classJob
    {
        string _title = "";
        publicstring Title
        {
            get { return _title; }
            set { _title = value; }
        }
 
        string _company = "";
        publicstring Company
        {
            get { return _company; }
            set { _company = value; }
        }
 
        int _id = 0;
        publicint ID
        {
            get { return _id; }
            set { _id = value; }
        }
 
        string _location = "";
        publicstring Location
        {
            get { return _location; }
            set { _location = value; }
        }
        public Job(int id, string title, string company, string location)
        {
            _title = title;
            _id = id;
            _company = company;
            _location = location;
        }
    }
}
 
 
 

List All Primary Keys and Foreign Keys

Original article:  http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=41896

set nocount on
create table #PK(constraint_schema sysname not null, constraint_name sysname not null, sql varchar(4000) not null, constraint PK_#PK primary key clustered(constraint_schema, constraint_name))
create table #cols(constraint_schema sysname not null, constraint_name sysname not null, column_name sysname not null, ordinal_position int not null, constraint PK_#PKcol primary key clustered(constraint_schema, constraint_name, ordinal_position))
create table #FK(constraint_schema sysname not null, constraint_name sysname not null,
unique_constraint_schema sysname not null, unique_constraint_name sysname not null,
sql varchar(4000) not null, constraint PK_#FK primary key clustered(constraint_schema, constraint_name))

insert into #PK
select constraint_schema, constraint_name, 'ALTER TABLE ' + quotename(table_schema) + '.' + quotename(TABLE_NAME) +
' ADD CONSTRAINT ' + quotename(CONSTRAINT_NAME) +
' PRIMARY KEY ' + CASE WHEN si.indid<>1 THEN 'NON' ELSE '' END +
'CLUSTERED (>cols<) WITH FILLFACTOR=' + cast(si.OrigFillFactor as varchar) + ' ON ' + quotename(fg.groupname)
AS SQL
from INFORMATION_SCHEMA.TABLE_CONSTRAINTS TC
INNER JOIN sysindexes si on TC.CONSTRAINT_NAME=si.name
inner join sysfilegroups fg on si.groupid=fg.groupid
WHERE CONSTRAINT_TYPE IN('PRIMARY KEY','UNIQUE')

insert into #fk
select c.constraint_schema, c.constraint_name, c.unique_constraint_schema, c.unique_constraint_name,
'ALTER TABLE ' + quotename(F.table_schema) + '.' + quotename(F.table_name) +
' ADD CONSTRAINT ' + quotename(F.constraint_name) +
' FOREIGN KEY(>cols<) REFERENCES ' + quotename(r.table_schema) + '.' + quotename(r.table_name) +
'(>rcols<)'
AS sql
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS F
INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS C ON F.constraint_schema=C.constraint_schema AND f.constraint_name=c.constraint_name AND F.constraint_type='FOREIGN KEY'
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS R ON R.constraint_schema=C.unique_constraint_schema AND r.constraint_name=c.unique_constraint_name AND r.constraint_type in ('PRIMARY KEY','UNIQUE')
ORDER BY F.table_name, r.table_name

insert into #cols
select constraint_schema, constraint_name, COLUMN_NAME, ORDINAL_POSITION from INFORMATION_SCHEMA.KEY_COLUMN_USAGE

declare @ctr int, @max int, @delim varchar(1)
select @ctr=1, @max=max(ordinal_position), @delim='' from #cols

set nocount on
while @ctr<=@max
BEGIN

update P SET SQL=Replace(SQL, '>cols<', @delim + quotename(c.column_name) + '>cols<')
FROM #PK P INNER JOIN #cols C ON P.constraint_schema=C.constraint_schema AND P.constraint_name=C.constraint_name
WHERE C.ORDINAL_POSITION=@ctr

UPDATE F SET SQL=Replace(Replace(SQL, '>cols<', @delim + quotename(c.column_name) + '>cols<'), '>rcols<', @delim + quotename(r.column_name) + '>rcols<')
FROM #FK F INNER JOIN #cols C ON F.constraint_schema=C.constraint_schema AND F.constraint_name=C.constraint_name AND C.ordinal_position=@ctr
INNER JOIN #cols R ON F.unique_constraint_schema=R.constraint_schema AND F.unique_constraint_name=R.constraint_name AND C.ordinal_position=R.ordinal_position

select @ctr=@ctr+1, @delim=','
END
set nocount on

update #PK SET SQL=Replace(SQL, '>cols<', '')
update #FK SET SQL=Replace(Replace(SQL, '>cols<', ''), '>rcols<', '')

select sql from #PK order by sql
select sql from #FK order by sql

drop table #pk
drop table #fk
drop table #cols

 

Wednesday, September 24, 2008

Here is an example of Asp.NET Web page - "complete" zip code text box

1) regex for xxx -> ="^(\d{5}|\d{5}\-\d{4})"   

2) zip code text box with

   a) regex  RegularExpressionValidator   

   b) RequiredFieldValidator               

<asp:TextBox ID="txtZip" runat="server" MaxLength="10"  Width="100px" ></asp:TextBox>

                            <asp:RegularExpressionValidator

                                ID="RequiredFieldValidatorZip"

                              ControlToValidate="txtZip"

                              ValidationExpression="^(\d{5}|\d{5}\-\d{4})$"

                              ErrorMessage="Zip code must be numeric nnnnn or nnnnn-nnnn."

                              Display="dynamic"

                              RunAt="server"></asp:RegularExpressionValidator>

                               <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="Zip is a required field!" ControlToValidate="txtZip"></asp:RequiredFieldValidator>

 

Thursday, August 28, 2008

 

Windows XP Backup

http://www.microsoft.com/windowsxp/using/setup/learnmore/bott_03july14.mspx

Wednesday, August 13, 2008

Generic  xmlTextReader
 
Original article:
 
 
                    ////------------------------------------------------------------------
                    ////convert XML string to MemoryStream
                    ////------------------------------------------------------------------
                    MemoryStream memoryStream = new MemoryStream();
                    byte[] data = Encoding.Unicode.GetBytes(strippedXml);
                    memoryStream.Write(data, 0, data.Length);
                    memoryStream.Position = 0;
 
                    ////------------------------------------------------------------------
                    ////convert MemoryStream to xmlTextReader
                    ////------------------------------------------------------------------
                    //XmlTextReader xmlTextReader = new XmlTextReader(Server.MapPath("test.xml"));
                    XmlTextReader xmlTextReader = new XmlTextReader(memoryStream);
 
                    ////------------------------------------------------------------------
                    ////
                    ////------------------------------------------------------------------
                    while (xmlTextReader.Read())
                    {
                        switch (xmlTextReader.NodeType)
                        {
                            case XmlNodeType.Element:
                                Debug.WriteLine(xmlTextReader.Name.ToString());
                                break;
                            case XmlNodeType.Text:
                                Debug.WriteLine(xmlTextReader.Value.ToString());
                                break;
                            case XmlNodeType.EndElement:
                                Debug.WriteLine(xmlTextReader.Name.ToString());
                                break;
                        }
                    }