Saturday, August 30, 2008

GetHashCode() have been changed

As its written in MSDN (http://msdn.microsoft.com/en-us/library/system.string.gethashcode.aspx):
Remarks:
The behavior of GetHashCode is dependent on its implementation, which might change from one version of the common language run-time to another. A reason why this might happen is to improve the performance of GetHashCode.

In the following versions exactly this happens:



  • 2.0.50727.3053

  • 2.0.50727.1433


Let's say you like to do something for load-balancing based on the following code:




return Math.Abs((key.GetHashCode() % serverAmount));



it will return a different server node in case of shared cache. To handle this issue we have added 2 things, first of all is an alternative hashing algorithm and second we check the run-time between clients and server and inform clients about it in case this happens.



If you are using a version of shared cache which is below 2.0.3.276 you need to keep all your systems up-to-date with the same CLR version or you decide to use a different hashing algorithm for your system. Within our notifier program you can check this quite easily.

To use following options you will firstly need to register, the registration can be done during installation or afterwards within a new option within menu context of SharedCache.com Notify application.

  • Check if all environments are using same CLR


  • A Test to check if you able to use all Hashing Algorithms



  • Get Informed if your environment is using same version of shared cache, this is mostly important to grant all communication options between clients and caching nodes on your servers.


for more information about hashing algorithms which are supported by shared cache visit my website: http://www.sharedcache.com/ - or go directly to http://www.sharedcache.com/cms/shared_cache_notify.aspx

Friday, August 29, 2008

LINQ to SQL Serialization

Use the Generics, Extension and Reflection features to implement a generic serialization class library for LINQ to SQL classes

http://www.west-wind.com/WebLog/posts/147218.aspx

http://sql.codeproject.com/KB/linq/linqsqlserialization.aspx

Tuesday, August 26, 2008

Build a Web Chat Application using ASP.Net 3.5, LINQ and AJAX (in C# 3.5)

Junnark Vicencio explains how to build a chat application within 2 hours.

Technologies Used: ASP.Net 3.5, AJAX, JavaScript, C# 3.5, LINQ-to-SQL, MS SQL Server 2000/2005

http://www.junnark.com/Articles/Build-a-Web-Chat-Application-Using-ASP-Net-LINQ-and-AJAX-CS.aspx

Thursday, August 14, 2008

Check if server is available before you make requests

I had to implement a fallback system in case one of my primary servers is not available anymore because of any reason. There were no option to access servers over a loadbalancer or something else then a direct routing to each server.

After some compassion's how much time I gone waste for each request between usage of sockets or HttpWebRequest / WebRequest I decided to work directly with Sockets.

The implementation I decided to go for were quite easy (remember: keep it simple as possible) and its fast like hell - 9ms I'm loosing each check if the server is available or not. We use 2 servers - so I have to remember that there is a total of 18ms I'm loosing each time we have a running cycle to analyse data. In general my tests gave showed me that 5 of the 9 ms are used for DNS.GetHostEntry(ServerName) - if you can use IP-Addresses then I suggest to do it that way. Check out one of my previous post about this DNS.GetHostEntry(ServerName) - IPAddress.Parse("127.0.0.1") vs. Dns.GetHostEntry("127.0.0.1")

With those ~20ms we can leave very good because a cycle needs right now something around 2.5min and it can be a max. of 15min. So how to solve this is the question, here the codesample from MSDN which I adapted and using to validate if my servers are online: http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.aspx

Formatted Code is available here: http://www.ronischuetz.com/code/CheckIfServerIsAvailable.htm



   1:      private static bool ConnectSocket(string server, int port)

   2:      {

   3:          Stopwatch sp = new Stopwatch();

   4:          IPHostEntry hostEntry = null;

   5:          bool result = false;

   6:          sp.Start();

   7:          // Get host related information.

   8:          hostEntry = Dns.GetHostEntry(server);

   9:          sp.Stop();

  10:          Log.Info(string.Format("ConnectSocket->Dns.GetHostEntry({0}) needed: {1}ms ",server, sp.ElapsedMilliseconds));

  11:          sp.Reset();

  12:   

  13:          // Loop through the AddressList to obtain the supported AddressFamily. This is to avoid

  14:          // an exception that occurs when the host IP Address is not compatible with the address family

  15:          // (typical in the IPv6 case).

  16:          foreach (IPAddress address in hostEntry.AddressList)

  17:          {

  18:              sp.Start();

  19:              IPEndPoint ipe = new IPEndPoint(address, port);

  20:              Socket tempSocket = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

  21:              tempSocket.ReceiveTimeout = 1000;

  22:              tempSocket.SendTimeout = 1000;

  23:              // this is very important!!! Do not delete this.

  24:              tempSocket.NoDelay = true;

  25:              

  26:              try

  27:              {

  28:                  tempSocket.Connect(ipe);

  29:                  #region Status Check

  30:                  if (tempSocket.Connected)

  31:                  {

  32:                      #region Connnected Section

  33:                      result = true;

  34:                      if (tempSocket != null)

  35:                      {

  36:                          try

  37:                          {

  38:                              tempSocket.Shutdown(SocketShutdown.Both);

  39:                              tempSocket.Close();

  40:                          }

  41:                          catch (Exception ex)

  42:                          {

  43:                              // do nothing - only release resources and don't let the system fuck up

  44:                          }

  45:                          finally

  46:                          {

  47:                              tempSocket = null;

  48:                          }

  49:                      }

  50:                      #endregion Connnected Section

  51:                      break;

  52:                  }

  53:                  else

  54:                  {

  55:                      continue;

  56:                  }

  57:                  #endregion End Status Check

  58:              }

  59:              catch (Exception ex)

  60:              {

  61:                  string title = string.Format("Could not connect to server:{0}:{1} -  " + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace, server, port);

  62:                  Log.Info(title);

  63:                  Log.Fatal(title);

  64:                  result = false;

  65:              }

  66:   

  67:              sp.Stop();

  68:              Log.Info(string.Format("ConnectSocket->hostEntry.AddressList({0}) needed: {1}ms to connect to server ", ipe.Address.ToString(), sp.ElapsedMilliseconds));

  69:              sp.Reset();

  70:          }

  71:          return result;

  72:      }
 
 

Wednesday, August 13, 2008

Visual Studio 2008 and .NET Framework 3.5 Service Pack 1

The next service pack is finally available. If you are using .NET 3.5, or want to use any of the new features that we have been talking about being added in this service pack, I’d strongly recommend you upgrade to this. You can download it here.

So what are the new features in this, well for a Service Pack, quite a lot. Check them all out:
ASP.NET Dynamic Data, which provides a rich scaffolding framework that enables rapid data driven development without writing code, and a new addition to ASP.NET AJAX that provides support for managing browser history (back button support). For more information, see What’s New in ASP.NET and Web Development.

Core improvements to the CLR (common language runtime) that include better layout of .NET Framework native images, opting out of strong-name verification for fully trusted assemblies, improved application startup performance, better generated code that improves end-to-end application execution time, and opting managed code to run in ASLR (Address Space Layout Randomization) mode if supported by the operating system. Additionally, managed applications that are opened from network shares have the same behavior as native applications by running with full trust.

Performance improvements to WPF (Windows Presentation Foundation), including a faster startup time and improved performance for Bitmap effects. Additional functionality for WPF includes better support for line of business applications, native splash screen support, DirectX pixel shader support, and the new WebBrowser control.

ClickOnce application publishers can decide to opt out of signing and hashing as appropriate for their scenarios, developers can programmatically install ClickOnce applications that display a customized branding, and ClickOnce error dialog boxes support links to application-specific support sites on the Web.

The Entity Framework is an evolution of the existing suite of ADO.NET data access technologies. The Entity Framework enables developers to program against relational databases in according to application-specific domain models instead of the underlying database models. For more information, see Getting Started with the Entity Framework. The Entity Framework introduces some additional features, including support for new SQL Server 2008 types, default graph serialization of Entities, and the Entity Data Source. This release of the Entity Framework supports the new date and file stream capabilities in SQL Server 2008. The graph serialization work helps developers who want to build Windows Communication Foundation (WCF) services that model full graphs as data contracts. The Entity Data Source provides a traditional data source experience for ASP.NET Web application builders who want to work with the Entity Framework.

LINQ to SQL includes new support for the new date and file stream capabilities in SQL Server 2008.

The ADO.NET Data Services Framework consists of a combination of patterns and libraries, which enable data to be exposed as a flexible REST (Representational State Transfer)-based data service that can be consumed by Web clients in a corporate network or across the Internet.

The ADO.NET Data Services Framework makes data service creation over any data source. A conceptual view model of the underlying storage schema can easily be exposed through rich integration with the ADO.NET Entity Framework. Services created by using the ADO.NET Data Services Framework, and also compatible Windows Live (dev.live.com) services, can be easily accessed from any platform. For client applications that are running on Microsoft platforms, a set of client libraries are provided to make interaction with data services simple. For example, .NET Framework-based clients can use LINQ to query data services and a simple .NET Framework object layer to update data in the service.

Windows Communication Foundation now makes the DataContract Serializer easier to use by providing improved interoperability support, enhancing the debugging experience in partial trust scenarios, and extending syndication protocol support for wider usage in Web 2.0 applications.


The .NET Framework Data Provider for SQL Server (SqlClient) adds new support for file stream and sparse column capabilities in SQL Server 2008.
As for Visual Studio 2008, the Service Pack can be found here.
The following technologies have been tested and verified to work with SP1:
Silverlight 2 SDK Beta 2 & Silverlight Tools Beta 2. (If Silverlight Tools Beta 2 is already installed, you must upgrade it after you install Visual Studio 2008 SP1. To upgrade, use the installer on the Silverlight Tools Beta 2 page on the Microsoft Download Center Web site.)

  • MVC Preview Release #3
  • ASP.NET Extensions/Dynamic Data Preview
  • VC 2008 Feature Pack
  • VB PowerPack Controls (2.0 & 3.0)
  • Expression Studio 2 (RTM)
  • SQL Server 2008
  • .NET Framework 3.5 SDK
  • XSLT Profiler
  • VSTA 2.0 SDK
  • Visual Studio 2008 SDK
If you encounter issues installing SP1, uninstall technologies and/or development add-ins not listed above, and then try SP1 Setup again.

Shared Cache - .Net Caching made easy

All information about Shared Cache is available here: http://www.sharedcache.com/. Its free and easy to use, we provide all sources at codeplex.

Facebook Badge