• 公布Windows Azure Toolkit for Windows 8


    Windows Azure Toolkit for Windows 8旨在使开发人员能更容易地创建一个Windows Metro style 应用程序,这个应用程序能赋予 Windows Azure计算和存储源源不绝的力量。它包含Windows 8 Cloud Application project template for Visual Studio,这使得开发人员更容易地创建一个利用Windows Azure服务的Windows Metro style应用程序。该模板生成一个Windows Azure project、一个 ASP.NET MVC 3 project和 Windows Metro style JavaScript application project。这些立即就让它与众不同,客户端和云计算项目整合到一起来启用随同Windows Push Notification Service (WNS)的推动通知服务。此外,Windows Azure项目演示了如何使用WNS方法以及如何利用Windows Azure Blob 和 Table 存储。

    Windows Azure Toolkit for Windows 8可供下载

    Push Notification Cloud Service架构

    对于那些熟悉使用Windows Phone 7 和Microsoft Push Notification Service (MPNS)的人来说,这是一个好消息,因为它与Windows Push Notification service (WNS)颇为相似。让我们来看看WNS工作的鸟瞰图。

    发送通知需要几个步骤:

    1. 请求一个通道。利用 WinRT API 从 WNS 请求一个Channel Uri。这个 Channel Uri将成为你发送通知到每一个应用程序实例的唯一标示符。
    2. 使用你的 Windows Azure cloud service注册通道. 一旦你拥有了一个通道,你可以随即存储它并将它与任一应用程序的特定数据关联起来(例如用户配置文件等),直到你的服务决定发送一个通知到特定通道。
    3. WNS的身份验证. 发送通知到你第一次所需的Channel URI来进行WNS的身份验证(使用OAuth2来获取你推向WNS的每一个紧随其后的通知的标记)。
    4. 发送通知到通道接受者. 一旦你拥有了自己的通道,通知有效负载和 WNS 访问令牌,然后,你就可以执行HttpWebRequest将通知发送到WNS来交付给你的客户端。

    幸运的是,Windows Azure Toolkit for Windows 8通过提供一系列项目模板使你通过简单的新建项目的操作就能从Windows Azure cloud service开始交付通知,这加速了项目的开发。让我们来看看这些toolkit组件。

    Toolkit 组件

    Windows Azure Toolkit for Windows 8包含一系列丰富的东西,包括Dependency Checker、Windows Push Notification Service recipe、 Dev 11 project templates、VS 2010 project templates 和示例应用程序 。

    Dependency Checker

    Dependency Checker旨在帮助识别并安装开发Windows 8上的Windows Metro style 应用程序 和Windows Azure 解决方案所需的但缺少的那些dependency。

    Dev 11 Windows Metro style app

    Dev 11 Windows Metro style app提供简单的UI和提供阐述怎样使用WinRT API从WNS请求一个通道所需的所有代码。例如,下面是从WNS请求一个Channel URI的相关代码:

     var push = Windows.Networking.PushNotifications;
            var promise = push.PushNotificationChannelManager.createPushNotificationChannelForApplicationAsync();
     
            promise.then(function (ch) {
                var uri = ch.uri;
                var expiry = ch.expirationTime;
                updateChannelUri(uri, expiry);
            });

    一旦你拥有了自己的通道,然后,你需要将这个通道注册到你的Windows Azure cloud service上。为此,示例应用程序调用updateChannelUri,在那里我们构建了一个简单的JSON有效负荷并使用WinJS.xhr
    API 将它POST到Windows Azure里运行的WCF REST service上。

    function updateChannelUri(channel, channelExpiration) {
            if (channel) {
            var serverUrl = "https://myservice.com/register";
            var payload = { Expiry: channelExpiration.toString(),
                                URI: channel };                      
     
            var xhr = new WinJS.xhr({
                   type: "POST",
                   url: serverUrl,
                  headers: { "Content-Type": "application/json; charset=utf-8" },
                  data: JSON.stringify(payload)
                 }).then(function (req) { … });
           } }

    VS 2010 Windows Azure Cloud Project Template

    该解决方案提供的Windows Azure Cloud project演示了为交付推送通知服务而构建Windows Azure service的几个有利条件。这些有利条件包括:

    1. 客户端应用程序的WCF REST service注册通道并演示了如何使用TableServiceContext将他们存储在Windows Azure 表存储里。以下代码列出了该项目暴露出的简单的WCF REST接口。

    [ServiceContract]
    public interface IWNSUserRegistrationService
    {
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare)]
        void Register(WNSPushUserServiceRequest userChannel);
     
        [WebInvoke(Method = "DELETE", BodyStyle = WebMessageBodyStyle.Bare)]
        void Unregister(WNSPushUserServiceRequest userChannel);
    }

    2. ASP .NET MVC 3 portal构建并使用WNS recipe向客户端发送Toast、Tile 和 Badge 通知。

    3.如何利用Tile的Blob存储和Toast notification image的示例。

    4. Portal使用的Windows Push Notification Recipe提供了WNS验证的简单托管API、构建有效负荷并发送通知到WNS。

    using Windows.Recipes.Push.Notifications;
    using Windows.Recipes.Push.Notifications.Security;
     
    ...
     
    //Construct a WNSAccessTokenProvider which will accquire an access token from WNS
    IAccessTokenProvider _tokenProvider = new WNSAccessTokenProvider("ms-app%3A%2F%2FS-1-15-2-1633617344-1232597856-4562071667-7893084900-2692585271-282905334-531217761", "XEvTg3USjIpvdWLBFcv44sJHRKcid43QXWfNx3YiJ4g");
     
    //Construct a toast notification for a given CchannelUrl
    var toast = new ToastNotification(_tokenProvider)
    {
      ChannelUrl = "https://db3.notify.windows.com/?token=AQI8iP%2OtQE%3d";
      ToastType = ToastType.ToastImageAndText02;
      Image = "https://127.0.0.1/devstoreaccount1/tiles/WindowsAzureLogo.png";
      Text = new List<string> {"Sending notifications from a Windows Azure WebRole"};  
    };                   
     
    //Send the notification to WNS
    NotificationSendResult result = toast.Send();

    5.正如你所看到的,Windows Push Notification Recipe简化了发送通知所需的代码,简化后只需3行。

    每个asset中网络端点的净结果都是一个通知,类似于下图阐述的那样,该图是使用Windows Azure Toolkit for Windows 8的一个Toast交付的截图。

    作为练习,建议你花一些时间利用网站搜索每个Toast、Tile 和Badge 通知类型一系列的可用模板。

    示例应用程序

    目前该toolkit中还包含两个示例应用程序,演示了其他Windows Azure功能的用法:

    1. PNWorker: 该示例说明了如何利用Windows Azure存储队列来将交付通知的工作转移到Windows Azure Worker Role上。更多详细信息,请参阅CodePlex文档。
    2. ACSMetroClient: 该示例是关于怎样在Windows Metro style应用程序中使用ACS。更多详细信息,请参阅Vittorio Bertocci的这个帖子
    1. Margie’sTravel: 如John Shewchuk的示例主旨中那样,Margie’s Travel示例程序演示了Metro style app是如何与Windows Azure一同工作的。更多详细信息,请参阅Wade Wegner的这个帖子。这个例子会在//Build大会之后加入。

    总结

    Windows Azure Toolkit for Windows 8为开发人员提供了一套丰富的可重复使用的asset,演示了如何从Windows 8的Metro style应用程序中快速地学会使用Windows Azure。下载该工具包并查看一步一步的演练,请参阅Windows Azure Toolkit for Windows 8

    Nick Harris 是Windows Azure的技术专员。Follow Nick吧!@cloudnick

    本文翻译自:http://blogs.msdn.com/b/windowsazure/archive/2011/09/14/announcing-the-windows-azure-toolkit-for-windows-8.aspx

  • 相关阅读:
    js:语言精髓笔记1--标识符与基本类型
    ember.js:使用笔记4 数组数据的分组显示
    ember.js:使用笔记3 活用{{bind-attr}}
    ember.js:使用笔记2-数据删除与存储
    ember.js:使用笔记1-数组数据统一显示
    工具:使用jekyll生成静态网站
    css:删除:×的效果
    js写随机一个颜色
    回调函数的使用
    jquery获取select标签的选中元素
  • 原文地址:https://www.cnblogs.com/new0801/p/6176599.html
Copyright © 2020-2023  润新知