现在阅读
A Study of Windows 8 'Contracts' – why, what and how?
0

A Study of Windows 8 'Contracts' – why, what and how?

由 ultracpy2018年1月26日

Introduction

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:

  1. Support for both x86 PCs
    and ARM tablets
  2. 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.
  3. 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.
  4. 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.
  5. Contracts
  6. etc.

This list is not exhaustive and this article we concentrate
on the fifth feature “Contracts” that are introduced in Windows 8 that enables
the applications (developed by distinct unknown developers) talk to each other.
To state it simple 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 to 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.

Why “Contracts”?

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 bit 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 do the heavy lifting so that apps don’t need to
know much about each other in order to create amazing experiences!

Contracts implementation consists three parties

  1. Source apps: This is the source of data
  2. Share Broker: This is an mediating layer that talks to source and target apps
  3. 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 also. 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.

Step 1:
The source application as 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 target app. The source application responds
to the event by starting filling the datapackage.

step1.png

Step2:
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 model it as links as per user’s criteria.

step2.png

Step3:
Now user can see a 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.

step3.png

Step4:
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.

step4.png

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

datapackage.png

Notes to consider for a source app

Over usage of this contracts should be avoided. For example “find”
in a worksheet should not be coupled to “Search” charm. The subsets of functionality that a source app should satisfy are:

  1. Listen for and handle a Share event to participate
  2. Content should be shared in two ways:
    1. Implicit – user selects Share without making a selection
    2. Explicit – user selects content in an app and then selects Share
  3. 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:

sourcesetup.png

Notes to consider for a share target app

The subsets of functionalities that a share target app
should satisfy are:

  1. Register as a Share target and specify the formats you accept
  2. Build your app UI to look best as part of the Share experience
    1. Selection of people or places to Share within your app
    2. Quick, lightweight experience
  3. Use the DataPackage to tailor the user experience
  4. Report completion
  5. 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:

targetsetup.png

Conclusion

The above article is not the exact implementation of contracts since the concepts itself is new, but will provide an overview of what are contracts and how are we going to deal with them in coming days. The pseudo code is not the part of exact implementation, but are a snapshots of the picture we are going to see when we develop applications in metro-world.

出处:https://www.codeproject.com/Articles/333411/A-Study-of-Windows-Contracts-why-what-and-how

关于作者
ultracpy
评论

你必须 登录 提交评论