Rajnish Noonia

Tag: Silverlight

  • Building a Page-Flip Photo Album with Deep Zoom

    Book control is another excellent page flip control which allows you to add any silverlight element as book page.It supports page down and page up as bidiretional navigation keys.Demo application & source code is attached below.
    [silverlight: http://www.pixytech.com/rajnish/uploads/code/BookDemo.xap, 850, 650]

    The objective of this article is to create photo album application which allows user to add pictures just by drag and drop on album.The picture will be splitted into parts and uploaded on server where it is re-constructed and again processed into deep zoom meta file (on fly) and link to this picture will be then added into album.Photo album will have deep zoom enabled pages.

    I couldn’t get much time to finish this project & hence i would call this as beta source code which includes the full source code of Book control (page flip)

    Beta Source code for book control is available here

  • Silverlight WebSockets – Duplex Communication

    A duplex communication system is a system composed of two connected parties or devices that can communicate with one another in both directions. Duplex communication is required when you need to send some data in the reverse direction i.e. from Server to client. For scenario purpose assume that something happens on server (some event is received from source) and message from server should be sent to connected clients. Off-course the solution should be highly scalable with low latency client and server.

    Let’s talk about silverlight client in our scenario

     There could be couple of options with silverlight client demonstrated by Gill Cleeren In series of article “The duplex story: looking at duplex communication in Silverlight 4”

    Silverlight 4.0 now supports 3 different types of duplex communications

    • HTTP Polling Duplex: Duplex requires that the server can itself initiate communication, which is not supported by HTTP, HTTP Polling duplex (HTTP long polling, or Comet-style) protocol allows us to do bi-directional communication over HTTP. What happens behind the scenes is the following:
      • The Silverlight client initiates the communication by sending an initial request to the service.
      • After the client is registered with the service, it continuously starts polling the service for updates.
      • Whenever the service has new messages to send to the client, they are queued up until a new poll arrives from the client.

    The HTTP Polling Duplex is therefore not real duplexing: it creates an illusion of duplex communication by polling (at network layer) so frequently that it looks as if the messages are pushed from the service to the client. If you still want to use this method here is the link for you to tune performance of http polling duplex.

    • Sockets: Socket is implemented through the use of a TcpListener, Being pure TCP endpoints, sockets are fast and true duplex communicators. However sockets in Silverlight can only work over ports between 4502 and 4534 making it unsuitable for duplex communication over the internet. Secondly you need to build policy server to provide clientaccesspolicy.xml for sockets.Note that Silverlight 4 also allows that the policy calls are made over HTTP.
    • net.tcp binding: this entirely new binding, added in Silverlight 4, also supports duplex communication. net.tcp combines advantages of both polling duplex and sockets. Its programming model is, just like polling duplex, based on WCF. That means that we can take advantage of automatic proxy generation inside Visual Studio.
    • Poll based communication: Not scalable, out of scope.

    So what’s next?

     HTML 5 – WebSockets

    Web socket protocol or WebSockets are “TCP for the Web,” a next-generation bidirectional communication technology for web applications being standardized in part of Web Applications 1.0.

    The Web Sockets API enables web applications to handle bidirectional communications with server-side process in a straightforward way. Once you get a Web Socket connection, you can send data from browser to server by calling a send() method, and receive data from server to browser by an onmessage event handler. The protocol is not raw TCP because it needs to provide the browser’s “same-origin” security model. It’s also not HTTP because web socket traffic differers from HTTP’s request-response model. you do need a new server implementation to communicate with web sockets .

    web socket prototype is out now at http://html5labs.interoperabilitybridges.com/prototypes/available-for-download/websockets/html5protos_Download or websocket msi from here

     for more information see : http://tomasz.janczuk.org/2010/12/websockets-wcf-service-silverlight-and.html

    Please also find the published websocket transport binding (Incomplete project)  here which i was trying to build using custom duplex WCF channel.

  • Persisting RIA Service Entities to Isolated Storage in Silverlight

    The Silverlight library in this article extends RIA service entities and provides save & load method to save/load entities directly into application storage (Isolation storage). The library supports dynamic quota management for application storage i.e. if an entity requires more space to store it will prompt user to confirm new size of quota store. The saving and loading supports asynchronous processing of entities with inbuilt compression which allows your application to provide non blocking UI. Library can be used to build online-offline mode based Silverlight applications without additional programming overheads.

    Code to save RIA Entities in the storage space

    EmployeeContext context = new EmployeeContext();
    dataGrid.ItemSource = context.Employees;
    Action<LoadOperation<Patient>> completeProcessing = delegate(LoadOperation<Patient> loadOp)
    {
        if (!loadOp.HasError)
            {
                loadOp.Entities.Save();
            }
            else
            {
                LogAndNotify(loadOp.Error);
                loadOp.MarkErrorAsHandled();
            }
    };
    context.Load(context.GetEmployeesQuery(), completeProcessing, null);

    Code to load RIA Entities from storage space

    EmployeeContext context = new EmployeeContext();
    context.Employees.Load();

    You can also use the same library to save and load genric data you need to provide the filename to which the object set is saved whereas with Ria EntitySet the fileName is optional which is calculated based on the data type of entity.
    Code to save List<string> into storge sapce

    List<string> names = new List<string>();
    names.Add("Employee1");
    names.Add("Employee2");
    names.Add("Employee3");
    names.Save("Employee4");
    names.Save("EmployeeesDataSet");

    Code to load List<string> into storge sapce

    List<string> names = new List<string>();
    names.Load("EmployeeesDataSet")

    Note: The Load method supports Asynchronous (default) and Synchronous operation where as Save method only supports Asynchronous operation.You can also override the Quota Management screen globally in your application and if not overrided the library will use in-built screen shown below (right image).

    How it works : diagram is self explanatory..

    Source code is now available here, Because of time constriants i was not able to comlete the code behind for the isolation storage screen above, however the library is now completed and published with silverlight unit test project.