Monday, May 04, 2009

Mesh Enabled Web application with Silverlight

Someone asked me about cloud computing and Azure platform and then asked me the future of MEWA in light of Silverlight 3 offline application. While i have my own thoughts on them and both do target different application segments, i will first like to demo on a Silverlight MEWA ; then SL 3 offline – online thing and of course the difference… (along with similarities)

Here is step by step procedure:

1. Down load Live services…

2. Make a new project in Live services .. choose Silverlight template

2. write code.. Here i have uploaded a sample which sorts a given list based on various algorithm.

3. Compile the code. If it compile well.. run it by pressing f5.

4. F5 will lead you to following page on live..

 

5. Select live service as indicated above and you will be presented with screen as below

6. Select a MEWA and click on create.

7.

8.Click on upload package on the above screen

9. Copy link from VS prompt as below

10. copy the Application self link as below once application is uploaded

 

11. paste the application self link as

12. Click OK

OUTPUT

Application in action… Sorting using Merge sort

List Sorted

As you may observe the application is executing over the MESH..

Now about SL3 offline thingy in next blog… :D

Technorati Tags: ,,,

WPF

I took an session on WPF for awareness on WPF and silverlight

Here is the presentation on WPF basics and the Demo code which i did along with.

The demo is about animation (rotation), binding (to a static class or to another control)…

here is a snapshot

here is the WPF code

   1: <Window x:Class="WpfApplication1.Window1"



   2:     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"



   3:     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"



   4:         xmlns:g="clr-namespace:System.Globalization;assembly=mscorlib"



   5:     Title="Window1" Height="800" Width="900">



   6:     <Canvas Height="800" Width="900">



   7:         <Canvas x:Name="mainCanvas" Width="300" Height="300" Canvas.Top="0" Canvas.Left="100">



   8:            



   9:             <Canvas.Background>



  10:                 <LinearGradientBrush>



  11:                     <GradientStop Offset=".6" Color="Red"></GradientStop>



  12:                     <GradientStop Offset=".2" Color="White"></GradientStop>



  13:                     <GradientStop Offset=".2" Color="Yellow"></GradientStop>



  14:                 </LinearGradientBrush>



  15:             </Canvas.Background>



  16:             <Ellipse Height="200" Width="100" Fill="Red">



  17:                 <Ellipse.RenderTransform>



  18:                     <RotateTransform x:Name="ellipseScale" Angle="0"></RotateTransform>



  19:                 </Ellipse.RenderTransform>



  20:             </Ellipse>



  21:             <Button Content="OK" Canvas.Top="50" Canvas.Left="60">



  22:                 <Button.Triggers>



  23:                     <EventTrigger RoutedEvent="Button.Click">



  24:                         <BeginStoryboard>



  25:                             <Storyboard Storyboard.TargetName="ellipseScale" Storyboard.TargetProperty="Angle">



  26:                                 <DoubleAnimation From="0" To="360" Duration="0:0:2"></DoubleAnimation>



  27:                             </Storyboard>



  28:  



  29:                         </BeginStoryboard>



  30:                     </EventTrigger>



  31:                 </Button.Triggers>



  32:             </Button>



  33:             <ListBox Height="200" Width="200" x:Name="lst" Canvas.Top="0" Canvas.Left="150"



  34:                      ItemsSource="{Binding Source={x:Static g:DateTimeFormatInfo.CurrentInfo}, Path=DayNames }">



  35:                 



  36:             </ListBox>



  37:             <MediaElement Canvas.Top="150" Canvas.Left="150"  Height="200" Width="200" Source="FluidWater1.wmv"></MediaElement>



  38:         </Canvas>



  39:         <TextBlock Text="working"></TextBlock>



  40:         <StackPanel Width="400" Height="300" Canvas.Top="300" Canvas.Left="100" Opacity=".5" >



  41:             <StackPanel.Background>



  42:                 <VisualBrush Visual="{Binding ElementName=mainCanvas}">



  43:                     <VisualBrush.RelativeTransform>



  44:                         <TransformGroup>



  45:                             <ScaleTransform ScaleX="1" ScaleY="-1"></ScaleTransform>



  46:                             <TranslateTransform Y="1" ></TranslateTransform>



  47:                         </TransformGroup>



  48:                     </VisualBrush.RelativeTransform>



  49:                 </VisualBrush>



  50:             </StackPanel.Background>



  51:         </StackPanel>



  52:     </Canvas>



  53: </Window>




 





I will be blogging more advanced stuff in nextblogs..



Happy WPF ing



Technorati Tags:

Tuesday, April 28, 2009

LINQ - the mathematical aspect

One of my colleague remarked that LINQ is "VERY SIMILAR" to TSQL. However, he also cursed that why the LINQ guys have implemented it "reversely".
What he meant that why the Select is reversed…

SQL query will be

   1: Select Name from Employee where sal > 80000 




LINQ





   1: var q = from emp in Employee



   2:         where emp.sal > 80000



   3:         Select emp;




I cant help but giving him references to Korth & Sudarshan and mathematical Projections…



That also reminded me of taking a quick tour of algebra which i am posting over here.. hope it helps in rekindling some old memories…:D



Koncepts first..



Technorati Tags:


Idempotent: when the operation (on function)is performed the result remains unchanged, no matter how many times it gets performed. For example, the number 1 is an idempotent of multiplication: 1 × 1 = 1, also max(x, x) = x. More info over here. Think stability.



Closure: the smallest object that both includes the object as a subset and possesses some given property. E.g.: x + y = z; where x,y,z are Natural numbers . adding two natural numbers to get another natural number. This operation may go on for ever.


However consider x-y=z. Here if we consider x=2, y=1 then



2-1=1. Which is NOT Closure (from one end) as the above function may produce negative values. e.g. given x=1 and y=2… which yields 1-2 = –1.



Think anonymous functions or inner classes. Because of closure property the inner class . function may access the members of the enclosing class.



THINK IQueryable<T> of LINQ. It provides for domain-level closure.



The combination of above two Idempotent and closure makes algebra complex and LINQ a great fun!!!



Because of the above two we have function composition, in which output of function may be linked to input of other and so on..



IQueryables can be combined together to create new IQueryables that also yield sequences of T. LINQ is closed on both levels. It’s closed at the level of the entities that it is retrieving, but it’s also closed at the level of the functions it uses to represent queries.



Interestingly speaking, NON closure of any function have given birth to new concepts… like NON- closure of substraction of NATURAL numbers gave birth to concept of WHOLE NUMBERS..



Associativity: The composition of functions is always associative. That is, if f, g, and h are three functions with suitably chosen domains and codomains, then f ∘ (g ∘ h) = (f ∘ g) ∘ h. Since there is no distinction between the choices of placement of parentheses, they may be safely left off.



The above three concept along with concept of Inversibility provides an base of MONAD (Category theory) and thus functional programming. Quoting wiki:



If F and G are a pair of adjoint functors, with F left adjoint to G, then the composition G \circ F is a monad. Therefore, a monad is a functor from a category to itself. If F and G are inverse functors the corresponding monad is the identity functor.



in C# 3.0 queries are actually monad comprehensions in disguise.



using Lambdas




   1: var r = 1.ToIdentity()



   2:          .SelectMany(x => 2.ToIdentity(), (x, y) => x + y);



   3:  



   4: Console.WriteLine(r.Value);








using LINQ





   1: var r = from x in 1.ToIdentity()



   2:         from y in 2.ToIdentity()



   3:         select x + y;








Now; coming back to original question:  why the Select is reversed in LINQ..



Actually LINQ to objects queries are analogous to the relational algebra and therefore they are not as much declarative in nature as they are a specification of a series of operations.



1.  Each query clause is evaluated independently of the previous clauses.  Only the binding information flows between them. (Idempotent) :D



2.  The clauses are evaluated in order, hinting at imperative evaluation. (Closure) :D



therefore, the performance of LINQ is based upon the order of clauses.



As it is evident from the above discussion that LINQ works in a fashion that output of one function is input to another… In above LINQ example select clause is used AFTER from clause. Which means output from from is fed into select for filtering and projection of results.



You can refer more from here.



Do let me know your thoughts/ suggestions on same.



Happy LINQing… :D





Technorati Tags:

Thursday, April 09, 2009

Silverlight presentation

Blogged with the Flock Browser

10 reasons why silverlight 3.0 excites me…

10 reasons why silverlight 3.0 excites me…

1. It really enforces good architecture: With principals like MVC (M-V-VM) implicitly into client side Xaml, DRY(Don’t repeat yourself) Built into RIA services and Scaffolding feature (Service Context) binding with ORMs like Entity Model and L2S (LinQ to SQL) in place, the solution is rock solid and very scalable.

2. Extensible architecture: Think Dependency injection / inversion of controls. Silverlight XAML dynamic loading makes such task easy and manageable. Learning curve to achieve the same is intuitive and les cumbersome than most of the other libraries.

3. Silverlight implicit collections: Language features embedded in XAML (silverlight rendering engine langauge) are powerful. Observable collection, Converters, Dependency property really makes it easy to develop new controls.

4. Data binding features: With SL 3.0 data binding is almost like its WPF counterpart. Bind almost anything to everything declarative. Programmers delight!!!

5. Animations /2d/3d mathematics: With excellent effects and very intutive matehmatics involoved in 2d / 3d rendering, Silverlight is way ahead in terms of other packages in which programmer is supposed to do more matrix multiplications rather than business problem in hand!!! (think of programmer who has to make a custom graph)

5. No more coding for specific browsers: Code in C#. No code in javascript. No coding required for each and every version of x,y,z browsers!! And SL will ensure it runs just fine..

6. In built SEO / Deep linking:

7. Support for Dynamic languages like Iron Python and Iron Ruby: This is specially exciting. Ploygot programming was never so easy. The mathematical capabilities of languages like python (it can parse expression like (2+4) * 5 + 6 / 7…) makes it very easy when required. And the deal is required when UI is supposed to look great..

8. Great Component support:

9. Out of browser experience: With features like Isolated storage and LINQ embedded. Offline experince is really great and very easy to implement in contrast with Google gears and SQL Lite.

10. Most important: INNOVATIONS : Great tools for development like VS, Blend and even XAML PAD!! Server connectivity, Binary serialization, Deep Zoom. The pace at which SL has adapted and grown is awesome.

Blogged with the Flock Browser

Monday, April 06, 2009

Discussing SilverLight!!

I was having an discussion with my wife on things to come in computer software and silverlight. below is a brief snippet:

My wife holds an computer engineering degree and is passionate about new innovations. She is a prolific programmer though she ONLY codes when she feels like(or finds a problem worth her attention) and thus is NOT a regular coder like mortals like me who are ... well, just coders, who codes for money:D


Wife: What is this buzz around Silverlight?
Subodh: Because we need smarter applications which makes extracting the required data easy and more meaningful. See; as human beings we require information. Computers provide information to us; but extracting the data using computers is cumbersome. Not many people are skillful in extracting the right information. As developers of applications our main motive is to provide easiest way to provide the information.
RIAs are a great platform as they provide animations, have in built ways to communicate with server asynchronously. The RIA application is smart enough to do some data crunching on its own and require to connect to server only when some data is required.

As we move towards smart clients; and as more people are comfortable with browsers; the momentum is towards RIAs which combine the goodies of a smart client within browsers. Silverlight provides an easy approach towards developing RIA as developers can leverage on the knowledge they aleady have on .Net platform.

Wife: I got it... But Why Silverlight? what exactly is Silverlight?
Subodh: Actually as with every platform, Silverlight have two faces. From a user perspective, Silverlight is a browser plug-in which when installed will provide Rich user experience to the user. The plugin is free download. Also the plugin is per OS and NOT per browser. what that means is that when silverlight is installed, the application built on top of it will work exactly the same on any browser ; be is IE, firefox or flock.

From a developer perspective Silverlight is a new development platform for developing RIAs. It interestingly takes all good practices from .Net platform.
For UI: SL uses XAML;
For event handling mechanisms: Javascript may be used in SL1.0; C#, VB .net may be used for SL 2.0; and there are languages like IronRuby and IronPython which is supported Silverlight Dynamic Language Runtime(DLR).
For comminicating with Server: Silverlight supports Http WCF. It also supports duplex. It even supports Sockets.


Wife: umm..  We have Silverlight 2.0... Whats deal with 3.0 version...

Subodh: Actaully, i personally like SL because it is the MIX of so many good things. The drive for SL3.0 is to bring in good practices. Now that SL2.0 is stable, the move is towards to bring in patterns like MVC (MVVM to be correct) and domain driven design. (DDD).
So we see that SL30 have a navigation project which supports features like deep linking and back and forward history of browsers. It even supports SEO. (search engine optimization)

DDD is implemented by using a Domain service, which works on the principle of DRY(Dont repeat urself). ROR(ruby on Rails) has been using the principle successfully. Domain service takes the pain out which was required earlier like creating a WCF service exposing it and then writing plumbing code to hook to the server side WCF service. Now the code at the client side is generated at run time, so the developer concentrates on just the Domain service. The validation logic is also put as cross cutting attributes on the entity property itself.

Wife: i got the MVC and the DDD part; what else is new in SL3.0?
Subodh: SL3.0 also now supports the WPF style of databinding in which an object property may be directly binded to another object declaratively in XAML itself... There are really some cool stuff which may be archived out of that just writing plain XAML. For example: a Domain service may be declared in XAML and binded to any controls data binding property with paging, filter and grouping stuff mentioned in XAML itself!!!! :D

Wife:  thats cool... I hear there is a lot on the SL UI controls also??
Subodh: Yes there are lot of new controls, for look and feel ; for graphs and dock panel etc...Also SL3.0 also have a support for 3d now!!! :D
And then there is support for scaffolding which makes programming RIA really easy.

I hope the above conversation will help you get the basics of SL...
I will be sharing some really interesting finding and gotchas on SL in nest series of blog.
Do keep your comments/ suggestions coming in.
Blogged with the Flock Browser

Thursday, April 02, 2009

Using Flock for Blogging

All entries are blogged using FLOCK: - my favorite browser.. :D
Blogged with the Flock Browser