» tagged pages
» logout

(Feed found, click Add Page to syndicate.) Error finding feed, please try again » Find feed title

A Blog Page allows you to add entries, for news or other time sensitive postings

(Login required to save to your tagged pages.)
(or Cancel)

Make further edits, (or Cancel)

(Login required to save to your tagged pages.)
(or Cancel)

(Editing anonymously: to be credited for your changes, login or register a new account)

Change Page Permissions? Changing these permissions will adjust who can modify this page.

alex (change)
Swik Users (change)
(or Cancel)
Upload an image from your computer:
or Copy an image from a URL:
or Erase the current icon:
Icon Preview:

or Cancel

Erase .NET? The contents of .NET page and all pages directly attached to .NET will be erased.

or Cancel

(Editing anonymously: to be credited for your changes, login or register a new account)

other page actions:
.NET

.NET

Tags Applied to .NET

2 people have tagged this page:

.NET Wiki Pages

.NET is a proprietary framework from Microsoft – it consists of both a large class library and a runtime environment called the Common Language Runtime.

Open source

Open-source implementations include Mono and dotGNU.

sorted by: recent | see : popular
Content Tagged .NET

JSON services in ASP.NET Ajax

Lately the use of client centric development model in .NET is getting increasingly popular.

json: del.icio.us/tag/json

SourceForge.net: .NET memcached client library

C#/.NET memcached client library. This library can be used by .NET projects to access memcached servers. Ported from the Java memcached library located at http://www.whalin.com/memcached/.

opensource: del.icio.us tag/opensource

Using Gridview to display Images from Database

In ASP.Net 1.x days Datagrid is one of the most common control that is used to display a table of data. With the introduction of ASP.Net 2.0 we have Gridview in the place of Datagrid while the Datagrid control is still supported. With the introduction of Gridview we can prevent some of the standard code we will repeat for edit, update, delete, sort etc

technology: dzone.com: tech links

ASP.NET AJAX Best Practices

While we develop AJAX applications, we often carelessly ignore giving up bad practices, which cause effects which are not so significantly visible when the site is not so large in volume. But, it’s often severe performance issue when it is the case for sites that make heavy use of AJAX technologies such as Pageflakes, NetVibes etc.

technology: dzone.com: tech links

SecureString in .Net 2.0

There are some disadvantages in using string if we want to store some important information’s like password, credit card numbers, bank pins, etc for some manipulations. The following list will help you understand it better.

technology: dzone.com: tech links

C# Dictionary Basics

Learn how to use the Dictionary collection object in C#.

technology: dzone.com: tech links

Asynchronous Execution in Silverlight, GWT and Javascript

When Rich Internet Applications reach a certain level of complexity, you start having concurrency problems similar, but not identical, to the problems with multiple threads -- the root cause is that http request callbacks and user interface events can come in an arbitrary order. This article works out an example that explains how this happens, as understanding the nature of asynchronous communication is the first step towards developing reliable apps.

technology: dzone.com: tech links

ASP.NET Validation Controls – Important Points, Tips and Tricks

ASP.NET validation controls provide an easy-to-use but powerful mechanism of ensuring that data is entered correctly on the forms. There are 6 validation controls included in the ASP.NET 2.0 and ASP.NET 3.5 versions.In this article, let us see some tips and tricks that can be applied to the validation controls.

technology: dzone.com: tech links

Exception Handling - Do's and Dont's

Exceptions provide a consistent mechanism for identifying and responding to error conditions. Effective exception handling will make code more robust and easier to debug. Exceptions are a tremendous debugging aid because they help answer:

technology: dzone.com: tech links

MVC Storefront, Part 9: The Shopping Cart

In this episode I dive into implementing the Shopping Cart in a basic way so I can run a spike to make sure my pattern can push data nicely back into the DB without problems

technology: dzone.com: tech links

So long Borland.. it has been a true rollercoaster ride with lots of fun on the way!

What does the future bring for the sell of CodeGear to Embarcadero? My take on it.

technology: dzone.com: tech links

BlogEngine.NET - DAL Architecture

So as I wrote a few days ago I have been looking at BlogEngine.NET and considered how I would have designed its lower layers. So lets kick off with the provider that's currently used in BlogEngine.NET for accessing the various storages (XML and RDBMS). The provider is responsible for accessing all data, that is Pages, Categories, Posts etc. Furthermore for each of these types of data it is responsible for the structure of the storage location, transforming the data from storage to objects including loading of related data. In my book this isn't good for extensibility, and as BlogEngine.NET provides multiple point for extending its functionality I would argue that it should be possible to extend its storage mechanism to handle new types of data just as easily. Currently extending the data access would involve adding new members to the provider and its implementations.

So to solve this problem (and a few others I will address shortly) my suggestion would be to make data access classes responsible for a single type only, these can share some common functionality that deals with the structure of the storage when we talk about the XML provider. So basically we want to specify how these classes should look, the most generic approach is represented by this interface.

public interface IRepository<T>
{
    //Retrieval
    T Load(Guid identifier);
    IList<T> LoadAll();

    //Modification
    void Save(T instance);
    void Delete(T instance);
    void Delete(Guid identifier);
}

I have made the assumption here that all data has a Guid identifier, of course this could be handled so that we are free to choose the type of our identifier. But for know im satisfied with the Guid-identifier

Instead of implementing our repositories right away we can abstract common details for storage types away in abstract classes. This way the implementation of our actual repositories are as slim as possible. I have (based on the way XML is stored in BlogEngine.NET) chosen two different storage types for XML and implemented the abstract classes SingleFileRepository<T> and SingleFolderRepository<T>. The first one handles storage of data types where all instances are in a single XML file, the second one handles storage of data types where each instance has its own XML file all contained in a folder. So the basic responsibility of these two classes is to handle details of the storage, that is the structure on disk and the structure in the files. Let me remind you that these abstract classes are only for simplifying the implementation of the actual repositories, if development later requires changing minor details we can override or even change the implementations on these, and if we want to start from scratch without the assumptions build into these abstract classes we can implement IRepository<T> any way we would like. This gives great flexibility in how different data is stored and the opportunity for code reusability is very much still there.

Lets take a look at the code for SingleFolderRepository:

public abstract class SingleFolderRepository<T> : IRepository<T> where T : class, IEntity
{
    protected readonly IBlogSettings settings;
    protected readonly IObjectXmlConverter<T> converter;
    protected readonly string storagelocation;

    public SingleFolderRepository(IBlogSettings settings, IObjectXmlConverter<T> converter)
    {
        this.settings = settings;
        this.converter = converter;
        this.storagelocation = settings.StorageLocationFor(typeof (T));
    }

    public T Load(Guid identifier)
    {
        string path = Path.Combine(storagelocation, identifier + ".xml");
        FileInfo datafile = new FileInfo(path);
        if (datafile.Exists)
        {
            return converter.Build(GetXml(datafile));
        }
        return null;
    }

    private string GetXml(FileInfo datafile)
    {
        string xml = string.Empty;
        using (StreamReader sr = new StreamReader(datafile.Open(FileMode.Open, FileAccess.Read, FileShare.Read)))
        {
            xml = sr.ReadToEnd();
        }
        return xml;
    }

    public IList<T> LoadAll()
    {
        List<T> instances = new List<T>();
        DirectoryInfo datadirectory = new DirectoryInfo(storagelocation);
        if (datadirectory.Exists)
        {
            foreach (FileInfo datafile in datadirectory.GetFiles("*.xml"))
            {
                instances.Add(converter.Build(GetXml(datafile)));
            }
        }
        return instances;
    }

    public void Save(T instance)
    {
        if (converter.IsNew(instance))
        {
            instance.Identifier = Guid.NewGuid();
        }

        string path = Path.Combine(storagelocation, instance.Identifier + ".xml");
        using (FileStream fs = File.Open(path, FileMode.Create, FileAccess.Write, FileShare.None))
        {
            using (StreamWriter writer = new StreamWriter(fs))
            {
                writer.Write(converter.Flatten(instance));
                writer.Flush();
            }
        }
    }

    public void Delete(T instance)
    {
        Delete(instance.Identifier);
    }

    public void Delete(Guid identifier)
    {
        string path = Path.Combine(storagelocation, identifier + ".xml");
        File.Delete(path);
    }
}

So notice the constructor. The dependencies that this class has is passed into the contructor so before we can use the repository we need settings for the blog and an IObjectXmlConverter for the type that the repository handles. The IObjectXmlConverter handles flattening of objects to XML and building objects from XML. Below is an example an implementation of this.

public class CategoryConverter : IObjectXmlConverter<Category>
{
    public Category Build(string xml)
    {
        XmlDocument doc = new XmlDocument();
        doc.LoadXml(xml);
        Category c = new Category();
        c.Identifier = new Guid(doc.SelectSingleNode("/category/").Attributes["id"].InnerText);
        c.Name = doc.SelectSingleNode("/category/").InnerText;
        return c;
    }

    public string Flatten(Category instance)
    {
        return
            XmlOutput.Create().XmlDeclaration()
                .Node("category")
                .Attribute("id", instance.Identifier.ToString())
                .InnerText(instance.Name).GetOuterXml();
    }
}

So this is where the mapping between the datastore and the objects happen, of course error handling should be in place here if we expect missing values in the data we load.

With this change in structure presented above we have seperated concerns of the data access into smaller reusable components, furthermore in my book this makes the code easier to extend and understand but thats a subjective matter.

So now its time to specify the actual repositories, we could settle for the functionality present on our generic IRepository but often we want more specific functionality for each datatype for instance fetching all posts in a specific category, paging of posts and so forth. So for each data type we define an interface with its actions. Currently in BlogEngine.NET much of this functionality is done in various places for instance sorting, filtering and paging. I would like to have our repositories responsible for this because the most efficient way to do these things depends on the type of storage. That is paging would for instance be done different for XML storage and RDBMS storage.

So as an example we could make our repository for posts have an interface like this:

public interface IPostRepository : IRepository<Post>
{
    PageableList<Post> GetPage(int pagesize, int pagenum);
    PageableList<Post> GetPageInCategory(int category, int pagesize, int pagenum);
    PageableList<Post> GetPageWithTag(int tag, int pagesize, int pagenum);
    PageableList<Post> GetPageFromMonth(int month, int year, int pagesize, int pagenum);
}

Notice that we might need more methods, but this illustrates some examples on how we let the repository handle paging so it can optimize it based on the data storage.

The actual implementation in the XML storage can be optimized but for now we load all data and do it in memory like BlogEngine.NET currently does. (I will discuss caching in a later post)

The form and responsibility of our repositories is now pretty clear. You might have noticed that I have passed classes dependencies through their constructor. To avoid having to construct these dependencies myself I will use an Inversion of Control container that manages these dependencies for me. Furthermore configuration of the IoC container is what helps use interchange the repositiores for XML and RDBMS.

tag4sree: Detached objects in nHibernate and Lazy loading

Small challenge: call method on null

Inspired by some talk I "overheard" on twitter I thought it would be interesting to post a small challenge. Is it possible to implement the missing parts of the following code so it compiles and runs without exceptions, if yes how would you do it? You are not allowed to modify the body of the Main method but the rest is up to you.

static void Main(string[] args)
{
    Foo f = null;
    f.Bar();
}

And yes its a pretty useless exercise :-)

tag4sree: Detached objects in nHibernate and Lazy loading

BlogEngine.NET - DAL Architecture

So as I wrote a few days ago I have been looking at BlogEngine.NET and considered how I would have designed its lower layers. So lets kick off with the provider that's currently used in BlogEngine.NET for accessing the various storages (XML and RDBMS). The provider is responsible for accessing all data, that is Pages, Categories, Posts etc. Furthermore for each of these types of data it is responsible for the structure of the storage location, transforming the data from storage to objects including loading of related data. In my book this isn't good for extensibility, and as BlogEngine.NET provides multiple point for extending its functionality I would argue that it should be possible to extend its storage mechanism to handle new types of data just as easily. Currently extending the data access would involve adding new members to the provider and its implementations.

So to solve this problem (and a few others I will address shortly) my suggestion would be to make data access classes responsible for a single type only, these can share some common functionality that deals with the structure of the storage when we talk about the XML provider. So basically we want to specify how these classes should look, the most generic approach is represented by this interface.

public interface IRepository<T>
{
    //Retrieval
    T Load(Guid identifier);
    IList<T> LoadAll();

    //Modification
    void Save(T instance);
    void Delete(T instance);
    void Delete(Guid identifier);
}

I have made the assumption here that all data has a Guid identifier, of course this could be handled so that we are free to choose the type of our identifier. But for know im satisfied with the Guid-identifier

Instead of implementing our repositories right away we can abstract common details for storage types away in abstract classes. This way the implementation of our actual repositories are as slim as possible. I have (based on the way XML is stored in BlogEngine.NET) chosen two different storage types for XML and implemented the abstract classes SingleFileRepository<T> and SingleFolderRepository<T>. The first one handles storage of data types where all instances are in a single XML file, the second one handles storage of data types where each instance has its own XML file all contained in a folder. So the basic responsibility of these two classes is to handle details of the storage, that is the structure on disk and the structure in the files. Let me remind you that these abstract classes are only for simplifying the implementation of the actual repositories, if development later requires changing minor details we can override or even change the implementations on these, and if we want to start from scratch without the assumptions build into these abstract classes we can implement IRepository<T> any way we would like. This gives great flexibility in how different data is stored and the opportunity for code reusability is very much still there.

Lets take a look at the code for SingleFolderRepository:

public abstract class SingleFolderRepository<T> : IRepository<T> where T : class, IEntity
{
    protected readonly IBlogSettings settings;
    protected readonly IObjectXmlConverter<T> converter;
    protected readonly string storagelocation;

    public SingleFolderRepository(IBlogSettings settings, IObjectXmlConverter<T> converter)
    {
        this.settings = settings;
        this.converter = converter;
        this.storagelocation = settings.StorageLocationFor(typeof (T));
    }

    public T Load(Guid identifier)
    {
        string path = Path.Combine(storagelocation, identifier + ".xml");
        FileInfo datafile = new FileInfo(path);
        if (datafile.Exists)
        {
            return converter.Build(GetXml(datafile));
        }
        return null;
    }

    private string GetXml(FileInfo datafile)
    {
        string xml = string.Empty;
        using (StreamReader sr = new StreamReader(datafile.Open(FileMode.Open, FileAccess.Read, FileShare.Read)))
        {
            xml = sr.ReadToEnd();
        }
        return xml;
    }

    public IList<T> LoadAll()
    {
        List<T> instances = new List<T>();
        DirectoryInfo datadirectory = new DirectoryInfo(storagelocation);
        if (datadirectory.Exists)
        {
            foreach (FileInfo datafile in datadirectory.GetFiles("*.xml"))
            {
                instances.Add(converter.Build(GetXml(datafile)));
            }
        }
        return instances;
    }

    public void Save(T instance)
    {
        if (converter.IsNew(instance))
        {
            instance.Identifier = Guid.NewGuid();
        }

        string path = Path.Combine(storagelocation, instance.Identifier + ".xml");
        using (FileStream fs = File.Open(path, FileMode.Create, FileAccess.Write, FileShare.None))
        {
            using (StreamWriter writer = new StreamWriter(fs))
            {
                writer.Write(converter.Flatten(instance));
                writer.Flush();
            }
        }
    }

    public void Delete(T instance)
    {
        Delete(instance.Identifier);
    }

    public void Delete(Guid identifier)
    {
        string path = Path.Combine(storagelocation, identifier + ".xml");
        File.Delete(path);
    }
}

So notice the constructor. The dependencies that this class has is passed into the contructor so before we can use the repository we need settings for the blog and an IObjectXmlConverter for the type that the repository handles. The IObjectXmlConverter handles flattening of objects to XML and building objects from XML. Below is an example an implementation of this.

public class CategoryConverter : IObjectXmlConverter<Category>
{
    public Category Build(string xml)
    {
        XmlDocument doc = new XmlDocument();
        doc.LoadXml(xml);
        Category c = new Category();
        c.Identifier = new Guid(doc.SelectSingleNode("/category/").Attributes["id"].InnerText);
        c.Name = doc.SelectSingleNode("/category/").InnerText;
        return c;
    }

    public string Flatten(Category instance)
    {
        return
            XmlOutput.Create().XmlDeclaration()
                .Node("category")
                .Attribute("id", instance.Identifier.ToString())
                .InnerText(instance.Name).GetOuterXml();
    }
}

So this is where the mapping between the datastore and the objects happen, of course error handling should be in place here if we expect missing values in the data we load.

With this change in structure presented above we have seperated concerns of the data access into smaller reusable components, furthermore in my book this makes the code easier to extend and understand but thats a subjective matter.

So now its time to specify the actual repositories, we could settle for the functionality present on our generic IRepository but often we want more specific functionality for each datatype for instance fetching all posts in a specific category, paging of posts and so forth. So for each data type we define an interface with its actions. Currently in BlogEngine.NET much of this functionality is done in various places for instance sorting, filtering and paging. I would like to have our repositories responsible for this because the most efficient way to do these things depends on the type of storage. That is paging would for instance be done different for XML storage and RDBMS storage.

So as an example we could make our repository for posts have an interface like this:

public interface IPostRepository : IRepository<Post>
{
    PageableList<Post> GetPage(int pagesize, int pagenum);
    PageableList<Post> GetPageInCategory(int category, int pagesize, int pagenum);
    PageableList<Post> GetPageWithTag(int tag, int pagesize, int pagenum);
    PageableList<Post> GetPageFromMonth(int month, int year, int pagesize, int pagenum);
}

Notice that we might need more methods, but this illustrates some examples on how we let the repository handle paging so it can optimize it based on the data storage.

The actual implementation in the XML storage can be optimized but for now we load all data and do it in memory like BlogEngine.NET currently does. (I will discuss caching in a later post)

The form and responsibility of our repositories is now pretty clear. You might have noticed that I have passed classes dependencies through their constructor. To avoid having to construct these dependencies myself I will use an Inversion of Control container that manages these dependencies for me. Furthermore configuration of the IoC container is what helps use interchange the repositiores for XML and RDBMS.

tag4sree: Hibernate - Objects

Page 1 | Next >>
Username:
Password:
(or Cancel)