Thursday, July 8, 2010

Fun .......


1. A small boy opens the door and looks at his sister's boy friend and asks innocently "Every day you come to meet my sister , don't you have your own sister"
2. Santa went for an interview Bank manager: what is cyclone ? Santa: It is a smallest loan given by bank to buy a cycle)))
3. Innocent kid handling his breakup ... Main tumhe bhulne ki bahut koshish karta hun, par kya karun mummmy roj BAADAAM khila deti hai. Aur muje tumhaari YAAD fir see aa jaati hai
4. Pintu was having habbit of eating nails of his hand, His parents sent him to Ramdev Baba for treatment..... . . . Now Pintu can also eat nails of his legs..
5. Teeth said 2 Tongue " If I just press u little hard, you will get cut.Tongue replied: "If I misuse 1 word against some1, then all the 32 of u will come out at once"
6. What is the height of flirting ? When your love letter starts with . . . . " TO WHOMSOEVER IT MAY CONCERN"
7. Ek aadmi ka ye sun kar heart fail ho gaya jab uski kaam waali bai ne kaha Saahab "Orkut pe muje b add kar lo"
8. Dada(Grand Father): Beta ja paani le aa. Pota(Grand Son): Mai nai laa sakta, mai game khel raha hun 2nd Pota (Second grand son): Rahne do dada g, ye to hai he BADATMEEZ.... ... .. ... .. .. Ap khud he ja k le aao.
9. World's shortest poem.. Baba black sheep have u any wool? .. .. ... .. . sheep: NO, get lost.
10. Jinn : Kya huqum hai mere Aaka ? Aaka: Mere account me jaldi se 10 crore rs aur katrina se shaadi 10 sec me karwa do. Jinn: Aaaka, huqum karo...bakwaas mat karo !!!
11. Police: Oye, carparking ki jagah bike kyu park ki hai ? Santa: just smiled and said "sirf do pahiyon ka farak hai UNCLE, aa jayenge
12. Ek dukhi aadmi bola: Aisi zindagi se toh maut achhy. Achanak yamdoot aya aur bola : Tumhaari jaan lene ka huqum hai. Aadmi: lo kar lo baaat, ab insaan majaak b nai kar sakta.
13. A poor man of U.P catches a fish but can't cook due to No gas No electricity No Oil Man puts fish back in to river. Fish comes up and shout "Mayaavati zindabaad
14. Santa london k ek hotel me murgi khaane gaya lekin murgi ka english word bhool gaya Waiter: What would you like to have sir ? Santa: 1 plate Egg's mother
15. Pathan Ladki se: I Love you ! Ladki:Tameez se baaat karo Pathan:Bismilllah Hir rehman Nir Reheeem, with due respect I beg to say that "I Love you".
16. Gabbar : ye hath muje de de Thakur. Frustrated Thakur : Le le, mere bhi le le, Kalia ke bhi le le, Basanti k bhi le le.Jai or veeru ke bhi le le aur DURGA MATA ban ja.
17. Taj Mahal ko dekh kar bola shahjahan ka pota.. Taj Mahal ko dekh kar bola shahjahan ka pota. "Aj apna bhi bank balance hota agar dada aashiq na hota".
18. Galib ne GF ko date par bulaaya aur wo late ayi. GF: sorry, I am late.Galib: Falak pe chand sitaaron ko neend aa rahy hai, dossri ka time ho gaya aur tu ab aa rahy hai.
19. Ek bachha door bell bajaane ki koshish kar raha tha. Ek old man ne dekha aur bell baja di.Aur bachhe se bola: Aur kuch beta? Bachha: Ab bhaago.

Saturday, December 26, 2009

SSIS (SQL Server Integration Services)

SQL Server Integration Services (SSIS) is one of the main issues of Microsoft BI (Business Intelligence) concept representing the data integration and data transformation in the enterprise level approach.

SSIS (SQL Server Integration Services) has the abilty to gather data from various resources in different kinds of formats, process this data, transform data and convert the processed data into any shape that you can use in your daily business as well as for data-mining and data warehouse applications.

By using SSIS, SQL Server developers and Database Administrators can reach data from XML files, text files, CSV files as well as relational databases.

By using SSIS, emailing data or many tasks like storing the processed data into a file folder can be managed easily bu not writing a line of code using the SSIS task packages.

Integration Services provides a platform to build data integration and workflow applications. The primary use for SSIS is data warehousing, as the product features a fast and flexible tool for data extraction, transformation, and loading (ETL). The tool may also be used to automate maintenance of SQL Server databases, update multidimensional cube data, and perform other functions.

Introduction

Maybe the question should be what isn’t new with SQL Server Integration Services. SQL Server Integration Services or SSIS is a completely new product written from the ground up for SQL Server 2005. It replaces DTS, a feature introduced with SQL Server 7 and enhanced with the SQL Server 2000 release. SSIS, like DTS, is a tool to import, export, and transform data. If you haven’t had a chance to play with SSIS yet, you’ll be surprised at how different it is and how much more it can do.

Three dimensional

The first difference I noticed, besides the fact that the work to build packages is done is Visual Studio 2005, is that there are three layers in which to work: Control Flow, Data Flow and Event Handlers.

The Control Flow page is the main area used to build the package. On the Control Flow area you can add many new tasks. Some are containers to hold other tasks such as the For Loop Container. Others perform work like the Execute SQL Task. Some are entirely new like the group of maintenance plan tasks. The one task that is the heart of the Control Flow area is the Data Flow Task. Once you add a Data Flow Task you can drill down to the Data Flow layer. A Data Flow page is created for each Data Flow Task added to the Control Flow page.

On the Data Flow page you set up connections and transforms to import, transform, and export data. Once again, there are some Data Flow Source and Destination objects that you would expect to see and a few surprises, like the XML data source. The next surprise is the number of Data Flow Transformations available. From Aggregate to Fuzzy Lookup to Unpivot, I counted 28 in all. Figure 1 shows a typical Data Flow where some data is imported, a new column is derived, and the results exported to a file.

http://www.sqlservercentral.com/articles/whatsnewwithssis/2234/newssis_Fig1.jpg

Figure 1: A typical data flow

Event Handlers is the third of the three layers. It is possible to attach an event handler to any of several events on each task at the Control Flow level. The tasks available in the Event Handlers Toolbox are identical to the Control Flow Toolbox, even the Data Flow task. You can also assign event handlers to a task within an event handler. The good thing is that you have lots of flexibility, the bad thing is that your package could become extremely complex and hard to understand so use caution here. You can use the event handlers to handle errors or check something before a task executes.

More control

SSIS gives you many new ways to control the flow of your package that could only be done before by writing code. One of the coolest control features is the ability to set up looping within the package. Two tasks, the For Loop Container and Foreach Loop Container, are available for this purpose. The For Loop Container (see Figure 2) can be used to repeat a set of tasks a given number of times. The Foreach Loop Container can be used to perform the tasks on each item in a collection, a file in a folder perhaps.

http://www.sqlservercentral.com/articles/whatsnewwithssis/2234/newssis_fig2.jpg

Figure 2: A For Loop Container

The precedence constraints used to connect one task to the next have been enhanced as well. The control flow between tasks may be based on the value of an expression in addition to or instead of the outcome of the previous task (see Figure 3). Again, you have the ability to fine-tune your package with little or no code.

http://www.sqlservercentral.com/articles/whatsnewwithssis/2234/newssis_fig3.jpg

Figure 3: The Precedence Constraint Editor

A package may also be restarted from the task that failed if Checkpoints are enabled in a package. Basically, you configure a file to log information as the package runs (see Figure 4). Then set the FailPackageOnFailure property to True for each task. If your package fails, you correct the problem and restart the package. The package will start up from the point of failure allowing you to save time and resources over starting the package from the beginning.

http://www.sqlservercentral.com/articles/whatsnewwithssis/2234/newssis_fig4.jpg

Figure 4: How to enable Checkpoints

Variables and expressions

System variables for the package and each task are available, and you can set up user variables as well. For example, you need to set up a variable to count the loops when using the For Loop Container. User variables can be set up at the package level or the scope of the variable can be limited to a container or task.

The configuration dialog of each Control Flow task has an Expressions page. Each task property can be controlled dynamically by using expressions. Use variables and the built in functions to build an expression and assign it to a property. This replaces the Dynamic Property Task found in DTS.

Debugging

The ability to step through a package as it runs will save lots of time when troubleshooting errors. Breakpoints can be assigned to events on each Control Flow task allowing you to view the value of variables. Figure 5 shows how to make the For Loop Container break when the loop count equals five.

http://www.sqlservercentral.com/articles/whatsnewwithssis/2234/newssis_fig5.jpg

Figure 5: Breakpoints

In the Data Flow area, Data Viewers may be configured at each step to view the data as it is imported or transformed (see Figure 6). A graph can also be configured as a Data Viewer if that would make more sense. After viewing the data, click the green arrow to resume the package.

http://www.sqlservercentral.com/articles/whatsnewwithssis/2234/newssis_fig6.jpg

Figure 6: A Data Viewer

Easier coding

There are many tasks and transforms that will reduce the need for scripting. Luckily, when you must write some code, the Script Task uses the Microsoft Visual Studio for Applications environment complete with Intellisense to help you navigate the SSIS object model. Variables, as long as they are in scope, may be accessed by the script. To those of you who prefer C#, sorry, only Visual Basic.Net is allowed. Don’t get this task confused with the old ActiveX Script Task still available for converted DTS packages.

Upgrading existing DTS packages

A wizard is provided to convert existing DTS packages to SSIS. Don’t count on this to work 100% of the time, though, because there is not a one-to-one mapping between the DTS and SSIS objects. Many of you have packages that are pretty complex, and you may have had to jump through some hoops to accomplish your goals. The dtsrun command is still supported, and a task specifically for running DTS packages is included in the Control Flow Toolbox. Be sure to read Brian Knight’s article, Upgrading SQL Server 2000 DTS to SSIS for more information.

Friday, August 7, 2009

New Features of Visual Studio 2008 for .NET Professionals


1. LINQ Support LINQ
essentially is the composition of many standard query operators that allow you to work with data in a more intuitive way regardless.The benefits of using LINQ are significant – Compile time checking C# language queries, and the ability to debug step by step through queries.
2. Expression Blend Support
Expression blend is XAML generator tool for silverlight applications. You can install Expression blend as an embedded plug-in to Visual Studio 2008. By this you can get extensive web designer and JavaScript tool.
3. Windows Presentation Foundation
WPF provides you an extensive graphic functionality you never seen these before. Visual Studio 2008 contains plenty of WPF Windows Presentation Foundation Library templates. By this a visual developer who is new to .NET, C# and VB.NET can easily develop the 2D and 3D graphic applications.Visual Studio 2008 provides free game development library kits for games developers. currently this game development kits are available for C++ and also 2D/3D Dark Matter one image and sounds sets.
4. VS 2008 Multi-Targeting Support
Earlier you were not able to working with .NET 1.1 applications directly in visual studio 2005. Now in Visual studio 2008 you are able to create, run, debug the .NET 2.0, .NET 3.0 and .NET 3.5 applications. You can also deploy .NET 2.0 applications in the machines which contains only .NET 2.0 not .NET 3.x.
5. AJAX support for ASP.NET
Previously developer has to install AJAX control library separately that does not come from VS, but now if you install Visual Studio 2008, you can built-in AJAX control library. This Ajax Library contains plenty of rich AJAX controls like Menu, TreeView, webparts and also these components support JSON and VS 2008 contains in built ASP.NET AJAX Control Extenders.
6. JavaScript Debugging Support
Since starting of web development all the developers got frustration with solving javascript errors. Debugging the error in javascript is very difficult. Now Visual Studio 2008 makes it is simpler with javascript debugging. You can set break points and run the javaScript step by step and you can watch the local variables when you were debugging the javascript and solution explorer provides javascript document navigation support.
7. Nested Master Page Support
Already Visual Studio 2005 supports nested master pages concept with .NET 2.0, but the problem with this Visual Studio 2005 that pages based on nested masters can't be edited using WYSIWYG web designer. But now in VS 2008 you can even edit the nested master pages.
8. LINQ Intellisense and Javascript Intellisense suppor
t for silverlight applicationsMost happy part for .NET developers is Visual Studio 2008 contains intellisense support for javascript. Javascript Intellisense makes developers life easy when writing client side validation, AJAX applications and also when writing Silverlight applicationsIntellisense Support: When we are writing the LINQ Query VS provides LINQ query syntax as tool tips.
9. Organize Imports or Usings:
We have Organize Imports feature already in Eclipse. SInce many days I have been waiting for this feature even in VS. Now VS contains Organize Imports feature which removes unnecessary namespaces which you have imported. You can select all the namespaces and right click on it, then you can get context menu with Organize imports options like "Remove Unused Usings", "Sort Usings", "Remove and Sort". Refactoring support for new .NET 3.x features like Anonymous types, Extension Methods, Lambda Expressions.
10. Intellisense Filtering:
Earlier in VS 2005 when we were typing with intellisense box all the items were being displayed. For example If we type the letter 'K' then intellisense takes you to the items starts with 'K' but also all other items will be presented in intellisense box. Now in VS 2008 if you press 'K' only the items starts with 'K' will be filtered and displayed.
11. Intellisense Box display position
Earlier in some cases when you were typing the an object name and pressing . (period) then intellisense was being displayed in the position of the object which you have typed. Here the code which we type will go back to the dropdown, in this case sometimes programmer may disturb to what he was typing. Now in VS 2008 If you hold the Ctrl key while the intellisense is dropping down then intellisense box will become semi-transparent mode.
12. Visual Studio 2008 Split View
VS 2005 has a feature show both design and source code in single window. but both the windows tiles horizontally. In VS 2008 we can configure this split view feature to vertically, this allows developers to use maximum screen on laptops and wide-screen monitors.Here one of the good feature is if you select any HTML or ASP markup text in source window automatically corresponding item will be selected in design window.
13. HTML JavaScript warnings, not as errors:
VS 2005 mixes HTML errors and C# and VB.NET errors and shows in one window. Now VS 2008 separates this and shows javascript and HTML errors as warnings. But this is configurable feature.
14. Debugging .NET Framework Library Source Code:
Now in VS 2008 you can debug the source code of .NET Framework Library methods. Lets say If you want to debug the DataBind() method of DataGrid control you can place a debugging point over there and continue with debug the source code of DataBind() method.
15. In built Silverlight Library
Earlier we used to install silverlight SDK separately, Now in VS 2008 it is inbuilt, with this you can create, debug and deploy the silverlight applications.
16. Visual Studio LINQ Designer
Already you know in VS 2005 we have inbuilt SQL Server IDE feature. by this you no need to use any other tools like SQL Server Query Analyzer and SQL Server Enterprise Manger. You have directly database explorer by this you can create connections to your database and you can view the tables and stored procedures in VS IDE itself. But now in VS 2008 it has View Designer window capability with LINQ-to-SQL.
17. Inbuilt C++ SDK
Earlier It was so difficult to download and configure the C++ SDK Libraries and tools for developing windows based applications. Now it is inbuilt with VS 2008 and configurable
18. Multilingual User Interface Architecture
MUIMUI is an architecture contains packages from Microsoft Windows and Microsoft Office libraries. This supports the user to change the text language display as he wish.Visual Studio is now in English, Spanish, French, German, Italian, Chinese Simplified, Chinese Traditional, Japanese, and Korean. Over the next couple of months. Microsoft is reengineering the MUI which supports nine local languages then you can even view Visual studio in other 9 local languages.
19. Microsoft Popfly Support
Microsoft Popfly explorer is an add-on to VS 2008, by this directly you can deploy or hosting the Silverlight applications and Marshup objects
SMTP and POP3 Mail server Setting

Thursday, July 9, 2009

LINQ:Language Integrated Query



Introducing Linq
Linq is short for Language Integrated Query. If you are used to using SQL to query databases, you are going to have something of a head start with Linq, since they have many ideas in common. Before we dig into Linq itself, let's step back and look at what makes SQL different from C#.Imagine we have a list of orders. For this example, we will imagine they are stored in memory, but they could be in a file on disk too. We want to get a list of the costs of all orders that were placed by the customer identified by the number 84. If we set about implementing this in C# before version 3 and a range of other popular languages, we would probably write something like (assuming C# syntax for familiarity): List Found = new List();foreach (Order o in Orders) if (o.CustomerID == 84) Found.Add(o.Cost);
Here we are describing how to achieve the result we want by breaking the task into a series of instructions. This approach, which is very familiar to us, is called imperative programming. It relies on us to pick a good algorithm and not make any mistakes in the implementation of it; for more complex tasks, the algorithm is more complex and our chances of implementing it correctly decrease.If we had the orders stored in a table in a database and we used SQL to query it, we would write something like: SELECT Cost FROM Orders WHERE CustomerID = 84
Here we have not specified an algorithm, or how to get the data. We have just declared what we want and left the computer to work out how to do it. This is known as declarative or logic programming.Linq brings declarative programming features into imperative languages. It is not language specific, and has been implemented in the Orcas version of VB.Net amongst other languages. In this series we are focusing on C# 3.0, but the principles will carry over to other languages.
Understanding A Simple Linq Query
Let's jump straight into a code example. First, we'll create an Order class, then make a few instances of it in a List as our test data. With that done, we'll use Linq to get the costs of all orders for customer 84. class Order{ private int _OrderID; private int _CustomerID; private double _Cost; public int OrderID { get { return _OrderID; } set { _OrderID = value; } } public int CustomerID { get { return _CustomerID; } set { _CustomerID = value; } } public double Cost { get { return _Cost; } set { _Cost = value; } }}class Program{ static void Main(string[] args) { // Set up some test orders. var Orders = new List { new Order { OrderID = 1, CustomerID = 84, Cost = 159.12 }, new Order { OrderID = 2, CustomerID = 7, Cost = 18.50 }, new Order { OrderID = 3, CustomerID = 84, Cost = 2.89 } }; // Linq query. var Found = from o in Orders where o.CustomerID == 84 select o.Cost; // Display results. foreach (var Result in Found) Console.WriteLine("Cost: " + Result.ToString()); }}
The output of running this program is: Cost: 159.12Cost: 2.89
Let's walk through the Main method. First, we use collection and object initializers to create a list of Order objects that we can run our query over. Next comes the query - the new bit. We declare the variable Found and request that its type be inferred for us by using the "var" keyword.We then run across a new C# 3.0 keyword: "from". from o in Orders
This is the keyword that always starts a query. You can read it a little bit like a "foreach": it takes a collection of some kind after the "in" keyword and makes what is to the left of the "in" keyword refer to a single element of the collection. Unlike "foreach", we do not have to write a type.Following this is another new keyword: "where". where o.CustomerID == 84
This introduces a filter, allowing us to pick only some of the objects from the Orders collection. The "from" made the identifier "o" refer to a single item from the collection, and we write the condition in terms of this. If you type this query into the IDE yourself, you will notice that it has worked out that "o" is an Order and intellisense works as expected.The final new keyword is "select". select o.Cost
This comes at the end of the query and is a little like a "return" statement: it states what we want to appear in the collection holding the results of the query. As well as primitive types (such as int), you can instantiate any object you like here. In this case, we will end up with Found being a List, though.You may be thinking at this point, "hey, this looks like SQL but kind of backwards and twisted about a bit". That is a pretty good summary. I suspect many who have written a lot of SQL will find the "select comes last" a little grating at first; the other important thing to remember is that all of the conditions are to be expressed in C# syntax, not SQL syntax. That means "==" for equality testing, rather than "=" in SQL. Thankfully, in most cases that mistake will lead to a compile time error anyway.
A Few More Simple Queries
We may wish our query to return not only the Cost, but also the OrderID for each result that it finds. To do this we take advantage of anonymous types. var Found = from o in Orders where o.CustomerID == 84 select new { OrderID = o.OrderID, Cost = o.Cost };
Here we have defined an anonymous type that holds an OrderID and a Cost. This is where we start to see the power and flexibility that they offer; without them we would need to write custom classes for every possible set of results we wanted. Remembering the projection syntax, we can shorten this to: var Found = from o in Orders where o.CustomerID == 84 select new { o.OrderID, o.Cost };
And obtain the same result. Note that you can perform whatever computation you wish inside the anonymous type initializer. For example, we may wish to return the Cost of the order with an additional sales tax of 10% added on to it. var Found = from o in Orders where o.CustomerID == 84 select new { o.OrderID, o.Cost, CostWithTax = o.Cost * 1.1 };
Conditions can be more complex too, and are built up in the usual C# way, just as you would do in an "if" statement. Here we apply an extra condition that we only want to see orders valued over a hundred pounds. var Found = from o in Orders where o.CustomerID == 84 && o.Cost > 100 select new { o.OrderID, o.Cost, CostWithTax = o.Cost * 1.1 };

Ordering
It is possible to sort the results based upon a field or the result of a computation involving one or more fields. This is achieved by using the new "orderby" keyword. var Found = from o in Orders where o.CustomerID == 84 orderby o.Cost ascending select new { o.OrderID, o.Cost };
After the "orderby" keyword, we write the expression that the objects will be sorted on. In this case, it is a single field. Notice this is different from SQL, where there are two words: "ORDER BY". I have added the keyword "ascending" at the end, though this is actually the default. The result is that we now get the orders in order of increasing cost, cheapest to most expensive. To get most expensive first, we would have used the "descending" keyword.While I said earlier that the ordering condition is based on fields in the objects involved in the query, it actually doesn't have to be. Here's a way to get the results in a random order. Random R = new Random();var Found = from o in Orders where o.CustomerID == 84 orderby R.Next() select new { OrderID = o.OrderID, Cost = o.Cost };

Joins
So far we have just had one type of objects to run our query over. However, real life is usually more complex than this. For this example, let's introduce another class named Customer. class Customer{ private int _CustomerID; private string _Name; private string _Email; public int CustomerID { get { return _CustomerID; } set { _CustomerID = value; } } public string Name { get { return _Name; } set { _Name = value; } } public string Email { get { return _Email; } set { _Email = value; } }}
In the Main method, we will also instantiate a handful of Customer objects and place them in a list. var Customers = new List { new Customer { CustomerID = 7, Name = "Emma", Email = "emz0r@worreva.com" }, new Customer { CustomerID = 84, Name = "Pedro", Email = "pedro@cerveza.es" }, new Customer { CustomerID = 102, Name = "Vladimir", Email = "vladimir@pivo.ru" } };
We would like to produce a list featuring all orders, stating the ID and cost of the order along with the name of the customer. To do this we need to involve both the List of orders and the List of customers in our query. This is achieved using the "join" keyword. Let's replace our query and output code with the following. // Query.var Found = from o in Orders join c in Customers on o.CustomerID equals c.CustomerID select new { c.Name, o.OrderID, o.Cost };// Display results.foreach (var Result in Found) Console.WriteLine(Result.Name + " spent " + Result.Cost.ToString() + " in order " + Result.OrderID.ToString());
The output of running this program is: Pedro spent 159.12 in order 1Emma spent 18.5 in order 2Pedro spent 2.89 in order 3
We use the "join" keyword to indicate that we want to refer to another collection in our query. We then once again use the "in" keyword to declare an identifier that will refer to a single item in the collection; in this case it has been named "c". Finally, we need to specify how the two collections are related. This is achieved using the "on ... equals ..." syntax, where we name a field from each of the collections. In this case, we have stated that the CustomerID of an Order maps to the CustomerID of a Customer.When the query is evaluated, an object in the Customers collection is located to match each object in the Orders collection. Note that if there were many customers with the same ID, there may be more than one matching Customer object per Order object. In this case, we get extra results. For example, change Vladimir to also have an OrderID of 84. The output of the program would then be: Pedro spent 159.12 in order 1Vladimir spent 159.12 in order 1Emma spent 18.5 in order 2Pedro spent 2.89 in order 3Vladimir spent 2.89 in order 3
Notice that Vladimir never featured in the results before, since he had not ordered anything.
Getting All Permutations With Multiple "from"s
It is possible to write a query that gets every combination of the objects from two collections. This is achieved by using the "from" keyword multiple times. var Found = from o in Orders from c in Customers select new { c.Name, o.OrderID, o.Cost };
Earlier I suggested that you could think of "from" as being a little bit like a "foreach". You can also think of multiple uses of "from" a bit like nested "foreach" loops; we are going to get every possible combination of the objects from the two collections. Therefore, the output will be: Emma spent 159.12 in order 1Pedro spent 159.12 in order 1Vladimir spent 159.12 in order 1Emma spent 18.5 in order 2Pedro spent 18.5 in order 2Vladimir spent 18.5 in order 2Emma spent 2.89 in order 3Pedro spent 2.89 in order 3Vladimir spent 2.89 in order 3
Which is not especially useful. You may have spotted that you could have used "where" in conjunction with the two "from"s to get the same result as the join: var Found = from o in Orders from c in Customers where o.CustomerID == c.CustomerID select new { c.Name, o.OrderID, o.Cost };
However, don't do this, since it computes all of the possible combinations before the "where" clause, which goes on to throw most of them away. This is a waste of memory and computation. A join, on the other hand, never produces them in the first place.
Grouping
Another operations that you may wish to perform is categorizing objects that have the same value in a given field. For example, we might want to categorize orders by CustomerID. The result we expect back is a list of groups, where each group has a key (in this case, the CustomerID) and a list of matching objects. Here's the code to do the query and output the results. // Group orders by customer.var OrdersByCustomer = from o in Orders group o by o.CustomerID;// Iterate over the groups.foreach (var Cust in OrdersByCustomer){ // About the customer... Console.WriteLine("Customer with ID " + Cust.Key.ToString() + " ordered " + Cust.Count().ToString() + " items."); // And what they ordered. foreach (var Item in Cust) Console.WriteLine(" ID: " + Item.OrderID.ToString() + " Cost: " + Item.Cost.ToString());}
The output that it produces is as follows: Customer with ID 84 ordered 2 items. ID: 1 Cost: 159.12 ID: 3 Cost: 2.89Customer with ID 7 ordered 1 items. ID: 2 Cost: 18.5
This query looks somewhat different to the others that we have seen so far in that it does not end with a "select". The first line is the same as we're used to. The second introduces the new "group" and "by" keywords. After the "by" we name the field that we are going to group the objects by. Before the "by" we put what we would like to see in the resulting per-group collections. In this case, we write "o" so as to get the entire object. If we had only been interested in the Cost field, however, we could have written: // Group orders by customer.var OrdersByCustomer = from o in Orders group o.Cost by o.CustomerID;// Iterate over the groups.foreach (var Cust in OrdersByCustomer){ // About the customer... Console.WriteLine("Customer with ID " + Cust.Key.ToString() + " ordered " + Cust.Count().ToString() + " items."); // And the costs of what they ordered. foreach (var Cost in Cust) Console.WriteLine(" Cost: " + Cost.ToString());}
Which produces the output: Customer with ID 84 ordered 2 items. Cost: 159.12 Cost: 2.89Customer with ID 7 ordered 1 items. Cost: 18.5
You are not restricted to just a single field or the object itself; you could, for example, instantiate an anonymous type there instead.
Query Continuations
At this point you might be wondering if you can follow a "group ... by ..." with a "select". The answer is yes, but not directly. Both "group ... by ..." and "select" are special in so far as they produce a result. You must terminate a Linq query with one or the other. If you try to do something like: var CheapOrders = from o in Orders where o.Cost < ordercounts =" from" customerid =" g.Key," totalorders =" g.Count()">Under The Hood
Now we have looked at the practicalities of using Linq, I am going to spend a little time taking a look at how it works. Don't worry if you don't understand everything in this section, it's here for those who like to dig a little deeper.Throughout the series I have talked about how all of the language features introduced in C# 3.0 somehow help to make Linq possible. While anonymous types have shown up pretty explicitly and you can see from the lack of type annotations we have been writing that there is some type inference going on, where are the extension methods and lambda expressions?There's a principle in language design and implementation called "syntactic sugar". We use this to describe cases where certain syntax isn't directly compiled, but is first transformed into some other more primitive syntax and then passed to the compiler. This is exactly what happens with Linq: your queries are transformed into a sequence of method calls and lambda expressions.The C# 3.0 specification goes into great detail about these transformations. In practice, you probably don't need to know about this, but let's look at one example to help us understand what is going on. Our simple query from earlier: var Found = from o in Orders where o.CustomerID == 84 select o.Cost;
After transformation by the compiler, becomes: var Found = Orders.Where(o => o.CustomerID == 84) .Select(o => o.Cost);
And this is what actually gets compiled. Here the use of lambda expressions becomes clear. The lambda passed to the Where method is called on each element of Orders to determine whether it should be in the result or not. This produces another intermediate collection, which we then call the Select method on. This calls the lambda it is passed on each object and builds up a final collection of the results, which is then assigned to Found. Beautiful, huh?Finally, a note on extension methods. Both Where and Select, along with a range of other methods, have been implemented as extension methods. The type they use for "this" is IEnumerable, meaning that any collection that implements that interface can be used with Linq. Without extension methods, it would not have been possible to achieve this level of code re-use.
DLinq and XLinq
In this article I have demonstrated Linq working with objects instantiated from classes that we implemented ourselves and stored in built-in collection classes that implement IEnumerable. However, the query syntax compiles down to calls on extension methods. This means that it is possible to write alternative implementations of Linq that follow the same syntax but perform different operations.Two examples of this, which will ship with C# 3.0, are DLinq and XLinq. DLinq enables the same language integrated query syntax to do queries on databases by translating the Linq into SQL. XLinq enables queries on XML documents.
Conclusion
Linq brings declarative programming to the C# language and will refine and unify the way that we work with objects, databases, XML and whatever anyone else writes the appropriate extension methods for. It builds upon the language features that we have already seen in the previous parts of the series, but hiding some of them away under syntactic sugar. While the query language has a range of differences to SQL, there are enough similarities to make knowledge of SQL useful to those who know it. However, its utility is far beyond providing yet another way to work with databases.

Silverlight


Content :


What is Silverlight?
Silverlight 1.0 :
Main features :
Silverlight 2.0 :
Main features :
How Silverlight would change the Web:
Getting Started With SilverLight :
What is Silverlight?
Silverlight is a new cross-browser, cross-platform implementation of the .NET Framework for building and delivering the next generation of media experiences and Rich Interactive Applications(RIA) for the web. It runs in all popular browsers, including Microsoft Internet Explorer, Mozilla Firefox, Apple Safari, Opera. The plugin required to run Silverlight is very small in size hence gets installed very quickly.
It is combination of different technolgoies into a single development platform that allows you to select tools and the programming language you want to use. Silverlight integrates seamlessly with your existing Javascript and ASP.NET AJAX code to complement functionality which you have already created.
Silverlight aims to compete with Adobe Flash and the presentation components of Ajax. It also competes with Sun Microsystems' JavaFX, which was launched a few days after Silverlight.
Currently there are 2 major versions of Silverlight:
Silverlight 1.0 and Silverlight 2.0( previously referred to as version 1.1).



Silverlight 1.0 :
Silverlight 1.0 consists of the core presentation framework, which is responsible for UI, interactivity and user input, basic UI controls, graphics and animation, media playback, DRM support, and DOM integration.
Main features of Silverlight 1.0 :
Built-in codec support for playing VC-1 and WMV video, and MP3 and WMA audio within a browser.
Silverlight supports the ability to progressively download and play media content from any web-server.
Silverlight also optionally supports built-in media streaming.
Silverlight enables you to create rich UI and animations, and blend vector graphics with HTML to create compelling content experiences.
Silverlight makes it easy to build rich video player interactive experiences.
Silverlight 2.0 :
Silverlight 2.0 includes a version of the .NET Framework, with the full Common Language Runtime as .NET Framework 3.0; so it can execute any .NET language including VB.NET and C# code. Unlike the CLR included with .NET Framework, multiple instances of the CoreCLR included in Silverlight can be hosted in one process. With this, the XAML layout markup file (.xaml file) can be augmented by code-behind code, written in any .NET language, which contains the programming logic.
This version ships with more than 30 UI controls(including TextBox, CheckBox, Slider, ScrollViewer, and Calendar controls), for two-way databinding support, automated layout management (by means of StackPanel, Grid etc) as well as data-manipulation controls, such as DataGrid and ListBox. UI controls are skinnable using a template-based approach.
Main features of Silverlight 2.0 :
A built-in CLR engine that delivers a super high performance execution environment for the browser. Silverlight uses the same core CLR engine that we ship with the full .NET Framework.
Silverlight includes a rich framework library of built-in classes that you can use to develop browser-based applications.
Silverlight includes support for a WPF UI programming model. The Silverlight 1.1 Alpha enables you to program your UI with managed code/event handlers, and supports the ability to define and use encapsulated UI controls.
Silverlight provides a managed HTML DOM API that enables you to program the HTML of a browser using any .NET language.
Silverlight doesn't require ASP.NET to be used on the backend web-server (meaning you could use Silverlight with with PHP on Linux if you wanted to).
Silverlight 2 includes Deep Zoom, a technology derived from Microsoft Live Labs Seadragon. It allows users to zoom into, or out of, an image (or a collage of images), with smooth transitions, using the mouse wheel. The images can scale from 2 or 3 megapixels in resolution into the gigapixel range, but the user need not wait for it to be downloaded entirely; rather, Silverlight downloads only the parts in view, optimized for the zoom level being viewed.
Silverlight 2 also allows limited filesystem access to Silverlight applications. It can use the operating system's native file dialog box to browse to any file (to which the user has access).

How Silverlight would change the Web:
Highest Quality Video Experience : prepare to see some of the best quality videos you have seen in your life, all embedded in highly graphical websites. The same research and technology that was used for VC-1, the codec that powers BluRay and HD DVD, is used by Microsoft today with its streaming media technologies.
Cross-Platform, Cross-Browser : Finally build web applications that work on any browser, and on any operating system. At release, Silverlight will work with Mac as well as Windows! The Mono project has also already promised support for Linux!.
Developers and Graphic Designers can play together! : Developers familiar with Visual Studio, Microsoft.net will be able to develop amazing Silverlight applications very quickly, and they will work on Mac's and Windows. Developers will finally be able to strictly focus on the back end of the application core, while leaving the visuals to the Graphic Design team using the power of XAML.
Cheaper : Silverlight is now the most inexpensive way to stream video files over the internet at the best quality possible. Licensing is dead simple, all you need is IIS in Windows Server, and you’re done.
Support for 3rd Party Languages : Using the power of the new Dynamic Language Runtime, developers will now be able to use Ruby, Python, and EcmaScript! This means a Ruby developer can develop Silverlight applications, and leverage the .net Framework!
Cross-Platform, Cross-Browser Remote Debugging : If you are in the need to debug an application running on a Mac, no problem! You can now set breakpoints, step into/over code, have immediate windows, and all that other good stuff that Visual Studio provides.
The best development environment on the planet : Visual Studio is an award winning development platform! As it continues to constantly evolve, so will Silverlight!
Silverlight offers copy protection : Have you noticed how easy it is to download YouTube videos to your computer, and save them for later viewing ? Silverlight will finally have the features enabling content providers complete control over their rich media content! Streaming television, new indie broadcast stations, all will now be possible!
Extreme Speed :There is a dramatic improvement in speed for AJAX-enabled websites that begin to use Silverlight, leveraging the Microsoft .net framework.


Getting Started With SilverLight:
In order to create Silverlight applications with following :
Runtime :
Microsoft Silverlight 2.0 : The runtime required to view Silverlight applications created with .NET Microsoft.
Developer Tools :
Microsoft Visual Studio 8.0 : The next generation development tool.
Microsoft Silverlight Tools for Visual Studio 2008 : The add-on to create Silverlight applications with Visual Studio 2008. This install will also install the Silverlight Developer Runtime and the Silverlight SDK. This add-on works with all versions of Visual Studio 2008 Service Pack 1, including Visual Web Developer.
Designer Tools :
Download the Expression designer tools to start designing Silverlight application.
Expression Blend 2.5The latest offering from Microsoft to create Silverlight content is
Expression Blend 2.5 June 2008 Preview.
Software Development Kit:
Microsoft Silverlight Software Development Kit: Download this SDK to create Silverlight Web experiences that target Silverlight 2.0. The SDK contains documentation, tools, Silverlight ASP.NET controls and the libraries needed to build Silverlight applications.
Eclipse Tools for Silverlight : An Open Source, feature-rich and professional RIA application development environment for Microsoft Silverlight in Eclipse.

Saturday, January 24, 2009

How to lose weight the healthy way


The healthiest way to lose weight is neither crash diets nor bursts of exercise. The body likes slow changes in terms of food and exercise.
For example, someone who has not exercised for years should not rush into running miles a day or pounding the treadmill. Not only will the struggle to do so leave you feeling disheartened and demotivated, you're also far more likely to injure yourself and set your fitness levels back further.
The same goes for people who suddenly start starving themselves. Diets that severely restrict calories or the types of food 'allowed' can lead you to be deficient in the nutrients and vitamins that your body needs.
So if you need to lose weight, what should you do?
Energy needs and weight loss
Your body uses food for energy. It stores any excess energy as fat. This means if you eat more food than your body needs for daily activities and cell maintenance, you will gain weight.
To lose weight, you need to get your body to use up these stores of fat. The most effective way to do this is to:
  • reduce the amount of calories you eat
  • increase your levels of activity.
This is why experts talk about weight loss in terms of diet and exercise.
Introduce changes gradually
Small changes can make a big difference. One extra biscuit a week can lead you to gain 5lb a year – cut that biscuit out of your diet and you'll lose the same amount.
You are also more likely to stick to, say, swapping full-fat milk for semi-skimmed or making time for breakfast each morning than a diet that sets rules for all foods.
You should think of weight loss in terms of permanently changing your eating habits. While weight-loss goals are usually set in term of weeks, the end game is to sustain these changes over months and years.
Increase your activity levels
Someone who increases the amount they exercise, but maintains the same diet and calorie intake, will almost certainly lose weight.
No matter if you hate gyms - even light exercise such as a short 20 minute walk will be beneficial if done most days of the week.
Every single time you exercise more than usual, you burn calories and fat.
There are lots of ways to increase the amount of activity you do. Team sports, racket sports, aerobics classes, running, walking, swimming and cycling will all improve your fitness levels.
Find something you enjoy that's easy for you to do in terms of location and cost. You are then more likely to build it into your routine and continue to exercise, despite inevitably missing the odd session through holidays, family commitments, etc.
  • Get out and about at the weekend. Leave your car on the drive and walk to the shops. Try to incorporate longer walks into outings to the park, coast or countryside and take a picnic so you are in control of what you are going to eat that day.
  • Every extra step you take helps. Always use the stairs instead of the lift, or get off the bus a stop before the usual one and walk the rest of the way.
  • Use commercial breaks between TV-programmes to stand up and do exercise, or consider using an exercise bicycle in the living room while watching your favourite programme.
Reduce your calorie intake

If you are overweight, you can't continue with your current eating habits.
It's not possible to reduce body fat while eating lots of food, cakes and sweets. This doesn't mean you can never have any treats, but you need to learn how to limit these foods to small quantities - say, for special occasions.
In terms of weight-loss, you can get your body to use up existing stores of fat by eating less and making healthier choices.
This doesn't mean crash diet (anything less than 1500 calories), which usually ends up with you either getting weaker or giving up in desperation. Quick-fix diets can lead to a yo-yoing effect of drastic weight loss followed by weight gain, resulting in a vicious cycle.
There are no shortcuts to losing weight in a healthy and reasonable way.
Eating 300 to 500 calories less per day should lead to a loss of between one and two pounds per week. This is a realistic target. It may seem slow, but would add up to a weight loss of more than three stone in a year.
Fat contains the most amount of calories out of all the food types (protein, carbohydrates), so a good way to achieve this is to cut down on fatty foods and eat more wholegrain bread, fruit and vegetables.
Below are ways to reduce calorie intake without having to alter your diet significantly.
  • Replace fizzy drinks and fruit cordials with water.
  • Swap whole milk for semi-skimmed, or semi-skimmed for skimmed.
  • Eat less lunch than usual. For example, make your own sandwich and limit the use of margarine/butter and full-fat mayonnaise (store-bought sandwiches often contain both).
  • Stop taking sugar in tea and coffee.
  • Have smaller portions of the food you enjoy.
  • Avoid having a second helping at dinner.
  • Cut out unhealthy treats such as confectionary, sugary biscuits and crisps between meals.
  • Cut down on beer and alcohol.
All these things will influence your health in a positive way.
Finally, don't be tempted to skip breakfast – or any meal to lose weight. While skipping a meal will reduce your calorie intake for that hour, it will leave you much hungrier later on.
Not only are you likely to overeat to compensate, but you'll often make bad choices to fill the gap: a cereal bar is not as healthy as a bowl of cereal or as filling, leading you to 'need' something extra for lunch.
Irregular eating habits also disrupt your body's metabolism, which makes it harder to lose weight in the first place.
Write down your plan
Once you've decided on what changes you're going to make, write them down. For example:
    Week 1
    • Exercise: one 20 minute walk every lunch hour.
    • Alcohol: none in the week, two small glasses of wine on Friday, Saturday, Sunday.
    • Food: no chocolate or biscuits in the week, choose healthy snacks such as fruit, trim all fat from meat, eat no fried or fast food.

Once you start your plan, weigh yourself once a week before breakfast. Keep a record of this weight and see if a pattern develops.
You could use a table like the one below to keep track of your goals, marking your progress for each day with a tick or a cross.
Week:
Current weight: AlcoholExerciseFood plan
Goals for week









..
ProgressAlcohol ExerciseFood planMoodComments
Monday

.....
Tuesday

.....
Wednesday

.....
Thursday

.....
Friday

.....
Saturday

.....
Sunday

.....
Be patient and persevere
It might take a week or two before you notice any changes, but they will steadily appear. After the first month you will be able to see the results and measure them in terms of looser fitting clothes.
Keeping your motivation up is one of the most difficult aspects of dieting. There will be days when healthy eating goes out the window and there will be weeks where you may not lose any weight – or put a little back on.
This is normal for everyone – dieters or not – so don't let it undo your plans for a slimmer you. You're not doing anything 'wrong', but you may need to look at your plan. Do you need to increase your activity levels? Make a few more changes to your diet? Put more effort into sticking to your current plan?
The other side of this is to make sure you celebrate your goals. While there is joy enough in stepping on the scales and seeing them dip lower, be sure to mark long-term progress with a reward such as new clothes or a night off from housework.
Celebrating is also a way to involve your nearest and dearest – it's up to you whether you want their encouragement in the form of gentle reminders not to eat certain foods, but support from other people can get you through the bumpy patches.
Health benefits of weight loss
Studies show that overweight women who lose between 10lb and 20lb halve their risk of developing diabetes. For men, the risk of heart problems reduces considerably.
Generally, we gain weight as we age. A few pounds over the years are not a problem, but people who gain more than 20lb compared to their weight as an 18-year-old will rapidly increase their risk of health problems due to that extra weight. In particular, women increase their risk of heart attack and double their risk of dying from cancer.
It may seem like these are problems to worry about in the future, but time flies by and tomorrow becomes today. By keeping your weight in the healthy range, you are less likely to be troubled by illnesses in your later years.