Object and Collection Initializers (C#)

C# 3.0 was released as a part of the Microsoft .NET 3.5 Framework. In this blog post, I’ll cover the object and collection intitializers feature of C# 3.0. Initializers introduce a concise syntax that combines object creation and initialization in a single step. It even allows for parentheses to be optional for paramaterless constructors as shown below:

 
Point p = new Point {
   X=3,
   Y=99 };
 
Employee myEmployee = new Employee() {
   Name       = "John Doe",
   Position   = "Marketing Manager",
   Department = "Marketing" };
Initializers work very well with constructors as shown below:. The following code snippet shows an instance where a parameterized constructor is called along with remaining properties initialized.
 
class Customer
{
   public Customer(string customerKey) { … }
   public string CustomerKey { get { … } }
   public string ContactName { get; set; }
   public string City { get; set; }
}
 
var c = new Customer("MARKS") {
   ContactName = "Mark Strawmyer",
   City = "Indianapolis"
}

myVSTS October 2009 Technical Talk (Presentation Slides)

Last week myVSTS user group invited Ms. Lai Ee to deliver a talk at the user group. Thanks for those who attended my talk. The following are the details of the talk:

 
Topic:
Improving Software Processes Through Application Lifecycle Management
 
Synopsis:
Microsoft Visual Studio Team System 2008 is a platform for productive, integrated, and extensible software development life-cycle tools. It helps software teams by improving communication and collaboration throughout the software development process. Application Lifecycle Management involves the co-ordination of developmental activities throughout the lifecycle of a project. In a software development project, developmental activities include modeling, code development, build, testing, and so on. This talk provides an overview of how Microsoft Visual Studio Team 2008 facilitates streamlined and efficient development of software in a team environment.
 
Agenda:
06:45pm – 07:00pm Registration
07:00pm – 07:15pm Keynote
07:15pm – 08:15pm Application Lifecycle Management Using Microsoft Visual Studio Team System 2008
08:15pm – 08:30pm Dinner
 
Just managed to snap 1 photo. 🙂 Thanks to Patrick. You may visit the album at: http://cid-d1df34a904545dc5.skydrive.live.com/browse.aspx/.res/d1df34a904545dc5!746?ct=photos
 

Setup a Hidden Camera for Watching a Folder (C#)

Watching activities inside a folder is often a task for application servers. For example, you have an application (APPLICATION1) which needs to wait until another application (APPLICATION2) uploads an XML file into a special folder. Once APPLICATION2 drops the file into the folder, APPLICATION2 does some processing according to the file contents.
 
using System.IO;
 
// Watches the C:\Temp folder and notifies creation of new text files
public static void WatchTempFolder()
{
    // Create the FileSystemoFileSystemWatcher object and set its properties
    FileSystemWatcher oFileSystemWatcher = new FileSystemWatcher();
    oFileSystemWatcher.Path = "C:\\Temp";
    oFileSystemWatcher.NotifyFilter = NotifyFilters.LastAccess
          | NotifyFilters.LastWrite | NotifyFilters.FileName |
            NotifyFilters.DirectoryName;
    oFileSystemWatcher.Filter = "*.txt";
    // Add event handlers.
    oFileSystemWatcher.Created += new FileSystemEventHandler(OnCreated);
    // Begin watching.
    oFileSystemWatcher.EnableRaisingEvents = true;
    // Wait for the user to quit the program.
    Console.WriteLine("Press \’q\’ to quit the sample.");
    while(Console.Read()!=’q’);
}
 
// The event handler
private static void OnCreated(object source, FileSystemEventArgs e)
{
    Console.WriteLine("File: " +  e.FullPath + " " + e.ChangeType);
}

Writing to Windows Event Log (C#)

You have written a server-based application. But as is the case with most servers, it runs in background, either as a Windows Service or may be with a hidden window. Now, how are you going to notify the System Administrator, in case some failures or important events occur? I would recommend that you use the Windows Event log for this purpose.
 
using System.Diagnostics;
 
public void WriteEventLog(string sCallerName, string sLogLine)
{
  if (!System.Diagnostics.EventLog.SourceExists(sCallerName))
    System.Diagnostics.EventLog.CreateEventSource(sCallerName, "Application");
 
  EventLog EventLog1 = new EventLog();
  EventLog1.Source = sCallerName; 
  EventLog1.WriteEntry (sLogLine, EventLogEntryType.Warning);
}
 
Note: Use the relevant EventLogEntryType for your application.

myVSTS October 2009 Technical Talk

myVSTS user group is organizing a technical talk this month. Admission is free. We have invited Ms. Lai Ee to share with us on ways to improve software processes through application lifecycle management. The following are the details of the talk:
 
Topic:
Improving Software Processes Through Application Lifecycle Management
 
Synopsis:
Microsoft Visual Studio Team System 2008 is a platform for productive, integrated, and extensible software development life-cycle tools. It helps software teams by improving communication and collaboration throughout the software development process. Application Lifecycle Management involves the co-ordination of developmental activities throughout the lifecycle of a project. In a software development project, developmental activities include modeling, code development, build, testing, and so on. This talk provides an overview of how Microsoft Visual Studio Team 2008 facilitates streamlined and efficient development of software in a team environment.
 
Agenda:
06:45pm – 07:00pm Registration
07:00pm – 07:15pm Keynote
07:15pm – 08:15pm Application Lifecycle Management Using Microsoft Visual Studio Team System 2008
08:15pm – 08:30pm Dinner
 
Speaker Profile:
Ms. Hen Lai Ee is the Application Lifecycle Management Consultant at K365Labs Sdn Bhd. She owns more than 8 years experience in the IT industry where she obtained professional certifications from Microsoft and Sun. She also accumulates in depth knowledge in Java and .NET technologies such as Java 2 Standard Edition (currently known as Java Standard Edition), Java 2 Enterprise Edition (currently known as Java Enterprise Edition), and also .NET Framework. She is able to describe these technologies to build different kinds of software, including Web-based applications, smart client applications, and XML Web services- components that facilitate integration by sharing data and functionality over a network through standard, platform-independent protocols such as XML (Extensible Markup Language), SOAP, and HTTP. She has published several of his research works in academic journals such as Journal of Computer Science and International Journal of the Computer, the Internet and Management.

Supported Windows Account Types to Run the SQL Server Agent Service

Sometimes, my customers complaint that their SQL Server Agent is not stable. I was really surprised. SQL Server Agent is pretty stable since the earlier versions of SQL Server. SQL Server Agent is a Microsoft SQL Server 2005 component that lets you automate some administrative tasks. SQL Server Agent runs jobs, monitors SQL Server, and processes alerts. Most of the time this is due to service account type that is configured. I thought it would be worthwhile to blog on this. The following are all the supported service account types to run the SQL Server Agent service: 
 
Service account type Nonclustered server Clustered server Domain controller (nonclustered)
Windows domain account (member of the Windows Administrators group) Supported Supported Supported
Windows domain account (nonadministrative) Supported Supported Supported
Network Service account (NT AUTHORITY\NetworkService) Supported Not supported Not supported
Local user account (nonadministrative) Supported Not supported Not applicable
Local System account (NT AUTHORITY\System) Supported Not supported Supported
Local Service account (NT AUTHORITY\LocalService) Not supported Not supported Not supported

myVSTS User Group October 2009 Technical Talk

This month myVSTS user group will be organizing a talk at Microsoft’s office. The following are the details of tha talk:
 
Date:
Thursday, October 22, 2009
Time:
6:45pm – 8:30pm
Location:
Microsoft Auditorium East, Level 29, Tower 2, Petronas Twin Towers, KLCC, 50088 Kuala Lumpur
 
Topic:
Improving Software Processes Through Application Lifecycle Management

Synopsis:
Microsoft Visual Studio Team System 2008 is a platform for productive, integrated, and extensible software development life-cycle tools. It helps software teams by improving communication and collaboration throughout the software development process. Application Lifecycle Management involves the co-ordination of developmental activities throughout the lifecycle of a project. In a software development project, developmental activities include modeling, code development, build, testing, and so on. This talk provides an overview of how Microsoft Visual Studio Team 2008 facilitates streamlined and efficient development of software in a team environment.

Agenda:
06:45pm – 07:00pm Registration
07:00pm – 07:15pm Keynote
07:15pm – 08:15pm Application Lifecycle Management Using Microsoft Visual Studio Team System 2008
08:15pm – 08:30pm Dinner

Upgrade to Microsoft .NET

Today I delivered two sessions at Upgrade to Microsoft .NET. Many people turned up for the event. The event is all about bringing software applications to the .NET level. Keeping up with technology is vital in today’s competitive environment. Business growth is dependent on applications that are secured, robust and scalable. Microsoft .NET and Visual Studio can help you achieve these criteria.

 
Special thanks for those who attended my sessions Migrate from VB6 to VB.NET? Where to start? and Ensuring quality in .NET applications.
 
Migrate from VB6 to VB.NET? Where to start?
Synopsis: This session provides an overview of Code Advisor for Visual Basic 6.0, Visual Basic 6.0 to Visual Basic .NET Upgrade Assessment Tool, and Visual Basic Upgrade Wizard. Code Advisor for Visual Basic 6.0 plugs-in to Visual Basic 6.0 to analyze code and suggest possible improvements. Visual Basic 6.0 to Visual Basic .NET Upgrade Assessment Tool analyzes Visual Basic 6.0 projects to determine what issues that need to be addressed. It also provides information about where to get help understanding each issue and the types of skills needed to address them. Visual Basic Upgrade Wizard upgrades Visual Basic 6.0 projects for further development in Visual Basic .NET. It does not modify the original Visual Basic 6.0 project, but rather creates a new Visual Basic 2008 project based on the original project.
 
Ensuring quality in .NET applications
Synopsis: This session provides an overview of the Web and load test types of Visual Studio Team System Test Edition (VSTSTE). VSTSTE includes a suite of test tools that are integrated closely with Visual Studio; they work not only in their own testing framework, but also within a larger framework of software life cycle tools. VSTSTE lets you create, manage, edit, and run tests, and also obtain and store test results. Several test types, including unit, Web, load, and manual tests, are integrated into Visual Studio. In this session, you’ll learn how to create, edit, run, and view Web and load tests.
 
 

Web and Load Testing with Visual Studio Team System

Today I delivered a talk "Web and Load Testing with Visual Studio Team System" at IGT Sdn Bhd (http://www.igt.com.my/). 14 people attended the talk. Patrick delivered the first session while I delivered the second session. The web test and load test features were initially introduced in Visual Studio 2005, and enhanced in Visual Studio 2008. These tests are available in the Team Test and Team Suite editions of Visual Studio Team System. Web tests enable you to generate http requests and responses, test for correctness of the responses, and measure response times and throughput. The primary scenario for web tests is to use them in a load test to generate load against a web application and measure web application performance. In order to efficiently generate load, Web tests work at the http layer, they do not drive the browser. Load tests enable you to simulate many users hitting using an application at the same time, and then measure server response times, throughput, error rates, and resource utilization on the servers under test. Load tests will help you ensure your applications will stand up under load and deliver acceptable performance. In addition to driving web tests to simulate user activity, load tests can also run “unit” tests under load, which enables you to drive load to any server with a .NET API.

Presentation Slides: http://cid-d1df34a904545dc5.skydrive.live.com/self.aspx/Public/Web%20and%20Load%20Testing%20with%20Visual%20Studio%20Team%20System.pdf