Posts

Showing posts from April, 2009

Unity - Dependency Injection Types

You can use RegisterType or App.config to achieve the same objectives. static void Main(string[] args) { IUnityContainer container = new UnityContainer(); UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity"); section.Containers.Default.Configure(container); //// You can override with container.RegisterType (); CoreService svc = container.Resolve (); svc.ExecuteService(); } Sample Service classes public class CoreService { [Dependency] public IService MyService { get; set; } public void ExecuteService() { MyService.SayHello("Jeremy"); } } public class CustomerService : IService { string IService.SayHello(string Username) { return "Customer Service " + Username; } } Sample App.Config File <?xml version="1.0" encoding="utf-8" ?> <configuration...
Sample App.Config type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration" />

Passing Parameter from C# to IronPython

Code in Python ///////////////////////////////////////////////// def calc(a, b): return a+b print calc(x,y) ///////////////////////////////////////////////// C# code to pass parameter into the IronPython code ScriptScope ScriptingScope = null; ScriptEngine ScriptingHostingEngine = null; ScriptingHostingEngine = IronPython.Hosting.Python.CreateRuntime().GetEngine("python"); ScriptSource ScriptRequest = ScriptingHostingEngine.CreateScriptSourceFromFile("c:\\del\\expression\\ScriptingTest\\ConsoleApplication1\\Program.py"); ScriptingScope = ScriptingHostingEngine.Runtime.CreateScope(); ScriptingHostingEngine.SetVariable(ScriptingScope, "x", 100); ScriptingHostingEngine.SetVariable(ScriptingScope, "y", 200); ScriptRequest.Execute(ScriptingScope);

Cool way to extract PropertyInfo

var VarPropertyEnum = from ReflectionEntity in Source.GetType().GetProperties()  select new { ReflectionEntity.Name, PropertyValue = ReflectionEntity.GetValue(Source, null).ToString(), PropertyDataType = ReflectionEntity.PropertyType }; However this only works if you have a simple data type.  :(

Cool way to add existing .Net DLL into Silverlight Project

I found this information from this link    http://www.netfxharmonics.com/2008/12/Reusing-NET-Assemblies-in-Silverlight To summarize :- 1. ildasm MyClass.dll /out:MyClass.il Disassemble your code and change the mscorlib version to 2:0:5:0;  .assembly extern mscorlib  {  .publickeytoken = (7C EC 85 D7 BE A7 79 8E ) // .z\V.4..  .ver 2:0:5:0 } }   You also need to change the public token key  7C EC 85 D7 BE A7 79 8E         Then you may need to remove public key from your generated IL file   .publickey = (00 24 00 00 04 80 00 00 94 00 00 00 06 02 00 00   // .$..............                 00 24 00 00 52 53 41 31 00 04 00 00 01 00 01 00   // .$..RSA1........                 B5 FC 90 E7 02 7F 67 87 1E 77 3A 8F DE 89 38 C8   // ......g..w:...8.                 1D D4 02 BA 65 B9 20 1D 60 59 3E 96 C4 92 65 1E   // ....e. .`Y>...e.                 88 9C C1 3F 14 15 EB B5 3F AC 11 31 AE 0B D3 33   // ...?....?..1...3                 C5 EE 60 21 67 2D 97 1...

RodentStore (Phillipe Cudre Mauroux, Eugene Wu and Samuel Madden)

Increase application database domain requires substantial amount of re-engineering effort such as caching or transaction. RodentStore is an adaptive storage engine that uses declarative storage algebra to specify logical schema in a disk. Central to this idea are 1) ability to support table using different physical representation 2) use storage algebra to specify data layout. Database Administrator --------> Algebra sepcification -----> Algebra Interpreter -----> Storage Backend. Interesting part of this artcile is RodentStore is not limited to SQL database but ORM like Django / Ruby on Rails. Physical Layout Challenges faced a) Translating Algebra expression with array completion b) Storage rendering algorithm is 'declarative'. --- leaving many item open for example how data are stored. Deciding what to do when a mix of data placement algorithm for example old and new is used. Adaptive storage engine is going to be an interesting project especially in porting databa...

F# / C# - from Chris Smith's Blog on F# tutorial .....

F# Code #light let square x = x * x let numbers = [1 .. 10] let squares = List.map square numbers printfn "N^2 = %A" squares open System Console.ReadKey( true ) C# Code using System; using System.Linq; class Program { static void Main() { Func square = x => x * x; int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; var squares = numbers.Select(square); Console.WriteLine("N^2 = {0}", squares.Aggregate("", (s, i) => s + " " + i)); Console.ReadKey(true); } }