Archive for April 15th, 2011

ASP.NET MVC – Code Usability Improvement (coming soon in v2011 volume 1)

In the next major release, we're introducing a useful improvement for working with the DevExpress ASP.NET MVC Extensions that will help improve code usability.

Add Method For Collections

We're adding a useful new overload for our collections' Add methods. So the fluent HTML code in our MVC Extensions that looked like this:

var column = settings.Columns.Add("Total");
column.UnboundType = DevExpress.Data.UnboundColumnType.Decimal;
column.PropertiesEdit.DisplayFormatString = "c";

Will now look like this with v2011 volume 1 release:

settings.Columns.Add(column => { 
    column.FieldName = "Total";
    column.UnboundType = DevExpress.Data.UnboundColumnType.Decimal;
    column.PropertiesEdit.DisplayFormatString = "c";
})

Benefits

The benefit for you with the new Add method is that it avoids the var structure and makes your code more readable!

Thanks to a DevExpress customer who asked me during a recent webinar about using more lambda expressions in our MVC extensions.

What do you think of this code improvement? Drop me a line below, thanks!

Build Your Best - Without Limits or Compromise

Try the DevExpress ASP.NET MVC Extensions online now: http://mvc.devexpress.com

Read the latest news about DevExpress ASP.NET MVC Extensions

Download a free and fully-functional version of DXperience now: http://www.devexpress.com/Downloads/NET/

Follow MehulHarry on Twitter


Http Message Channels in WCF Web Apis Preview 4

The new WCF Web Apis Preview 4 released yesterday in the wcf.codeplex.com introduced a new extensibility point for intercepting messages at channel level. The name for this new feature is “Http Message Channels” and the good thing is that you don’t need to rely anymore on the REST Starter Kit request interceptors for doing the same thing. Actually, a Http Message Channel is more useful as you can intercept either request or response messages, and also you get an Http message with all the context information you might need and not a WCF generic message, which usually requires some additional processing.

A Http Message Channel uses the new Task-Based Asynchronous pattern for implementing asynchronous work, which simplifies the implementation a lot. This is how a generic Http Message Channel looks like,

public class MyHttpChannel : DelegatingChannel
{
    public MyHttpChannel(HttpMessageChannel innerChannel)
        : base(innerChannel)
    {
    }
 
    protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
        // DO YOUR WORK Here
    }
}

You need to derive the base class “DelegatingChannel” and override the method “SendAsync” to provide your implementation. You only receive the request message as input argument, but you can call the inner channel in the stack for processing the request and getting an instance of the response message if you want to do some processing on the response as well.

The following example shows a typical channel for validating a API key. The API key is passed in a custom header “X-AuthKey” as part of the request message-

public class ApiKeyVerificationChannel : DelegatingChannel
{
    public const string KeyHeaderName = "X-AuthKey";
 
    IKeyVerifier keyVerifier;
 
    public ApiKeyVerificationChannel(HttpMessageChannel innerChannel)
        : this(innerChannel, new KeyVerifier())
    {
    }
 
    public ApiKeyVerificationChannel(HttpMessageChannel innerChannel, IKeyVerifier keyVerifier)
        : base(innerChannel)
    {
        this.keyVerifier = keyVerifier;
    }
 
    protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
        IEnumerable<string> values = null;
        if (request.Headers.TryGetValues(KeyHeaderName, out values))
        {
            var key = values.First();
 
            if (this.keyVerifier.Verify(key))
            {
                return base.SendAsync(request, cancellationToken);
            }
        }
 
        return Task.Factory.StartNew(() =>
            {
                var response = new HttpResponseMessage(HttpStatusCode.Unauthorized, "You need to provide a valid key for consume these Apis");
                return response;
            });
    }
}

This implementation basically validates the received key in the http header and calls the inner channel for further processing of the request (base.SendAsync). However, if the key is not provided or it is invalid, a new response is returned and the execution is interrupted.

As you can see, this interception mechanism is also great for implementing common concerns like security that needs to run much before the service is invoked.

Finally, a custom Http Message Channel can be injected in the WCF pipeline with the new fluent configuration interface as it is showed bellow,

public class Global : System.Web.HttpApplication
{
    private void Application_Start(object sender, EventArgs e)
    {
        var config = HttpHostConfiguration.Create().
            SetMessageHandlerFactory(typeof(ApiKeyVerificationChannel));
 
        // setting up contacts services
        RouteTable.Routes.MapServiceRoute<ContactsResource>("contacts", config);
    }
}
The SetMessageHandlerFactory receives either an array of “Type”s representing the channels or an instance of a HttpMessageHandlerFactory that knows how to instantiate new channels. You might want to extend the default HttpMessageHandlerFactory to use your favorite DI framework to resolve the channels.

Quote of the Day: On learning from history

More and more I see those who have not learned from history. From the highest politicians in the land to the schoolchildren we’re raising, in most cases, they don’t even study history. And we do so at our own peril. One of my favorite quotes on this topics is:

“The past is not dead. In fact, it's not even past.” - William Faulkner


Average Flash Games Developer

MochiMedia has conducted survey of Flash games market for 2010. Let me present few key points about average Flash games developer for last year.

Our average Flash games developer is 'he' in 97% of the cases and only 3% is 'she'. He is around 24 years old and he is most likely from United States.

Average Flash games developer doesn't create Flash games full time, it's mostly a part time activity and he develops Flash games for 2 years using ActionScript 3.0 and during that time he has developed 3-4 full games. Each of those games got about 200.000 plays during its lifetime. He is most like working by himself.

Coding and game design are best aspects of his game creation process. Average Flash games developer needs 1-2 months to create single game. He makes up to $500 for that game.



I've mentioned how our average Flash game developer comes from United States, however, there is evident raise in number of developers from non-western countries comparing to last year:

o Russia 6% (up 2%)
o Ukraine 4% (up 2%)
o India 4% (up 3%)
o Brazil 3% (up 1%)
o Indonesia 3% (up 1%)

This is reasonable raise because average $500 for a single game in US/UK maybe is not big deal and may be considered as small bonus, but in Indonesia and India this is good money. Conclusion is that Flash games market is maturing and moving fast from hobby to real business which is good news for both players and developers.

*_*

Average Flash Games Developer

MochiMedia has conducted survey of Flash games market for 2010. Let me present few key points about average Flash games developer for last year.

Our average Flash games developer is 'he' in 97% of the cases and only 3% is 'she'. He is around 24 years old and he is most likely from United States.

Average Flash games developer doesn't create Flash games full time, it's mostly a part time activity and he develops Flash games for 2 years using ActionScript 3.0 and during that time he has developed 3-4 full games. Each of those games got about 200.000 plays during its lifetime. He is most like working by himself.

Coding and game design are best aspects of his game creation process. Average Flash games developer needs 1-2 months to create single game. He makes up to $500 for that game.



I've mentioned how our average Flash game developer comes from United States, however, there is evident raise in number of developers from non-western countries comparing to last year:

o Russia 6% (up 2%)
o Ukraine 4% (up 2%)
o India 4% (up 3%)
o Brazil 3% (up 1%)
o Indonesia 3% (up 1%)

This is reasonable raise because average $500 for a single game in US/UK maybe is not big deal and may be considered as small bonus, but in Indonesia and India this is good money. Conclusion is that Flash games market is maturing and moving fast from hobby to real business which is good news for both players and developers.

*_*

  • Sponsored Links

  • April 2011
    M T W T F S S
    « Mar   May »
     123
    45678910
    11121314151617
    18192021222324
    252627282930  
  • .

    Copyright © 1996-2010 Answer My Query. All rights reserved.
    iDream theme by Templates Next | Powered by WordPress