Posts

Exception Do and Don'ts

From Microsoft MSDN. 1.Do not return error codes. Exceptions are the primary means of reporting errors in frameworks. 2.Do report execution failures by throwing exceptions. Consider terminating the process by calling System.Environment.FailFast. Do not use exceptions for normal flow of control, if possible. Except for system failures and operations with potential race conditions 3. onsider the performance implications of throwing exceptions. 4.Consider using exception builder methods. It is common to throw the same exception from different places. To avoid code bloat, use helper methods that create exceptions and initialize their properties. 5.Do not throw exceptions from exception filter blocks. If you're C# programmer ; you can ignore this. 6.Avoid explicitly throwing exceptions from finally blocks. Implicitly thrown exceptions resulting from calling methods that throw are acceptable.

Example Microsoft Unity Block Configuration : Passing Value to Constructor

This is a sample of our configuration file that allows us to initialize value to our constructor. /// Our Constructor //// [InjectionConstructor] public MyClass(string myParam, string myParam2) { string p1 = myParam; string p2 = myParam2; }

Example : Using Microsoft Unity Block from Configuration File

/// Client code /// using Microsoft.Practices.Unity.Configuration; using System.Configuration; using Microsoft.Practices.Unity; namespace unityman { class Program { static void Main(string[] args) { IUnityContainer mycontainer = new UnityContainer(); UnityConfigurationSection config = (UnityConfigurationSection)ConfigurationManager.GetSection("unity"); config.Containers.Default.Configure(mycontainer); MyInterface proxy = mycontainer.Resolve (); proxy.SayHello(); } } } ////// App.config Configuration File //// Optionally you can change MyClass from FriendClass to see it's effects. //// MyInterface, MyClass and FriendClass codes using System; using System.Collections.Generic; using System.Text; using Microsoft.Practices.Unity; namespace myunityclass { public class MyClass : MyInterface { public MyClass(MyParam myParam) { myParam.UserAddress = "1111"; ...

FFMpeg on MSVC++

Instead of building FFMPEG using Cygwin and Msys you can get the libraries from here . Next goto you need to extract this into a folder. Once you have extracted you need to create a simple Win32 console application in Visual Studio and configure its properties. Under Configuration Properties C/C++->Additional Include Directories = C:\del\ffmpeg\include\libavcodec;C:\del\ffmpeg\include\libavutil;C:\del\ffmpeg\include\libavformat; C:\del\ffmpeg\include\libswscale Linker->General->Additional Libraries Directory = C:\del\ffmpeg\lib Linker->Input->swscale-0.lib avdevice-52.lib avformat-52.lib avcodec-51.lib avutil-49.lib To test your project out, use to following codes and see if you can compile it . extern "C" { #include #include #include #include } int _tmain(int argc, _TCHAR* argv[]) { //// Just to load the codes /// av_register_all(); } Next please make sure you copy the required *.dll (from the distribution above) to your project folder...

ILCode for newobj by creating a new custom Type

AssemblyName _assemblyName = new AssemblyName(); _assemblyName.Name = "newObj"; AssemblyBuilder _assemblyBuilder = Thread.GetDomain().DefineDynamicAssembly(_assemblyName, AssemblyBuilderAccess.RunAndSave); ModuleBuilder _modBuilder = _assemblyBuilder.DefineDynamicModule(_assemblyName.Name + ".exe"); TypeBuilder _typeBuilder = _modBuilder.DefineType(" ILCode.Program"); TypeBuilder _customType = _modBuilder.DefineType("ILCode.myCustomType", TypeAttributes.Public); Type[] arg = { typeof(string) }; ConstructorBuilder _customTypeConstructor = _customType.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, arg); PropertyBuilder _prop1 = _customType.DefineProperty("MyId", PropertyAttributes.None, typeof(int), new Type[0]); PropertyBuilder _prop2 = _customType.DefineProperty("MyName", PropertyAttributes.None,...

MSIL Hello World

AssemblyName _assemblyName = new AssemblyName(); _assemblyName.Name = "helloWorld"; AssemblyBuilder _assemblyBuilder = Thread.GetDomain().DefineDynamicAssembly(_assemblyName, AssemblyBuilderAccess.RunAndSave); ModuleBuilder _modBuilder = _assemblyBuilder.DefineDynamicModule(_assemblyName.Name+ ".exe"); TypeBuilder _typeBuilder = _modBuilder.DefineType("Foo"); MethodBuilder _methodBuilder = _typeBuilder.DefineMethod("Main", MethodAttributes.Static, typeof(void), System.Type.EmptyTypes); ILGenerator _il = _methodBuilder.GetILGenerator(); _il.EmitWriteLine("hello World "); _il.Emit(OpCodes.Ret); _typeBuilder.CreateType(); _modBuilder.CreateGlobalFunctions(); _assemblyBuilder.SetEntryPoint(_methodBuilder, PEFileKinds.ConsoleApplication); _assemblyBuilder.Save(_assemblyName.Name + ".exe"); _il = null;

MSIL IF Statement

This example shows you how to generate IL for a simple IF statement Code in C# int x = 1000; if (x > 2000) Console.WriteLine("Hey There"); Using Reflection Emit AssemblyName _assemblyName = new AssemblyName(); _assemblyName.Name = "ifS"; AssemblyBuilder _assemblyBuilder = Thread.GetDomain().DefineDynamicAssembly(_assemblyName, AssemblyBuilderAccess.RunAndSave); ModuleBuilder _modBuilder = _assemblyBuilder.DefineDynamicModule(_assemblyName.Name + ".exe", true); TypeBuilder _typeBuilder = _modBuilder.DefineType("IfType"); MethodBuilder _methodBuilder = _typeBuilder.DefineMethod("Main", MethodAttributes.Static, typeof(void), System.Type.EmptyTypes); ILGenerator _il = _methodBuilder.GetILGenerator(); LocalBuilder _intName = _il.DeclareLocal(typeof(int)); Label body = _il.DefineLabel(); _il.Emit(OpCodes.Ldc_I4, 1000); _il.Emit(OpCodes.Stloc_0); _il.Emit(OpCodes.Ldloc_0); _il.Emit(OpCodes.Ld...

anonymous delegate class object

////////////////////////////////////////////////////////// The code example below show you how to use anonymous delegate ////////////////////////////////////////////////////////// using System; using System.Collections.Generic; using System.Text; namespace YummyYummy { class Program { static void Main(string[] args) { doStuff(); } private static void doStuff() { List _list = new List (); List _subList; _list.Add(addClientInfo("AAA", "1111")); _list.Add(addClientInfo("BBB", "2222")); _list.Add(addClientInfo("CCC", "3333")); _list.Add(addClientInfo("AAA", "4444")); string _targetSearchString = "AAA"; ClientSessionEntity _client = _list.Find(delegate(ClientSessionEntity _entityA) { return _entityA.transaction...

Newline in Flex

I just can't get this up my head. In order to use newline in Flex i just have to use "\r" this symbol. Gosh!!

Flex and Javascript - ExternalInterface

The best article i read about Flash and javascript interaction can be found here .

Manipulating ArrayCollection

Manipulating Flex ArrayCollection This shows you how to manipulate flex data structure called ArrayCollection. Assuming that you have the following data [Bindable] private var medalsAC:ArrayCollection = new ArrayCollection( [ { Country: "USA", Gold: 35, Silver:39, Bronze: 29 }, { Country: "China", Gold: 32, Silver:17, Bronze: 14 }, { Country: "Russia", Gold: 27, Silver:27, Bronze: 38 } ]); To retrieve let say Russia record, you can do the following /// get the Rusia Info ///// var _target:Object = medalsAC.getItemAt(2); To change its value, use the following codes ///// set the Rusia Info ///// _target["Gold"] = 50; medalsAC.setItemAt(_target, 2); If you want to add a new country let say Cz...

Self Signing Certificate for IIS

Create a self signing certificate for IIS VS2005 provides tools to do this which is called makecert and pvk2pfx. First all you need to do is run the following batch file and specify a name for it. For example yourBatchFile.bat testCert The content of batch file is as follows makecert -r -pe -n "CN=testCert" -sky exchange -sv %1.pvk %1.cer pvk2pfx -pvk %1.pvk -spc %1.cer -pfx %1.pfx Once you have this installed, please goto Start->Run->MMC->File->Add SnapIn->Add->Certificates A wizard will appear asking you the scope of your certificates. Choose Computer account and Finish. Select Local Computer and again click Finish. Click Close and then OK. This will bring you to a Certificates Console . Expand Personal -> Certificates, right click and select Import . The wizard will prompt you for the certificate that you have generate earlier. Provide the test.pfx. When ask for password click Next, Next and Finish . You need to repeat the same process for Trusted Ro...

Document

Start from the top Page DocTypes Setting your page rendering mode. What is the use of docTypes? It basically tells the browser which version of html that will be used to render your page. There are many variation which includes a) strict b) loose c) frameset d) xhtml1-strict e) xhtml1-transitional.dtd f) xhtml1-frameset.dtd g) declaration for html 3.2 and 2.0 http://htmlhelp.com/tools/validator/doctype.html Determine your page Layout. It is crucial to determine your page layout first and then test it with different browser to see if the positioning is correctly done. Use minimal Table in your page More Div + CSS There should be only one level table in your page. Putting two level of table is something you might need to consider twice. For positioning, formatting that the job of CSS Follow the XHTML convention and apply the final touches to it by using WC3 Validator service http://validator.w3.org/ CSS should be used to align your text, phase out the use of spacer gifs and Make your pag...

BizTalk notes

To quick (close to useless) guide to create biz transformation solution in BizTalk Server. Define Schema ---> Define Messages --> Map Message to Schema --> Perform Message Transformation and operations ---> Setup your project file --> Create your snk ---> Deploy from V Studio --> Configure your project accordingly in BizTalk *Create all your schema and messages first* Things can get easier.

Flex 2 Events

I found a great blog where you can get information on how to create Flex 2 custom events . Its better than going through pages of documentation.

Custom Server Controls Vs Entirely Custom Controls

Sometimes you find yourself writing custom controls which uses server control provided by Microsoft. These controls include TextBox, GridView and Button. With these control you don't have to implement IPostBackDataHandler (unless you're doing something customization) as you can wire the event shown here. protected override void CreateChildControls() { base.CreateChildControls(); _txtBox = new TextBox(); this.Controls.Add(_txtBox); _txtBox.Text = _defaultText; System.Web.UI.WebControls.Button _txtBtn = new Button(); this.Controls.Add(_txtBtn); _txtBtn.Click += new EventHandler(_txtBtn_Click); _txtBtn.Text = _cmdText; } void _txtBtn_Click(object sender, EventArgs e) { ////// triggerring take place here ///////// } If you need to customized your control above to implement IPostBackDataHandler for your custom server control, then just r...

Interesting WPF Tools

Found some interesting WPF Tools a) swfToXAML b) MayaToXAML c) LightWavetoXAML d) Adobe Illustrator to XAML Some really interesting stuff is going on.......

WebPart - UserControl Loaded Multiple Times and GridView Event not Triggerd

Creating user control declaratively in your WebPart won't give your alot of problem. But when you try to load pro grammatically a user control (ascx) into your webparts using something like this:- Your WebPartPage Control uc = this.LoadControl(@"webparts\CompanyNews.ascx"); uc.ID = "webPartyMan"; GenericWebPart wp2 = wp.CreateWebPart(uc); wp.AddWebPart(wp2, LeftZone, 1); You found that you loaded it multiple times and somethings GridView events are not triggered. What the trick? You only load your ascx once (you won't load it ever again) and right after you dynamically load it call SetPersonalizationDirty(); This is done using your custom WebPartManager; This is a very simplified version of your custom webPartManager (loadPersonalizationBlob and savePersonalizationBlob) namespace CoreWebPart { public class myWebPartManager : WebPartManager { public void SetDirty() { SetPersonalizationDirty(); } } } ///// end nam...