Discussion Board

Results 1 to 1 of 1
  1. #1
    Registered User highcedar's Avatar
    Join Date
    Apr 2012
    Posts
    8
    通过 Live Connect API,Windows Phone 7.0、7.5 和 8.0 应用可以使用 Hotmail、Messenger、SkyDrive 及其他与 Live Connect 兼容的服务中的信息。

    使用 C# 引用 Live Connect API

    若要在 Microsoft Visual Studio 2010 中从 Windows Phone 项目引用 Live Connect API,请执行下列操作:
    1.安装 Live SDK(如果尚未这样做)。
    2.在你的项目中,右键单击“解决方案资源管理器”中的“引用”>“添加引用”。
    3.在“.NET”选项卡上,单击“Microsoft.Live.Controls”,长按 Ctrl 键,然后单击“Microsoft.Live”。
    4.单击“确定”。
    5.向代码中添加相应的 using 语句,如下。

    using Microsoft.Live;
    using Microsoft.Live.Controls;


    如果 Live Connect 登录控件未显示在 Microsoft Visual Studio 工具箱中,请执行下列操作以添加该控件:
    1.在你的项目中,如果“工具箱”不可见,则打开可扩展应用程序标记语言 (XAML) 设计器,单击“视图”>“工具箱”。
    2.右键单击“工具箱”的空白区域,然后单击“选择项目”。
    3.单击“浏览”。
    4.转至 Live SDK 安装文件夹。在此处,转到 \Windows Phone <version>\References\ 文件夹,其中 <version> 是你要用于构建应用的 Windows Phone 版本,例如 Windows Phone 7.5 所对应的 7.5。单击“Microsoft.Live.Controls.dll”>“打开”>“确定”。
    注意 默认情况下,Live SDK 安装在 \Program Files\Microsoft SDKs\(对于 32 位计算机)或 \Program Files (x86)\Microsoft SDKs\(对于 64 位计算机)的 \Live\v5.0\ 文件夹中。

    代码示例
    http://msdn.microsoft.com/zh-cn/libr...h826552#csharp

    后台传输

    Windows Phone 7.5 应用可以发起向 SkyDrive 的文件上载和下载请求,即使发起请求的应用被挂起或退出,请求也将继续。这种功能称为“后台传输”。
    对于 Windows Phone 7.5 应用,即使开始下载的应用被挂起或退出,你也可以下载文件。操作方法如下。
    1.在初始化 LiveConnectClient 变量的代码中,为 LiveConnectClient.BackgroundDownloadCompleted 事件声明处理程序。(或者,如果你想要查看后台文件下载的进度、在文件上载之后进行其他操作,或查看后台文件上载进度,还可以选择处理 LiveConnectClient 类的 BackgroundDownloadProgressChanged、BackgroundUploadCompleted 和 BackgroundUploadProgressChanged 事件。)然后调用 LiveConnectClient.AttachPendingTransfers 方法,该方法会检查在应用的上一个实例中启动的挂起后台文件传输。下面是相应代码。

    Code:
    private void btnSignin_SessionChanged(object sender, LiveConnectSessionChangedEventArgs e)
    {
        if (e.Status == LiveConnectSessionStatus.Connected)
        {
            session = e.Session;
            client = new LiveConnectClient(session);
            client.BackgroundDownloadProgressChanged +=
                new EventHandler<LiveDownloadProgressChangedEventArgs>(OnBackgroundDownloadProgressChanged);
            client.BackgroundDownloadCompleted +=
                new EventHandler<LiveOperationCompletedEventArgs>(OnBackgroundDownloadCompleted);
            client.BackgroundUploadProgressChanged +=
                new EventHandler<LiveUploadProgressChangedEventArgs>(OnBackgroundUploadProgressChanged);
            client.BackgroundUploadCompleted +=
                new EventHandler<LiveOperationCompletedEventArgs>(OnBackgroundUploadCompleted);
            client.AttachPendingTransfers();
            infoTextBlock.Text = "Signed in.";
        }
        else
        {
            infoTextBlock.Text = "Not signed in.";
            client = null;
        }
    }
    2.启动后台文件下载并针对 BackgroundDownloadCompleted 事件(还可以选择包括 BackgroundDownloadProgressChanged 事件)实现事件处理程序,如下。

    Code:
    private void StartBackgroundDownload(object sender, RoutedEventArgs e)
    {
        client.BackgroundDownloadAsync("file.8c8ce076ca27823f.8C8CE076CA27823F!161",
            new Uri("/shared/transfers/TheNumber5.jpg", UriKind.RelativeOrAbsolute), "TheNumber5Download");
    }
    
    void OnBackgroundDownloadProgressChanged(object sender, LiveDownloadProgressChangedEventArgs e)
    {
        if (e.UserState.ToString() == "TheNumber5Download")
        {
            infoTextBlock.Text = e.UserState.ToString() + ": " + e.BytesReceived + " of " + 
                e.TotalBytesToReceive + " bytes downloaded (" + e.ProgressPercentage + "%)";
        }
    }
    
    void OnBackgroundDownloadCompleted(object sender, LiveOperationCompletedEventArgs e)
    {
        if (e.UserState.ToString() == "TheNumber5Download")
        {
            if (e.Error == null)
            {
                infoTextBlock.Text = "Download completed.";
            }
            else
            {
                infoTextBlock.Text = "Error downloading file: " + e.Error.ToString();
            }
        }
    }
    Last edited by highcedar; 2013-02-13 at 02:19.

Similar Threads

  1. Unable to connect to Windows Phone 8 device
    By Mendzapp Ltd. in forum Windows Phone General
    Replies: 7
    Last Post: 2012-12-07, 11:24
  2. Connect to phone from windows service
    By stealth117 in forum PC Suite API and PC Connectivity SDK
    Replies: 4
    Last Post: 2008-09-27, 19:32
  3. N82 can not connect windows hyperterminal
    By wdynasty in forum General Development Questions
    Replies: 0
    Last Post: 2008-06-06, 05:19
  4. connect to windows xp
    By Gigs_ in forum Wired and Wireless interfaces (Closed)
    Replies: 2
    Last Post: 2006-09-04, 14:57
  5. Replies: 1
    Last Post: 2002-07-16, 06:44

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved