A design pattern can solve many problems by providing a framework for building an application. Design patterns, which make the design process cleaner and more efficient, are especially well-suited for use in C# development because it is an object-oriented language. Existing design patterns make good templates for your objects, allowing you to build software faster. This article describes several popular design patterns you can use in your own applications, including the singleton, the decorator, the composite, and the state classes, which can improve the extensibility of your applications and the reuse of your objects.
Ref:
Microsoft Application Architecture Guide 2.0 eBook -http://www.codeplex.com/AppArchGuide/Release/ProjectReleases.aspx?ReleaseId=20586
Design Patterns: Solidify Your C# Application Architecture with Design Patterns -
http://msdn.microsoft.com/en-us/magazine/cc301852.aspx
Implementing the Singleton Pattern in C# - http://www.yoda.arachsys.com/csharp/singleton.html
Implementing Singleton in C# - http://msdn.microsoft.com/en-us/library/ms998558.aspx
Creational Patterns: Writing Abstract Factory pattern with c# -
http://www.codeproject.com/KB/architecture/Abstract_Factory.aspx
Dofactory - http://www.dofactory.com/Default.aspx
Design Patterns - State Pattern -
http://blog.cumps.be/design-patterns-state-pattern/
Six Design Patterns to Start With - http://codebetter.com/blogs/jeremy.miller/archive/2006/04/11/142665.aspx
The State Pattern: An Underappreciated Pattern -
http://codebetter.com/blogs/jeremy.miller/archive/2006/04/30/143733.aspx
State Machine Design Pattern -
http://dotnet.zcu.cz/NET_2006/Papers_2006/short/B31-full.pdf
Search this Blog:
Design Patterns in C#
When to Use Delegates Instead of Interfaces in C#
Both delegates and interfaces allow a class designer to separate type declarations and implementation. A given interface can be inherited and implemented by any class or struct; a delegate can created for a method on any class, as long as the method fits the method signature for the delegate. An interface reference or a delegate can be used by an object with no knowledge of the class that implements the interface or delegate method.
Delegate approach is very similar to the interface approach. But here the classes are not bound to implement any interface. They only need to have methods which match the delegate signature. Class need not know whom to notify and which methods to call. It just has a set of delegates which it needs to invoke. Hence this removes the tight coupling between the two classes.
Both approaches require an explicit step to integrate the two pieces of code. The fundamental difference between the two approaches is that the delegate-based design requires that explicit step to take place at the point of integration, not at a particular type definition. The delegate-based approach specifically does not assume that the target method will have any awareness of its integration partner, rather, it's just a method that can be called by anyone with sufficient security/access permissions. In contrast, the interface-based approach requires the target method to have an a priori understanding of the integration contract. (by Don Box)
When you implement an interface, and you pass a reference to that interface to someone, you're engaging in a contract which says: whenever you call one of those functions, the same object will handle the call [in different methods]. When you expose a set of delegates, you don't have that guarantee. Calls could be redirected to different objects. This breaks the idea of an interface as a whole contract, switching to a model of methods [delegates, actually] as individual contracts
Use a delegate when:
• An eventing design pattern is used.
• It is desirable to encapsulate a static method.
• The caller has no need access other properties, methods, or interfaces on the object implementing the method.
• Easy composition is desired.
• A class may need more than one implementation of the method.
Use an interface when:
• There are a group of related methods that may be called.
• A class only needs one implementation of the method.
• The class using the interface will want to cast that interface to other interface or class types.
• The method being implemented is linked to the type or identity of the class:
for example, comparison methods.
Ref:
Delegates vs. Interfaces - http://www.devsource.com/c/a/Using-VS/Delegates-vs-Interfaces/
Use of Interfaces and Delegates for an Extensible Design - http://www.codeproject.com/KB/architecture/ClassDesign.aspx
C++ C# Interoperability
Three complementary technologies enable these managed/unmanaged interactions:
1. Platform Invoke (sometimes referred to as P/Invoke) enables calling any function in any unmanaged language as long as its signature is redeclared in managed source code. This is similar to the functionality that was provided by the Declare statement in Visual Basic® 6.0.
2. COM interop enables calling into COM components in any managed language in a manner similar to using normal managed components, and vice versa. COM interop is comprised of core services provided by the CLR, plus some tools and APIs in the System.Runtime.InteropServices namespace.
3. C++ interop (sometimes referred to as It Just Works (IJW)) is a C++-specific feature, which enables flat APIs and COM APIs to be used directly, as they have always been used. This is more powerful than COM interop, but it requires much more care. Make sure that you check the C++ resources before you use this technology.
Ref:
.NET to C++ Bridge -
http://blogs.microsoft.co.il/blogs/sasha/archive/2008/02/16/net-to-c-bridge.aspx
Interoperability Mini-Guide -
http://tssblog.techtarget.com/index.php/interviews/interoperability-bridging-net-and-java/
Calling Win32 DLLs in C# with P/Invoke -
http://msdn2.microsoft.com/en-us/magazine/cc164123.aspx
P/Invoke Revisited - http://msdn2.microsoft.com/en-us/magazine/cc163910.aspx
Is PInvoke dead - http://weblogs.asp.net/kennykerr/archive/2005/06/20/Is-P_2F00_Invoke-Dead_3F00_.aspx
An Overview of Managed/Unmanaged Code Interoperability -
http://msdn2.microsoft.com/en-us/library/ms973872.aspx
Chris Green's Unix/Windows and .Net/Java Interoperability Blog - http://blogs.msdn.com/chris.green/
Design Guidelines, Managed code and the .NET Framework - http://blogs.msdn.com/brada/articles/361363.aspx
C++ to C# comparisionhttp://esersahin.wordpress.com/2008/11/13/c-quick-equivalents/
Thread Synchronization (C# Programming Guide) - http://msdn.microsoft.com/en-us/library/ms173179.aspx
C# Observer Pattern (using Delegates & Events) - http://msdn.microsoft.com/en-us/library/ms954621.aspx
Msdn Delegates - http://msdn.microsoft.com/en-us/magazine/cc159272.aspx
Events and Delegates - http://msdn.microsoft.com/en-us/library/17sde2xt(VS.71).aspx
Raising multiple events - http://msdn.microsoft.com/en-us/library/0sx1bz6x(VS.71).aspx
Popular Soap Engines
Axis (stands for the Apache eXtensible Interaction System) provides transparent access to web services for Java programmers. This allows Java programmers to focus on the business logic of their applications rather than worry low-level network protocols (like SOAP) in order to use a web service.
Apache Axis2 is the core engine for Web services. It is a complete re-design and re-write of the widely used Apache Axis SOAP stack, built on the lessons learnt from Apache Axis.
Apache Axis2 not only supports SOAP 1.1 and SOAP 1.2, but it also has integrated support for the widely popular REST style of Web services . The same business logic implementation can offer both a WS-* style interface as well as a REST/POX style interface simultaneously.
Apache Axis2 is built on Apache AXIOM , a new high performant, pull-based XML object model. Axis2 has support for Spring Framework.
gSoap:
gSOAP is a cross-platform development toolkit for C and C++ SOAP XML Web services (SOAP1.1/1.2,WSDL1.1). gSOAP supports XML serialization of native C/C++ data types. Includes SOAP/XML engine, Web server, stub/skeleton compiler, WSDL tools, and much more.
The gSOAP tools provide a SOAP/XML-to-C/C++ language binding to ease the development of SOAP/XML Web services and client application in C and C++. Most toolkits for C++ Web services adopt a SOAP-centric view and offer APIs that require the use of class libraries for SOAP-specific data structures. This often forces a user to adapt the application logic to these libraries. In contrast, gSOAP provides a C/C++ transparent SOAP API through the use of compiler technology that hides irrelevant SOAP-specific details from the user.
The gSOAP stub and skeleton compiler automatically maps native and user-defined C and C++ data types to semantically equivalent XML data types and vice-versa. As a result, full SOAP interoperability is achieved with a simple API relieving the user from the burden of SOAP details, thus enabling him or her to concentrate on the application-essential logic.
Apache Axis2/C: Axis2/C is a Web services engine implemented in the C programming language. It is based on the extensible and flexible Axis2 architecture. Apache Axis2/C can be used to provide and consume WebServices. It has been implemented with portability and ability to embed in mind, hence could be used as a Web services enabler in other software.
Apache Axis2/C supports SOAP 1.1 and SOAP 1.2, as well as REST style of Webservices. A single service could be exposed both as a SOAP style as well as a REST style service simultaneously. It also has built in MTOM support, that can be used to exchange binary data.
Apache Axis C++: Axis C/C++ (Axis CPP) is a non-Java implementation of Axis. At its core Axis CPP has a C++ runtime engine. The provided tooling allows you to create C++ client-side stubs and server-side skeletons. The server skeletons can be deployed to either a full Apache web server using the supplied apache module or a "simple_axis_server" - which is a simple HTTP listener (designed to help you test your services).
There is also limited support for C wrappers around the generated Server and client objects. However, at the current time it is not recommended that these be used in a production environment.
Systinet WASP: Systinet WASP is a platform-independent, standards-compliant set of infrastructure products for building Web services applications in Java and C/C++. WASP also includes the industry's most advanced UDDI registry for companies that need to organize, discover, reuse and manage Web services
SOAPLite:
SOAP::Lite is a collection of Perl modules that provides a simple and lightweight implementation of SOAP, XML-RPC, UDDI and other webservice-related specifications.
PocketSoap:
This is an Open Source [MPL] SOAP client COM component for the Windows family, originally targeted at PocketPC (hence the name), there is also a Win32 version that works on Windows 95/98/Me/NT4/2000/XP/2003. The package includes a HTTP 1.1 transport for making HTTP based SOAP requests, however the transport is separate from the main SOAP core, so any other transports can be easily added. James Clark's excellent Expat XML Parser is used for parsing the response SOAP messages.
.NET Remoting Vs. Web Services – What To Choose?
While developing distributed applications, developers are often faced with the question of whether to choose Remoting or Web Services as the preferred choice. The answer to this question depends on certain factors that are specific to the application and the distributed data transfer strategy being followed. Let’s discuss each of the factors one by one
Security
Security is a major factor to consider while developing distributed applications. As both Web services and .Net Remoting architecture depend on the IIS security features, there is nothing much to choose between the two based on this factor. If, however, IIS is not being used as a host, Remoting is the only option left.
Communication Mode/ Protocol
If the application is to be used by customers on a LAN/WAN, using Remoting with TCP and binary formatters will be a better option as it does not play with data (no need of formatting or data packaging as in SOAP).
If TCP is the protocol being used for communication, using web services is again out of question.
Data Volume
If the amount of data being transferred is huge, using web services will deplete performance. Web services require transformation and serialization of data and this will result in terrible application performance.
Platform/ Interoperability
If both the client and server are using .NET Runtime for execution, remoting will be the best choice as it can utilize the strongly typed data for communication at both ends.
Web Services on the other hand is an easy picking when either client or server or both are running on some platform other than .NET.
State Management
Web Services are inherently stateless and they never correlate multiple calls from the same user unless session management is explicitly enabled in the Web Service. IF enabled, they provide state management using the inherent ASP.NET state management capabilities.
In Remoting, however, you can perform state management in the following ways:
Stateless Objects: Use .NET remoting with Server Activated Single Call objects
Stateful Objects (Per Application): Use .NET remoting with Server Activated Singleton objects.
Stateful Objects (Per Client): Use .NET remoting with Client-Activated Objects
Flexibility/ Scalability
Web Services work through firewalls and other network security as it uses HTTP and XML for packaging and transporting data. Remoting on the other hand cannot provide such flexibility but in the case of using HTTP with SOAP which diminishes the performance of the application.
Web Services are also much more scalable than remoting as they support many platforms and can be used in applications that are not dependent on .NET Runtime.
Performance
.NET remoting provides the best performance when using Binary formatters and TCP protocol. In effect, the different combinations of protocols and formatting provide different performance levels for web services and remoting. Here is the table that lists them.
How To Check .Net Framework Version Installed ???
How To Check .Net Framework Version Installed ???
1. Query the UserAgent string of Internet Explorer web browser. This is the easier way, I think, as every Windows bundled with IE!
Although you need to remember this simple, one line JavaScript:
javascript:alert(navigator.userAgent)
Copy and paste that line of JavaScript code to IE Address bar and press ENTER key, you will see a pop-up dialog box with .NET version installed.
2. Navigate to this Windows Registry path
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP
The major version number of each .Net framework releases installed can be found at this Registry path. Click the major version number key and there is a string value called “version” on the right-pane that reports the full version number of that .Net framework.
3.Navigate to the Registry path that keeps the IE User Agent String:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\5.0\User Agent\Post Platform
4.C:\WINNT\Microsoft.NET\Framework /C:\Windows\Microsoft.NET\Framework
directory will have the directories for the version you have installed on your machine.
To be generic , C:\%windir%\Microsoft.NET\Framework will have the directories for the version you have installed on your machine.
5. Query GetCORSystemDirectory Function() API of MsCorEE.dll regarding the the install directory for the version of the runtime that is loaded in the current process.
Sample Code:
[C#]
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
[DllImport("mscoree.dll")]
// Declaration
internal static extern void GetCORSystemDirectory([MarshalAs(UnmanagedType.LPTStr)]
System.Text.StringBuilder Buffer,
int BufferLength, ref int Length);
// Gets the path to the Framework directory.
System.Text.StringBuilder sb = new System.Text.StringBuilder(1024);
int size;
// returned value in size can be ignored
GetCORSystemDirectory(sb, sb.Capacity, ref size);
...
...
...
Ref:
http://www.walkernews.net/2008/05/16/how-to-check-net-framework-version-installed/
http://blogs.msdn.com/astebner/archive/2004/09/14/229802.aspx
Delegates and Events (C#)
A delegate is a type that references a method. Once a delegate is assigned a method, it behaves exactly like that method. The delegate method can be used like any other method, with parameters and a return value.
Delegates have two main usages in C# programming -
1. callbacks
2. event handling
3. asynchronous method calls
5. Win32 callbacks (from Unmanaged Code)
A delegate in C# is similar to a function pointer in C or C++. It's equivalent of C/C++ callback mechanism.This feature uses Pointers to Functions to pass them as parameters to other functions.Using a delegate allows the programmer to encapsulate a reference to a method inside a delegate object. The delegate object can then be passed to code which can call the referenced method, without having to know at compile time which method will be invoked
Events are the actions of the system on user manipulations (e.g. mouse clicks, key press, timer etc.) or any event triggered by the program.Events enable a class or object to notify other classes or objects when something of interest occurs. The class that sends (or raises) the event is called the publisher and the classes that receive (or handle) the event are called subscribers.
Ref:
Delegates and Events - http://www.csharp-station.com/tutorials/lesson14.aspx
Working with Delegates in C# - http://www.devsource.com/c/a/Languages/Working-with-Delegates-in-C/
Delegates And Events - The Uncensored Story - Part 1 : http://www.codeproject.com/KB/cs/delegates-part1.aspx
Delegates and Event Handlers - http://www.brainbell.com/tutors/C_Sharp/Delegates_and_Event_Handlers.htm
C++ -> C#: What You Need to Know to Move from C++ to C# -
http://msdn.microsoft.com/en-us/magazine/cc301520.aspx
http://www.akadia.com/services/dotnet_delegates_and_events.html
http://www.codersource.net/csharp_delegates_events.html
http://www.codeguru.com/csharp/csharp/cs_delegates/eventhandling/article.php/c4769
http://www.jot.fm/issues/issue_2004_05/column8.pdf
http://en.csharp-online.net/CSharp_Delegates_and_Events