Tuesday, May 18, 2010

MicroSoft Silverlight

Microsoft Silverlight is a web application framework that provides functionalities similar to those in Adobe Flash, integrating multimedia, graphics, animations and interactivity into a single runtime environment. Initially released as a video streaming plugin, later versions brought additional interactivity features and support for CLI languages and development tools

Overview

Silverlight provides a retained mode graphics system similar to Windows Presentation Foundation, and integrates multimedia, graphics, animations and interactivity into a single runtime environment. In Silverlight applications, user interfaces are declared in Extensible Application Markup Language (XAML) and programmed using a subset of the .NET Framework. XAML can be used for marking up the vector graphics and animations. Silverlight can also be used to create Windows Sidebar gadgets for Windows Vista.
Silverlight supports Windows Media Video (WMV), Windows Media Audio (WMA) and MPEG Layer III (MP3) media content[7] across all supported browsers without requiring Windows Media Player, the Windows Media Player ActiveX control or Windows Media browser plugins. Because Windows Media Video 9 is an implementation of the Society of Motion Picture and Television Engineers (SMPTE) VC-1 standard, Silverlight also supports VC-1 video, though still only in an Advanced Systems Format (ASF) container format. Furthermore, the Software license agreement says VC-1 is only licensed for the "personal and non-commercial use of a consumer".[8] Silverlight, since version 3, supports the playback of H.264 video.[9] Silverlight makes it possible to dynamically load Extensible Markup Language (XML) content that can be manipulated through a Document Object Model (DOM) interface, a technique that is consistent with conventional Ajax techniques. Silverlight exposes a Downloader object which can be used to download content, like scripts, media assets or other data, as may be required by the application.[10] With version 2, the programming logic can be written in any .NET language, including some derivatives of common dynamic programming
languages like IronRuby and IronPython




Versions

Silverlight 1.0


A Silverlight 1.0 application hosted in Internet Explorer. Interactivity is provided by Silverlight, but user input controls are HTML controls overlaid on top of Silverlight content
Silverlight 1.0, which was developed under the codename Windows Presentation Foundation/Everywhere (WPF/E), consists of the core presentation framework, which is responsible for the user interface (UI), interactivity and user input, basic UI controls, graphics and animation, media playback, Digital restrictions management (DRM), and DOM integration.It is made up of the following components:
Input – handling input from devices like keyboard, mouse, stylus etc.
UI core – managing rendering of bitmap images (including compressed raster images like Joint Photographic Experts Group (JPEG)), vector graphics, text and animations.
Media – playback of MP3, WMA Standard, WMV7, WMV8 and WMV9/VC-1 streams.
XAML – to allow the UI layout to be created using XAML markup language.
A Silverlight application starts by invoking the Silverlight control from the Hyper Text Markup Language (HTML) page, which then loads up a XAML file. The XAML file contains a Canvas object, which acts as placeholder for other elements. Silverlight provides various geometrical primitives like lines, ellipses and other shapes, to elements like text, images, and media, etc. The elements are properly positioned to achieve the desired layout. Any arbitrary shape can be created as well. These elements can be animated using Event triggers; some animation effects are predefined, others can be created as composite of the pre-defined effects. Events like keyboard or mouse movements can also raise Events which can be handled by custom scripts.
Programmatic manipulation of the UI is achieved by using scripting languages to modify the Document Object Model of the Silverlight Canvas object. To facilitate this, Silverlight exposes a DOM application programming interface (API), accessible from any scripting language supported by Silverlight, which in version 1.0 release is limited to JavaScript running in the browser. However, there are no UI widgets built in. The native widgets of the browser must be overlaid on top of the Silverlight Canvas for user input. Support for data formats is limited to XML and JavaScript Object Notation (JSON) only

Silverlight


A Silverlight 2 application hosted in Internet Explorer. Version 2 brings improved interactivity and support for some native .NET languages and development tools
Silverlight 2 (previously referred to as version 1.1)[14] includes a version of the .NET Framework, implementing the same full Common Language Runtime (CLR) version as .NET Framework 3.0; so it can execute programs written in any .NET language. (By default, however, you cannot reference assemblies compiled with the regular .NET Framework.[citation needed]) Unlike the CLR included with .NET Framework version 3.5 and earlier, but like .NET Framework 4.0, multiple instances of the CoreCLR included in Silverlight can be hosted in one process.[15] 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. It can be used to programmatically manipulate both the Silverlight application and the HTML page which hosts the Silverlight control. The XAML markup as well as the code, is compiled into .NET assemblies which are then compressed using ZIP and stored in a .xap file.[16]
Silverlight ships with a lightweight class library which includes features such as extensible controls, XML Web Services, networking components and Language Integrated Query (LINQ) APIs. This class library is a subset of, and is considerably smaller than, .NET Framework's Base Class Library (BCL). Silverlight code runs in a sandbox, thus preventing the invocation of platform APIs.[17]


Silverlight 2 Architecture

The version of .NET Framework in Silverlight adds a subset of Windows Presentation Foundation (WPF) UI-programming model, including support for shapes, documents, media and animation objects of WPF. Beta 2 onwards, it 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. Third-party libraries of expanded UI-control sets are also available.


A set of Silverlight controls rendered with different skins
The included BCL provides classes for collections, reflection, regular expressions, string handling and data access. It also supports LINQ, with full support for LINQ to Objects and expression trees. Almost all of the System.Linq and System.Linq.Expression namespaces are exposed. It also supports serialization of objects, for data persistence. Silverlight can handle data in Really Simple Syndication (RSS) or JSON format, in addition to XML. The BCL provides enhanced support for working with XML data, including the XMLReader and XMLWriter classes. Silverlight 2 also supports asynchronous programming via the use of the threading libraries.
Silverlight also includes classes for data access over XML-based Web services, Representational State Transfer (REST), Windows Communication Foundation (WCF) Services and ADO.NET Data Services. The networking support in Silverlight can be used by Silverlight applications to communicate using Hypertext Transfer Protocol (HTTP), or at the lower socket level. Cross-domain communication is supported. Silverlight uses an XML-based configuration file to control the cross-domain resource-access policy, for both HTTP and socket connections. It can be used by site administrators to control which resources a Silverlight application can access, when that application did not originate in the domain of the site. In addition, Silverlight also supports the Adobe Flash Cross-domain policy file format. Silverlight sockets can only initiate a connection; they cannot listen for connections.
Silverlight 2 includes[18] the Dynamic Language Runtime (DLR) which allows dynamic compilation and execution of dynamic (scripting) languages. Compilers for the languages based on the DLR (including IronPython and IronRuby) are [to be?] packaged with the Dynamic Languages application in the .xap package.The Dynamic Languages software development kit (SDK) includes a web server named Chiron, that can dynamically package all the dependencies for the Dynamic Languages application and serve it to the browser. The first upcoming languages written for the DLR are Managed JScript, IronPython 2.0, and IronRuby. Microsoft also plans to build Visual Basic .NET 10.0 (VBx) on the DLR. All four languages share the same infrastructure, to allow Silverlight to compile and execute the language source. Conversely, other .NET languages must be compiled ahead-of-time and delivered to Silverlight as .NET assemblies. The implementation of Managed JScript conforms to the ECMAScript 3.0 specification, and Microsoft asserts that it is 250 times faster than interpreted JScript.


A Python interpreter in Silverlight 2 hosted in Mozilla Firefox
With the integration of .NET Framework, Silverlight also allows HTML-managed code interaction, which enables the manipulation of HTML DOM elements from managed code,and permits JavaScript code to call managed code and use objects instantiated by managed code. Silverlight encloses JavaScript objects and DOM elements in managed wrappers to make them available from managed code. While there is no provision for calling JavaScript code directly in the 1.1 alpha release, managed-code events can fire JavaScript handlers. A Silverlight instance does not need to have a UI component in order to manipulate the HTML DOM from managed code. It is done by creating a XAML Canvas with both width and height set to zero, and using its code-behind code to modify the Document Object Model of the HTML page via the APIs in the System.Browser namespace.
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. Beta 2 onwards, Deep Zoom uses an XML-based file format.


A Silverlight 2 application using DeepZoom, running in Safari 3.1, on Windows XP
Media features in Silverlight 2 include:[31]
WMA Professional support, including WMA 10 Pro low-bitrate modes. However, multi-channel audio content is still down-converted to stereo output.
Content protection powered by Microsoft PlayReady DRM client.
Server-side playlists in Windows Media Services.
Media Stream Source API.
The Media Stream Source is the API responsible for enabling adaptive streaming of media. Adaptive streaming allows the player application to choose the bit rate of the media based on available client bandwidth and central processing unit (CPU) resources.[18] Media Stream Source allows the developer to specify a custom method of retrieving media data, the only requirement being that the final video and audio streams be presented to Silverlight runtime in a format that Silverlight can decode (VC-1, H.264, WMA, MP3, etc.). This allows extensible support for otherwise natively unsupported file formats (i.e. MP4, Matroska, Ogg), protocols (i.e. Shoutcast) and delivery methods (i.e. adaptive streaming, peer-to-peer (P2P)). Microsoft first publicly showcased Media Stream Source by powering the NBC Olympics website with their own implementation of adaptive streaming.
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). The file is sanitized of path information, to prevent the application from getting access to information such as user name, and can be opened only in read-only mode. For local storage of data, Silverlight provides isolated local storage (isostorage), namely, outside the browser cache, in a folder hidden inside the private user-profile folder. It is set to 1 MB per URL by default,but this can be changed by the user.[18] Data stored by a Silverlight application in the isostorage is identified by the URL from which it loads, and can be accessed by that application only. All instances of Silverlight share the same isostorage, so all instances of the same Silverlight application can share the saved data, even if they are running on different browsers.
Silverlight CoreCLR uses an attribute-based security model, as opposed to the Code Access Security (CAS) model of the desktop version of .NET Framework. Assemblies are marked with a security attribute, which can be transparent (SecurityTransparentAttribute), safecritical (SecuritySafeCriticalAttribute) or critical (SecurityCriticalAttribute). Methods in transparent assemblies run with partial trust, and codes within such assemblies cannot call critical methods (methods which can cause system-wide changes); neither can transparent assemblies contain unverifiable code (use the unsafe C# keyword or use pointers) or invoke system functions by means of P/Invoke. Code in both critical and safecritical assemblies run with full trust, and are therefore not subject to such limitations. However, a transparent method can call a safecritical method, and a safecritical method can call a critical method. In such a case, the safecritical method will verify that the call is both safe and within the limited rights of the caller; if so, then the safecritical method will proxy the call to the requested critical method. In fact, the IsoStorage APIs are exposed as safecritical methods.[33] An assembly whose security attribute is unset is run as a transparent method. Analogous limitations also apply to type-inheritance; namely, in the cases of virtual-method calls and interface-method calls.[34] Silverlight assemblies can contain members that are not usable by CoreCLR, as long as they can be processed by the .NET Framework CLR; such methods will not be loaded when the assembly is being executed by CoreCLR.[35]
However, only platform code is allowed to be marked as critical or safecritical. The Silverlight runtime ensures that platform assemblies are loaded only from the Silverlight installation directory, and are digitally signed by Microsoft. This effectively means that user-application assemblies can only be transparent code (run under partial trust and limited rights).Platform code can be marked with either attribute. The BCL methods of the .NET Framework, which have the Internet attribute set, allowing them to be called from untrusted code originating from Internet, are exposed in Silverlight BCL as transparent methods.


Silverlight 3


A Silverlight 3 application, with one instance running in a web browser as well as installed locally. The start menu icon is also shown.

Silverlight 3 includes an increased number of controls—including but not limited to DataGrid, TreeView, various layout panels, DataForm for forms-driven applications and DataPager for viewing paginated data. Some of these controls are from the Silverlight Toolkit. In addition, Silverlight 3 includes a navigation framework to let Silverlight applications use the hyperlinked navigation model as well as enabling deep-linking (linking directly to specific pages) within Silverlight applications.
On the media front, Silverlight 3 supports Advanced Audio Coding (AAC) audio decoding as well as hardware-accelerated H.264 video decoding. Silverlight 3 also offers 1080p smooth streaming. The native multimedia pipeline is also programmatically exposed, so that other formats can also be supported by third-parties using managed code decoders.Silverlight 3 supports perspective 3D which enables 3D transformations of 2D elements.These transformations, as well as many 2D operations like stretches, alpha blending etc are hardware accelerated. Custom animations, including transforms and blends, can be created on Silverlight elements using High Level Shader Language (HLSL) to make use of pixel shaders.A bitmap API is provided to let Silverlight 3 applications manipulate bitmaps.Silverlight now uses the graphics processing unit (GPU) to accelerate the composition of Visual Trees (like WPF, Silverlight elements correspond to Visual elements, which, when coupled with the layout information, forms a Composition Tree or Visual Tree which is then rendered to form the final display; see WPF architecture). Visual trees can now be cached; this increases performance in cases like transforms, which creates lots of throw-away intermediate states, by not making the state transitions on the main Visual tree. Silverlight 3 now also supports ClearType text rendering.


A Silverlight 3 application demonstrating local file access.
UI elements in Silverlight 3 supports element-to-element binding—which allows one element to be bound to the state of another element,[40] as well as a validation mechanism for data binding.[37] Unlike Silverlight 2, which allowed the applications to save files only to the local isostorage, Silverlight 3 applications can save to any location on the file system via the system Save File dialog. However, the path where the file is saved will still be hidden from the Silverlight application. Any external assemblies used by Silverlight applications are cached too so that they need not be redownloaded for subsequent instantiations of the application.
Silverlight 3 also includes a LocalConnection API to communicate (using a named pipe style model) among multiple running applications on the same machine, irrespective of the browser and can monitor for network connectivity events. Silverlight 3 can optionally use Binary XML to communicate with WCF services.
Silverlight 3 supports Out-of-Browser experiences, i.e., Silverlight applications can be installed to the system for offline access (provided the application manifest is designed to allow local installation) where they run outside the browser. They are launched using the Start Menu or desktop shortcuts, and run without the browser window.Applications can check whether they are running inside a browser or not.When running outside of a browser, HTML interop is disabled. In addition, access to the Function Keys is enabled. Locally installed Silverlight applications still run in a sandbox