Category: Uncategorized

  • The Zen of Architecture

    The Zen of Architecture


    Listened to The Zen of Architecture by Juwal Lowy… He has some very interesting points. Everything can be found in the iDesign.net website. Read and learn.

    I think the principles makes sence, but it might be a little over engineered for the relatively small projects that im handling. If i implemented his thoughts, I would spend more time doing plumbing of WCF services than on implementing business logic.

    Still, one has to take the parts of his stuff that makes sence.

    Now i’m up for a session about certification – 70-630 Configuring SharePoint 2007.

  • TechEd 2009 Day 3

    TechEd 2009 Day 3


    I didn’t make it to the blog yesterday, but I will try to put a little info on later about the stuff that happened.

    Today is going to be an exiting day. There is so many sessions I would like to follow but too little time:

    Slot 1:
    Zen of architecture – with Juwal Lowy… Im going to this one.
    Understanding virtualization and MOSS 2007

    Slot 2:
    Preparation for MOSS configuration exam

    Slot 3:
    Applied Entity Framework – I think i will take this one
    Expploring proper MOSS 2007 Installation and topologies

    Slot 4;
    Essential Linq with C# – Probably to intermediate
    Practical web testing
    SharePoint search challenges and tricks
    Building scalable and availabvle web apps with MS Code name Velocity
    Expression Blend from a Dev’s point of view
    How to protect Sharepoint with SCDPM 2007 sp1

    Slot 5:
    ADO Entity Framework – Tips and tricks
    Version and upgrade of sharepoint solutions
    Sharepoinbt online features functionality and customization..

    And a lot of other interesting stuff.

    Over and out.

  • First day at Tech Ed 2009

    First day at Tech Ed 2009


    The TechEd conference of 2009 is kicked off. I am attending with two colleagues from D60, Thomas Garp and Henrik Drachman.

    The stored procedure panel

    I really had high expectations to this one. Finally we were going to end the battle between the T-SQL and SP guys. The panel discussed the various problems with both methods of SQL access, including performance, security and application architecture. The conclusion was, that there is no conclusion. The stored procedures are better in ways of security, performance (Both by using compiled execution plans and by lowering the actual network trafic) and gives a better application architecture by separating the datalayer completely. On the other hand, using T-SQL provides a flexibility that cant be provided by SP’s. A final comment was, that SP’s should be used unless there is compelling reasons not to do so… I think I can agree on that one.

    Keynote
    This years keynote speaker was Bill Veghte, who spoke about Win 7, Windows Server 2008r2 and other stuff. The keynote provided a few interesting point but it was largely a waste of time. The highlight was the announcement of shipdates for win 7 and W2k8r2 before christmas.

    A lap around MS Asp.Net 4.0 and Visual Studio 2010
    This session covered some of the new functionality in VS 2008. Especially snippets for HTML and improvement of the way ASP.Net markup is written was demonstrated. This will give a significant lift to the way HTML and markup is written.
    There was a lot of demos of Ajax, Data access etc, but nothing really interesting. The best announcement was the introduction of the ability to have a debug and production web.config file in a project. ABOUT F…ING TIME!

    Developing SharePoint solutions with the VSeWss3.0 1.3
    Version 1.3 of the VSeWSS 1.3 is in a CTP and soon available. In VS 2010 these tools will be build into the development environment.

    In version 1.3 there is a number of changes: A number of deployment settings have been added, most of the resembling the Carsten Keutmann tool. These tools will probably be the stuff that will make the VSeWSS usable 🙂

    There is also functionalty to rename features, moving files etc in the dev. environment.

    Most important is that the VSeWSS now can run on a 64 bit machine. This functionality is very much needed. There still isn’t a visual designer, but that should also be part of the Visual Studio 2010.

    Thats it for the commercials in this event… The rest was demos and lots of usable code examples. There wasn’t really any earth shaking news, but still good be confirmed in the strategy im using when developing solutions for MOSS-

  • Nerdy joke.

    Its early morning and a long day is ahead… I thought this might start me up in a decent way:

     

    A SQL query walks into a bar and sees two tables. He walks up to them and says ‘Can I join you?’

     

  • Code markup in Tech blogging

    Anybody who knows a good tool for tech blogging – especially for making code markup?

    Often it is necessary to include a peace of code in this blog, but the result looks awful. The only posible way to make some kind of format is to encapsulate the code in <code> blocks. An alternative way is to use some of the tools avaliable on the net (e.g. http://delphi.fosdal.com/2008/07/source-code-highlighting-in-blogger.html) but that requires a lot of cut/paste.

    I just want a simple windows application that supports rich text and pasting of code. Somebody must have made this!

    Any suggestions?

    — 2008 10 22 Update —
    Today MSDN Magazine, october 2008 arrived in my mailbox. On page 12, in the Toolbox article, several diferent tools for colorcoding source is mentioned. My favorite is this one:
    http://www.jtleigh.com/people/colin/software/CopySourceAsHtml/

    Its a plugin to Visual Studio that integrates into the context menu, providing a “Copy as HTML” link.

  • Language confusion in Moss

    I had yet another Moss confusion this morning. I have installed an English Moss and then configured the server with a Danish language pack. When i opened up a site directly from my development server, everything was displayed nicely in danish. The top bar greated me with a “Velkommen Kaj” (I guess even US/UK readers can guess what that means in danish 🙂 ). When i opened up the site directly on my laptop, the greating was in English…

    As my little green StarWars friend would say:

    Strange that is.. yeah!

    This does not only apply to the greating, but also to the Site Actions menu and help collection.

    So the same site is shown with different language settings on two different machines.

    After a little investigation, i found out that my laptop was set to be located in America. (Control Panel –> Regional and language Settings –> Location). This is what caused it to show these things in English.

    Only developers from out of this planet will be able to explain why this is the way Moss is behaving. But it is! So learn it and behave correctly. If only Moss used my computers language setting, I could understand. Even better, it would just use the language setting of the site. But it does not!

    Luckily i hadn’t configured my laptop to be located in Uzbekistan!

  • Memoryleak finally found

    I have had a long time bug in a website, causing memory to leak. I have really tried everything to ensure that all objects were disposed etc. But nothing helped. In the end, I handled it by recycling the process IIS process when the memorylevel was to high. IT IS NOT A GOOD OPTION… But I had spend so much time looking at this, and I couldn’t find the cause.

    It is kind of “I couldn’t find the forrest because it is covered by trees.”…

    But a lesson is to wait some time (In my case a few months :-)) and the look at it again.

    The problem is, that I’m doing a series of image operations to scale down a picture and apply rounded corners. One of the operations is:

    using (Image img = System.Drawing.Image.FromHbitmap(bmp.GetHbitmap()))

            {

                stream = HandleImageFile(img, _width, _height);

            }

    … blablabla… and then some work with the stream.

    The problem is caused by the Bitmap.GetHbitmap() method. I didn’t bother to read the documentation when i originally wrote the code… I just looked at intellisence. The problem is that the GetHbitmap returns an IntPtr object, and these objects are not cleaned up by the Garbage Collector (As it is written in the documentation tsk tsk.)

    So the solution is:

    [System.Runtime.InteropServices.DllImport("gdi32.dll")]

    public static extern bool DeleteObject(IntPtr hObject);

     

    static bool HandleImage()

    {

        IntPtr hBitmap = new IntPtr();

        try

        {

            hBitmap = bmp.GetHbitmap();

     

            using (Image img = System.Drawing.Image.FromHbitmap(hBitmap))

            {

                stream = HandleImageFile(img, _width, _height);

            }

        }

        catch

        {

            throw;

        }

        finally

        {

            DeleteObject(hBitmap);

        }

    } 

    Check the original docs here:
    http://msdn.microsoft.com/en-us/library/1dz311e4(VS.85).aspx

  • Composite Control Event in ASP.NET

    This blog describes the different events that are relevant for rendering a composite control. It is very important to use these events correctly if you want the correct results. Even small mistakes in the use of the events can cause problems later on with events etc.

    Writing a composite control is something most ASP.NET developers will do at some point. It isn’t a simple task if you do not know exactly how to do it. But following these basic rules will make your life much easier – and as a bonus, it will also make the reading of the code much easier for the people who will take over your work if you get hit by a car.

    Composite controls must inherit Control and implement INamingContainer.

    Constructor

    The constructor is no different than usual. Set all values that define how the control is rendered here

    OnInit

    Create instances of controls that will be rendered on the page. If the controls has events that need to be captured, its necessary to create the events here. Otherwise the events will not be captured.

    Also this is the place to set the static attributes of the controls.

    Note that the controls are defined as protected attributes on the class and not just as local variables in the OnInit method. Also note that the controls are not added to the class’s control collection yet.

    protected ImageButton _btnEdit;

    protected override void OnInit( EventArgs e )

    {

    base.OnInit( e );

    _btnEdit = new ImageButton();

    _btnEdit.ImageUrl = “/UI/Images/edit.jpg”;

    _btnEdit.Width = 46;

    _btnEdit.Height = 18;

    _btnEdit.Click += new ImageClickEventHandler( BtnEdit_Click );

    _btnEdit.AlternateText = “Edit”;

    ….

    ….

    }

    CreateChildControls()

    The CreateChildControls is used for adding the sub controls to the class control collection. And nothing else happens here. It is tempting to set attributes etc here, but you shouldn’t do that. If you want to build the entire output of controls, they all must be added here – and in the right order. But a good rule is to only add the controls that has interaction with the user. Not attributes for the rendering. Add buttons, text boxes, but do not add controls to render line breaks, images etc.

    protected override void CreateChildControls( )

    {

    base.CreateChildControls();

    this.Controls.Add( _btnEdit );

    this.Controls.Add( _btnSend );

    }

    RenderControl

    If you, like described above, only add controls that interact with the user, you need to override this method to render the control. The method makes it possible to render HTML around the controls you added in the CreateChildControls method. You can decide when to render the child controls. If you implement this in the Render method, the sub controls will be rendered when the base.Render is called. This means that they will be rendered before or after the HTML you would like to render. Using the RenderControl event, you can decide when the controls will be rendered and by that render them in the correct HTML context.

    Always use the writer parameter to generate the HTML, because it implements some logic that will render correct HTML in different browsers.

    public override void RenderControl( HtmlTextWriter writer )

    {

    base.RenderControl( writer );

    // Render title html

    writer.RenderBeginTag(HtmlTextWriterTag.H3);

    writer.Write(“Top of buttons”);

    writer.RenderEndTag();

    writer.WriteLine();

    _btnEdit.RenderControl( writer );

    writer.RenderBeginTag(HtmlTextWriterTag.BR);

    writer.RenderEndTag();

    _btnSend.RenderControl( writer );

    writer.RenderBeginTag(HtmlTextWriterTag.H3);

    writer.Write(“End of buttons”);

    writer.RenderEndTag();

    }

    Render

    The render method should only be used if you do not wish to build the HTML through the RenderControl method. Using the Render method mean that you only generate HTML from the controls you have added to your control collection. Doing that will render the controls in the same order as they were added to the control collection.

    It can still be very valuable to implement this method. It can be used to catch exceptions thrown by the rendering of one of the controls in the control collection.

    protected override void Render( HtmlTextWriter writer )

    {

    try

    {

    base.Render( writer );

    }

    catch ( Exception ex )

    {

    string message = “Error while rendering a control”;

    //Do logging etc.

    }

    }

    Other events

    There is a bunch of other events that can be necessary to implement to for instance control viewstate etc. These special events can be found in the event hierarchy below.

    Event hierarchy:

    Instantiate Constructor

    Initialise OnInit method and Init event

    Begin tracking view state TrackViewState method

    (PostBack Only)

    Load view state LoadViewState method

    Load PostBack Data IPostBackDataHandler.LoadPostData method

    Load OnLoad method and Load event

    (PostBack only)

    Raise Changed Events IPostBackDataHandler.RaisePostDataChangedEvent method

    Raise PostBack Event IPostBackDataHandler.RaisePostBackEvent method

    PreRender OnPreRender method and PreRender event

    Save View State SaveViewState method

    Render Render & RenderControls Method

    Unload OnUnload method and Unload event

    Dispose Dispose method

  • System.DirectoryServices.AccountManagement namespace

    The AccountManagement namespace is part of the .Net 3.5 framework, and provides an easy way to access and modify directory services.

    I used to have my own ADHelper library that encapsulated the methods in System.DirectoryServices namespace.

    Recently, i had to find out if a user was member of a specified group. This was possible, but it took a lot of lines of code. With the AccountManagement namespace it can be done in a few lines:

        static void Main()

        {

           UserPrincipal user = UserPrincipal.Current;

           if (user == null && !IsMemberOf(user, Settings.Default.EditorRole))

           {

             // user is found

           }

        }

     

        static bool IsMemberOf(UserPrincipal user, string roleName)

        {

            bool result = false;

            if (user != null)

            {

                PrincipalSearchResult groups = user.GetGroups();

                if (groups != null)

                {

                    foreach (Principal principal in groups)

                    {

                        if (principal.Name.Equals(roleName, StringComparison.CurrentCultureIgnoreCase))

                        {

                            result = true;

                            break;

                        }

                    }

                }

            }

            return result;

        } 

  • Clean up the Using blog in Visual Studio 2008

    Clean up the Using blog in Visual Studio 2008

    When you create a new class, its normally filled with using statements in the top. Usually you only use one or two of these statements.

    Visual Studio 2008 has a great feature for cleaning up the code:
    1. Right click somewhere in the editor
    2. Select “Organise Usings”
    3. Select “Remove and Sort”
    This removes unused Usings and stort them. You can also choose to only remove unused usings or to sort the using statements.