February 2008 - Posts

From MDC to EDC

In 2003, Microsoft Egypt started a public technical event called Middleeast Developers Conference (MDC). MDC was an annual event usually held by the end of January or beginning of February, lasting for 4 full days, day zero with local speakers talking about most recent Microsoft technologies, and day 1 to 3 with international speakers showing the latest previews of pre-release Microsoft technologies and development related products. It was honored by the presence of Bill Gates for the keynote in 2004 and 2005.

For long, it has been the only public event related to Microsoft technologies (besides the product launches of course). The attendees counted in thousands when there was even no active user groups in Egypt or individuals holding their own technical events. Even later with the presence of other one-day events, MDC was still the biggest technical event ever that most Egyptian developers working with .NET technologies wait all the year (even with critic that the last 2 rounds had about turning from pre-release previews to sometimes 1-year old repeated sessions!).

Later, other countries in the Middleeast thought they should make their own version of the ~DC events - GDC (Gulf Developers Conference), and JDC (Jordan Developers Conference). It was a little bit weird in the last round of the conference to have a "Middleeast" conference while it's not exactly meant to target the entire "Middleeast", so, by the end of MDC 2007, Microsoft Egypt announced that the next round of their conference will not hold the name "Middleeast" in it, but "Egypt" instead. The conference starting 2008 is renamed to be "Egyptian Developers Conference", EDC.

The Timing, Registration, etc

As mentioned before, conference is usually held around the beginning of February. This year, mid-February has passed without even announcing the schedule of the event this year or whether it was even totally canceled. The rumors went saying that it'll be by the time of VS2008/SQL2008/WIN2008 launch events and merged with that (which start in the beginning of March, but until today, I have no idea whether we'll even have the launch separate event in Egypt or no. Most likely that's merged!!

Yesterday, Sherif El-Touny from Microsoft Egypt announced that:

The EDC starts April 13 to April 15, 2008
In international City Stars Hotel

If you know the location, you might be guessing that Microsoft is expecting much less attendees this year!, and it'll more suggest that it's merged with the launch event!

 

That was announced on a facebook group Sherif created for following the news of the event, which is kind of him given the confusion caused by passing the usual time of the event without any public statement about its schedule (at that time).

There's no announced registration website so far. The only public semi-official channel to get the  event news is via the facebook group, which is located at: http://www.facebook.com/group.php?gid=7828778398

Yes, of course I'll be blogging about any further updates once I get any!

Note on previous MDC sessions

For more information on previous MDC turns, and coverage of some of its sessions, you can refer to my "Local Events" blog posts located in my old blog.

 

 Today is my 22nd birthday. Since yesterday, I have been feeling like a celebrity :) :). I could no longer count the wall posts about it. All the great people to thank :).

Also, I knew the habit in SilverKey is having a great birthday party for each and every one of us. Today was even more special than my previous one! More than 20 guys and gals around me with very large amount of sweat cakes. We had nice photos (that will take my dear colleagues months to put on facebook of course, LOL). We had really fun. It was the first day for our new colleague, Amr, who seems to be an interesting guy really.

 So, to all the guys in SilverKey (Egypt and Azerbaijan), and all my friends on facebook whether technical guys and ex-work mates, concert/reading friends, or , great performer. I'm not sure what word can be enough to thank you all. Thanks a million, a billion, for giving me that funny celebrity feeling :D

 

The Problem

In an N-tier application, you keep your logic in a business logic tier, typically a different VS project that can be used from a website, a windows service, or desktop application, and that should be valid to writ unit tests against on its own.

But how about if your requirements say that you need to to upload some file for the business logic to work? Think of a scanned image (signed contract maybe?) or just a comma separated value file containing some emails.  Typically the business logic tier will be the place to to handle this, but how can you send the uploaded file to it? You can get the file as "HttpPostedFile" from the "Request.Files" collection or the file upload control itself, but, to receive it in the business logic, project, the easiest way is to add reference to "System.Web" dll and accept the type "HttpPostedFile" as method argument or so, and when in need to save the file physically, you call the "SaveAs" method of "HttpPostedFile" ... So simple right ?

But how about unit testing? "HttpPostedFile" has no public constructor and is sealed class (you cannot inherit from). How will you write a unit test for a method that accepts "HttpPostedFile" as argument to work? You'd go finding a way to mock that or just forget about testing that particular method!!

The Simple Solution

Well, it's more simple than you think. An "HttpPostedFile" has a property called "InputStream", which is of type "System.IO.Stream". Hey, that has nothing to do with "system.Web" :). You can create your own FileStream or whatever other stream in the unit test, and then only worry about other areas you want to test related to the method in your business logic.

Because I know dealing with streams is quite ugly (at least it is to me!), I wrote an example that will walk you though a sample usage of that property. I have the complete example VS solution as attached file at the end of the example code below.

Example


The Business Logic

In a real world example, the business class will have various parameters including the file, but in this example, I have made my business class (I call it "FileLogic") just worry about the file. It has a method that treats the stream coming to it as containing just text, reads that text and returns it. Note the type of the only method parameter

/// <summary>
/// This is the simplest method ever. Read the stream whether from web upload or whatever
/// As the name implies, it treats the stream contents as text.
/// </summary>
public string ReadTextFile(Stream inputStream)
{
    using (var reaader = new System.IO.StreamReader(inputStream))
    {
        return reaader.ReadToEnd();
    }
}

Another example of a method in the business logic project is one that actually saves the file. Instead of just calling "SaveAs(filepath)", you need to copy the stream yourself. Usually there's more than one way to do so, the problem in most of the ways is determining the size of the stream. An "HttpPostedFile" knows the size of the file, but as I'm not getting the "HttpPostedFile" (and it wouldn't sound great if I requested the file size as a method parameter!), I dealt as if I do not know the actual file size. See the code for this method:

/// <summary>
/// Writes the stream context that comes to it whether from web or whatever!
///     and saves it to the path set by property called "SavingPath"
/// 
/// I meant to not make the save path a method property because 
///     in real situation that value would come most likely from 
///         configuration, DB or some other code logic
/// </summary>
public void WriteBinaryFile(Stream inputStream)
{
    using (var reader = new BinaryReader(inputStream))
    {
        int bufferSize = 1024;
        byte[] buffer = new byte[bufferSize];
        int count = 0;
        int offset = 0;
 
        using (var writingStream = 
            new System.IO.FileStream(this.SavingPath, System.IO.FileMode.OpenOrCreate))
        {
            while ((count = reader.Read(buffer, offset, buffer.Length)) > 0)
            {
                writingStream.Write(buffer, offset, count);
            }
            writingStream.Flush();
            writingStream.Close();
        }
        reader.Close();
    }
}


The UI (Website)

Before we dig into the unit test sample, let's see how our page code will look when dealing with this business logic class.

Consider a page with controls like these:

 <%-- 
     Note: I used the FileUpload control of .NET 2.0 and above, 
         but I could also use something like:
     <input type="file" runat="server" id="inFileTest" />
 --%>
 <asp:FileUpload runat="server" ID="upldTestFile" />
 
 
 <%-- Used a text file read operation as a simple exsample --%>
 <asp:Button runat="server" ID="btnReadFile" Text="Read text file in the page" 
     onclick="btnReadFile_Click" />
     
 <%-- Note that even text files can be treated as binary files :) --%>
 <asp:Button runat="server" ID="btnWriteFile" Text="Write Copy of the file (any type)" 
     onclick="btnWriteFile_Click" />
 
 <br />
 
 <%-- I'll show the read happened by referencing to it --%>
 <asp:Literal runat="server" ID="litReadFileResult" />
 
 <%-- I'll show the file was written by linking to it. 
         In real world, you may want to encapsulate this in an HTTPHandler 
             not expose the file itself --%>
 <asp:HyperLink runat="server" ID="lnkWriteFileResult" 
     Text="Click here to get the saved file" />

The code behind for such page with our custom logic class (in a sample manner still), would look like this:

/// <summary>
/// Created for the "ReadTextFile" method
/// </summary>
protected void btnReadFile_Click(object sender, EventArgs e)
{
    if (!upldTestFile.HasFile) { /* Call whatever error msg method and, */ return; }
 
    var fileLogic = new FileLogic();
    litReadFileResult.Text =
        "The text file contents are: "
            + fileLogic.ReadTextFile(upldTestFile.PostedFile.InputStream);
    litReadFileResult.Visible = true;
}
 
/// <summary>
/// Created for the "WriteBinaryFile" method
/// </summary>
protected void btnWriteFile_Click(object sender, EventArgs e)
{
    if (!upldTestFile.HasFile) { /* Call whatever error msg method and, */ return; }
 
    //Save the file to "sample.text" under the website root (referenced as "~/"
    string relativeSavePath = "~/" + upldTestFile.FileName;
 
    var fileLogic = new FileLogic();
    
    // Converting path to phyical then setting it in the business logic class
    //  The physical path typically does not yet exist, as we'll create new file to it
    fileLogic.SavingPath = Server.MapPath(relativeSavePath);
 
    fileLogic.WriteBinaryFile(upldTestFile.PostedFile.InputStream);
 
    lnkWriteFileResult.NavigateUrl = relativeSavePath;
    lnkWriteFileResult.Visible = true;
}

I'd say that this part is not much different than it'd be if we were passing the "HttpPostedFile" object complete.


The Unit Test

So, that's what we have been hassling, complicating code, and dealing directly with streams for its sake!

As our application will not necessarily be a file sharing application, we'll be in need for the file as part of a bigger operation. A unit test will not be only concerned with the file upload task, but also the rest parts of the business operation our method intends to do. However, in this sample, I've decided to make it just test the file uploading functionality, and included really simple ways in the unit test.

Instead of the file upload, I used a physical file that I get its path from a method called "GetTestFilename" (I could have used configuration file, static property or else for the file stream, or used any other kind of stream still).

See how the test methods look in this example (using NUnit):

/// <summary>
/// Checks method "ReadTextFile" to see whether it gets the same text as sent file
/// </summary>
[Test]
public void TestReadTextFile()
{
    var fileLogic = new FileLogic();
    var sampleFileInfo = new System.IO.FileInfo(GetTestFilename());
    string correctResult = sampleFileInfo.OpenText().ReadToEnd();
    string testResult = fileLogic.ReadTextFile(sampleFileInfo.OpenRead());
    
    Assert.AreEqual(correctResult, testResult);
}
 
/// <summary>
/// Checks whether method "WriteBinaryFile" creates the file
/// </summary>
[Test]
public void TestWriteBinaryFile_FileExists()
{
    var fileLogic = new FileLogic();
    
    string newFilename = System.IO.Path.GetTempFileName();
    fileLogic.SavingPath = newFilename;
 
    var sampleFileInfo = new System.IO.FileInfo(GetTestFilename());
    fileLogic.WriteBinaryFile(sampleFileInfo.OpenRead());
 
    Assert.IsTrue(System.IO.File.Exists(newFilename));
}
 
//There should be one more method for checking the file contents are the same
// Skipped for sample!

 

The Complete VS 2008 Solution

I've attached a complete VS Solution of this example with few more comments than here so that you can see it more closely. This is a ZIP compressed VS 2008 solution.

File iconMeligy.Samples.TestableWebFileUpload.zip

 

Background of this Article (Totally Useless. Serious Warning)

Almost a year and half ago (Just a month after joining SilverKey), I was asked to build a file sharing area as a module of community site for one of our biggest clients. This involved much extension of an existing file upload business logic component that was written for internal usage in other systems for the same client to allow logical folders and large file upload with very high frequency at certain times of the year. A month or more ago (just before my exam vacation), another developer was asked to build a new file sharing component for another client but for certain business field not community stuff, and to make it generically reusable in any other systems (as our original component was quite tied to other rules in the general infrastructure of all the systems for the same big client). I was involved in design meetings with the other developer of course for what insights and snippets could be taken from the original component and my own extension as well.

After I got back from vacation (last week or so). I heard some notes from our tester (who also does his own unit tests whether or not the developer does :D), about the business logic not being "testable" because the business logic was passed "HttpPostedFile". The same applied to the old component actually.

So, today I wasn't exactly in the best mood, and a friend was asking me why I wasn't blogging for long (I said because I was more into reading than writing nowadays), so, I thought why not spend the night in refreshing my mind by writing some really basic example to show how to overcome that simple issue that I believe most people just do not realize!

Disclaimer

Again, this is something I wrote as a fix for some bad mood and was intended just to be a very simple example. I know 1000% that there're other better ways to write each and every part of this code, and many issues was not covered. The desired parts to show here were the layering (including unit tests) and different ways to deal with streams. To be clear, I'll make sure to support questions and such about it, but I'm not sure whether you can consider this a promise !!

 

Today was .NETwork usergroup second gathering. The usergroup is the first and only large/effective "offline" usergroup in Egypt (although there're many others in INETA). They had a great success in their first gathering when they brought Steven Forte to talk about SQL Server 2008 new features for developers and ASP.NET MVC design pattern. I had a detailed post about it in my GWB blog at that time. Check it out for details.

Background: First To Second Gathering (Warning: Boring Part!!)

The .NETwork gatherings so far are more like small independent events. We -SilverKey Tech- were the first to start such events with our full day event, DemoDay (See GWB posts on DemoDay I, DemoDay II ), and later ITWorx had their CuttingEdge Club (See GWB post); which were both great corporation contribution to the developer community (and I believe we need more guys to start doing similar events), but, didn't have much of "offline user group" nature between each round of either events (although almost each of us is friend to the other or at least friend of a friend!!). While .NETwork preferred the same "event" model, they had online and offline communication between the users of the usergroup (although mainly between students and organizers so far, but it's a step anyway). It's very interesting what Mahmoud Ghozz (one of the organizers) told me that the 2nd gathering session topics/speakers setup was done mainly through just phone calls!

So, in the 1st gathering, they were very successful getting all support from Microsoft Egypt, who held the meeting in their building and provided deserts as cool treat, LOL! They also used corporate contacts of the organizers to get Steven Forte (a frequent MDC speaker) to deliver the sessions. That was more than great but it was hard to keep. I think there were two main issues there: the fact that the gatherings need a determined location that can be available for "frequent" gatherings, and the other fact that to comply with the event model and also for the sake of hosting more events, the speakers need to be "local", from Egypt. The two goals were so clear as Remon (the main organizer) announced them in the 1st gathering, and were nicely achieved in the 2nd one.

The idea was simply simply getting the location from a private university. Sure any university would welcome that! They chose the Canadian University in Egypt, which was (like all private universities) quite far from Cairo that it still required buses to get the attendees (Not sure whether the university or Microsoft Egypt - who also brought free food I heard :D - provided the buses), and got an Egyptian MVP and Egyptian Microsoft Redmond Employee to deliver the sessions. That was a great step in stability that I heard some intentions that the gathering is going to be in the same location every 3rd Saturday of every month. Great news to here :).

So, as you see, it's insightful great advance, and I really like that to the extend of getting you too bored before starting walking through the sessions, so, let's start!

Session 1: WCF – Messaging & Channel Model (By Khaled Hnidk)

Khaled is a BizTalk MVP, and when he talks, you can see clearly that he just knows pretty much what he's talking about, which used to be a little bit missing from certain speakers in events I attended during the last few years (but is increasing nowadays thanks God). It's interesting how he went slowly during the session, but still delivered one of the deepest sessions I have attended in the topic (and I have attended many!). What helped this is that he was wrongly thinking or informed that the session time was 2 hours not 1.5, so, he a lot to say, and those who know the sessions I deliver or attend know how much I LOVE that ;).

As most of the attendees were students (I may talk about it more thoroughly after covering the sessions), he started the talk with regard to Webservices, why they exist at all, and the webservice (ASMX) model. When a client want to send a message to the service, it needs to serializes the message, send it through a transport layer (client proxy), get to the service transport layer, which de-serializes the message in order to process it. He discussed the idea of dispatching (directing requests to service method calls) in that model through WebMethod attributes. After processing, the service response is sent back to the client through the same steps, but in opposite direction.

Then he went into webservice model limitations. You know, in terms of method of communication and static host, requiring HTTP method (and hence HTTP server) to work, and also having to define security through attributes making the security code that's part of the message header something you care about when writing the service itself, and have to maintain along with it (although it's not part of the service logic). Added to that the limitation of the message itself, for example, as the message size would be dependant on server general web settings, and you have no built-in way to define metadata of the service (i.e., how about a sequence required for message calls?). He mentioned how WS-* standards have come to sort of try to work around such limitations, which required Microsoft to release Webservice Extensions (WSE) to support those in its ASMX implementation.

Well, as you may think, that was a where the talk of WCF started and took place. Khaled reminded the audience that now we have multiple ways of communication. On .NET, there's COM+, Remoting, Webservices (ASMX) - hey, with and/or without WSE -, which are too much. Of course other platform vendors have their own stack of tools/standards as well (like the stuff coming from IBM). Yes, of course. That's what WCF came to unify and improve its model from the .NET developer side. Before going further, Khaled approached Microsoft's decision on hiring Don Box, the father of SOAP, and having him to work on creating WCF.

Getting into WCF ABC (Address, Binding, Contract), Khaled stated how a message in WCF can be hosted in any application, event a simple console, and the host needs to have an endpoint "Address" to be called through. Getting the client to know "how" to call the service (i.e., whether it requires SSL, what max. amount of data can be sent at a time, etc) is the "Binding". Now what to expect from the service or what the service "can do for you" is the contract. Being recently married, he compared the model to what you do when you get a worker to do some painting or such for your house. To arrange the deal, the worker would example give you his mobile phone number (hey, "Address"). He would tell you "You can call me from ... to ..." (That's "Binding"), he will agree with you to deliver a certain service -let's say painting- (Which is a "Contract"). Khaled noted that almost the same concepts apply to the client.

Still talking about ABC (invested by Clemens, on a side note from Khaled), he showed a figure of the message lifecycle, and focused on the messaging communication:

  • Request / Response (Each client request has a service response on the same wire)
  • One way (A message will be sent and that's it)
  • Duplex (After a request, there'll be a response, not in the same time frame, not even using the same address/binding).

He used a funny example of that, slapping! If you slap someone in the room and he slaps you back, that's "Request/Response". If he just does nothing, that's "One Way" communication. If he leave you right away, just to wait you (or get someone) to slap you in the street, that's a "Duplex" communication!!

Going through addressing scenarios and special talk about the transport layer, Khaled had more to say about Duplex Communication. You know, you need to host the service, define ABC of the endpoint. The client is a bit similar, after all, the client has a service that has an endpoint, but this one complies to what what the service that the client requests does define.

Using the same demonstration of ABC and message lifecycle, Khaled went into talking about "Binding". He described the lifecycle as the channel model stack. Below in the stack you have the transport layer (Last), then upwards comes the message encoder (that's the serializer), and then you have more layers of your choice in the middle, typically the security layer, and then the dispatcher at the top of the stack (First).

Talking about security, he noted that you may want to use symmetric session key (one key for communication during a session), that for example would require the security layer to send additional message (other than the message you are sending itself) to set that key first for the client and then later will use that key to encrypt your message when sending it. That brought up a new topic, "In Band" and "Out Of Band" messages. This concept is important for those who do work on extending WCF features. Simply "In Band" messages are the messages that your service code deals with and has to worry about- in short, knows about! "Out of Band" messages on the other hand are ones your service will not ever know about, like that key message mentioned before, and like the messages of WS-MessageDelivery Large Message Exchange (WS protocol that defines splitting of large message into smaller ones and combining them as one message back). Knowing the difference between both -Khaled reminds- is a necessity for those doing security extensions for WCF.

Still with binding, we went into "Behaviors", as the name implies, this means changing (overriding) the way WCF works. To explain that, we started digging into demos.  The first demo was walking through a pre-created solution (Khaled recommended to have a separate VS Project for each service host, and a separate VS Solution for the service - that's another VS Solution for the service client). He walked through the defined contract (that's an interface that the service class implements), and related attributes. Serializing the non-primitive .NET types (say classes) involved in the service and using DataMember on the members needed for the service to operate properly. He noted that out of band messaging like security will be configured in the binding not the service code. He then moved to the service host, showing the snippet to tell the host which service is should host at all :). The host app.config file (which he calls -for fun- app."ounfid", that's "Hedgehog" in Arabic!) has the binding. He showed how that's defined using the service class name, and showed different endpoints demonstrating that each endpoint has its own ABC, showing the binding models that come with WCF out-of-the-box (answering a side question, he stated the binding can be defined in code as well).

The next topic in the same context was meta data exchange, defining different channel model than standard. Yes, that's where the behaviors come to play. The behavior is defined either for a service, endpoint, or operation (Method). He showed how you can for example inherit one of the built-in service behaviors and override its main processing models. An interesting point he showed was using HTTPWS binding on the host (meaning the host will provide the service over HTTP with WS standards), and while just defining HTTPWS binding on the host was enough, Creating a reference from the client application to the service showed that the client had each detail (instruction) it needs of that binding stated in its app.config, that's like whether there's quota for message size. That's "right" because, that client might have been for example a JAVA application that knows nothing about binding and needs these instructions. The last part of the session was tracing the states of the client calling a service, proxy creation, opening and closing the connection to the service.

The next demo started by iterating over dispatchers collection. that's a dispatcher on each endpoint for direction to class methods, plus an additional undocumented zombie dispatcher that you read about only in blogs, Khaled mentioned. He noted that he "saw very few developers that needed to override dispatchers versos other WCF stuff"

Now we started talking about service instances (creating service object that has the methods to call from the service class) by mentioning state management as the enemy (for the expensive memory it requires), Khaled reminded everybody of having a service instance per message. It was a good time to mention the 4 tenets of SOA (Service Oriented Architecture):

(Note: I merged the original terminology with Khaled's explanation)

  • Boundaries are explicit: Or service isolation (Each service is a separate contract)
  • Services Are Autonomous (You cannot deploy a service partially, or to clarify: each service should be able to perform regardless of any other service availability or so)
  • Services Share Schema And Contract, NOT The Class (You shouldn't need an assembly to use the service, just the schema, like WSDL for example)
  • Service Computability Is Based On Policy

Back to overriding service behaviors, Khaled demoed different service instance creation modes (when a new instance of the service is created). that's Per-Call (every service request), Per-Session (every new client session), and Single (just one instance for all client calls, which is not good for memory performance). He showed us the number of service instances created in each mode for a client connection with 2 service operation (method) calls, and one more connection with single operation making every service instance response a GUID field he added to the service class.

The next topic was "channel factory", he briefly mentioned you create a factory for overriding channel by code, that's meaningful when the biding is variable in runtime. Speaking of binding and endpoints, I wanted to know his recommendation on hosting services in console-like applications like windows services, etc versos in IIS, He seemed to agree with me that IIS is the practical option, and added a note on the in-the-box power of IIS 6 application pools. He also added that Windows 2008 has another practical option, which is WAS (Windows Activation Services).

The next topic was WCF tracing. Khaled demoed setting up tracing configuration like tracing sources for tracing each message/activity, adding tracing listener to a text file, and opening the trace file using Windows SDK 6 SVCTraceViewer tool, going through the log entries for mapping to service model (like initializing the service host, etc), and showing tracing entries mapping to the transport layer. He gave everybody an few advices. To go home and play with the SVC Viewer tool if they want to learn, and to remember that tracing the host (mainly IIS) would be through Windows Event Viewer, while tracing the service behavior itself would be through that SVC viewer tool.

After a side question about encrypting part of the message not the whole message (which would be for certain business processes) that he recommended instead of having single service, splitting the services and having a central workflow as main service that splits the message and directs it to the right services; he went on a detailed demo for overriding Endpoint behavior. You get a method for applying client behavior (if the behavior is on the client endpoint, if not, just throw a meaningful exception there!), and another to apply the behavior on the service, which he used for a dispatch behavior for the WCF Message Inspection WCF Patterns (inspecting parts of the message and request parameter filtering). You access the message after receiving the request (that's before executing the service code) and before sending response (yes, that's after executing service code). Note that a message is immutable (that means you cannot change it). You normally take the message (passed to you by ref), put it in a buffer, do whatever you need to with the message buffer, and use it to create a new message that you replace the original message with. The last step needed after writing the behavior is adding it to the config.

Here was the end of the demos. The rest of the slides and demos were cut due to discovering that half hour difference I mentioned above. The next part Khaled added after asking someone in Microsoft if she believes Microsoft would love to deliver certain messages to his audience. He stated that at the very beginning, but I thought it would be more appropriate for me to bypass it until we reach the part he started telling these messages, and here it came!

The first talk was about BizTalk 2006 R2 WCF LOB (Line Of Business) Adapter SDK . A framework for with legacy code. You create the meta data in band stuff), inherit some classes and implement certain interfaces, which after you're done can be used as yet other WCF channels than you can be bound to. It has tools that help generate you all you need to start (Overview). He also mentioned the SDK adapter pack which is contains adapters for SAP, Siebel and Oracle, etc. The last words were about "Project Oslo", which is a set of process/workflow modeling tools that aim to be the actual runtime of the code, not just a code generator like WF designer model. He said it's said to be released with first quarter of 2009, and it's work in progress with regard to Emacs-like editor.

As a whole it was a great session. although many things had to be simplified for the majority attendance of students, and, that misunderstanding of time thing made us go very slow  in the beginning, and then have to skip parts at the end. Still, the guy is pretty knowledgeable and I now that next time he presents, I'll likely be there.

Session 2: SQL Server Manageability (By Mohamed Meshref)

I used to know Meshref in ArabTeam2000 forum (a short while after he was accepted to join Microsoft SQL Server Team in the U.S.) and later MiddleeastDevelopers yahoo group. He is know for having a special way in talking about stuff, especially when it comes to talking about Microsoft (and it always does of course). Unfortunately, the guys was kind of sick yesterday (Oh, it's already yesterday!), and it was hard for him to do the talking, however he managed to deliver a light interactive session with good demos still :).

At the beginning, Meshref went talking about Resource Governor, it was mentioned by Steven in the first gathering (which I wrote about), but, I think it's an essential feature (Many guys were "not" of the 1st gathering attendees still, and it didn't take much for the talking).

The next features he talked about were all built with regard SMO (SQL Server Management Object), that's a library that has representation of all SQL Server Objects that enable doing something like another SQL Server Management Studio theoretically possible (Just kidding - let's say a way to reach many parts of SQL Server Management Studio features by code). That's very logical building in my opinion and I like the fact that Meshref and the other SQL Server did stick to it.

The biggest feature Meshref talked about was Declarative Management Framework. This is basically a policy management framework. It allows you to define a certain policy on any object available within SMO (You do it normally through the familiar management studio), like setting a certain naming convention for all tables in the DB for example, and the policy can be applied to all DBs in the server, and/or exported to other server(s). Meshref went on demoing the creation of a new policy, showing that a policy can consist of more than one condition (and each condition can be reusable in other policies - think of it as Many-to-Many relationship). He showed how the policy does prevent violating it when enabled, and then went back to show us how we can set a description for the policy to appear to the user trying to violate it.

Afterwards, he showed how we can "evaluate" our policy. That means seeing which objects do not comply with the policy (for example, objects created before the policy was created and and set active). At this point, Meshref mentioned the difference between the two types of conditions:

  • Deterministic: Those are the fixed rules, similar to setting a certain property of an object to always have a certain static value. The cool thing about such conditions, Meshref demoed, is that when you are using it, and checking what objects do not comply to your policy, you just click a single button to make SQL Server apply the policy for you on all the non-complaint objects or only one of them.
  • Non-deterministic: Those are the dynamic conditions well, the conditions in all are a bit limited to say "dynamic"!), En example to that is defining that all your table names should be "like 'tbl_*'". Such condition cannot be applied automatically. You click the same button, but to apply it yourself this time.

By the way, I asked Meshref whether there're performance worries when using large number of policies (yeah, I was thinking of managed stored procedures), and he said that they tested them over huge number of policies (I think those were 15,000!!!), and I shouldn't worry.

Before going to the next demo, Meshref highlighted that the DMF is a SQL Server Engine feature, not a feature of SQL client or so. It makes sense and was important for feature after the demo. The demo was setting different policy modes for when the policy will be evaluated:

  • On Demand: Policy evaluated only when you go evaluate it yourself.
  • Schedule :Using SQL Serer agent to evaluate the service according to certain schedule and log that.
  • On Change Prevent: The policy is enforced. No one will be able to bypass the policy as long as it's enabled
  • On Change Log: When someone tries to bypass the policy, this is let go, and just logged

The next feature was Multi Server T-SQL. This is a small SQL Server Management Studio (SSMS) feature that is still great. Simply, this enables you to right click the top of the Servers tree in SSMS, choose new query, and the new query you write gets executed on all the servers you have registered in SSMS. Because this thing is on the client side, the registered servers can be any version (well, I think I mean SQL Server 2000+ still).

The next demo was on PowerShell Integration. Being able to write something like "CD [ServerName]", "Dir" (gets DB list), "CD [DB Name]", "CD Tables", "Dir" (gets stables list in the DB) is really fun thing to do :D. This is intended to replace SQLCMD old SQL command tool as said by Meshref. I asked him whether I need to do anything on the server to access it via PowerShell on another machine, and he said it's the same stuff required to use SSMS against it from another machine - interesting!

Then he demoed SQL Server Intellisense. I don't need to talk much about this I guess :). Meshref stated that they do caching of the objects you use to enable some sort of "Client Complication" as he called it, which is validating your query (including column and parameter names, etc) when working against a remote Server without having to actually send the query to it.

The next big thing was "Data Collection Framework". That's a SQL Agent based feature that is very useful for dataware housing through it's performance monitoring collection sets and their collection items. He demoed us sample reports of what is collected and it was SQL Objects usage reports, and performance measures (CPU, Memory, etc). The two questions he was about this feature was that whether this requires SQL Reporting Services, whose answer was No, and whether it's available to consume through SMO APIs, and the answer was yes.

The last thing he showed before the session ends was a small [x] that appears next to objects in SSMS when they are not compliant with current policies. Good to see. Actually the rest of the session was mainly weird questions from some attendees. Maybe I talk about that in a next post

Conclusion (You knew there has to be one!)

OK, it's morning already, and today is suddenly yesterday. I just wanted to say that I really enjoyed the day and the cool guys. The day was great, and I wanted to tell .NETwork what I believe is missing here.

Actually the .NETwork guys as I mentioned have made great success in setting up sessions. You made a great frequency. You maintained communication between half or so of the group members, but this leads to ask about the next step. I believe (as I said to Mahmoud) that there should be friendly group gatherings with even higher frequency than the events. Those can always be with little number of guys and with normal talks without sessions or having single session in the meeting. That's mainly how I hear about usergroup most frequent activities, and I'd love to see it. I believe that this will eventually attract more professional developers, whose presence will help raise the levels of the starting level developers, because with having starters as the majority always, you find yourself sort of stuck in certain level of knowledge exchange instead of increasing that level. I think having regular gatherings in certain times as that "3rd week of a month" intention as well as more smaller gatherings will bring more developers whose presence can take the hands of those starters. It'll take months to be sensed though. I'm not talking about 3 or 4 months here, but 7 or 10, but that's affordable I believe as some guys tried for few years.

 

To everyone around, I'd like you to check the usergroup and attend the next gathering. I'll post about it enough time before it happens and will link to the session slides and videos as soon as I know they're available, but, don't count on me, and check the usergroup yourselves ;)

 

This is also from an internal mail to SilverKey Tech Egypt office dev. team. Slightly modified this time! (Yes, I know. I should stop this habit of link collection and get back to writing - hopefully soon)

hmm, how about more links as a blog readers bonus,..

Reading the news that Ruby.NET is dead although doesn't feel the best thing to hear, is still logical, and more explicitly it's even "right". After all, it reminded me with the other story about the death of AJAX.NET Professional. I wrote a detailed take on that earlier (in my former blog) and although you might consider this spamming, I feel the same talk needs to be brought back into conversation, because I feel like I want to say the same things, so, I'm quoting it entirely here in this blog.

Few hours ago, Michael Schwarz, the creator of AJAX.NET Professional (A.KA. AJAXPro), the most successful AJAX framework for ASP.NET after Microsoft's ASP.NET AJAX Framework (A.K.A., ATLAS) has stated that he'll no longer be working on the project. Furthermore, he even recommended users to move to Microsoft's AJAX Framework instead!! The reasons Michael mentioned why he will stop the project used by 13.3% of ASP.NET developers doing AJAX work include the fact that ASP.NET AJAX is part of ASP.NET 3.5 itself, and that he believes future innovation on the client side will be in other areas not just AJAX.

I haven't used AJAXPro in production myself, but I used to provide support for few other friends who did, and it was really a neat piece of software. The ability to have wrappers for YUI and other pure client libraries impressed me, but I never used it on production stuff for one reason. I expected this moment to come !!

This brings me to the same thing I used to worry about myself and later was a major concern when I started getting slightly involved in ALT.NET movement. The old quote says "You never lose your job because you chose Microsoft",  and that's usually true. AJAXPro story has always been weird to me. I kept wondering when will the story keep like this, good implementation from Microsoft, and another very interesting implementation from the outside, besides few more working implementations. It's not just about AJAXPro, but is a general issue.

Don't get me wrong. I believe that AJAXPro was one GREAT reason behind the current quality of ASP.NET AJAX (plus other additions, like having briliant guys working on it, especially Nikhil). Same as I believe that Castle's MVC framework named MonoRail was one of the teachers for ASP.NET MVC  and both appeared simply because RubyOnRails was a great MVC framework that made most people suddenly value MVC and surprisingly some people even hate webforms as if it was found by the devil (I wrote about it before in the context of other areas like D)I. Even more examples are NUnit and VSTS Tester features. But what then ??

VSTS never killed NUnit and I don't will. Instead, NUnit is not the only testing framework, there's also MbUnit later and even XUnit recently. On the other hand, AJAXPro is now over. More interesting stories are Subsonic and BLINQ. Now the founder of Subsonic works for Microsoft and Subsonic itself is gaining excellent popularity because it's 100% FREE while LLBLGen (the best ORM for .NET in my opinion) and .NETTiers (while requires buying CodeSmith), and is even competing with other FREE options like NHibernate and Microsoft's own FREE ORM, LINQ2SQL. Once Subsonic started (and it was called ActionPack as for ActionPack of RubyOnRails) I blogged that we don't really need something competitive to BLINQ, and I said it's waste of effort (because of the old quote). Now BLINQ itself is likely dead, never heard of it or Managed JScript for long. Anyway, at this time the timing was the factor, if Subsonic appeared before BLINQ, it'd make sense, but that it appears while BLINQ was in development instead of working with BLINQ and LINQ2SQL and providing lots of ideas, feedbacks and even toolkits for better jobs, it didn't look right. If you think this is 100% against ALT.NET mentality, you haven't got my point yet.

The point is, such frameworks and alternative tools are so important for us as developers. They are the true reason behind the quality of Microsoft frameworks. If there's an area where there should be a framework or a tool, and nobody for the competitive platforms has considered creating one, and even more no one in the .NET world has tried creating one, Microsoft will almost never bother creating it's own. Even if they do, the fact that they have no competitor and/or teacher will make their result a really crappy one, which is normal for anyone working from scratch (no previous experiences in the world) with market dominance (completely no competition), not just for Microsoft. Don't get me wrong on "learning" too. I heard Microsoft guys are not allowed to read other's code for legal issues, but at least learn from feature sets and high level architectures shared among many bloggers!

So, clearly, if you are going for stability, it's Microsoft. If you looking for feature set and quicker results it's ALTernatives (speaking inside the domain of .NET Framework), because Microsoft always comes late, and they will ever do. Again, it's not about Microsoft specifically. The other quote says "If you are fat, you can't run". Once Microsoft gets it, in most situations they do it best, but after so long time. This means sooner or later you have to switch back to Microsoft, and maybe I'm the one who's too lazy here or so, but this fact that "you have to switch sometime" really annoys me, but this is how it goes.

Let's see some examples: now ASP.NET MVC is expected to kill Monorail. What Monorail thought of as I read was to be some framework that works around ASP.NET MVC and work with it not compete with it. Also, ASP.NET AJAX is getting mature enough to compete with other .NET AJAX framework like AJAX.NET Professional and this simply killed the other framework; while ASP.NET AJAX is still way behind when compared to pure client frameworks whether older like script.aculo.us or newer like jQuery. The fact it's the best for webforms means that people working with webforms will always use it, while others working with Monorail or AS.NET MVC itself will probably go for jQuery or so. VSTS is now in it's 2nd version still (VSTS 2005, VSTS 2008) and this is very early for it's testing features to affect other testing frameworks especially when you consider the huge price difference (FREE vs. thousands of dollars). The old, not always outdated quote says "Microsoft releases a great working product, starting with version 3". Subsonic is now pushed by Microsoft while they still push Linq2SQL powerfully, but again, this is "now", how about later ?? Remember (or add to your information) than until today other player in the ORM ground like LLBLGen is even better than LINQ2SQL itself that it for example has a very sophisticated designer studio and more importantly has more support for prefeteching loading with least queries) related entities at the same time, and this something big. The next version will even provide LINQ syntax which makes the difference smaller, but again, it's quite way expensive. It'd make more sense to me than the current mess if the guy behind LLBLGen and the guy behind APAXPRo both simply joined Microsoft and their work was acquired. That they continue working on the same stuff but under Microsoft's umbrella without ugly huge corporate restrictions and complete freedom, sort of similar to the guys working on ASP.NET MVC. But we do not work in an ideal world !!

So, we'll still living in the same miss. Microsoft only is a very limited painful yet guaranteed option, ALT option is the total amazement and innovation but can simply disappear in a moment.

Happy mess, geeks :D :D :D

Bringing up the topic again. I have many talks about it in private chats, etc, and I put it here again mainly as I'm wondering what others might have to say about it here.

It all started with an email Mohamed Hossam (AKA, Bashmohandes) sent to SilverKey Tech. (the company I work for) local office here in Egypt, referring to the article "Foundations of Functional Programming - Part 1 - B# .NET Blog".

It inspired me to send few more language links:

I also referred to the latest version of DLR hosting spec., stating that it's quickly changing and already not up to date still.

Besides, I included some more reading bonuses:

So, I thought I should share them here as well!, although I hate to keep the habit of just "sharing links" rather than "writing my own posts", but let it be ... for now!

More Posts