Thursday, May 26, 2011

Silverlight Integration with PHP - Technique

Silverlight Integration with PHP - Technique
Most reusable Technique. Bringing bridge between Silverlight and PHP.
Abstract
The Technique – to bridge between Silverlight and PHP this technique proven and accepted all over similar type of requirements. Intension of developing this technique was to establish communication bridge between Silverlight control and PHP which could be reused in any complex requirement;

Lets first answer “Why Silverlight and PHP ?”:
- Silverlight – Stateful model – .NET Framework – UI Capabilities – Cross-platform
- Leaverage best of both technology Silverlight and PHP worlds.
- PHP – Rapid application programming – Ideal as back-end using JSON or SOAP – Re-use your existing PHP logic
- Silverlight – Rapid rich user interface development – Create rich interfaces using a rich framework





Technique Pre-cursor
There was main challenge there was backend database and PHP service was implemented, need was to represent this data in Rich interactive application. There was another need that application should run not only in browser but as well as out of broswer mode.

We are strong supporter to develop frontend in Silverlight 4 as its cross browser and cross platform and leverages the .net framework ocean.it runs out of browser mode.

The challenge was how to fetch data from PHP service and in Silverlight and viseversa.
we had lots of brainstorming on it, we came up with some options like:
1. Writing WCF rest service wrapper –but there will be extra cost for service maintenance.
2. We also though of using PHP nuSOAP – adding nuSOAP service refrenece in Silverlight, but we explored there is lots of complexity and limitations while handling collection data of different data types
Keeping in mind above challenges it was essential to come over this problem.


Solution description
Then after lot of googling, struggling and trial-&-errors. we gave thought on usage JSON. I referred some Silverlight forum, MSDN helps, and stared writing some code for proof of concept project.
JSON (JavaScript Object Notation) is a lightweight data-exchange format.I worked many sceniaro where are serialized and deserilised JSON data in Silverlight. So it was good thought that what if PHP response me JSON data and I use it in Silverlight to manipulate.
Refer the snap bellow that simplify, how the communication will happen between silverlight and PHP.






As snap says we need to 3 things in place:
- PHP service that response data
- Call PHP service method either using WebClient or HttpWebRequest
- Serialise,deserialse JSON data.

Pseudo Code for Sample Silverlight method that calls PHP service and pass emailed and password:


Pseudo Code for Sample PHP method that returns records from databased based on give parameters:



Pseudo Code for Sample Silverlight to handle service call completed event:


Pseudo Code for Sample Silverlight – Company class used for data deserialization:
So now you need to simply integrate silverlight control as object tag in PHP page alike you used to add in .html or aspx page. And make sure you have configured correct paths for PHP service call where services actuly hosted. below is the final flow of design.
1. Your PHP services hosted those server processed data
2. Silverlight control calls PHP service method with required parameters, either using WebClient or HttpWebRequest.
3. PHP service processs parameter and return required response.
4. On service call completed event gets the handle to the Silverlight control and passes the results to "DataBind" method.
5. DataBind method desterilizes the JSON string to original object and performs the desired processing.
Thats it!!, just follow deployment easy steps and configure webpart and see experience.


Salient features
The salient Features of this innovation are:
1. Simple technique that fulfill basic need of establishing communication between Silverlight Client control with PHP
2. Easy to deploy.
3. No restriction for Silverlight control development.


Competitive approaches
we learned this technique after lot of googling, struggling and trial-&-errors. First we searched for same type of sample applications so that we can reuse them, but only on few approaches like nuSoap Php service and Zend Framework was there, and after exploration I observed that:
- There was no any fullfledged proof of sample
- Lots of complexity and deployment challenges
- Additonal cost for developing or utilizing Zend framework.
And this was not helping me to solve my problems. Because I looking such technique that will give very dynamic commination of Silverlight client control to server code. So I started with my own code and came with very good, configurable custom silverlight webpart for Sharepoint.


Applicability
This approach can easily adapted to Similer kind of platform requirement like:
1. Where you have already MySQL and PHP service environment and want to provide rich interface
2. You want to leaverage clientside technology - Silverlight features like
a. Run application out of broswer
b. Printing
c. Generate images
d. Export to excel
e. play audio/video
f. and lots more…


Reference :
http://www.json.org/
http://msdn.microsoft.com/en-us/library/cc197957(v=vs.95).aspx

Monday, September 6, 2010

Windows Phone 7 and Development Tools



In previous blog we talked about all Windows Phone 7 and new features. Today’s topic is more developers oriented and we will talk about what are basic development tools we will need to start with windows phone 7 development.

Microsoft provides two different frameworks for developing Windows Phone 7 Application.

XNA Framework: To develop Windows based games.
Silverlight Framework: To develop event based and XAML based Windows Phone 7 Applications.
So first let’s see what development system requirements are:

•Windows Vista (x86 and x64) ENU with Service Pack 2 – all editions except Starter Edition
•Windows 7 (x86 and x64) ENU – all editions except Starter Edition
•Installation requires 3 GB of free disk space on the system drive.
•2 GB RAM
•XNA Game Studio deployment to Windows Phone Emulator requires a DirectX 10 or later graphics card with WDDM 1.1 driver.
•DirectX 10 capable card with a WDDM 1.1 driver is needed to take advantage of GPU acceleration on the Windows Phone Emulator for a Silverlight application. The DX10 card is optional for Silverlight applications.
•Windows Phone Developer Tools BETA - compatible with the English version of Visual Studio 2010 RTM and Visual Studio 2010 Express.

And here are the steps to setting up Development Environment:

Download Microsoft Windows Phone 7 Developer Tools Beta from the link below and follow the steps.

http://www.silverlight.net/getstarted/devices/windows-phone/



Assume that machine is ready with development system requirement (i.e. OS, HD, RAM).

Step1: Install the required version of Visual Studio 2010 (Skip this step if already installed)

Microsoft provides two different frameworks for developing Windows Phone 7 Application.

•XNA Framework: To develop Windows based games.
•Silverlight Framework: To develop event based and XAML based Windows Phone 7 Applications.
So first let’s see what development system requirements are:

•Windows Vista (x86 and x64) ENU with Service Pack 2 – all editions except Starter Edition
•Windows 7 (x86 and x64) ENU – all editions except Starter Edition
•Installation requires 3 GB of free disk space on the system drive.
•2 GB RAM
•XNA Game Studio deployment to Windows Phone Emulator requires a DirectX 10 or later graphics card with WDDM 1.1 driver.
•DirectX 10 capable card with a WDDM 1.1 driver is needed to take advantage of GPU acceleration on the Windows Phone Emulator for a Silverlight application. The DX10 card is optional for Silverlight applications.
•Windows Phone Developer Tools BETA - compatible with the English version of Visual Studio 2010 RTM and Visual Studio 2010 Express.
And here are the steps to setting up Development Environment:

Download Microsoft Windows Phone 7 Developer Tools Beta from the link below and follow the steps.

http://www.silverlight.net/getstarted/devices/windows-phone/



Assume that machine is ready with development system requirement (i.e. OS, HD, RAM).

Step1: Install the required version of Visual Studio 2010 (Skip this step if already installed)

Step2:
Start Windows Phone 7 Tools Beta installation by double clicking on vm_web.exe which is
downloaded from the link above. The vm_web.exe is online installer and will download and install
following tools:



•Microsoft Silverlight for Windows Phone 7 Beta
•Microsoft Expression Blend for Windows Phone 7 Beta
•Microsoft XNA Game Studio for Windows Phone 7 Beta
After following these steps your development environment is ready for developing Windows Phone 7 Applications.
Note: During installation, an active internet connection is required.

While doing development for Windows phone please note following important points:

•While you develop Silverlight UI [using xaml] you need to understand and follow certain guidelines. Microsoft has provided Control Templates specific to Silverlight application for Windows Phone to match evolutions in the overall OS. Start Windows Phone 7 Tools Beta installation by double clicking on vm_web.exe which is
downloaded from the link above. The vm_web.exe is online installer and will download and install
following tools:



•Microsoft Silverlight for Windows Phone 7 Beta
•Microsoft Expression Blend for Windows Phone 7 Beta
•Microsoft XNA Game Studio for Windows Phone 7 Beta
After following these steps your development environment is ready for developing Windows Phone 7 Applications.
Note: During installation, an active internet connection is required.

While doing development for Windows phone please note following important points:

•While you develop Silverlight UI [using xaml] you need to understand and follow certain guidelines. Microsoft has provided Control Templates specific to Silverlight application for Windows Phone to match evolutions in the overall OS.

•To make it easy to create XAML UI for Silverlight application Microsoft has made available Expression Blend for Windows Phone, Blend is now integrated completely into the Windows Phone Developer Tools Beta.
•Using Developer Registration Utility you can unlock you Windows Phone 7 device for development purposes.
•If you want to deploy XAP files directly to an unlocked device, you can use XAP Deployment Tool.
•If you planning to create virtual development environment then wait at present following Scenarios Not Supported For Development Environment:
◦Windows XP and Windows Server are not supported.
◦Virtual PC and Hyper-V are not supported.
•Windows Phone Developer Tools Beta includes database components. These components are not supported for application development.
•When using Visual Studio 2010 Ultimate for Silverlight application development for Windows Phone , the following features are not supported:
◦Profiler
◦IntelliTrace
◦Lab Management
◦Testing
◦Data
◦Show Data Source
◦Add New Date Source
◦Schema Compare
•If you are using Visual Studio 2010 Ultimate or Professional for Silverlight application development for Windows Phone, Add Service Reference features not supported. To Add WCF Service Reference in your application in VS2010 Professional or Ultimate, you have to run
slsvcutil.exe from visual studio command prompt in order to generate Service Reference and Client Configuration file. Click here to see How to use slsvcutil.exe.

Windows Phone 7 Project Templates for Silverlight:

Once your development environment setup done, open visual studio and try to create new project of type “Silverlight for Windows Phone”.
There are three types of template to start development of Windows phone 7 for Silverlight.



1.Windows Phone Application: A project for creating windows phone application.
2.Windows Phone List Application: A project for creating windows phone application using List and Navigation Controls.

3.Windows Phone Class Library: Windows Phone Class Library Project.
That’s it your development environment is ready to go for developing app for windows phone. Microsoft's Windows Phone Developer blog is claiming that over 300,000 people have downloaded the Windows Phone Developer Tools so far and this number is increasing rapidly.


In next post I will talk more on specific to silverlight application development for Windows phone 7 .

Windows Phone 7 and new features


In previous blog we talked about all 7 hubs those coming with Windows Phone 7. Today I will tell about new features or you can you software and hardware coming with this version.

Actually Windows Phone 7 is based on Windows CE 6 Kernel and is a touch-operated OS and it is news that initial launch it will be available with resolution WVGA (480 x 800) and sooner it will support HVGA (320 x 480). And to run consistently it will need device equipped with
• 1 GHZ CPU
• Min 256 MB RAM
• Finger based Device content Navigation
• WI-FI, GPS, FM-Tuner and High Resolution Camera
Additional to all common feature of today’s phone device, windows phone gives following featured Software’s:
User Interface: in this version UI is drastically changed and developed based on interfaces of the ZUNE and Windows Media Center. The home screen viewed as of "tiles", which by default are links to important features such as phone, music and videos, email, office, and contacts.
Silverlight Support: for Silverlight developers its good new that after long waiting Microsoft introduce Silverlight support in Windows phone series. So developers need to start exploring what and how to do silverlight development for windows phone and there will be defiantly huge requirements for developing silverlight application for Windows phone.
Browser: Yes you all right it will be Internet Explorer only. Browser will be a modified version of Internet Explorer 7, which will not support Flash, Silverlight and HTML5 at launch. The specialty of this browser will be to automatically update itself and the layout engine.
Xbox LIVE: Xbox LIVE experience on a phone, including Xbox LIVE games, Spotlight feed and the ability to see a gamers’ avatar, Achievements and gamer profile




Search: Yes Microsoft Bing will be the only default search engine on Windows Phone 7 devices.




Email and Calendar: As it will be integrated with light version of office outlook it will supports outlook POP mail and calendar with some fancy UI.




Me: this hub will be center to aggregates all social media and XBOX live content – to update Social Networks.
• Software Updates: According to news channel, this phone software updates will be delivered to Windows Phone users via Microsoft Update, as they are for desktop Windows users.
Zune: Integrated media player is basically the Zune- its look and feel, functionality and the Zune Pass subscription support which allows unlimited music streaming.
Marketplace: This hub will make you easy to access center for find and download suitable certified software and games for your device. Click here to see more about Marketplace.




It looks Windows Phone 7 devices will work 100% consistently across hardware coming from HTC, Samsung, LG and Dell.

In next post I will talk more on Windows phone 7 application development.

Exploring Windows Phone 7 Series 7 Hubs



Windows Phone 7 is emerging Microsoft’s operating system for windows phone devices. This new Operating system is going to drastically changed supported device skin with amazing User interface and lots many more features.

Basically Windows Phone 7 Series includes six hubs built on special themes those are mostly liked by end user and used in their daily activities:

1. People. This hub specific for an engaging you with your social networks and make you connected with live feeds from social networks and media.
2. Office. This is best hub I liked most because it connects me with my daily work as it has provided with access to Office, OneNote and SharePoint Workspace all in one place.
3. Browse and Bing Search: This is going to appreciates by the people who love to travel and explore new places, this hub will fully equipped with Bing maps to help you to see maps and directions. And also Quick Search like a pro when surfing by highlighting the word and hitting “search”.
4. Marketplace. This hub will make you easy to access center for find and download suitable certified software and games for your device. Click here to see more about Marketplace.
5. Pictures. This hub makes it easy to share pictures and video to a social network in one step. Windows Phone 7 Series also brings together a user’s photos by integrating with the Web and PC, making the phone the ideal place to view a person’s entire picture and video collection.
6. Games. This hub will be for those game lovers who already playing Xbox LIVE games, as this hub will include Xbox LIVE experience on a phone, including Xbox LIVE games, Spotlight feed and the ability to see a gamer’s avatar, Achievements and gamer profile.
7. Music and Video. This hub will bring incredible media experience to those music lovers as it will provide you best of Zune, and will allow you to include media content from a your PC, online music sites and built-in FM radio.



Microsoft Windows phone development team is planning to release Windows Phone 7 by October 2010, so keep you updated with Windows phone 7 news.
In next post I will talk more on Windows phone 7 features.

Sunday, July 25, 2010

Silverlight application and Performance nuggets

Silverlight application and Performance nuggets

So far I worked with Silverlight different versions to develop many RIA applications, World is moving toward Rich interactive application, customer wants to have their web application more interactive and end user centric. And customers are now realizing importance of migrating their simple html web app to RIA; because of Rich user experience they found benefits in end user stickiness to their app and ultimately growth in their business.

I started working on Silverlight 1.0 application those codes in JavaScript, and now Silverlight 4 is emerged where we develop code behind in C#, Vb.net and other supported manage codes. After working with different Silverlight application I realized that while matching customer and design expectation it’s very important to keep eye on application performance. And so I came up with certain important check point to validate that we are not compromising on application performance.

Performance checks for Silverlight app:

Avoid using .findName to access control from XAML:

function onLoginButton_Click(sender, args)

{

var txtLogin = sender.findName('txtLogin');

string strloginName = txtLogin.Text;

}

FindName has to walk through the tree of XAML objects to find out expected match which is very performance perspective. Either you can try following options:

  1. Naming the target element and use it directly where it required [using x:Name in xaml]
  2. Using findName initialize object in application loaded event, and use stored global reference where it required.

Avoid naming elements if it really not needed:

Many times we do not concern while naming xaml element. Designers give naming to make it easy for them to navigate through templates/ object trees in Blend they creating. We developers does not care while naming controls like border, stackpanel etc. but let me tell fact that for every naming XAML markup creates a variable. Obviously each of those variables eats precious byte space in the InitializeComponent call. I will suggest:

  1. Use naming only for controls those referred in code behind like Button, TextBox, ListBox, etc
  2. Avoid naming controls like TextBlock,Border, borders, lines, rectangles and similar.
  3. Use data binding where there is need to refer controls

Don’t ignore importance of settings while integrating Silverlight applications in web pages

When we create Silverlight application in visual studio it creates test web pages .aspx/.html. And we developers go live with same test pages; there some small setting can help us to improve good performance.

  1. 1. Avoid Using Windowless Mode

Set the Windowless property to true only when necessary. The default is false. Windowless mode is highly expensive. More..

  1. Reduce MaxFrameRate

You can see the MaxFrameRate value by enabling a performance-tuning option that displays frames per second for Silverlight rendering. This maximum number of frames that Silverlight can render per second. The default value is 60 second. You can reduce this to desired number.

To set parameter of object on HTML page:

param name="framerate" value="24"

To set it in Silverlight code:
App.Current.Host.Settings.MaxFrameRate=24;

Set the frame rate of your application to only be what is needed. For video, you will want around 60. For animation, around 20-30.
More..

  1. Use EnableGPUAcceleration

Basically GPU is a processor attached to your graphics card that is generally used for calculating floating point operations. In addition, it is very useful to save you a lot of CPU time.

To enable EnableGPUAcceleration on your Silverlight control For HTML modify the Silverlight control to include the following param:

param name="EnableGPUAcceleration" value="true"

For ASPX add the following attribute:

asp:Silverlight ID="SilverlightControl" EnableGPUAcceleration="true" runat="server" Source="~ /SL.xap" MinimumVersion="3.0.40307.0"

For silverlight controls set CacheMode in code behind like:
ControlGrid.CacheMode = new BitmapCache();

else in XAML:

Grid x:Name="ControlGrid" CacheMode="BitmapCache"

  • To use it you must enable it both on your Silverlight control/plug-in as well as any of the controls you want to leverage it.
  • By default this option is disabled.

And it enables visual controls to be cached as bitmaps and whenever re-rendering required we can bypass the expensive rendering phase for the cached visuals and just display them.

More..

Replace Opacity by setting Visibility

Always use setting Visibility to Collapsed or Visible instead of fading or change elements opacity. Because Opacity is associated with higher costs because the object is still hit tested and technically rendered.

Animations

  • Many and big size controls animations are highly CPU costly as there is redrawn regions and multiple frame calls. So avoid such heavy use of animations or try to minimize their frequency.
  • There is additional cost to animate properties like height, width, visibility, alignments and margin as that call to layout relevant changes.
  • Avoid Text resizing animations, as there is extra cost to optimize text for readability.
  • We can always use images replace to static text.

Tools to profile Silverlight applications

There are many tools out for profiling your Silverlight applications, select one of them as per your application and need. Here are some samples:

1. Visual studio profiler

2. Xte profiler

Threading

Threading is basically used to multiple concurrent jobs in same application. Using threads in your Silverlight application can improve performance by increasing the responsiveness of your application. There are multiple ways you can try in Silverlight.

- Using Threadpool

  • allows you to spawn multiple background threads.

- Using Dispatcher class

  • The Dispatcher class greatly simplifies calling the UI thread with a static method BeginInvoke.

- Using DispatcherTimer

  • The DispatcherTimer is a special timer integrated into the Dispatcher queue that is reevaluated on every Dispatcher loop

- Using BackgroundWorker class.

  • provides an easy way to run time-consuming operations on a background thread. The BackgroundWorker class enables you to check the state of the operation and it lets you cancel the operation

Other important points to be noted

  • Do not create only 1 single xaml for all UI. Cut it in separate controls and use them whenever required.
  • Do best utilization of UI thread, as Silverlight has full control of the UI thread.
  • Handle memory leakage, and do not forget to stop threads, background calculation, if not needed.
  • Do not create redundant styles create a separate resource files for styles and use them as required.
  • Try to do best utilization of storyboards because Silverlight performs animation it only redraws the dirty rectangles.
  • Always use Image.Stretch = “Fill” to load large images to prevent any layout updates due to stretching. So if you use Stretch = “Fill” there is no potential clipping happening which adds extra edges.
  • Do not specify Width and Height for following controls, Let plug-in render it at its natural size.
  1. MediaElement - let the media element display at its natural size. If you need to change the display size of the element, it is best to re-encode the media to the desired size by using a media encoding tool
  2. Path - Setting explicit Height & width calls additional stretching, which affects performance. better rely on the explicitly set coordinates of the Path object to control its shape and position.[basically avoid using Path controls as they very heavy to use]
  • If application is very large, consider loading pieces of it "on demand".
    1. Break up large application in controls and modules
    2. We can do on demand .xap ,assembly, resource files download
  • Avoid setting Transparent Background for Silverlight controls.
  • SL app Loading time increase because of your XAP file. if you use more image, video in sliverlight project XAP file size will be increasing.
  • Avoid large use of event handlers. When you attach normal events, registering an event handler creates a strong reference from the event source to the listening object, And this reference persist still the lifetime of event source.

Reference:

http://msdn.microsoft.com/hi-in/bb693295(en-us).aspx

http://www.microsoftpdc.com/2009/P09-10

http://silverlight.newagesolution.net/SilverlightTutorials/UsingThreadpoolInSilverlight.aspx

Thursday, December 31, 2009

“Wish you all a very happy new year 2010”

When the clock strikes twelve on December 31st, people all over the world cheer and wish each other a very Happy New Year. For some, this event is no more than a change of a calendar. For others, the New Year symbolizes the beginning of a better tomorrow. So, if you look forward to a good year ahead, spread happiness with these wonderful New Year wishes.

Let hold hands together in the New Year to face all challenges and strive towards building a strong, united and prosperous INDIA, and may this New Year bring peace, prosperity and happiness to everyone.

“Wish you all a very happy new year 2010”

Tuesday, December 29, 2009

About "Pune User Group"

In one of Windows Mobile training session I came across to know about "Pune User Group". Then I started talking with some of Active members of this group.

Pune User Group ( PUG) a group of people who are interested in Microsoft Technology and willing to share knowledge to community.

I really loved their spreading knowledge using various platform, Now I have Registered with this group, I would like to encourage you to join PUG as a member, PUG membership is free. So if you are not yet PUG member then please register yourself on PUG website http://www.puneusergroup.org

There are various areas where PUG works, 2 main types of activities are offline activities, and online activities. Online activities contains posting articles, answering questions on PUG forum, and also online marketing of PUG brand. Second option is offline contribution where you can take sessions in PUG events, meeting, etc. and also can volunteer for PUG events, on an average for every moth there is at least one event, you can check PUG portal for more events.

Once you started contributing to PUG, after 4 months (minimum 3 events for offline activities) of continuous contribution to PUG (any of above type) you will be eligible to join “TeamPune” group inside PUG, TeamPune is a core Volunteers group inside PUG , this groups take care of all activities of PUG. You will come to know all these things and fun behind all this work once you start working with PUG.

If you really interested and are dedicated and devoted to the noble cause of spreading knowledge. This is a platform for you to share your experiences and educate professionals through the learnt lessons of the best Gurus in IT industry....We believe that "Knowledge is wealth.." and we "Gain Knowledge by Sharing knowledge.." [- PUG’s Mantra]