Archive for the '.NET 2.0' Category Page 2 of 5

16MayWhat is wrong with people?

Did I miss the memo about having to be religious about the tools you use. In my mind anything that falls in the category religion should be banned as it is a cancer on society. Philosophy is good. Budhism is a philosophy to which I would subscribe for example. I am allergic to people that tell me what to think, probably why I never really fell for the “ruby community”. I don’t need convincing, I’ll do that myself, I just want correct information and plenty of it. 

That being said I stumbled across this thread where people are actively discouraging Miguel de Icaza to implement silverlight and co in Mono

http://linux.slashdot.org/article.pl?sid=07/05/03/2033219

These are the reactions to it on channel 9.

http://channel9.msdn.com/ShowPost.aspx?PostID=305405#305405

 

I personally use both I use Linux and I use vista both on a 64 bit system.  I like the whole simplicity of linux but the applications for it are not nearly as finished as the ones that are there on the windows platform.

For example MonoDevelop doesn’t come anywhere near Visual studio. Gimp is no photoshop, ….

Microsoft provides a more viable eco system for people to make money of what they do. I do wish Microsoft would support open source a bit more instead of copying it and thus mostly killing the OSS project. Although I do understand that they are a business

If I would have more time I’d certainly want to contribute to Mono but unfortunately there are only so many hours in a day and these hours are not enough.

To get back to my original point. You can be passionate about something, and everybody that has spent some time talking to me will have picked up on the fact that I don’t just accept the technologies that are being shoved down our throats these days.

The reason I don’t read blogs on Ruby anymore is the following: I simply couldn’t stomach the people going on and on about how cool their mac is and yet they need to reboot it on a regular basis. My vista pc at work hasn’t rebooted for the last 2 weeks now, before that I got a BSOD regarding memory management :)
Furthermore there are programmers that keep going on about the fact that notepad/vi/emacs/textmate/eclipse are the best tools for developing applications.
I don’t know about you but for me programming is about creating stuff, preferrably fast and visual studio is the perfect fit for it.

Granted my vista pc doesn’t look nearly as cool as a mac or an ubuntu with berryl machine but I am far more productive for my job on it.

So my conclusion for this post would be :
Don’t get religious about your tools/language/platform but choose the best one for the job at hand.

Uhm.. this post turned out to be a big rant instead of my intended post which was going to be about how much I look forward to C# 3.0 and the DLR.

As soon as I can get my hands on some of the bits I’ll be posting my findings.

01MayNBlogr Presentation in Wellington


Tonight I got the chance to present my nblogr application to a larger audience. Unfortunately I’m in the process of fixing bugs in NBlogr and one of those bugs required me to make a change to NBlogr.Web/views/default/shared/mainmenu.boo . I had made this change on sunday around midnight right before I went to bed. Of course I forgot to test the application because and it wouldn’t run on my presentation.  When I got home it took me about 3 minutes to fix. I had to import a reference to Base4.Storage in the mainmenu.boo file.

I’d like to thank everybody for coming, their patience and listening to my ramblings.

Anyway I’ve included my slide deck in this post and I think it might be a good idea to post a couple more links to some of the people I mentioned in my talk.
http://www.base4.net  – Alex James, Auckland
http://blog.bittercoder.com – Alex Henderson, Auckland
http://www.ayende.com/blog
http://hammet.castleproject.org

http://www.castleproject.org
http://www.nunit.org
http://www.nblogr.com

svn repository:
https://svn.koolkraft.net/nblogr/trunk

NBlogr-Wellington 02 _05_2007.ppt (440 KB)

To get nblogr running on your machine follow these steps :

Make sure you have a subversion client installed or subversion itself.

C:\Projects> svn co https://svn.koolkraft.net/nblogr/trunk
C:\Projects> osql -E
1> create database nblogr
2> go
1> quit

open the nblogr solution.

change the connection string in web.config

The different configuration options are explained in the web.config

If you want to use a different extension than aspx you have to change the httphandler configuration and set the extension in nblogr/routing

if you want urls to be rewritten without an extension you will have to enable wildcard handling.

hit ctrl-f5 and it should take you through the configuration. If ctrl-f5 doesn’t work try setting up the application in IIS.

Update:
James Hippolite from telecom was so kind to blog most of the bullet points of my slides. Which can be found here http://tvornz.spaces.live.com/blog/cns!A93B6100E328706D!388.entry?_c=BlogPart&_c02_owner=1

11DecDevExpress is giving away their controls

DevExpress is giving away 40 controls for free. The only thing you need to do is register on their site and you’ll get an email with the controls.

Over 40 Controls – Free of Charge

05DecMicrosoft is listening after all

Well today has been an interesting day.  I signed up for a day of presentations on user experience, which is something that can always improve. Turns out it are a bunch of presentations on Microsoft Expression (I guess in some ways that has to do with user experience )It’s not something I personally will be using as it is more designer focussed and I use visual studio for all my development and web design.

Over the last couple of months or so I have been sensing that Microsoft isn’t what they used to be and I’m not the only one that is inclined to think that way

Mostly because I’m currently working as a sole developer in my own company I feel very much left out by them.

Most of the issues I have is to quickly develop something, where I am in full control of what happens, is not something that is easily done in asp.net.  (For more on reasons why I like castle vs asp.net webforms : Am I too late, A bit further down the castle track

 

Back to the original story
Those presentations didn’t really hold value for me but I got into a conversation with 2 microsoft employees that were there with the goal of finding out why people like me are moving to rails and what microsoft isn’t giving us and they should.

My main points of discomfort would be:

Feeling of not being in control

Complexity to get it to render out pages

Slow development pass (might be ok if you’re a giant company in which people actually hold meetings and have managers but not in my case). I’m all about agile (not to be confused with the TFS agile method) development. Plan, build, ship within 2 months would be average.

Need to know a page lifecycle (which is statefull programming in a stateless environment, need i say more)

Complexity to get things done

No proper sample code available that shows something beyond “Hello world”

Anyway we had this interesting talk about it, now it’s again a case of waiting to see if they can make a change before the new year to keep me interested.

While I’m on the subject. Next week will be the week in which I’ll try to build my first RoR site. I’m pretty confident that it will work out and then i can finally assess myself which one is better for what.

Ok I’m off to buy Agile webdevelopment with ruby now

07NovBoo, Ironpython, Scriptaculous, MS Ajax and me

Over the weekend I got the idea of learning ironpython by moving the codebase that I have for nblogr to ironpython script and compiling it.

Everything went fine until I had to decorate a method to make it cache/participate in a transaction/set a layout on a controller because ironpython in all its beauty doesn’t support attributes on methods or classes.

I’m also missing a reference for ironpython. Something that shows the available functions and the syntax for inheritance etc.  which slowed me down of course.

Why do I want a dynamic language ?

The 2 main reasons are : Duck typing and readable anonymous functions.  In c# there is the concept of anonymous delegates but that code really looks like it has been hit by a train, ugly.

I’ve been writing in boo for a while now just as a templating language and yes I like boo a lot.  It combines the nice features of python with the c# language in a wrist friendly way. (I never got the point of wrist friendly thing until I got carpal tunnel syndrome, now it suddenly is a major issue)

I sure wish there would be a language service for visual studio to do boo development but I’ve been using sharp develop 2.1 to check it out.

SharpDevelop 2.1 is a nice piece of work definitely for an open source IDE’, it beats eclipse in my book

In boo everything is an object also your functions and expressions (read it has anonymous functions).  Boo is strong typed but mimics duck typing in some form.

To conclude this little intermezzo : my next project will be written in boo :)

On the ajax library front I would have to report that I haven ‘t looked at atlas/ms ajax since the beginning of september . I had decided to use it again when they finally release the framework.  So I’ve been checking out these other libraries that are out there.  I checked out jquery which is a cool library but it is also slower in execution than the other ones.

The next one on the list was scriptaculous and that is the one I’ve been using in my projects now.  Scriptaculous does exactly what is expected and uses the javascript prototype model which happens to be one i like :)

The move from the guys at MS to make their ajax extensions based on prototype was surprising but very positive in my book :) So when they release it i’ll look at creating an javascript provider for nblogr so that you would be able to switch between your favourite library (we have plans to support the major libraries out of the  box.) 

del.icio.us tags: , , ,

14OctRedirecting based on a role in the loggedin event of the login control

Today I had to fix a website that is built by the guys over in Russia. Completely asp.net no castle involved whatsoever. There is not even an O/R mapper in the application.

Real basic stuff. Sql datasource gridview/formview type of things.

The client asked me to do redirect their site to certain pages depending on which role the user is in.

Cool. Let’s handle the LoggedIn event of the Login control. This is what I started of with. Makes perfect sense to me that that should work.

    protected void Login1_LoggedIn(object sender, EventArgs e)

    {

        if (Roles.IsUserInRole(“School”))

            Response.Redirect(string.Format(“~/Career/School.aspx?ID={0}”, CareerUser.GetUserTypeId(Membership.GetUser().ProviderUserKey)));

        if (Roles.IsUserInRole(“Student”))

            Response.Redirect(string.Format(“~/Career/Student.aspx?ID={0}”, CareerUser.GetUserTypeId(Membership.GetUser().ProviderUserKey)));

        else

            Response.Redirect(“~/Login.aspx”);

    }

Now as expected that didn’t do the trick. But this does

    protected void Login1_LoggedIn(object sender, EventArgs e)

    {

        /*I have to do it this way because there is no cookie set yet so Membership.GetUser() returns an empty object.

        * The same goes for the roles. No cookie means no data for the standard function.

        */

        Login login = sender as Login;

        Guid userObjectKey = (Guid)Membership.GetUser(login.UserName).ProviderUserKey;

        Guid userId = CareerUser.GetUserTypeId(login.UserName, userObjectKey);

        if (Roles.IsUserInRole(login.UserName, “School”))

            Response.Redirect(string.Format(“~/Career/School.aspx?ID={0}”, userId));

        if (Roles.IsUserInRole(login.UserName, “Student”))

            Response.Redirect(string.Format(“~/Career/Student.aspx?ID={0}”, userId));

        else

            Response.Redirect(“~/Login.aspx”);

    }

Just thought I’d share this for other people that have this problem.

Anyway this is wtf numero 10 today. And I haven’t had these moments in the last couple of weeks, using castle and all, so I was feeling a little nostalgic about the whole thing.

01SepFileUploading for NBlogr

To upload files in nblogr. I wanted the user to have the possibility to upload as many files as they wanted but only show one file element.

The upload procedure has to work without reloading the page entirely but there is no way of getting the size or the bytes of a file through the html input file control from clientscript without popping up a security warning.
And what do I personally think about security warnings : they are a necessary evil but limit you a lot in the development of contemporary sites with rich client interaction.
If I am to present a site to my parents and they have to figure stuff out themselves I’m pretty sure that once the read the words : Security warning, Potential risk etc… they will click no ==> site doesn’t work ==> site == crap

I wanted to include an upload with progress bar but decided to let that idea go and just give an implementation of a multiple file upload with a single inputelement. Maybe I will put this in during the next iteration. That way I can probably release a ctp this weekend and start thinking about a plugin architecture (thanks for the idea JD)

Because of the file issues i have to run it in an iframe :-s and have the page and the frame talk to eachother.

31AugObjectdatasource, gridview and custom paging

I’ve spent the last couple of hours trying to work something out that boggled my mind.

I have a base4 class that I wrapped in a Dataobject in my Businesslayer.

On my page (actually in a user control) i have a gridview that binds to an object datasource and stores the list of retrieved values in the viewstate. The business object is paged server side and supports sorting.

The business object looks at it’s simplest like this :

There are 2 methods for every retrieval function. the first method is the method that fetches the list of data to display and the second method just gives the full row count. There are 2 methods because their signatures need to be the same.

What i then did was handle the objectSelected event of the object datasource and pass the e.ReturnValue to a property of my control that stores the list in viewstate.
When i select something in the gridview I always got an exception thrown telling me that the variable in viewstate was null.

After a lot of debugging sessions (in a solution that takes about 10 minutes or a little longer to build) I found out that i get a value in the viewstate but then lost it again in the same operation.

And that’s when it hit me. The object datasource selected event gets also fired for the count method and empties the viewstate. So now I have a second round trip to my database to stick the values in the viewstate and everything works.

So if anybody comes across a similar problem this is how i got around it.
I do realize the importance of caching ;)

The objectdatasource definition:

“ObjectDataSource1″ runat=“server” DataObjectTypeName=“Smap.Data.Contact”
EnablePaging=“True” MaximumRowsParameterName=“pageSize” OldValuesParameterFormatString=“original_{0}”
SelectCountMethod=“GetByCompanyNameCount” SelectMethod=“GetByCompanyName” SortParameterName=“sortExpression”
TypeName=“Smap.Businesslogic.Contacts.ContactSource” EnableViewState=“true” OnSelected=“ObjectDataSource1_Selected”>

“SearchList” Name=“searchString” PropertyName=“Text”
Type=“String” />
“sortExpression” Type=“String” />
“startRowIndex” Type=“Int32″ />
“pageSize” Type=“Int32″ />

And the objectdatasource selected event :

    protectedvoid ObjectDataSource1_Selected(object sender, ObjectDataSourceStatusEventArgs e)

    {

        if (e.OutputParameters.Keys.Count > 0)

        {

            foreach (object key in e.OutputParameters.Keys)

            {

                Response.Write(string.Format(“Key: {0}, Value: {1}, Type: {2}
,key,e.OutputParameters[key],e.OutputParameters[key].GetType()));

            }

        }

        Contacts = source.GetByCompanyNameByPage(SearchList.Text, gvContacts.SortExpression, gvContacts.PageIndex, gvContacts.PageSize) asItemList<Contact>;

    }




The business object :

using System;

using System.Collections.Generic;

using System.Text;

using System.ComponentModel;

using Smap.Data;

using Base4.Storage;

 

namespace Smap.Businesslogic.Contacts

{

    [DataObject]

    publicclassContactSource

    {

        [DataObjectMethod(DataObjectMethodType.Select,true)]

        publicIItemListContact> GetByCompanyName(string searchString, string sortExpression, int startRowIndex, int pageSize)

        {

            //Set the default sortexpression is none is provided.

            if (string.IsNullOrEmpty(sortExpression))

                sortExpression = “CompanyName”;

 

            //The objectdatasource returns the index of the first row that is to be retrieved

            //Base4 needs the page number

            int pageNumber = getPageNumber(startRowIndex, pageSize);

 

            //initialise the object path with the sort expression

            ObjectPath path = initialiseObjectPath(sortExpression);

 

            //Add our parameter

            path.New(“CompanyName”).LIKE(string.Format(“%{0}%”, searchString));

 

            //Tell base4 which pages that need to be retrieved.

            path.PageNumber = pageNumber;

            path.PageSize = pageSize;

 

            //Return our list to the object datasource

            returnStorageContext.FindContact>(path);

        }

 

        [DataObjectMethod(DataObjectMethodType.Select, true)]

        publicIItemListContact> GetByCompanyNameByPage(string searchString, string sortExpression, int pageNumber, int pageSize)

        {

            //Set the default sortexpression is none is provided.

            if (string.IsNullOrEmpty(sortExpression))

                sortExpression = “CompanyName”;

 

            //initialise the object path with the sort expression

            ObjectPath path = initialiseObjectPath(sortExpression);

 

            //Add our parameter

            path.New(“CompanyName”).LIKE(string.Format(“%{0}%”, searchString));

 

            //Tell base4 which pages that need to be retrieved and their length.

            //The gridview returns the page index which is zero-based, base4 asks for a page number which starts at 1.

            path.PageNumber = ++pageNumber;

            path.PageSize = pageSize;

            returnStorageContext.FindContact>(path);

        }

 

 

        publicint GetByCompanyNameCount(string searchString, string sortExpression, int startRowIndex, int pageSize)

        {

            //Gets the count of all the contacts.

            returnStorageContext.FindAllContact>().Count;

        }

 

 

        privateObjectPath initialiseObjectPath(string sortExpression)

        {

            ObjectPath path = newObjectPath();

            if (sortExpression.Trim().Length > 0)

            {

                string[] sortParams = sortExpression.Split(“,”.ToCharArray());

 

                foreach (string s in sortParams)

                {

                    OrderByDirection direction = s.IndexOf(“DESC”) > -1 ? OrderByDirection.Descending : OrderByDirection.Ascending;

 

                    string orderby = s.Substring(0, s.IndexOf(“DESC”) > -1 ? s.IndexOf(“DESC”) : s.Length);

 

 

                    path.AddOrderBy(orderby, direction);

                }

            }

 

            return path;

        }

 

        privateint getPageNumber(int startRowIndex, int pageSize)

        {

            //if the start index is smaller than 0 return 0 otherwise return the index of the current page.

            int number = startRowIndex <= 0 ? 0 : (int)Math.Ceiling(Convert.ToDouble(startRowIndex / pageSize));

 

            //make our zero-based index into a number starting at 1;

            return ++number;

        }

 

    }

}

29AugA generic builder for unit tests

I’ve been using base4 quite a lot lately :) . And obviously I like it. But anyway for unit testing i found myself writing
virtually the same builder class over and over again.

And since it is just test data that needs to be removed later it is always
very similar. I started thinking about my problem and came to the conclusion
that I could easily enough build a generic class that iterates over the object
and takes all the properties that belong to that type and not to any of the
parent types and fill them with valid data for their returntype.

I got to work and not so long after that I came up with the following class:

using System;

using System.Collections.Generic;

using System.Text;

using Base4.Storage;

 

namespace NBlogr.NUnitTests.HelperClasses

{

    publicclassBuilder where T : class,IItem,new()

    {

        privateList items;

 

        publicList Items

        {

            get

            {

                if (items == null) items = newList();

                return items;

            }

            set { items = value; }

        }

 

        publicvirtual T Add()

        {

            return Add(null);

        }

 

        public T Add(int? index)

        {

            T t = new T();

            return Add(t, index, true);

        }

 

        publicvirtual T Add(T t, int? index, bool generateValues)

        {

            IItem item = t;

            if (generateValues)

            {

                foreach (PropertyImpl p in item.TypeDefinition.Properties)

                {

                    switch (p.ReturnTypeName)

                    {

                        case“bool”:

                        case“Boolean”:

                        case“System.Boolean”:

                            item[p.Name] = index.HasValue;

                            break;

                        case“string”:

                        case“String”:

                        case“System.String”:

                            if (index.HasValue)

                                item[p.Name] = string.Format(“Unittest {0} {1}”, item.TypeDefinition.Name, index);

                            else

                                item[p.Name] = string.Format(“Unittest {0}”, item.TypeDefinition.Name);

                            break;

                        case“uint”:

                        case“short”:

                        case“int”:

                        case“long”:

                        case“Int16″:

                        case“Int32″:

                        case“Int64″:

                        case“System.Int16″:

                        case“System.Int32″:

                        case“System.Int64″:

                            item[p.Name] = index.HasValue ? index.Value : newRandom().Next();

                            break;

                        case“byte”:

                        case“Byte”:

                        case“System.Byte”:

                            item[p.Name] = index.HasValue ? Convert.ToByte(index.Value) : newbyte();

                            break;

 

                        case“double”:

                        case“Double”:

                        case“System.Double”:

                            item[p.Name] = index.HasValue ? Convert.ToDouble(index.Value) : newRandom().NextDouble();

                            break;

 

                        case“byte[]“:

                        case“Byte[]“:

                        case“System.Byte[]“:

                            Byte[] bytes = newbyte[128];

                            Random rnd = newRandom();

                            rnd.NextBytes(bytes);

                            item[p.Name] = bytes;

                            break;

 

                        case“Guid”:

                        case“System.Guid”:

                            item[p.Name] = Guid.NewGuid();

                            break;

                    }

                }

            }

            item.Save();

 

            items.Add((T)item);

 

            return item as T;

        }

 

        publicvoid BuildList()

        {

            BuildList(5);

        }

 

        publicvoid BuildList(int length)

        {

            if (items == null) items = newList();

 

            for (int i = 0; i < length; i++)

            {

                int index = i + 1;

 

                Add(index);

            }

 

        }

 

        publicvoid CleanUp()

        {

            if (items != null && items.Count> 0)

            {

                foreach (IItem item in items)

                {

                    item.Delete();

 

                }

            }

        }

    }

}

24AugAptana for writing atlas script

I write quite a lot of javascript code these days and have been looking for a couple of months for ways to make my life easier.

Easier would mean in my opinion to get some kind of intellisense or autocomplete while writing javascript.

As it turns out in visual studio orcas these features will be available so I’ll be a very happy vs orcas user i guess :) .  But in the meantime there is a free eclipse based IDE around aptana that let’s you take advantage of autocomplete etc.

I added the atlas debug files to the default code profile and I was in business.


Recent Flickrs

    Blogroll

    Recent Listening

    Scrobbler