Friday, 27 February 2009

Windows XP DOS Commands

Command-line reference from TechNet

Popular MS-DOS Commands:
Displays incoming and outgoing network connections; protocol, ip address and port number.
  • telnet.exe
  • ipconfig.exe
  • ping.exe
  • XCOPY
Popular Windows Processes:
  • taskmgr.exe
  • winver.exe
  • shutdown.exe: it shut downs your PC
  • shutdown.exe /r: it restarts your PC
  • cmd.exe
  • calc.exe (note: to open Calculator)
  • dvdplay.exe
  • notepad.exe
  • perfmon.exe (note: to open Performance Monitor tool)
  • appwiz.cpl (note: to open Add/Remove Programs)
  • mstsc.exe -console (opens the Remote Desktop Connection in console mode)
  • Eventvwr.msc (opens the Windows Event Viewer)
  • secpol.msc: it opens the Local Security Settings window where you can specify local or account policies

Tuesday, 24 February 2009

NUnit Test Generators


Shallow Copy vs Deep Copy in .NET

Shallow Copy:

// Creates a shallow copy
public object Clone()
{
return this.MemberwiseClone();
}

Deep Copy:

// Creates a deep copy
public object DeepCopy()
{
MemoryStream stream = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();

formatter.Serialize(stream, this);
stream.Seek(0, SeekOrigin.Begin);

object copy = formatter.Deserialize(stream);
stream.Close();

return copy;
}

http://www.codeproject.com/KB/cs/ShallowVsDeepCopy.aspx


Sunday, 22 February 2009

Refactoring to Patterns

http://www.industriallogic.com/xp/refactoring/catalog.html

Software Development AntiPatterns




Bad Code Smells

"Have a look at this application and identify where we need to / better do refactoring"

Apart from understanding refactoring techniques, understanding code smells help identify where you need to apply the refactoring techniques. Main code smells are given below:
  • Duplicated Code.
  • Long Method.
  • Large Class.
  • Long Parameter List.
  • Divergent Change.
  • Shotgun Surgery.
  • Feature Envy.
  • Data Clumps.
  • Primitive Obsession.
  • Switch Statements.
  • Parallel Inheritance Hierarchies.
  • Lazy Class.
  • Speculative Generality.
  • Temporary Field.
  • Message Chains.
  • Middle Man.
  • Inappropriate Intimacy.
  • Alternative Classes with Different
  • Interfaces.
  • Incomplete Library Class.
  • Data Class.
  • Refused Bequest.
  • Comments.
More info:

Friday, 20 February 2009

Multithreading and Locking in C#

The main purpose of using multithreading in applications is to improve performance.

Process and Thread

  • An application, an executing program, consists of one or more processes.
  • A process, in the simplest terms, is an executing program.
  • One or more threads run in the context of the process
  • Each process is started with a single thread, often called the primary thread, but can create additional threads from any of its threads.
  • The System.Threading namespace contains various types that allow you to create multithreaded applications.
  • The Thread class is perhaps the core type, as it represents a given thread.
  • If you wish to programmatically obtain a reference to the thread currently executing a given member, simply call the static Thread.CurrentThread property.

ThreadPool

The ThreadPool class provides your application with a pool of worker threads that are managed by the system, allowing you to concentrate on application tasks rather than thread management.

  • By default, the limit is 25 worker threads per CPU and 1,000 I/O completion threads.
  • You use the thread pool by calling ThreadPool.QueueUserWorkItem from managed code (or CorQueueUserWorkItem from unmanaged code).
  • There is only one thread pool per process.

Application Domain

  • Application domains, which are represented by AppDomain objects, help provide isolation, unloading, and security boundaries for executing managed code.
  • Multiple application domains can run in a single process
  • Several threads can belong to a single application domain
  • Application domains are created using the CreateDomain method.
  • AppDomain instances are used to load and execute assemblies (Assembly).
  • Threads are free to cross application domain; however, at any given time, a thread executes in a single application domain: AppDomain ad = Thread.GetDomain();

Thread Synchronization:

  • lock{} does the work of Monitor.Enter and Monitor.Exit when we need to lock a section based on an object
  • The object that we want to lock by must be a reference type not a value type. Every object has one field called SyncBlock and only one thread is allowed to own this field. lock keyword works with this field.
  • Don't use Type for your lock; it may cause having deadlocks

More Info

Thursday, 19 February 2009

6 Ways to Instantiate Delegates in C#

A delegate is a reference to a method.

It's sometimes confusing how to instantiate a delegate, so I thought to write this.

There are 6 ways to instantiate a delegate as the following example shows:

Example:

    delegate int MyDelegate(int a,int b);
    public void MyMethod()
    {
      // simply just assign the method name
      MyDelegate myDelegate1 = Add;          

      // instantiate the delegate and pass the method name
      MyDelegate myDelegate2 = new MyDelegate(Add);

      // assign an anonymous method (C# 2.0)
      MyDelegate myDelegate3 = delegate(int a, int b) { return a + b; };

      // assign a lambda expression - format 1 (C# 3.0) 
      MyDelegate myDelegate4 = (int a,int b) => { return a + b;};

      // assign a lambda expression - format 2 (C# 3.0) 
      MyDelegate myDelegate5 = (a,b) => { return a + b; };

      // assign a lambda expression - format 3 (C# 3.0) 
      MyDelegate myDelegate6 = (a, b) => a + b;
    }
    public int Add(int a, int b)
    {
      return a + b;
    }

Notes:
Once you have the delegate instance, you can
  • Run it e.g. myDelegate1(2, 3);
  • Pass the delegate instance to a method
  • Return a delegate instance from a method
More info:

All about NMock

What you can and can't mock?
  • You can create a mock object from an interface or a non-static class
  • You can't create a mock object from a static class
More Info:

Wednesday, 18 February 2009

All about SharePoint

Getting Started:
Development
Screencasts:
E-Books:
Blogs:
Forums:
Best Practices:

Wednesday, 11 February 2009

All about Dependency Injection

Dependency Injection is a technique that relieves us from the pain of static binding and makes the system design decoupled or at least loosely coupled.

In a tightly coupled system, the layers (e.g. UI, BLL and DAL) are dependent on each other. If we change something in one layer, then all the layers need to be recompiled and redeployed.

Why Loosely Coupled?
  • Reuasability
  • Maintainability
  • Scalability
  • Mocking (for testing purposes)

More Info:

Frameworks:

Tuesday, 10 February 2009

NGEN

The Native Image Generator (Ngen.exe) is a tool that improves the performance of managed applications.

Ngen.exe creates native images, which are files containing compiled processor-specific machine code, and installs them into the native image cache on the local computer. The runtime can use native images from the cache instead using the just-in-time (JIT) compiler to compile the original assembly.

USAGE Considerations:
  • Native images load faster than MSIL because they eliminate the need for many startup activities, such as JIT compilation and type-safety verification.
  • Native images require a smaller initial working set because there is no need for the JIT compiler.
  • Native images enable code sharing between processes.
  • Native images require more hard disk space than MSIL assemblies and may require considerable time to generate.
  • Native images must be maintained.
  • Images need to be regenerated when the original assembly or one of its dependencies is serviced.
  • A single assembly may need multiple native images for use in different applications or different scenarios. For example, the configuration information in two applications might result in different binding decisions for the same dependent assembly.
  • Native images must be generated by an administrator; that is, from a Windows account in the Administrators group.
  • Large applications generally benefit from compilation to native images. Small applications generally do not benefit.
  • For long-running applications, run-time JIT compilation performs slightly better than native images. (Hard binding can mitigate this performance difference to some degree.)

Monday, 2 February 2009

Developer Events in London

What?
Why?
  • To meet people, build and maintain network
  • To learn from the events and from other members
  • To have fun in learning