Monday, October 13, 2008

Mono 2.0 is a portable and open source implementation of the .NET framework for Unix, Windows, MacOS and other operating systems.

What is Mono?
Mono is a software platform designed to allow developers to easily create cross platform applications. It is an open source implementation of Microsoft's .Net Framework based on the ECMA standards for C# and the Common Language Runtime.
According to Novell: "We feel that by embracing a successful, standardized software platform, we can lower the barriers to producing great applications for Linux".

The components that make up Mono are:
C# Compiler - The C# compiler is feature complete for compiling C# 1.0 and 2.0 (ECMA), and also contains many of the C# 3.0 features.
Mono Runtime - The runtime implements the ECMA Common Language Infrastructure (CLI). The runtime provides a Just-in-Time (JIT) compiler, an Ahead-of-Time compiler (AOT), a library loader, the garbage collector, a threading system and interoperability functionality.
Base Class Library - The Mono platform provides a comprehensive set of classes that provide a solid foundation to build applications on. These classes are compatible with Microsoft's .Net Framework classes.
Mono Class Library - Mono also provides many classes that go above and beyond the Base Class Library provided by Microsoft. These provide additional functionality that are useful, especially in building Linux applications. Some examples are classes for Gtk+, Zip files, LDAP, OpenGL, Cairo, POSIX, etc.

The benefits are:
Popularity - Built on the success of .Net, there are millions of developers that have experience building applications in C#. There are also tens of thousands of books, websites, tutorials, and example source code to help with any imaginable problem.
Higher-Level Programming - All Mono languages benefit from many features of the runtime, like automatic memory management, reflection, generics, and threading. These features allow you to concentrate on writing your application instead of writing system infrastructure code.
Base Class Library - Having a comprehensive class library provides thousands of built in classes to increase productivity. Need socket code or a hashtable? There's no need to write your own as it's built into the platform.
Cross Platform - Mono is built to be cross platform. Mono runs on Linux, Microsoft Windows, Mac OS X, BSD, and Sun Solaris, Nintendo Wii, Apple iPhone. It also runs on x86, x86-64, IA64, PowerPC, SPARC (32), ARM, Alpha, s390, s390x (32 and 64 bits) and more. Developing your application with Mono allows you to run on nearly any computer in existance (details).
Common Language Runtime (CLR) - The CLR allows you to choose the programming language you like best to work with, and it can interoperate with code written in any other CLR language. For example, you can write a class in C#, inherit from it in VB.Net, and use it in Eiffel. You can choose to write code in Mono in a variety of programming languages.

In order to view the Mono 2.0 Release Notes click here.

C# | Code | Other
Posted by: Eran Nachum (c)
Post Date: 10/13/2008 8:57:49 AM (Jerusalem Standard Time, UTC+02:00)
Disclaimer | | Trackback   #
 Sunday, March 16, 2008

Hi,

Great post that gathers around 100+ resources that could make the web developer life much more easier; code snippets, sites that automate processes, cheat sheets and more and more...

This priceless list is listed here.

BTW, don't become confused from the first image - I also know that this is not a common vision in our world of code... ;)

Posted by: Eran Nachum (c)
Post Date: 3/16/2008 3:35:27 PM (Jerusalem Standard Time, UTC+02:00)
Disclaimer | | Trackback   #
 Wednesday, February 06, 2008

I read a great article about performance and scalability. Some of the issues there were helped me a lot and the rest were sharpen my knowledge.

So, if you are an ASP.NET developer (beginner or senior), It is recommended for you to read that one by Omar Al Zabir at the codeproject site here.

Some if the things that he talks about are: ASP.NET pipeline optimization, Things you must do for ASP.NET before going live, Caching AJAX calls on browse and more...

Worth a reading...

Posted by: Eran Nachum (c)
Post Date: 2/6/2008 5:08:10 PM (Jerusalem Standard Time, UTC+02:00)
Disclaimer | | Trackback   #
 Thursday, January 10, 2008

Is Google is so kind or what? One more great tool and FREE of course that leashed by Google is the Google Chart API.

By their introduction, The Google Chart API returns a PNG-format image in response to a URL. Several types of image can be generated: line, bar, and pie charts for example. For each image type you can specify attributes such as size, colors, and labels.

If you want to generate charts, graphs, pies etc. this is a great tool for you - the web developer. This tool gives a good fight to all other charts generator like .NET Charting for example and other unwanted ActiveXs modules that need to be installed on the client (we always want to avoid this action - at least me), because it is FREE and also because it is Google.

So I already generated myself:

chart

You can find it here.

Code | HTML | Other
Posted by: Eran Nachum (c)
Post Date: 1/10/2008 7:47:56 PM (Jerusalem Standard Time, UTC+02:00)
Disclaimer | | Trackback   #
 Sunday, January 06, 2008

First a small introduction to the HTML 5 introduction; If you are wondering why I didn't published during the last 2 weeks, the reason is a great vacation in New York - in one simple word - Insane. (pics will be delivered on the following days).

Now to our topic - HTML 5. We all used to (and still) work and know greatly HTML 4 - which actually is exists something like a decade, but HTML 5 is stands in front of us (but is still to come - the work is still on progress according W3C) and comes to simplify our life (as client developers - side by side to the server hard work of course).

Indeed, HTML 5 will going to introduce a whole new set of elements that will make out lives to much more easier, also based on the fundamentals of HTML 4. The main innovations comes to replace the HTML 4 basic elements as DIV for an instance (which is one of the most used elements) with simplify elements that will use to represent the purpose of each one of them, like header, footer, section etc. - each one of then is a new well known element in the new language. A page rendered with HTML 5 could be shown like the following code snippet:

<body> 
   <header>...</header> 
   
<nav>...</nav> 
   <article> 
      <section> ... </section> 
   </article> 
   <aside>...</aside> 
   <footer>...</footer>
</body>

One of the new innovations is the language definition. It means that HTML 5 is being defined in terms of the Document Object Model (DOM) as a tree representation that will be interpreted by the browser. This definition came from the idea of separating the language itself from its syntax, which can be defined independently.

As we know from previous HTML formats (HTML 4), there are 2 kinds of syntaxes: the HTML itself which is serialized as plain HTML or XHTML which is serialized as XML.

The coin has two sides - each holds its benefits (you also aware of it right? ;)).

The benefits of using HTML 5 (which based on the familiar HTML) are the compatible of existing browsers and the second thing is the acquaintance of it by the authors (in our case - people like me and you!).

On other hand, using XHTML 5 will encourages authors to write well-formed markup, which some authors may find easier to maintain and Integrates directly with other XML vocabularies.

This is still under consideration, so we have to wait to the decision...

Some more tutorials and information regarding HTML 5 you can find in the W3C site here.

Code | HTML
Posted by: Eran Nachum (c)
Post Date: 1/6/2008 9:46:09 PM (Jerusalem Standard Time, UTC+02:00)
Disclaimer | | Trackback   #
 Sunday, December 02, 2007

Long time no written, I know.... I am quite busy these days at work and in my private time working on the web 2.0 startup with my colleagues.

I received an email from Kevin Gao, which is the leading developer of a nice source control software that called SourceAnywhere Hosted of Dynamsoft in order to check out their software tool. I decided to write about this tool, because this one is very suitable to me these days while working on my startup project. I actually needed a good source control in order to manage my code files properly.

So, some conclusions regarding this tool, after working with it close to a month. Let start from the important thing for small developers like me - this tool is FREE to use for up to 3 users, which can be suitable for small to medium projects with low number of developers.

The second thing that was fine by me is the interface of this software, which is very similar to the Microsoft source control (admit it or not - I am a fan of it... ;)), this gave me great a familiar navigation ability between the functionality possibilities and indeed there are some nice possibilities and abilities, like: users and groups roles management and managing your code files (the usual functionality such as rollback, commit, check in/out etc.)

The only disadvantage that I could think about here is a lack of files' state indicator. Dislike other source control tools that I worked with (like: Microsoft source safe control which indicates a file content changes or file state directly in the Visual Studio environment or the SubVersion control system, which indicates the file's state in in the actual file system folder), this tool doesn't indicates it and this is kind of annoying.

Generally I think this is a great tool to use it in order to manage your code version - again for small to  medium applications/projects.

You can read about it and download it free of charge (for up to 3 users of course) here. Have fun!

Posted by: Eran Nachum (c)
Post Date: 12/2/2007 7:45:40 PM (Jerusalem Standard Time, UTC+02:00)
Disclaimer | | Trackback   #
 Wednesday, October 03, 2007

Firstable, before I am going to write the following words, I want to mention and admit that I am realy a big fan of Microsoft technologies, its innovetions and its line of philosophy; Most of the time they are doing good job (in some cases I would implement some things in other way, but this issue if for other post...).

What I want to talk about in this post is the C# language's development from the first version of .NET until the further to come which is .NET 3.5 in Visual Studio 2008.
In the beginning of .NET 2.0 there were great and major language improvement, like generics, anonymous methods/delegates and more nice things (that indeed, helps us to write more nice, agile and elegant code). BUT major things often require new keywords to support the 'enhanced' language, for an example: the <TEntity> syntax in order to use and implement generics.

In the generics case, this syntax is required in order to make a usage with this great feature, but in most cases new keywords are BAD, just bad because developers have the annoying habit of using non-keywords as identifiers. An example for new keyword is the pair: return yield. In the first version of iterators, you had to use yield when you wanted to "return" an iterator value back, and as we know everything worked just fine, so why should they need to add the return keyword in order to return the iterator's value? (I'll be glad to get the answer if you got it...)

I tried to figure out and see what Microsoft tried to do regarding this issue and found that they ment to provide a utility that you could run over your source code, and it would replace any identifier that had become a keyword with the escaped version. It should do this by putting an "@" sign in front of it. I don't think that tool at least was published...

Today, just before .NET 3.5 is releases out (not in beta of course), we can see on beta versions and examples the new keywords and innovations that had been added to the language which demands from us to adjust ourselves to the new syntax.

At the bottom line, it makes us a little bit of hard time at the begining, but it enhances our language and gives us a learning challenge and the ability of upgrading our code (maybe not easy to read on the first time but easy to implement and to make it more agile and generic). 

;-)I encourages these changes, but don't forget - everything could work just fine without these new stuff.

C# | Code | Other
Posted by: Eran Nachum (c)
Post Date: 10/3/2007 11:34:29 AM (Jerusalem Standard Time, UTC+02:00)
Disclaimer | | Trackback   #
 Tuesday, July 10, 2007

I am working against 3rd level party assembly in my current web application. I need to send US address information to this assembly and to retrieve an answer whether this address is exist or not. This assembly requires validation against X.509 certificate (to ensure that only permited client could use the 3rd level's services), which is installed on the server that runs the application (in dev environment this is my local PC).
More details about it here.

The problem: In order to authenticate against this certificate, the process that runs the application need to 'hold' sufficient credentials in order to get an access to the certificate and to do the authentication. Here comes our problem; when trying to access this certificate through the asp.net application, we run into a problem - It's impossible, because the process that runs the web application is ASPNET and doesn't has the needed credentials in order to authenticate the certificate and get the info from the 3rd level.

Suggested solutions:

  1. Credentials. Read the credentials from the web.config (username, password and domain) and impersonate the user using these credentials. This will 'save' the impersonated user all over the impersonation context (System.Security.Principal.WindowsImpersonationContext) and the authenicate action against the certificate will be done using this credentials. One more important thing, to ensure this data protected, encrypt it before puting it into the web.config.
  2. I thought about IIS Application Pool. This is a great feature that came up in IIS 6.0, which enables you the ability of creating one or more applications and allows us to configure a level of isolation between different Web applications. You can set the identity of an application pool which will be the account under which the application pool's worker process runs. So I thought to set it over there, but I had one big problem, an IIS 5 was installed on the production server and it is not a dedicated server. (More details about application pool here).
  3. Host .NET component in COM+. This is the third solution and the best for me at the current circumstances; Because I am working with a several applications (assemblies) I want to host the component that validates the user against the 3rd level party, this will give me a unified behavoir for all the applications while doing this action (Instead of setting these properties in web.config file of each web application we want to use {solution 1, remember?}). In other words, I'll set the username and password on the COM+ component just once in order to grant the process that runs this component the right and sufficient credentials. .NET provides a way to host your .NET components inside COM+ environment. All the functionality you need to write a COM+ aware component in .NET can be found in System.EnterpriseServices namespace.

So how we do it (hosting .NET assembly in COM+)?

Take a look on this code:

using System;
using System.Collections.Generic;
using System.Text;
using System.EnterpriseServices;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;

namespace ComPlusTest
{
    [Transaction(TransactionOption.Required),
        ObjectPooling(MinPoolSize=2, MaxPoolSize=5, CreationTimeout=20000),
        ComVisible(true)]
    public class TestClass : ServicedComponent
    {
        protected override void Activate()
        {
            base.Activate();
            DoSomeAction(Action activate)
        }

        protected override void Deactivate()
        {
            base.Deactivate();
            DoSomeAction(Action deactivate)
        }

        protected override bool CanBePooled()
        {
            DoSomeAction(Action pooled)
            return base.CanBePooled();
        }

        public void ValidateAddress(string address)
        {
            try
            {
               // Do the validation against the 3rd party
               ContextUtil.SetComplete();
            }
            catch(Exception ex)
            {
               // Handle exception
               ContextUtil.SetAbort();
            }
        }

        [AutoComplete()]
        public void JustAction()
        {
            DoSomeAction(Action simpleAction);
        }

        private void DoSomeAction(Action act)
        {
            // Do the action
        }
    }
}

Lets dissect it:

  1. Firstable you can see that the class is derived from ServicesComponent (which sits in the System.EnterpriseServices namespace). I marked our TestClass with some attributes. The first one in Transaction; The values for this attribute are same as in traditional VB/VC++ development i.e. Required, RequiresNew, Supported etc. MinPoolSize and MaxPoolSize specifies values for minimum and maximum object instances. The ComVisible attribute must be set to true to give the accessibility of an individual managed type or member, or of all types within an assembly, to COM (I spent lots of time trying to figure out some exceptions that I had while overriding the ServicesComponent class).
  2. the class is marked to require a transaction each method will execute in a transaction (existing or new). Once the ValidateAddress has been executed we need to either commit or rollback the transaction. This is done via static methods of ContextUtil class. The method SetComplete is used to commit a transaction where as SetAbort is used to rollback a transaction.
  3. Just for example, I defined a methid called JustAction. This method is marked with an attribute AutoComplete which means that once the method execution is over the transaction is automatically committed (equivalent to ContextUtil.SetComplete). In case of any error the transaction will be rolled back (equivalent to ContextUtil.SetAbort).
  4. Overrided Activate, Deactivate and CanBePooled methods are just for testing (in order to observe the flow behavior).

Now, you have to sign your assembly with a strong name and to add the following attributes to the AssemblyInfo class of your project:

[assembly: ApplicationName("ComPlusTest")]
[assembly: ApplicationActivation(ActivationOption.Library)]
[assembly: AssemblyKeyFileAttribute("ComPlusKey.pfx")]

Posted by: Eran Nachum (c)
Post Date: 7/10/2007 4:49:24 PM (Jerusalem Standard Time, UTC+02:00)
Disclaimer | | Trackback   #
 Sunday, June 10, 2007

These days I am working on a very big web application...

In one of my aspx pages I had needed to save lots of data in the ViewState object in order to persist data between postbacks, but when I looked at the rendered HTML, I saw a large hidden field for carring the ViewState.

ASP.NET 2.0 came up with a new feature that helps to reduce the amount of the hidden filed's ViewState data that called: PageStatePersister.

When we add an override the PageStatePersister property and use the built-in SessionPageStatePersister, the behavior of the page remains the same, but the storage used for the bulk of the state data is shifted from the hidden field to session state.

Implamantation instance:

protected override PageStatePersister PageStatePersister
{
   get { return new SessionPageStatePersister(this); }
}

In several cases you'll only want to override this property in your page and to shift the ViewState data into the Sesson object, but if you'll want to use it (wisely of course) on your entire web application? You should implement this property in a particular custom base page and to inherit it to all of your application pages.

The only disadventage that I could think about here is the data existent, session can lose its data and information if its timeout has ended, but ViewState can hold the data forever on the page, because it's hard coded.

Posted by: Eran Nachum (c)
Post Date: 6/10/2007 3:08:17 PM (Jerusalem Standard Time, UTC+02:00)
Disclaimer | | Trackback   #
 Thursday, May 31, 2007

I am working now on a large web application, that need to be used by more than one websites (at least 5 of them, websites and web services), therefore I have needed to do some isolating here with my main core projects.

Some background...
I have a common assembly (web application) that holds only the user controls, server controls and custom controls, which need to serve the all other web applications that are using them. This assembly has a reference to the other web application in order to have some information about some properties, session variables and global members, by this information, it knows to gereate some actions on runtime (or even in design). BUT, in the other hand, this web application need to use the controls that the first assembly has published, here we have a problem, we got a circular references, which is now allowed in .NET framework, also it isn't allowed anywhere I think...

So, how we gonna solve this problem?

The solution is quite simple and is known as Seperate Interface Pattern. (Click here to get some more info).

The main steps to implement it are:
Let define a project that called ProjectA and holds the user controls (etc...) implementations along with InterfaceB. ProjectA would maintain a reference to InterfaceB, which will hold any properties such as members, methods, events etc...

Now, lets define ProjectB which will implement InterfaceA. Now, ProjectB would reference ProjectA and (BUT) ProjectA would not reference ProjectB of course.

The result, ProjectA can access to ProjectB's specific exposed members and ProjectB can use the controls of ProjectA.

.NET 2005 | Bugs | Code | Patterns
Posted by: Eran Nachum (c)
Post Date: 5/31/2007 2:26:25 PM (Jerusalem Standard Time, UTC+02:00)
Disclaimer | | Trackback   #
 Thursday, May 17, 2007

Hi fellows, how are you?

I read a nice article regarding editing and encrypting/decrypting web.config sections. The nicest thing in that feature is the ability to access to the web.config content via the actual code behind (and) in run-time. (Could be a lot of reasons to access the file from the code itself, and the API is very 'friendly').

Click here to get the directive to this article.

Bye bye...

Posted by: Eran Nachum (c)
Post Date: 5/17/2007 10:23:55 AM (Jerusalem Standard Time, UTC+02:00)
Disclaimer | | Trackback   #
 Sunday, April 29, 2007

Hi again..

I am here again with the same issue, and this is because a long conversation that I had with Oren Ellenbogen (ex. co-worker) about some extending and refactoring of the former post solution (you can see it here if you missed it).

The main goal in the Session/Application objects encapsulation was the ability of avoiding casting each time that we would use these objects, this is annoying especially we uses the specific object in most of the flows of the application.
The other goal is getting the ability of managing these objects in one centered place.

NOW, some extesibility...
This object need to be maintened everytime that we want to add a new session/application object. Good usage of generics will solve this problem -> this will bring up the ability of adding new objects everywhere that we'll want (example in the continuance...).

So, look at the following implemetation:

public static class SessionRepository
{
   public static bool IsExist(string objectKey)
   {
      return HttpContext.Current.Session[objectKey] != null;
   }

   public static TObject GetInstance<TObject>(string objectKey)
   {
      return (TObject)HttpContext.Current.Session[objectKey];
   }

   public static void Add<TObject>(string objectKey, TObject obj)
   {
      HttpContext.Current.Session.Add(objectKey, obj);
   }
}

Some usage:

if (SessionRepository.IsExist("SomeObjectKey"))
{
   SomeObject obj = SessionRepository.GetInstance<SomeObject>("SomeObjectKey");

   // Do your things...
}

SessionRepository.Add<SomeObject>("SomeObjectKey", SomeObject);

This way of implementation comes to help us with the casting issue and it gives up extensibilty options. I think that there is a small disadventage here - we also need to remeber the keys of the objects in the session object - but there is nothing perfect.

Summary:

  1. Both of the solutions are good and each has each advantages/disadventages, you can prefer the best way of using.
  2. The first way (shown in the former post) enables you a direct access to the object stays in the session/application, but need to be managed for each time we want to add new object into the session/application.
  3. The way shown here holds a different approach, enables you extensibility, but you don't have the explicit access to these objects.
  4. In both ways, the casting issue is covered!

That's it for today.

Commets will be appriciated...

Posted by: Eran Nachum (c)
Post Date: 4/29/2007 2:41:05 PM (Jerusalem Standard Time, UTC+02:00)
Disclaimer | | Trackback   #
 Thursday, April 19, 2007

Hi!

In most of ourweb applications, we (must) use the session object, which gives us better way of data storing (session object lives over the HTTP protocol and exists all over the user's session lives {except of expiration etc...}).

The access to the session objects and variables is quite easy and simple, BUT, what happens when you want to store your complex struct or object in the session (even some other system object)? THEN, you must cast this session variable, and check if it alives before you can access its properties etc...

I have a good suggestion that also will encapsulate the sesison's variables and will be easy to manage, pay attention:

Firstable, I created a static class, called: Repository, which will expose the session variables as properties, and the access to these objects will be much more easy and explicit.

The repository static class:

public static class Repository
{
    public static SomeObject SessionSomeObject
    {
        get
        {
           return HttpContext.Current.Session["SomeObject"] as SomeObject;
        }
        set
        {
            HttpContext.Current.Session["SomeObject"] = value;
        }
    }

    // Some more properties declarations
}

(This class gathers all the session/application members = good and convenient code management).

NOW, look at the 'old fashioned' and regular way that the sytax suggests us (if we don't use the Repository static class):

if (Session["SomeObject"] != null)
{
   myObject = ((SomeObject)Session["SomeObject"]).MyProperty;
}
else
{
   // bla bla bla...
}

In the above example, we must check if the object is alive in the session firstly if we want to access its properties (unless we do it, it will throw us a runtime error). In the bottom example we cover this case with one sentense of code:

myObject = Repository.SessionSomeObject.MyProperty;

Here, even if the object is null, it will we create an instance of it and will return us some default value of the object's property.

Have a good day...

p.s.
This code relates also to the Application object!

Posted by: Eran Nachum (c)
Post Date: 4/19/2007 12:19:24 PM (Jerusalem Standard Time, UTC+02:00)
Disclaimer | | Trackback   #
 Wednesday, April 11, 2007

You can download it, it is ready, right from the oven...

The best thing that I found there is the Validation Application Blocks, which is new and wasn't in the earlier versions.
"Developers can use this application block to create validation rules for business objects that can be used across different layers of their applications." (quoted form the msdn site).

You can find it here: http://msdn2.microsoft.com/en-us/library/aa480453.aspx

Enjoy...

Posted by: Eran Nachum (c)
Post Date: 4/11/2007 10:40:47 AM (Jerusalem Standard Time, UTC+02:00)
Disclaimer | | Trackback   #
 Sunday, March 25, 2007

Hey guys how are you?

I wanted to share you with nice dillema that was raised by one of our team leaders, called: Boaz Davidoff.
He encountered with a situation that he wanted to create new instance of an object that inherits from a parent object (which is no problem right...?), BUT firstly he wanted to initiate some members in the child object before of creating the parent object and just after it to call the parent object constructor.

It turns out that this situation is quite impossible in .NET, because by default, you must call the base ctor firstly and just after it to do your stuff, for an example:

public class A
{
    int a1, a2;

    public A(int a1, int a2)
    {
        this.a1 = a1;
        this.a2 = a2;

        // Do your stuff
    }
}

public class B : A
{
    public B(int b1, int b2) : base(b1, b2)
    {
        // Do your stuff
    }
}

I wanted here, by calling B ctor, to make some manipulations over b1 and b2 (before calling the base ctor), but encountered with a PROBLEM.

So, take a look on this solution:

public static B CreateBObject(int c1, int c2)
{
    // Do some manipulation over c1 and c2

    return new B(c1, c2);
}

private B(int b1, int b2) : base(b1, b2)
{
    // Do the rest of your stuff
}

Some explanations:
I created again B ctor, which the only different from the other B ctor is by that it is private (in other words: this object cannot be initialize from outside this class).
Now, the addition... I added a static method called CreateBObject, which receives the same params, does some manipulation over them, after it calls the B's private ctor and returns B object like we wanted in the first time.

Nice, huhh? I would like to have some comments

p.s.
Thanks Boaz

Posted by: Eran Nachum (c)
Post Date: 3/25/2007 5:33:02 PM (Jerusalem Standard Time, UTC+02:00)
Disclaimer | | Trackback   #