Monday, May 23, 2011

A simple javascript for face book share button...

javascript:var a=window.open('http://www.facebook.com/sharer.php?u='+prompt('Enter URL',window.location.href)+'&t='+prompt('Enter Title',''),'sharer','toolbar=0,status=0,width=626,height=436');
 
copy and paste above in your browser and hit enter J
 
Mehul Trivedi
trivedimehulk@gmail.com
 
 
 

Friday, May 20, 2011

Some useful instant javascripts for web developers....

All these scripts must run in browser address bar.
 
  1. This will ask you to enter the javascript code you want to execute from browser against current page
 
javascript:var a=eval(prompt('Enter JS'));
 
  1. This will show you cookies planted by current site
 
javascript:alert((document.cookie));
 
  1. This would show you the size of viewstate generated on an ASP.NET page
 
javascript:alert(document.getElementById(prompt('Enter variable name:','__VIEWSTATE')).value.length/1024 +'kb');
 
  1. This would resize your browser to standards 1024 layout to check the page layout constraints
javascript:window.resizeTo(1024,768);
 
I normally keep them handy in favorites!
 
 
Mehul Trivedi
trivedimehulk@gmail.com
 
 
 

Friday, May 13, 2011

SOA - convert any exception to a fault exception for your clients...

Mates,
 
I have been reading an interesting article that struck my mind while designing an SOA architecture in .NET 3.5/WCF services.
 
The objective was to convert all the exception (type any) as a service host, convert them to a generic fault contract type and send it to client, so that they can process it.
 
I found an easy way by using Microsoft Application Blocks and “Fault Contract Exception Handler”, we can actually trap the exception using MABs, transform / map the fields from exception to the custom fault contract we have defined and reThrow it J
 
 
Mehul Trivedi
 
 
 
 
Mehul Trivedi
Office: +1 (954) 514-4667
 
 
 

Tuesday, May 10, 2011

How to use Microsoft Enterprise Library Exception Handling and Logging Application blocks to log exceptions in rolling log files

  1. Configure your configuration file.
  1. Add exception handling block
  2. Add exception policy
  3. Add exception type
  4. Add exception logging handler
  5. Modify the trace listener by removing the default to a rolling log file
  6. Configure all the values

  1. Add reference of MABs (exception and logging) in your app as shown below

  1. Handle the exception…

Running the code would generate the rolling log file in your web application directory.
trivedimehulk@gmail.com

A simple javascript solution to trap onblur before it happens... IE only...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<script>
var onblurf = false;
function acmeup() {
if (window.event.keyCode == 9) {
onblurf = true;
} else {
onblurf = false;
}
}
function acme(e) {
if (onblurf) {
alert('fired on tab out');
}
}
</script>
<input type="text" id="txtname" onblur="acme(event);"
onkeydown="acmeup();"
/>
</body>
</html>
 
trivedimehulk@gmail.com
 
 
 

Tuesday, May 3, 2011

How to create C# data transfer object (DTO) class from a given XML?

  • Have your xml ready
  • On visual studio command prompt
 
        xsd <ur xml file path> - this will generate xsd
        xsd <ur just generated xsd file> /classes- this will generate cs
 
and finally use following sample code to load xml
 
StreamReader str = new StreamReader("cd_catalog.xml");
      XmlSerializer xSerializer = new XmlSerializer(typeof(CATALOG));
 
      CATALOG myCdCatalogue = (CATALOG)xSerializer.Deserialize(str);
 
      foreach (CATALOG.CDRow cd in myCdCatalogue.CD)
      {
        Console.WriteLine(cd.TITLE);
        Console.WriteLine(cd.ARTIST);
        Console.WriteLine(cd.COUNTRY);
        Console.WriteLine(cd.COMPANY);
        Console.WriteLine(cd.PRICE);
        Console.WriteLine(cd.YEAR);
        Console.WriteLine();
      }
      str.Close();
 
>>> xml to C#, C#, .net 3.5, XML
 
trivedimehulk@gmail.com
 
 

External configuration source issue in Unit Testing in Visual Studio...

The unit test project in visual studio by default does not support external configuration file. Basically when you debug / run your tests the external configuration files you have used are not copied over to out directory.
 
The simplest work around to this is as follows:
 
  1. Add a test run configuration file at solution level
  2. Select deployment leaf in the test run configuration
  3. Add extra files that you want to be copied over to out folder in test run config
 
Now you should have the extra files being copied over to output directory making the test run successfully.
 
trivedimehulk@gmail.com