Mr.Agile's profilesadek's spacePhotosBlogLists Tools Help

Blog


    November 27

    My Blog

    My blog is now on www.sadekdrobi.com
     
    if u want to read more , and to have further examples about the Model View Presenter in asp.net, then keep in touch, promise :)
    November 19

    OBSEV: Model View Presenter w/Command (DataGrid)

    This weekent went fast, i didnt really have time to work on a sample code . Here i post a sketch, a class and a sequence diagram, showing an example of Model View Presenter with a command pattern implementation , for a datagrid.
    The initBinder method on the binderObject subscribes it to the deffirent events of the datagrid.
    then treatement can be added for the deffirent events.
     
    DataBinders with xml mappping can be provided, so that reflexion can be used to map model to the dataVinderObject at run time.
    i promise more explaination about benefits of applying such a pattern, and the more sophisticated Demo.
     
    for now i ll let you view the diagrams, feel free to comment!
    November 16

    REFX : Microsoft Open Specification Promise

    Microsoft irrevocably promises not to assert any Microsoft Necessary Claims against you for making, using, selling, offering for sale, importing or distributing any implementation to the extent it conforms to a Covered Specification (“Covered Implementation”), subject to the following. This is a personal promise directly from Microsoft to you, and you acknowledge as a condition of benefiting from it that no Microsoft rights are received from suppliers, distributors, or otherwise in connection with this promise. If you file, maintain or voluntarily participate in a patent infringement lawsuit against a Microsoft implementation of such Covered Specification, then this personal promise does not apply with respect to any Covered Implementation of the same Covered Specification made or used by you. To clarify, “Microsoft Necessary Claims” are those claims of Microsoft-owned or Microsoft-controlled patents that are necessary to implement only the required portions of the Covered Specification that are described in detail and not merely referenced in such Specification. “Covered Specifications” are listed below.

    This promise is not an assurance either (i) that any of Microsoft’s issued patent claims covers a Covered Implementation or are enforceable or (ii) that a Covered Implementation would not infringe patents or other intellectual property rights of any third party. No other rights except those expressly stated in this promise shall be deemed granted, waived or received by implication, exhaustion, estoppel, or otherwise.

    http://www.microsoft.com/interop/osp/default.mspx

    November 13

    OBSEV :: SOA and Orchestration with .net 3.0's WCF / WF

    I promised Demos for the .net 3.0, and here is my first and simplest J

    Talking SOA, there are several important principles about it, one of them ORCHESTRATION.

    Business Logic is never Logical (martin fowler) , so it could be a good idea to externalize this “logic” and make it so easy to do composing services from lower layers in the application architecture, this way, you offer your client an easy tool, to compose reusable services to form the needed business process.

    That what Orchestration is somehow about, one important standard implementation is BPEL, an XML representation of the services composition, and here were my demo starts.

    .NET 3.0 delivers a very easy SOA platform, Windows Communication Foundation (WCF), that really helps with interoperability , uses AOP so it is quite easy to add behaviors to the offered service, through configuration file, Transactions, Security , Compression …etc , will be translated into soap headers, confirmed to standards, I pretty happy about this platform  .

     

    But I still need human Orchestration tool, and here it comes .net 3.0 with its Windows Workflow Foundation (WF), I am really amazed with how easy to use this tool is, I strongly urge you to replace your workflow , or orchestration tool with it.

     

    My demo that follows illustrates a very simple application, that has two services (WCF), that are composed with WF into a third Service , that is published through asmx webservice J

     

     

    [ServiceContract()]

        public interface ICalculator

        {

            [OperationContract]

            int Sum(int par1,int par2);

     

        }

        [ServiceContract()]

        public interface IBenefitCalculator

        {

            [OperationContract]

            float CalculateRatio(int par);

          

        }

     

        public class Calculator : ICalculator

        {

            public int Sum(int par1,int par2)

            {

                return par1+par2;

            }

     

        }

        public class BenefitCalculator : IBenefitCalculator

        {

            public float CalculateRatio(int par)

            {

                return par*10/100;

            }

     

           

        }

     

    One of the main conceptions behind WCF is the separation between code (that is for programmers) and configuration of behavior (that is for administrators)

    Here all what I did is create two interfaces m and implemented them, all what I had to do in this dll library is add the attribute [ServiceContract()] for the interface and  [OperationContract] for the exposed signature.

    I did another project which is the host for my WCF services, quite simple, a web form that has two buttons, for starting services and stopping them.

    Code for doing this is quite straightforward

    internal static ServiceHost myCalculatorServiceHost = null;

            internal static void StartCalculatorService()

            {

                Uri baseAddress = new Uri("http://localhost:8080/calculator");

                myCalculatorServiceHost = new ServiceHost(typeof(WCFCalculators.Calculator), baseAddress);

                myCalculatorServiceHost.Open();

            }

     

     

    It would be better to keep the service address in the config file, so think about doing it.

    That’s all about code, now we have to define the End Points ABC (Address is already defined in the code, so we still have to define Binding and Contract)

     

    <services>

          <service name="WCFCalculators.Calculator" behaviorConfiguration="MyServiceTypeBehaviors">

            <endpoint contract="WCFCalculators.ICalculator" binding="basicHttpBinding" bindingConfiguration="Binding1" />

          </service>

          <service name="WCFCalculators.BenefitCalculator" behaviorConfiguration="MyServiceTypeBehaviors">

            <endpoint contract="WCFCalculators.IBenefitCalculator" binding="basicHttpBinding" bindingConfiguration="Binding1"  />

          </service>

        </services>

     

    I used basic basic http binding, changing it to secured doesn’t really need a lot to do, just a small configuration change,

    Here is the binding I used

     

     

    <basicHttpBinding>

            <binding name="Binding1"

                     hostNameComparisonMode="StrongWildcard"

                     receiveTimeout="00:10:00"

                     sendTimeout="00:10:00"

                     openTimeout="00:10:00"

                     closeTimeout="00:10:00"

                     maxReceivedMessageSize="65536"

                     maxBufferSize="65536"

                     maxBufferPoolSize="524288"

                     transferMode="Buffered"

                     messageEncoding="Text"

                     textEncoding="utf-8"

                     bypassProxyOnLocal="false"

                     useDefaultWebProxy="true" >

              <security mode="None" />

            </binding>

          </basicHttpBinding>

     

    Now as I have my services ready, my host as well, I go for orchestration, that was the simplest part, I just added a new workflow library, I added WebServiceInputActivity/ WebServiceInputActivity which says that the input to my workflow will be a web service call, I had to set the activating activity to true, to tell the workflow to start on the webservice call,

     Then the composition of the two other services was quite graphic, I didn’t touch to any code, I just had to right click on the workflow project and choose publish as asmx webservice.

    AND THATS ALL!!!

    To run the solution, u should start the host project, start the services, then call the orchestration service.

     I hope this could illustrate a little bit of goodness about .net 3.0 ! i ll try in future demos to involve transaction, thats where fun comes in :D

    ps:forgot to tell that WF xoml is an xml representation of the WF and can be exported as BPEL.

    Source Code in C#

    November 08

    .NET 3.0 is out!!!

    YES! WCF WPF WF !
     
    now we can really start our SOA with WCF, keep tuned for samples ;)

    Generics : Be Carefull OF Overloading, AND dont forget Object Orientation

    I am thankful for Mitsu Furuta's Presentation about generics, and then for his answers to my question in his blog.

    Acutely i am always happy to follow Mitsu's presentation. He is always very accurate, each word he puts on his PPT is important, and has a meaning, a very important one!

    The presentation i am talking about was about C# 2.0 , on of the things he discussed was generics ,and one of the slides had two extremely important sentences : be careful with methods overloads, and dont forget about Object orientation.

     

    Problem:

    Reading this i remembered the issue i got in C# in generic collections. specifically in IDictionary<K,V>, my problems with this class were the following:

    1: Dictionary<K,V> implements IDictionary<K,V> and the non generic IDictionary.

    so u can make something like

     

    IDictionary<int,int> d=new Dictionary<int,int>;

    then cast it like this

    IDictionary d1=(IDictionary)d;

     

    so inserting here any object in the IDictionary will throw a runtime exception, and no copile time check is done! ( see why is it done like this below)

     

    2:using the operator [] on the first instance (the generic one) with a key that doesnt exist will throw an exception, whereas doing the same with the no generic one will just return null!

     

    int i=d1k] throws exception if k doesnt exist

    object o=d1[k]  return null if k doesnt exist

     

    so imagine having IDictionary<object,object> , isnt the signature of the [] operator identical with the one of the non generic IDictionary?

    then i told myself "what a bizarre compiler!".

    so i told my self (whats the! two different behavior for the same method in the same class??? how come!)

     

    Explantation:

     

    in the case number 1, Mitsu cleared it out for me! DONT FORGET OBJECT ORIENTATION! Deferent type of a generic task has nothing in common, they just look the same, but there is no inheritance, no polymorphism, so YES , you need to implement the same interface, to be able to call polymorphically the methods of that interface!

     

    and about the two behavior of the [] operator in IDictionary<k,v> and IDictionary, YES they can have the same signature BUT THIS IS EXPLICITE INHERITANCE!

    explicit inheritance is a feature in C# where u can implement the same method , differently for different classes, by using InterfaceName.Method();

    i didnt know this feature before, the two methods live in different scopes in the class, so there is no overloading.

     

    but anyway, u should be careful about generics, any static field or method is static per closed type and not per generic class.

    and also be careful about overloading, specially after closing the class with the type.

     

    thanks mitsu! :)

     

     

     

     

     

    November 06

    OBSEV: Model View Presenter w/Command (sadek)

    Thinking about Martin’s Article, and the MSDN extension of MVP,I realize the importance of this pattern. I even see that a whole extension framework can be built on this pattern, I will explain more…
    I believe in the dumb view, a view that doesn’t contain any logic, not even data binding.
    Martin’s MVP together with the MSDN’s article answered several questions, and showed ways to keep the view really clean, but we sacrifice ASP.net’s productivity (DataSource xml mappers, binding mechanism…etc )
    But here comes a question, should we really sacrifice all of that? The answer is yes and no!
    In my point of view, yes we should avoid putting logic in the page handler, I know that wizards are easier, but they are not healthier! This binding and mapping mechanism live in the code behind, which is not unit tested, that means a source code that can grow buggy, and yet not covered by the tests.
    But the good news is, No we don’t have to forget about productivity, as long as we are capable of creating our healthy ways to do it.
    In my observation I will try to suggest solutions to these kind of problems, u are free to take it, to like it, or not. Anyway any comment will be helpful to develop the solution.
    My solution is inherited from the Command Pattern (GoF).
    Back to the dumb view, so we move all the logic to the presenter, and we leave the code behind with properties and events, and we subscribe the presenter to these events.
    The DataBinding is done by a command object, actually I am calling it command just to remind that all commands share the same interface, with one method (the Execute() method) and these commands encapsulate  the logic.
    I don’t guess that sticking to the strict definition of the command pattern is important, we can have the Interface having more than one method, the most important thing, is to share the interface with one or more executing methods .
    Following sketch is a class diagram and a sequence diagram that illustrates the interaction between the the page (view) , the presenter, the command and the model.
    The benefits of such a model is to avoid code duplication by providing the data binding  logic , encapsulating it inside  a class, and providing the possibility of implementing an xml mapping to the model (using app.config or even custom configuration files that look like the asp.net DataSource mapping).

    This example is quite simple and straightforward as it is about the simplest databinding (which is to a drop down list)
    Later I will provide another observation , with a more sophisticated example, illustrating more functionalities (update,delete,edit).

    Refx >> Model-View-Presenter for Asp.net

    Martin Fowler talked about the Model-View-Presenter in his blog , then he came back and splitted it into 3 patterns

     Presentation Model, Supervising Controller, Passive View

    the degree od seperation between model, controller and view varies in each of the three.

    I recommend reading Martin's articles about the MVP for deeper understanding of the patterns.

    follows is a REFLECTION, an article in msdn Magazine, implementing the MVP in asp.net, quite interesting, especially on this event based web framework.

    The author chose to present the Model View Presenter using Test Driven Development, pointing it out (MVP) as solution for implementing the TDD approach in asp.net .

     

    http://msdn.microsoft.com/msdnmag/issues/06/08/DesignPatterns/default.aspx

    What is Reflections-Observations

    Reflections-Observations is a website that i am doing, but didnt release it yet.
    What is a Reflection ?
    We are reading ll the time, discovering new things, a reflection is a representation of an article, paragraph, book, video, webcast etc...to point out the key points it has.
    Why Reflection?
    Personally i work in IT field, i read materials, that i feel important.A refletion is a way and a method to share knowledge, then to add my own observation to it.
    Actuelly the idea of the coming web site, is to be a place for people to add their reflections, then others add their observations or comments to it.
    Here i should point out a deffirence, an observations is not a comment.
    an observation adds to the reflection something related to the reflector's knowledge, which means he develops the original idea. Whereas comment is an opinion or a point of view.
    Observation treats the subjects and develops its content.
    For now i am the only Reflector/Observer, but in the website everyone will be.
    I will use conventions in this blog, so i start a reflection text with Refx and the observation with Obsev.Hope you're comfortable with the shortcuts.
    The content will be mostly related to programming/architecture, but that doesnt mean there will be no other.
    Regards
    Sadek Drobi