Windows 8 is the complete revamp of the existing Windows operating system as said by the Microsoft developer team. Microsoft took every care to enhance the features of existing operating systems in order to implement a fluid, fast and consistent operating system all over different hardware architectures and fully utilize the advantages of cloud to personalize usage.
To list a few of Windows 8 features, we have the following:
- Support for both x86 PCs and ARM tablets
- Windows To Go, a new feature in Windows 8 that enables enterprise administrators to create USB drives containing complete, managed Windows images that users can use to boot and run Windows on any Windows 7 or Windows 8 capable computer.
- Windows Store, to compete with Apple, Windows has confirmed the introduction of a Windows Store, similar to Mac App Store, which allows users to browse through Windows applications, while developers can publish their Metro-style apps on Windows 8 devices.
- Fluid, fast and best user interface. Speaking about the UI, Windows 8 certainly has got a mind blowing interactive UI, which has been extensively redesigned to a “Metro-style” design, which shows the most important information to you, embodies simplicity, and gives you full control over it. The UI is designed to provide a fluid and intuitive interaction and navigation with (multi-)touch, or a mouse and keyboard.
This list is not exhaustive and in this article, we concentrate on the fifth feature “Contracts” that are introduced in Windows 8 that enables the applications (developed by distinct unknown developers) to talk to each other. To state it simply, contracts here are developer clipboard, a universal clipboard of apps and services that ties back to Internet Explorer 10.
Note: Before going in depth about contracts, if you are new to Windows 8 environment, I would recommend you have a good understanding of Windows 8 Metro style UI and what are the new features and responsibilities it’s going to provide for a developer.
The answer to this question is quite simple; “because users often come across information they’re excited to share with someone or utilize in another app”. In the Metro interface of Windows 8, where only one application has the screen at a time, this will be a boon to developers and users alike, working to increase the usefulness in situations where one app owning the screen at a time is necessary.
So What Are “Contracts” All About?
Steven Sinofsky, the President of the Windows Division, in his keynote of Build events, mentioned contracts as being a key element of the Windows 8 development platform.
As per his words, “Applications should be able to work together without knowing anything about each other”. He cited an example using a few of the different “charms,” or main icons, in Windows 8. (The five charms are Devices, Settings, Share, Search and Start.) Applications and services — including the coming Windows Live app/service hybrids — that implement contracts will be able to make use of a data package from Internet Explorer 10, enabling users to remain inside of an app from which they are sharing, searching, etc. In Windows 8, there are share contracts, search contracts and “picker” contracts.
Sinofsky also hinted that the closest analogy to a “contract” is a clipboard. (As per history, the former Microsoft Chief Software Architect Ray Ozzie has a concept of “universal clipboard” — dating back to 2006. Ozzie’s universal clipboard, which he released under a Creative Commons license, was focused on connecting Web sites and desktop applications using a combination of RSS feeds, other XML data and the desktop clipboard. It’s not sure whether Windows 8 team relied on Ozzie’s vision and code, if at all.)
In Windows 8, an application can expose features through a contract. The contract details what the offered feature needs to work and what it will produce. Think of it like the input/output paradigm in Apple's Automator; but able to be tapped into by any application on the system, not just through a single central authority like Automator. More importantly, these features can be tapped into seamlessly, the user never having to leave the current application but still being able to tap into the full functionality present on their device.
A Little Technicality of “Contracts”
The “currency” (here, currency refers to the trading items between source and target apps) in a Share contract is known as a
DataPackage. The data can be captured and shared in a number of different formats, including text, URI, HTML, images and other extensible formats.
Source apps in the Share scenario can include news, magazines, media, games, social networking data, notes captured via a note-taking program and data stored in the cloud. Target categories on which Microsoft is expecting developers to focus include social networking, communication, entertainment, print services, “device connected” scenarios, note-taking and cloud storage.
Here, Windows does the heavy lifting so that apps don’t need to know much about each other in order to create amazing experiences!
Contracts implementation consists of three parties:
- Source apps: This is the source of data.
- Share Broker: This is a mediating layer that talks to source and target apps.
- Target apps: These are the recipients of the data and shows them in their UI context.
Note: In ideal cases, every application should be a perfect source and best target. Hence, at times, we refer source apps as ‘share source apps’ and target apps as ‘share target apps’.
Hence, “Share target” refers to applications, which acts as targets as well as share the information. Being a Share target will increase usage of your app or service and keeps your service fresh with content that matters to users.
The four steps involved in sharing from source to target are depicted in terms of pictures as follows:
The source application has to register itself with datatransfer manager. Now share broker (which is a mediator to both source and target apps), on the user request, will send an event to the source app on behalf of the target app. The source application responds to the event by starting to fill the datapackage.
The source app completes filling the datapackage and completes all its async operations before responding to share broker with datapackage. The share broker does an additional step of filtering the data received from source app and models it as links as per user’s criteria.
Now user can see search results on the screen from the source app. At this point, the user can click the desired result he wants to explore. So once he clicks on the links, the share broker notifies the target app with the data and the target app prepares its user interface to show the result it received on its user interface.
This is the final step, where in the target app shows the result made up of source app’s data and reports a completed notification to share broker.
More about 'datapackage'
The data package can contain any data in it. Source apps should include as many representations of the data as possible to maximize the set of target apps.
Pseudo code that represents the datapackage construction is as follows:
Notes to Consider for a Source App
Overusage of this contract should be avoided. For example “
find” in a worksheet should not be coupled with “
Search” charm. The subsets of functionality that a source app should satisfy are:
- Listen for and handle a Share event to participate
- Content should be shared in two ways:
- Implicit – user selects Share without making a selection
- Explicit – user selects content in an app and then selects Share
- Build data package for best results
The most anticipated source apps categories are News, Magazine, Media, Games, Social networking, Note taking, Cloud storage, etc.
Pseudo code for setting up a share source app:
Notes to Consider for a Share Target App
The subsets of functionalities that a share target app should satisfy are:
- Register as a Share target and specify the formats you accept
- Build your app UI to look best as part of the Share experience
- Selection of people or places to Share within your app
- Quick, lightweight experience
- Use the
DataPackage to tailor the user experience
- Report completion
- Return a Quicklink
The anticipate share target apps are Social networking, Communication, Entertainment, Print service, Device connected, Note taking, Cloud storage, etc.
Pseudo code for setting up a share target app:
The above article is not the exact implementation of contracts since the concept itself is new, but will provide an overview of what are contracts and how we are going to deal with them in the coming days. The pseudo code is not the part of exact implementation, but are snapshots of the picture we are going to see when we develop applications in the metro-world.