YouTube Video Preview in Outlook Inbox

by Chintan Shah17. September 2012 06:08

Since the day Outlook.com was launched by Microsoft. I have been the biggest fan of it. I just love the simplicity and speed of Outlook.com. recently I discovered this new feature which shows you Video preview of a link sent inside email. That is super awesome. No other mail service provides this feature. Now, You can actually see YouTube video from same inbox without opening separate tab. here is the screenshot attached.

 

 

Tags: ,

General

SQL Server Query Optimization : NOLOCK and CTE (Common Table Expressions)

by Chintan Shah17. September 2012 01:51

I was recently working on a project which involved extensive calculations and use of Temporary table. The application is used to do many calculations and generate a Report. In the initial implementation it was taking around 10 min to generate a report. Client wanted it to be in 10 seconds. It was just exceptionally high complexity task. We had to reduce the time to 10 seconds anyhow. We started by indexing the columns which were used in query. It helped us gain around 50% boos in 1st Try. Woow!! Now that was some gain we got and were optimistic on hitting the target set by client. But, We still had Mt. Everest Task in our had to cut 5 min to 10 sec.

 

As usual my 1st choice is to go to SQLAuthority.com and lookout for Best Practice in Query. Here is the article I read. The article was really short and too the point. Infect, There are many good advice inside their comment section. I got all valuable information from their and started Googleing more on the optimizations suggested.

Following are the optimizations we implemented:

1. USE SP instead of UDF

We did converted many UDFs to SPs. But there were few which can not be converted. It had slight improvement in overall speed. I don't have the exact number but, Its around 2 to 4% change in execution speed.

 

2. Don't Use Views if possible

We were using Indexed Views in the SPs. We did eliminated 2 or 3 views that we could remove without changing lots of code.Performance improved just few bits. hardly around 1 to 1.5% only.

 

3. Few things We tried from Comments. Use NOLOCK

It was suggested in one of the comment that using NOLOCK can optimize performance a bit. Since, Our requirement was not have very high concurrency. We implemented NOLOCK on select queries and it improved significant. It gave us almost 10% gain over current situation.

 

4. Don't Use Temporary tables.

This was one of he biggest improvements we achieved. We were using Temporary tables because we wanted to reuse lots of calculated data. We searched for an alternative. We got CTE (Common Table Expressions). It works like Temporary table but does not have high amount of overhead. Though, We implemented it but it was not possible to implement it in all the code. But, it gave us almost 15% boost.

 

We still have not hit 10 seconds mark. But, running somewhere around 2 to 3 min mark. will try with some hardware improvements and SQL server configurations. Hope this helps you.

 

Till next time Happy Coding.

Tags: , ,

SQL Server

Checking DBNull and Converting to a Type

by Chintan Shah20. March 2011 02:42

Hello Readers,  

 

Recently while working on a project, I encountered a situation in which the data I fetch from database may contain a lot of NULL values. So what I had to do was to First check if a cell value is not DBNull and then I would cast it into a specific type. The result was that, my code was getting bloated. So, I thought of creating a generic function which could check if a value is DBNull or not and if it is DBNull, then return its default value. 

Before using this code, this was the situation:

using (DataTable table = GetSomeDataFromDatabase())
{
if (table.Rows.Count > 0)
{
foreach (DataRow row in table.Rows)
{
var value = !Convert.IsDBNull(row["appName"]) ? Convert.ToString(row["appName"]) : string.Empty;                            
}
}
}

As you can see, the code looks bloated. Now imagine a row with 10 to 15 columns. It would become too redundant to write code repeatedly. So, I created this function to reduce redundancy:

public static T ConvertToType<T>(object value)
{
if ((value == null) || Convert.IsDBNull(value))
{
if (typeof(T) == typeof(string))
{
return (T)string.Empty;
}
return default(T);
}
return (T)Convert.ChangeType(value, typeof(T));
} 

Using this function, the code becomes more clear and precise. 

var value = ConvertToType<string>(row["appName"]);

 

Now, let me explain you what I have done. 

In my function I have utilized the Convert,ChangeType(Object,Type) function to convert database values to any of the type which implements IConvertible Interface. I specially had to give consideration to string type since their default value is null and I wanted an empty string for DBNull value.

Hope this helps. Please let me know any improvements are required. Till then, Happy Coding....... :)

Tags: , , ,

Create Fluent API in C#

by Chintan Shah15. March 2011 09:26

 

A Fluent Interface is a way of implementing Object Oriented API in order to use method chaining to relay the instruction context of a subsequent call. If you have ever used jQuery, you must be aware of the flexibility that jQuery provides using chaining of the methods. Code created using Fluent Interface is more readable and easier to understand but it can be a nightmare debugging it as multiple fluent functions will form only a single statement.

Let’s see an Implementation of the Fluent Interface API.


This is our Interface for the FluentCalculator:

namespace FluentAPI
{
public interface ICalculatorFluent
{
ICalculatorFluent Add(int number);
ICalculatorFluent Subtract(int number);
ICalculatorFluent Multiply(int number);
ICalculatorFluent Divide(int number);
int Result();
}    
}

 

Now, let’s see how to implement this interface in order to get a Fluent Calculator.

namespace FluentAPI
{
public class CalculatorFlent : ICalculatorFluent
{
private int result = 0;
public ICalculatorFluent Add(int number)
{
result = result + number;
return this;
}
public ICalculatorFluent Subtract(int number)
{
result = result - number;
return this;
}
public ICalculatorFluent Multiply(int number)
{
result = result * number;
return this;
}
public ICalculatorFluent Divide(int number)
{
result = result / number;
return this;
}
public int Result()
{
return result;
}
}
}

 

As you can see, we are chaining the methods on the same instance of the class. This way, we achieve Flexibility and Readability of the sequence of operations. Now let’s see all code in action.

namespace FluentAPI
{
class Program
{
static void Main(string[] args)
{
CalculatorFlent calculator = new CalculatorFlent();
int result = calculator.Add(100)
.Multiply(2)
.Divide(4)
.Subtract(25)
.Result();
Console.WriteLine(String.Format(" ((((0 + 100) * 2) / 4) - 25) = {0}",result));                        
}
}
}

This will output 25. As you saw, we just implemented a nice API using fluent approach. I hope you liked it.

Gearing up for the next post, till then, Happy Fluenting... J 

Tags: ,

Getting Started With Silverlight 4

by Chintan Shah22. October 2010 00:12

Hello Readers,

This is the first part of a multi part tutorial series of learning silverlight. Today we shall be creating our first Silverlight 4 "Hello World" Application in Visual Studio 2010. In this article I assume that you have sufficient knowledge about XML and C#. To complete this tutorial you will need following things.

1. Visual Studio 2010 (Express edition will do fine).

2. Silverlight Tools for Visual Studio.

Now, after getting everything in place. Start Visual Studio 2010 and Click on New Project and give HelloWorld in Application name and hit OK.

 

Now, it will open up new window asking you to Host the Silverlight application in a new web site. We will keep that option selected and in the Web Application type we will keep the default selected. now, at the bottom it asks for target silverlight version and whether we want WCF RIA services in application or not. we will select Silverlight 4 and we dont need WCF RIA Service.

 

 

Now, when you click OK. It will bring up its new much improved WYSIWYG IDE for editing and creating Silverlight application visually. here we have two sections.

1. Silverlight Designer (On Top)

2. XAML Editor (On Bottom)

 

 

Now, go to Toolbar on the left side and select few shapes and draw them on white surface just like you draw anything on Paint Bush and put a TextBlock on the white board abd write Hello World inside it.

 

Now hit F5 and a new Browser window will open. there you have. we just created a Simplest Silverlight Application of all time. see this is that easy just drag and drop.

 

 

In the next tutorial I will be talking about the folder structure of Silverlight project and few essential files needed for Silverlight to run. till then Happy Silverlighting :)

Tags: ,

General Introduction to Silverlight and Alternatives

by Chintan Shah15. October 2010 01:41


Hello Readers,


Now days you must have come across a word called "Silverlight". Well, you might think what is silverlight. And being a common man It's hard to understand by the language given by Microsoft of Silverlight.

"Silverlight is a powerful development platform for creating engaging, interactive user experiences for Web, desktop, and mobile applications when online or offline."

Now, For a common man to understand Silverlight. I have my own version of definition to give.

"Silverlight is a Technology for creating engaging application for web and desktop which can run on your PC, Mobiles and even on your entertainment devices like XBOX 360."

 

Why the hell we need Silverlight (We have been using Flash!!!) ??

Well, I guess that's a valid point why the hell we need silverlight since we have flash. In my opinion, when flash was designed. Its focus was more on creating interactive Ads. Its foundation is based on Ads. so It was never built for modern day application. and Silverlight has been targeted at much bigger market of Enterprise customers who want LOB (Line of Business) Application for their environment and also to continue using their existing skill set. So, Silverlight's foundation is more application oriented. which means that you can get better applications and games up and running in almost no time. and plus its optimized for modern day hardware to utilize power of current multi-core processors.

What are other alternatives to Silverlight?

There are 4 major compititors to Silverlight.

 

1. AJAX

AJAX is a very tough competitor  for Silverlight. AJAX is much light weight then Silverlight and doesn't require any plug-ins in browser. It provides great UI and a very responsive UI (My favourite Gmail Smile). but, where it lacks is when employing complex business logic. javascript is a very powerful language but it seems to lack some of the feature of traditional and modern day programing languages. so, building a complex business application and maintaining it is very tough.

2. Flash / Flex

Flash.Flex is considered biggest competition for Silverlight. It has been around for over 10 years and has really matured into exceptional platform for application development. It has the highest user base with installed plug-in. Flash plug-in is lighter in download then Silverlight.

Well, all is well with flash then how silverlight can compete with such a giant. Well well, This giant has a big problem. Adobe is not a developer company Its a designer friendly company. And on the other hand Microsoft is well know for its love for its developers. which means you get better development tools to develop silverlight (My favourite Visual Studio and Expression Blen). Plus Silverlight is very very much developer friendly and designer friendly. and since its a microsoft product you can expect a ton of resource to learn silverlight.

When it comes to install user base. Silverlight has more than 60% of total market covered and its progressing really fast. Plus you can get a whole lot of developers who can develop on silverlight using existing .Net skill set.


3. JavaFX

JavaFX has backing of one the oldest platform-independent framework JAVA. yes just like java, JavaFX also runs everywhere. JavaFX also allows you to use you existing skill set of Java and for designing it uses CSS like syntax. and Java also has huge user install base.

Now comparing to Silverlight its still an immature product to develop for. Its has been around for 2 years now. but has not matured enough. plus, there are very less resource available to learn JavaFX quickly. JavaFX can catch up with Flash and Silverlight in very near future. It has great potential to do so.


4. HTML 5

These days we all are hearing about how HTML 5 will change face of Web. At present HTML 5 is just a draft and that draft is implemented by many different vendors. I can say it will take around a year and half for wide adaption of HTML 5. at present you can't depend on HTML 5 for your business demands. plus it is only supported by few browsers and that too in beta stage. HTML 5 promises to bring great features through <canvas> and <video>. plus it will be able to provide much needed features that lacked in HTML 4.


Conclusion

All in all, All other technology are great at creating web application. then why silverlight?. this can be a big debate to answer this question just like that. when selecting between these technologies lots of factors come under consideration like.

1. Your existing skill set.

2. Target Audience

3. Target Devices.

4. Cost and Time for Development.

5. Stability in Technology.

Why i think silverlight has great future is because,

1. Its backed by a giant in developers "Microsoft"

2. It has many unique features and excellent line of Development Tools.

3. Internet is full with the silverlight resource.

Tags: , , ,

HTTP Binding vs NetTcpBinding

by Chintan Shah1. October 2010 00:12

Hello Readers,


Today I faced an interview from a client regarding my WCF experience. He
asked me which of the following bindings will perform better, either httpBinding or
netTcpBinding. As many of you might know the answer, I answered netTcpBinding.
So, he asked me to elaborate the pros and cons of both the bindings and here is
what my answer was:


1. Environment

If you are working in an Intranet environment, then netTcp is the best choice. But, if
you are working on an Internet application where you don’t have control over other
environments, then http is a safe bet as many firewalls block TCP traffic. But, since
Http is considered as a harmless protocol, it is allowed by most of the firewalls.


2. Target Consumer of Service

If your Target consumers of service are .Net clients or you are certain that this
service will be consumed by homogeneous clients only then you can go for netTcp
binding. But, here http has huge lead over netTcp as Http binding opens doors to
thousands of clients which require knowing only http protocol.


3. Interoperability

With netTcp you really don’t have any interoperability. But with http binding you have
loads of options for interoperability.


4. Performance and Security

When you are designing an application for a network intensive operation, netTcp
just outperforms http by miles. Also, netTcp provides a strong security by supporting
both Message and Transport security options without huge overheads. While http
binding are not that efficient, the fundamental reason is because netTcp uses binary
encoding to transfer data which is extremely fast where as http uses markup encoder
which are not that performative, plus while using only http binding, your information
will go in plain text and you will be required to use Message security or purchase an
SSL certificate to host services on HTTPS.

Well, that’s all for today. Client seemed happy with my answers and assigned us the
project :)

Note : By HttpBinding i meant both wsHttpBinding and BasicHttpBinding.


Tags: , ,

Hello World

by Chintan Shah26. September 2010 01:30

Hello Readers,


I am Chintan Shah. I work on WPF, WCF, Silverlight and ASP.Net. I learn a lot everyday and I love to share all those things with you. so, from now onwards be sure to check my blog for interesting topics.

Tags:

Blog

About the author

I work on WPF, WCF, Silverlight and Asp.Net. I am working as a developer at Promact Infotech Pvt Ltd. I love blogging and sharing knowledge.