CodeCloudy

Azure | .Net | JQuery | Javascript | Umbraco

How to Expose a Description for Enums

Step1: add a description tag to the enums.

 [Flags]
   internal enum SuperHero 
   {
      [Description("Clark Kent")]
      Superman = 1,
      [Description("Peter Parker")]
      SpiderMan = 2,
      [Description("Bruce Banner")]
      Hulk = 4,
      [Description("Tony Stark")]
      IronMan = 8,
   }

Step 2: Create an common class. (eg: Common or ExtentionMethods). Then add the following methods.

private const char ENUM_SEPERATOR_CHARACTER = ‘,’;

      public static string GetDescription(Enum value)
      {
         // Check for Enum that is marked with FlagAttribute
         var entries = value.ToString().Split(ENUM_SEPERATOR_CHARACTER);
         var description = new string[entries.Length];
         for (var i = 0; i < entries.Length; i++)
         {
            var fieldInfo = value.GetType().GetField(entries[i].Trim());
            var attributes = (DescriptionAttribute[])fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
            description[i] = (attributes.Length > 0) ? attributes[0].Description : entries[i].Trim();
         }
         return String.Join(", ", description);
      }
 public static string Description(this Enum value)
      {
         return GetDescription(value);
      }

Step 3: Add a reference to you extension class.

example: using YourNamespace.Common;

Step 4: Use it where you need it.

 var secretIdentity = SuperHero.Superman.Description();
 var superHeroes = SuperHero.Superman | SuperHero.SpiderMan;
 var secretIdentities = superHeroes.Description();

if you are using Razor:

@YourEnum.Description()

Advertisements
Leave a comment »

Umbraco CMS Database – SQL Azure Migration

After created the schema for the cms in SQL Azure, Need to add a clusterd index to the dbo.umbracoUserLogins before inserting records

       CREATE CLUSTERED INDEX umbracoUserLogins_Index ON umbracoUserLogins (contextID)

if you forget to do this, you will get some errors like following:

Tables without a clustered index are not supported in this version of SQL Server. Please create a clustered index and try again.

No worries. add the clustered index and re-run the umbracoUserLogins insert sql queries. Done.

1 Comment »

Free Web Chat Widgets Comparison

ZohoChat

provides 3 different types of widgets

  • Live Support Connect your customers with your support executives.
  • Shoutbox Allows your website blog visitors to interact with you instantly.
  • Live Chat Allows one on one communication with your website blog visitors.

Meebo Me

http://www.meebome.com/

Supports Chat between Public to Website Administrators Only

Plugoo

http://www.plugoo.com/

pros: admins can use existing IM accounts to chat with public users.

chatango

http://chatango.com

CBOX

http://cbox.ws/features.php

free version has its disadvantages

Leave a comment »

Entity Framework 5.0 Performance Improvements

An O/RM, like any layer of abstraction, introduces overhead to data access. In EF 5.0 we have taken steps to reduce this overhead and improve performance. As a result in one of our tests, repeat execution time of the same LINQ query has been reduced by around 6x. We also have an end-to-end application that we use for performance testing that is running 67% faster.

LINQ to Entities Query Repeat Execution Time

In EF 5.0 we are introducing automatic compilation of LINQ to Entities queriesFrom the first version of EF, developers have been able to compile LINQ queries explicitly by calling CompiledQuery.Compile, but many developers either were not aware of this ability or found the API harder to work with than regular LINQ. In EF 5.0 we took on some of this work for you, so that the translation of inline LINQ queries is now cached without having to use CompiledQuery. This improvement, together with an optimization in how we evaluate query parameter values, has had a profound impact on the query performance of EF:

ExecutionTimeResults

The graph above represents the relative time spent in the execution of a query that retrieves an entity by its key. The same logical query was executed via ADO.NET, LINQ to SQL and several EF methodologies. In the benchmark, the query is executed in a loop using different key values each time. From the graph above we can see that before these performance improvements, executing a LINQ to Entities query for the second time took 23.14 times as long as the same SQL query using classic ADO.NET. With automatic query compilation and the changes to parameter evaluation, we’ve improved the performance of LINQ to Entities queries nearly 600% when compared against EF 4.0. As a bonus, EF 4.0 applications will get this performance improvement for free by just upgrading to .NET 4.5.

End-to-End Performance

It would be amazing if we could give you 600% improved performance across the board. Unfortunately, most applications do more interesting things than run the same query repeatedly. Internally we have a suite of performance tests that run a variety of operations designed to simulate the typical usage a real-world application would have. We set thresholds based on the performance of EF 4.0 to ensure that we do not regress performance. These test runs are showing a 67% performance increase over EF 4.0 since we upgraded the server to EF 5.0:

clip_image004

Leave a comment »

Web Essentials

 

Add Tooltips for you Forms.

http://flowplayer.org/tools/demos/tooltip/form.html

Leave a comment »

Disable text selection highlighting

function clearSelection() {     if(document.selection && document.selection.empty) {         document.selection.empty();     } else if(window.getSelection) {         var sel = window.getSelection();         sel.removeAllRanges();     } } 

You can also apply these styles to the span for all non-IE browsers:

span.no_selection {     -moz-user-select: none; // mozilla browsers     -khtml-user-select: none; // webkit browsers }
Leave a comment »

Best File Uploaders

1. jQueryFileUpload.Net

A very basic framework around jQueryFileUpload scripts, to host in ASP.Net.
source code available.
Download: https://github.com/i-e-b/jQueryFileUpload.Net

2. blueimp jQuery-File-Upload

you need to add the files to a solution in order to test the demo.

 http://blueimp.github.com/jQuery-File-Upload/

3 .net jquery for asp.net

you need to add the files to a solution in order to test the demo.

jQuery file upload control in asp.net

Download: http://www.webtrendset.com/wp-content/uploads/2011/06/Asp.NetjQueryFileUpload.zip




	
Leave a comment »

Cloud Friendly Umbraco 5 is Out

http://umbraco.com/umbraco-5-status.aspx

What is V5

In a nutshell, Umbraco v5 is a ground-up rebuild of your favorite CMS and is built on top of ASP.Net MVC 3. It will look the same and have all of the same great Umbraco ideas powering the new CMS but the underlying architecture has been completely upgraded.

Leave a comment »

New Tech Updates

Protect your kids from the bad net

http://www.kidzui.com/

Do not use these following web applications. they use your email to hack your email account.

http://todo.ly/

Todo.ly is an intuitive and easy to use online Todo list, and Task Manager.

It helps you to get organized, simplify your life, and to get things done. Create todo lists, and manage them online from anywhere.

Leave a comment »

The maximum string content length quota (8192) has been exceeded while reading XML data.

Solution:

<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name=”MyService” maxReceivedMessageSize=”2147483647″>
<readerQuotas maxDepth=”2147483647″ maxStringContentLength=”2147483647″
maxArrayLength=”2147483647″ maxBytesPerRead=”2147483647″
maxNameTableCharCount=”2147483647″ />
<security mode=”TransportWithMessageCredential”>
<transport clientCredentialType=”None” />
<message clientCredentialType=”UserName” />
</security>
</binding>
</wsHttpBinding>
</bindings>

Leave a comment »