Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts

Apr 18, 2016

Good Technical Study Links:


MVC Fluent API EF









-------------------------------------------------

Simple Web Token



---------------------------------------------------------
Instrumentation and Performance Metrics


----------------------------------------------------------------------------

SOA Patterns and standards:








-----------------------------------------------------------------------------------------------------------------------

WebAPI / REST related:



-----------------------------------------------------------------------------------------------------------------------

Precompile controllers and views






Lazy(T) Class





-----------------------------------------------------------------------------------------------------------------------

Weak Reference Class








-----------------------------------------------------------------------------------------------------------------------

SOA Entity Composition:














Apr 12, 2016

Find Max length of string array


My requirement was to get the string with the longest value and the shortest value from a huge array. Naturally I was inclined to use the Max() and Min() extensions of Array. But it was throwing queer results. I was stumped, why was it not behaving uniformly? Then I realized for Max or Min on a string all it does is a alphabetical sorting and returning the top and the bottom of the sorted list. I also added a simple lambda solution to it.


Feb 1, 2016

Configure ASP.NET SignalR in a web farm


I had a problem after I put into production a Visual Studio project with SignalR library.

In localhost every call seemed to be right but after the publishing step, some random request returned me an http error. After some google search I found that the problem was that the site is published in a web farm with 7 differents servers. In this case could happen that the first call is send from one server and managed from another server in the farm.

Every server has its encryption and decryption own code and if you want SignalR calls return a valid http status you should share these keys from the servers in the farm. So for each server in the farm open IIS and go to Sites and single click in the site where SignalR is used. In the central panel now go to Machine Key and double click.

Uncheck “Automatically generate at runtime” and “Generate a unique key for each application” and put a valid unique validation Key and a valid unique decryption key in the text boxes.

Look at the picture below, you should have something similar to this.

[Excerpted from: http://nextstepblog.altervista.org/configure-asp-net-signalr-in-web-farm/?doing_wp_cron=1454300698.7938909530639648437500]



Other Important Links:

http://www.asp.net/signalr/overview/performance/scaleout-with-sql-server

http://www.tugberkugurlu.com/archive/scaling-out-signalr-with-a-redis-backplane-and-testing-it-with-iis-express

http://www.hanselman.com/blog/AsynchronousScalableWebApplicationsWithRealtimePersistentLongrunningConnectionsWithSignalR.aspx

Nov 18, 2015

Asynchronous Programming with Async and Await (MSDN) + Extra

https://msdn.microsoft.com/library/hh191443.aspx

https://code.msdn.microsoft.com/Async-Sample-Example-from-9b9f505c


http://www.abhisheksur.com/2010/10/c-50-asynchronous-made-easy.html




(Excerpted from http://www.abhisheksur.com/2010/10/c-50-asynchronous-made-easy.html)



What is await ? 

According to Whitepaper published on the CTP, await keyword lets you to wait your program and lets the program to be declared as a continuation of all the existing awaits so that the compiler automatically waits for all other awaits to be finished until the program continues its execution. 
In other words, say you have invoked 3 asynchronous methods from your code an asynchronous block from your code, you would just write the way you would have written this synchronously with a single keyword await before the call. The call lets the compiler wait until the execution successfully completes. Just as shown below : 
async Task GetStringsFromUrlAsync(string url)
{
     WebClient client = new WebClient();
     return await client.DownloadStringTaskAsync(new Uri(url));
}

This involves the call to DownloadStringTaskAsync which is already implemented for WebClient. Now as you can see I have specified the await just before the call to Asyncrhonous method DownloadStringTaskAsync, it will keep the call on wait. 

Even though if I say use :

async Task GetStringsFromUrlAsync(string url)
 {
      WebClient client = new WebClient();
      Task<string> modifieduri = client.DownloadStringTaskAsync(new Uri(url));
      string result = await modifieduri;
      return await client.DownloadStringTaskAsync(new Uri(result));
}

It means the second Task depends on the first one. So in this case the First DownloadStringTaskAsync will be called. This call actually returns Task(Task for any other operation) which you can keep on wait until it is finished using await keyword. So when you execute, the first call will block until the result is fetched and then it will take the string result and call the next one. 

Thus you can see how you can use await on Task variable to wait the object for completion without any implementation of custom callbacks, global objects etc.


What is async? 

Now, how to implement the asynchronous method? Hmm, async keyword can be placed just before the function call to make the method asynchronous. 

By specifying the async keyword against your method call, the compiler will automatically select your method to be asynchronous, which means it will move to the next line before returning the result in parallel until it finds an await. In the example I have provided theDownloadStringTaskAsync is actually an extension which specifies to be called with async.

Async method can return void, Task or Task based on what you need in your environment. But it is mostly preferable to return at least a Task object so that the caller can better handle the call. 

For any async method, you should put await before fetching the result, otherwise you might end up with blank/null result. await works with async to stop the further execution before finishing the other operations in context.

Jan 2, 2013

List of good techie blogs

.NET Blogs:  

The list of the .Net Gurus, whose blogs, sites and Tweets every aspiring .Net developer should religiously follow.


Sl.
Name
Title
Blog/Site
1.        
Scott Guthrie
Product Manager of the .NET Framework, Microsoft
weblogs.asp.net/scottgu, twitter.com/scottgu
2.        
Scott Hanselman
Principal Program Manager, Microsoft
www.hanselman.com/ , twitter.com/shanselman
3.        
Phil Haack
Senior Program Manager of ASP.NET team
haacked.com, twitter.com/haacked
4.        
Jonathan Carter
Technical evangelist for Visual Studio and the .NET Framework

5.        
James Senior
Technical Evangelist for Microsoft
http://blogs.technet.com/b/james/
6.        
Jeffrey Richter
Co-founder of Wintellect. Designed and wrote much of the CLR
www.wintellect.com/CS/blogs/jeffreyr/default.aspx
7.        
Jeff Atwood
Co-Owner of Stack Overflow
http://www.codinghorror.com/blog/
8.             
Jeff Prosise
Co-founder of Wintellect
www.wintellect.com/cs/blogs/jprosise/
9.        
Stephen Walther
Senior Program Manager on the ASP.NET Ajax
stephenwalther.com,
10.    
Dino Espositio
Consultant
weblogs.asp.net/despos
11.    
Scott Hunter
Senior Program Manager on the ASP.NET team
http://blogs.msdn.com/scothu/
12.    
David Ebbo
Architect on the ASP.NET team
http://blogs.msdn.com/davidebb/ ,  blog.davidebbo.com
13.    
Eric Gunnerson
Software Developer / Evangelist at Microsoft
http://blogs.msdn.com/b/ericgu/



Other interesting blogs:
http://dotnetweblog.wordpress.com/
http://www.misfitgeek.com/
http://bogdanbrinzarea.wordpress.com

Some Interesting posts:


AJAX/Jquery/Javascript Blogs 

[placeholder]

Dec 24, 2012

Parallel Programming, Tasks etc...

A book from Microsoft on Parallel programming coding guidelines.
You can download here