October 2005 Entries

AOP: A .NET Remoting Version

A while back, Nick posted how you can use the Spring .NET Framework to have Design by Contract with AOP.  I’ve been talking to him about you can do the same thing using a .NET remoting proxy to your object and intercept the calls to your objects.  To do this, I needed three classes: An attribute to initialize the attaching at class level for wiring the AOP guts, a class that wires up the AOP guts and a sink that performs the interception.  This is a modified version of Nick’s code: using System;using System.Reflection;using System.Runtime.Remoting.Activation;using System.Runtime.Remoting.Contexts;using System.Runtime.Remoting.Messaging;namespace Lozanotek{        public interface IEvaluator    {        bool Evaluate(object arg);    }    [AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = true)]    public class PrologAttribute : Attribute    {        private int index;        public IEvaluator evaluator;        public PrologAttribute() { }        public PrologAttribute(int index, Type evalType, params object[] args)        {            this.Index = index;            Object obj = Activator.CreateInstance(evalType, args);            if (obj != null)                this.evaluator = obj as IEvaluator;        }        public IEvaluator Evaluator        {            get { return evaluator; }            set { evaluator = value; }        }        public int Index        {            get { return index; }            set { index = value; }        }        public bool Evaluate(object arg) { return evaluator.Evaluate(arg); }    }    public class StringLengthEvaluator : IEvaluator    {        private int min = 0;        private int max = 0;        public StringLengthEvaluator(int min, int max)        {            this.min = min;            this.max = max;        }        public bool Evaluate(object arg)        {            int len = arg.ToString().Length;            return (len <= max) && (len >= min);        }    }    [AttributeUsage(AttributeTargets.Class)]    public class AOPClassAttribute : Attribute, IContextAttribute    {        public void GetPropertiesForNewContext(IConstructionCallMessage msg)        {            msg.ContextProperties.Add(new AOPProperty());        }        public bool IsContextOK(Context ctx, IConstructionCallMessage msg) { return false; }    }    internal class AOPProperty : IContextProperty, IContributeServerContextSink    {        public AOPProperty() { }        public void Freeze(Context newContext) { }        public bool IsNewContextOK(Context newCtx) { return true; }        public string Name         {            get { return "AOPProperty"; }         }        public IMessageSink GetServerContextSink(IMessageSink nextSink)         {             return new AOPMessageSink(nextSink);         }    }    internal class AOPMessageSink : IMessageSink    {        private IMessageSink next;        public AOPMessageSink(IMessageSink next) { this.next = next; }        public IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink) { return null; }        public IMessageSink NextSink         {             get { return next; }         }        public IMessage SyncProcessMessage(IMessage msg)        {            bool proceed = true;            if (msg is IMethodMessage)            {                proceed = Invoke(msg as IMethodMessage);            }            return (proceed) ? NextSink.SyncProcessMessage(msg) :                new ReturnMessage(null, null, 0, null, (IMethodCallMessage) msg);        }        private bool Invoke(IMethodMessage msg)        {            bool results = true;            MethodBase method = msg.MethodBase;            Type attrType = typeof(PrologAttribute);            PrologAttribute[] prologs = method.GetCustomAttributes(attrType, true) as PrologAttribute[];            if (prologs != null)            {                foreach (PrologAttribute pl in prologs)                {                    if (pl != null)                    {                        IEvaluator eval = pl.Evaluator as IEvaluator;                        if (eval != null)                        {                            object[] args = msg.Args;                            results = eval.Evaluate(args[pl.Index]);                            if (!results) { break; }                        }                    }                }            }            return results;        }    }    [AOPClass]    public class Person : ContextBoundObject    {        [Prolog(0, typeof(StringLengthEvaluator), 0, 5)]        public void SayHello(string name)        {            Console.WriteLine("Hello {0}", name);        }    }    class Program    {        [STAThread]        static void Main(string[] args)        {            Person p = new Person();            p.SayHello("Javier");            p.SayHello("Jav");                        Console.ReadLine();        }    }} If you have any questions or comments, let me...

posted @ Monday, October 31, 2005 10:19 PM | Feedback (639)

Mo' Money, Mo' Money

Nick first showed me this.  But I couldn’t post it due to my little incident. My blog is worth $1,693.62.How much is your blog worth?

posted @ Monday, October 31, 2005 7:34 PM | Feedback (621)

Software Architecture: What's your take on it?

I like software architecture (sa).  Why?  Because it really makes you think about your current problem domain (requirements) and how you should go about solving it through the use of abstractions (models, diagrams, documents, source code, etc.).  When thinking about sa, you should not attach a tool (a language, framework, pattern) to a name (C#, Java, .NET, J2EE, MVC, etc).  Just keep it simple and abstract.  I don’t want to get preachy about it, just sharing my point of view. What got me thinking this way?  Well, it all started with this site.  After getting addicted to the content, I bought this...

posted @ Friday, October 28, 2005 7:00 PM | Feedback (611)

.NET Generics

For those of you out there looking to work/are currently working with generics, check out these articles on MSDN by Juval Lowy.  Pretty good stuff! Generics FAQ: .NET Framework Generics FAQ: Best Practices Generics FAQ: Fundamentals Generics FAQ: Tool Support I’ve only read through the first two.  So far, so good!

posted @ Thursday, October 27, 2005 11:11 PM | Feedback (612)

VS2005 Is RTM!

That’s right, people have been bloggin about it!  VS2005 is now RTM!  If you’re an MSDN subscriber, go get it!

posted @ Thursday, October 27, 2005 10:29 PM | Feedback (611)

Exchange Server Is Back!

Only took two freaking days, but I was able to get my exchange server back and running.  Theoritically it could have taken less, but when you only work on it 2 hours a day … it takes a little longer. And now to the IIS and SQL Server!!

posted @ Thursday, October 27, 2005 10:24 PM | Feedback (611)

Blog Downtime

Me, being the idiot that I am managed to mess up my dc server (and also managed to take out my Exchange Server) along with the blog for two days!  Yay for me!  Fortunately, I was able to get a mock web server up and running for the time being. What’s on my agenda?  Well, build a new dc, install exchange, build a new web server/db server and bring the world back to a happy place. I guess that’s what I get for my stupid a** mistakes.

posted @ Wednesday, October 26, 2005 9:59 PM | Feedback (615)

Revisting With An Old Friend

It has been two years since I’ve done any Scheme.  For those of you that are not familar with Scheme, you can read more about it here.  A great feature of the language is that procedures (functions/methods) are first-class.  This means that procedures can be created dynamically, stored in data structures, returned from other procedures.  If you’re C# inclined, you can do the same thing using anonymous delegates. Any who, here’s some good ol’ Scheme code for the always popular fibonacci function and factorial (recursive of course!): (define fib (lambda (f) (if (eq? f 0) 1 ...

posted @ Thursday, October 20, 2005 9:12 PM | Feedback (625)

Indigo Proxies: Changing Endpoint Metadata At Runtime

During my Indigo talk at the HDC, I was asked about load balancing to another endpoint if your current proxy endpoint is down.  I took a look at this problem during lunch today, and this is what I did to solve it: If you created your proxy using svcutil, you will have a local copy of the service interface. In my second demo, I had the IEightBallService interface under my EightBallProxy.cs file.  The main proxy class, EightBallServiceProxy, inherits from System.ServiceModel.ClientBase<T> and implements the generated IEightBallService interface.  The EightBallServiceProxy class also encapsulates a System.ServiceModel.ChannelFactory<T>.  Which in turn, exposes a ServiceEndpoint through the ChannelFactory<T>.Description.Endpoint property.  So,...

posted @ Tuesday, October 18, 2005 10:15 PM | Feedback (670)

Quick ASP.NET Coding

ScottGu posts a great tutorial on how to use the CreateUserWizard control to create a new user in the new membership subsystem in ASP.NET. Thanks Scott for taking the time to write this great tutorial!

posted @ Tuesday, October 18, 2005 9:19 PM | Feedback (678)

Project Phoenix

Nicholas Wigant pointed me to this little find on next month’s MSDN magazine, Phoenix Rising Phoenix is an extensible framework for the analysis, optimization and modification of code during compilation.  Phoenix will provide a toolkit that will eventually replace the standard compiler back end (c2.exe) as well as the .NET just-in-time (JIT) and pre-JIT (ngen.exe). The main concept behind the Phoenix framework is to take the compile unit and convert it to an internal intermediate representation (IR) using a unit reader.  The framework will supply readers for native code, IL and abstract syntax trees (AST).  From the new IR representation, the program is then...

posted @ Tuesday, October 18, 2005 9:08 PM | Feedback (636)

ASP.NET Provider Model White Papers

For those of you that are ASP.NET 2.0 junkies (myself included), you can check out this white paper describing the layout, usage and development of the new Provider Model model within ASP.NET.  The white paper has 9 sections with this break down: Introduction to the Provider Model Membership Providers Role Providers Site Map Providers Session State Providers Profile Providers Web Event Providers Web Parts Personalization Providers Custom Provider-Based Services Hands-on Custom Providers: The Contoso Times I've yet to look through them all, but from reading the intro, this looks pretty sweet!

posted @ Tuesday, October 18, 2005 7:14 PM | Feedback (612)

Heartland Developer Conference (HDC) Reflections

I know it has been a couple of days since the HDC but I’ve been quite busy since I got home on Friday night, that I haven’t had time to blog about it! First of all, I would like to thank Joe Olsen for letting me speak at this years conference!  It’s cool to feel like *big time* dev from time to time!  (Also, I hope that he lets me speak at next year’s conference in Omaha!) I had a great time handing out with Eric Johnson, Phillip Rieck, Jeff Brand, Matt Milner and the rest of the DSM gang! Second, I would like to...

posted @ Monday, October 17, 2005 10:48 PM | Feedback (617)

IndiPad: My Version

A couple of days ago, Don Box posted about WFPad.  In his post he mentioned that he wanted IndiPad.  Well, after working on for two hours last night, this is my take on IndiPad: This version of IndiPad has limited functionality!!  To open a .config file, you will need to select it’s corresponding assembly.  In other words, if you want to open myclient.exe.config, you need to select myclient.exe in the dialog.  Why?  Well, I’m using the ConfigurationManager.OpenExeConfiguration method to load the .config file into a Configuration object.  This way, I can get the system.serviceModel/services and system.serviceModel/client config sections (Ok, I cheated and disected...

posted @ Monday, October 10, 2005 9:51 PM | Feedback (619)

Generics: Default Values (continued)

Today at work, Seth, one of my friends, was explaining me the default behavior of VB.NET as a response to my previous post.  Apperantly, VB.NET boxes native types automitically for you.  So when you set an Integer to Nothing, it’s all good.  In other words the following code is all good in VB.NET, Dim i As Integer = 10Dim o As Object = io = Nothingi = CInt(o) As expected, this C# code throws a NullPointerException in the unboxing from object to integer, int i = 10;object o = i;o = null;i = (int) o; All I have to say is that VB.NET is messed up.

posted @ Monday, October 10, 2005 8:51 PM | Feedback (628)

.NET Remoting to WCF Migration Post

Matt Tavis posted a pretty good guide for converting your .NET Remoting components to WCF.  Pretty good read!  Quick tally of hands, how many of you out there use .NET Remoting as, well, your remote solution?

posted @ Monday, October 10, 2005 8:08 PM | Feedback (2279)

We've All Been There...

Another great Dilbert treasure,

posted @ Sunday, October 9, 2005 10:46 AM | Feedback (1656)

Generics: Default Values

While working with generics, I’ve realized this about their behavior with default values for types in C# and VB.NET.  For example, if you have the following simple generic method in C#: public static T GetDefault<T>(){    return null;} For those C# inclined, you will notice that this function will not compile. Why? Since the method is generic (and without constraints), the compiler cannot assure the value of null for the type. In other words, the call int i = GetValue<int>(); obviously breaks this assumption. Fortunately, the language offers the default construct that will return, well, the default value for a generic type. In other words, for int it will return 0 and for...

posted @ Thursday, October 6, 2005 10:28 PM | Feedback (628)

ASP.NET 2.0 App Offline Feature

FYI:  If you add a file called app_offline.htm to your web application, ASP.NET will shut down the app domain and redirect all requests to that page!  So, if you’re one of those companies (or work for one) that happens to do big changes to your website during the day, you now have a good way of doing it. Thanks to ScottGu nd Erik Porter for posting this!

posted @ Thursday, October 6, 2005 9:32 PM | Feedback (620)

Charles Petzold Has A Blog!

If you’re serious about Windows development, you must add Charles Petzold’s blog to your reader’s list!!

posted @ Thursday, October 6, 2005 9:19 PM | Feedback (611)

WinFX September Nice-to-knows

[OverDuePost] I should have posted this about a week ago when I first ran into these issues.  If you’re planning on installing WinFX September CTP (beta2), know this: This CTP installs a new version of the framework.  You must first uninstall your current framework version. Due to the new version of the framework, SQL Express doesn’t work. The SDK and VS Extensions only work with beta2 of Studio. As previously posted, your beta1 WinFX code will need to updated to work with beta2.  I got a little ahead of myself when I was installing the CTP and because of it, I had to reformat my laptop.  Hope this helps anyone who’s about...

posted @ Thursday, October 6, 2005 8:37 PM | Feedback (613)

IADNUG: Another Great Presentation

I would like to thank Jeff Brand for taking the time to present at our user group meeting. He always does a great job in engaging the audience in his presentation.  I like to call him “No Fluff, Just Stuff” Brand. Thanks Jeff!

posted @ Thursday, October 6, 2005 8:19 PM | Feedback (633)

Joel Pobar On .NET Languages

Joel Pobar has posted some great information on developing your own .NET languages.  He also posts the source code for his Good for Nothing (GFN) compiler.  He also lists a pretty solid list of .NET books for all to read.

posted @ Tuesday, October 4, 2005 8:36 PM | Feedback (626)

Microsoft Codenames

For you MS heads out there, check out this list of codenames for Microsoft products.  Oh, how I recall playing with Snowball and Janus.

posted @ Tuesday, October 4, 2005 7:44 PM | Feedback (622)

Current Booklist

I’m currently switching my reading time between these three books: Software Factories: Assembling Applications with Patterns, Models, Frameworks, and Tools This is a pretty sweet book because it talks about the current problems in software development and proposes a solution for solving them and automating (industrializing) the software development process.  The authors are key architects for VSTS. Enterprise Services with the .NET Framework : Developing Distributed Business Solutions with .NET Enterprise Services Really good book by Christian Nagel.  He covers all the bases for ES development and is a great read for new to experienced developers.  Currently I’m using this book as a good...

posted @ Monday, October 3, 2005 10:29 PM | Feedback (622)

WCF Clients: Proxy or ChannelFactory?

Michelle Leroux Bustamante (dasBondle), posts a good question:  What’s a WCF best practice, Proxies or ChannelFactory?  If you take a look at her comments, you can read my two cents on the issue.

posted @ Saturday, October 1, 2005 11:19 PM | Feedback (624)

WCF Beta2 Changes

Earlier, I had mentioned that I will blog about the changes for beta2 of WCF.  Well, Omri Gazitt already blogged these evident changes. If any of you have have written any apps with beta1, I recommend you read his post to help you troubleshoot your changes.

posted @ Saturday, October 1, 2005 11:09 PM | Feedback (651)