Tuesday, August 16, 2011

Write Some Technique Points I Learned or Touched recently

Framework:

Test Framework:(Web application system)
Selenium/WebDriver
qunit

Mock Framework:
Moq, NMock
Moles

Automation Test:
Pex

Coded UITest, CodedUITest1.cs, UIMap.uitest (XML file), UIMap.Designer.cs, UIMap.cs,

IoC Container:
NInject
Unity

Logging:
Log4Net(partial trust, more efficient)
Enterprise Library(Logging Block, Caching Block) (good configuration tool)

Auth:
OpenAuth, Membership Provider

Data Access:
Entity Framework 4 (CTP 5.0) POCO, DbContext, DbSet


Tools:

WPF:
WPF Performance Suite(installed from Windows SDK7.0/7.1)

WPF tools:
Snoop, Mole

Web Browser Tools:
fiddler, Firbug(FireCookie, FireQuery), IE F12 Developer Tool

Code Tools:
StyleCop
FxCop
(Visual Studio 2010 Uiltimate, Code Analysis)

Documentation:
GhostDoc

ReSharper(5.1/6.0), StyleCorp plugin

Source Control:
MS VSS, IBM Synergy, SVN(TortoiseSVN, AnkhSvN)(SVN, branch, tags, trunk)

Assembly:
Reflector, ILDisambler /Obfuscator

Design Pattern:
Facade
Strategy(IoC)
Repository(CRUD)
Template
Factory
Singleton
Decorator
Proxy

Agile:
iteration
sprint
burn down hours
jira has build in Agile componet

NuGet
IIS Express
WebMatrix
SqlCE

Service:
FaultException (Fiddler)
Service Studio
SoapUI
WCF Web Api

MVC:
Razor

JQuery:

JQuery UI, prototype.js, Widget($.fn),Jquery Templating, JSMin, JsonP(Same Origin Policy)

Configuration:
Web.config: xdt
Code Analysis: CustomDictionary.xml

VSExtensions:
Muse.VSExtension, StyleCop for ReSharper

UI Tools:
Silverlight/ Ajax: SeaDragon Deep Zoom Composer
Silverlight, Easing functions, HtmlBridge/ScriptableMember Attribute/HtmlPage.RegisterScriptableObject,
OOB and Isolated Storage(25M for OOB) and Elevated trust mode, dynamic/AutomationFactory

SiteMinder (CA, Netegrity), WebRequest.CookieContainer pass cookie to create an secure WebRequest

Json Serialization:
System.Web.Extension

Caching:
Serverside Caching
Clientside Caching

WCF 4.0, ServiceHost class,svc -less, skip contract interface


Generic Constraints Situations

Here paste a form:

onstraint

Description

where T: struct

The type argument must be a value type. Any value type except Nullable can be specified.

where T : class

The type argument must be a reference type; this applies also to any class, interface, delegate, or array type.

where T : new()

The type argument must have a public parameterless constructor. When used together with other constraints, the new() constraint must be specified last.

where T : Baseclass

The type argument must be or derive from the specified base class.

where T : Iinterfacename

The type argument must be or implement the specified interface. Multiple interface constraints can be specified. The constraining interface can also be generic.


Let's take the constructor constraints as an example:

where T: new(), this means when we instantiate T, we limit the class constructor doesn't have parameter,

and where T: new(int,string), Then when we instantiate T, we can only write T t=new T(3, "string") like this.

Wednesday, August 10, 2011

WebRequest and WebResponse Examples

As there are lot's of contents to talk about in C# network programming, in this article I am going to talk only a bit on the WebRequest/WebResponse briefly.

In this article I am going to talk about something on WebRequest, WebResponse method. I will talk about the WebRequest Method property to be "GET", "POST", "HEAD" et al to Get or Post a uri or get the Header contents. For the "POST", I am going to write some examples on the context type to be "text/xml" or "application/x-www-form-urlencoded" types. I am also going to write some sample code to talking about create a Webrequest object to call a SiteMinder protected resources.


The simplest example use "GET" method to request a uri:
eg.

var request=WebRequest.Create("http://...");
We can set the request properties, such as:
request.Credentials=CredentialCache.DefaultCredentials;
sometimes need use network credentials:(request.Credentials=new NetworkCredential(UserName, Password))
Sometimes we need to specify the Authentication lvl, such as:
request.AuthenticationLevel=System.Net.Security.AuthenticationLevel.MutualAuthRequested;

For the AuthenticationLevel, it can be None, MutualAuthRequested, MutualAuthRequired. which means no authentication, need client side authentication, and both server and client sides authentication mechanism.




Tuesday, August 2, 2011

Dynamically Create Image and write Text Over it

using System.Drawing;

using System.Drawing.Imaging;

using System.Globalization;

///
/// The program.
///
internal class Program
{

private static void Main(string[] args)

{

var chartWidth = 500;

var chartHeight = 200;

Bitmap bitmap = new Bitmap(chartWidth, chartHeight);

Graphics graphics = Graphics.FromImage(bitmap);

using (Font font = new Font("Arial", 20, FontStyle.Bold))

{

var text = string.Format(CultureInfo.InvariantCulture, "Chart Unavailable");

SizeF size = graphics.MeasureString(text, font);

graphics.DrawString(

text,

font,

Brushes.Black,

(((float)chartWidth / 2) - (size.Width / 2)),

(((float)chartHeight / 2) - (size.Height / 2)));

graphics.Dispose();

}

bitmap.Save("test.png", ImageFormat.Png);
//bitmap.Save(memoryStream, ...)

}

}
}

Create Section in the Configure file and Read Parameters from it

Create section in config file is pretty much like:
< ? xml version="1.0" encoding="utf-8" ?> 
<configuration>
  <configSections>
    <section name="InstrumentationSettings" type="System.Configuration.NameValueFileSectionHandler" />
  < /configSections>
  < ! -- < InstrumentationSettings file="instrumentation.xml"  /> --> 
  <InstrumentationSettings>
    <add key="MachineName" value="EMC01" />
    <add key="UserID" value="03" />
    <add key="CPU" value="2.8G" />
    <add key="Memory" value="2G" />
  < /InstrumentationSettings> configuration>

To Read the information, the code is pretty much like:

using System; using System.Collections.Specialized; 
using System.Configuration;        
internal class Program     
{         
       private static void Main(string[] args)         
      {        
          var instSettings = ConfigurationManager.GetSection("InstrumentationSettings") as NameValueCollection;            
            if (null != instSettings)
            {               
               Console.WriteLine(instSettings["MachineName"]);
            }
        }
}
Similar code like:
                    
 Dictionary< string,string >  instSettingsDict = new Dictionary< string, string >();
            if (null != instSettings)
            {
                for (int i = 0; i < instSettings.Count; i++)
                {
                 instSettingsDict.Add(instSettings.Keys[i], instSettings[instSettings.Keys[i]]);
                }
            }