惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
量子位
A
Arctic Wolf
L
Lohrmann on Cybersecurity
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
WordPress大学
WordPress大学
V
Vulnerabilities – Threatpost
博客园 - Franky
C
Cyber Attacks, Cyber Crime and Cyber Security
The Cloudflare Blog
Last Week in AI
Last Week in AI
The Hacker News
The Hacker News
I
Intezer
J
Java Code Geeks
P
Privacy International News Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
Secure Thoughts
Cisco Talos Blog
Cisco Talos Blog
阮一峰的网络日志
阮一峰的网络日志
S
Securelist
Security Latest
Security Latest
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
小众软件
小众软件
Jina AI
Jina AI
有赞技术团队
有赞技术团队
人人都是产品经理
人人都是产品经理
博客园_首页
酷 壳 – CoolShell
酷 壳 – CoolShell
T
The Exploit Database - CXSecurity.com
雷峰网
雷峰网
T
Tenable Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Privacy & Cybersecurity Law Blog
Simon Willison's Weblog
Simon Willison's Weblog
博客园 - 【当耐特】
T
Threat Research - Cisco Blogs
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
MongoDB | Blog
MongoDB | Blog
D
DataBreaches.Net
N
News | PayPal Newsroom
Google Online Security Blog
Google Online Security Blog
K
Kaspersky official blog
H
Help Net Security
宝玉的分享
宝玉的分享
罗磊的独立博客
Webroot Blog
Webroot Blog
月光博客
月光博客
B
Blog RSS Feed
Recorded Future
Recorded Future

博客园 - zhangdong

软件架构和设计 在Visual Studio 2010中定义GDI+自定义控件——自定义控件介绍 Visual Studio 2010 Team System 动手实验室——架构师工具 Visual Studio 2010 Team System 动手实验室 Silverlight 框架 .NET Framework 3.5 Silverlight 的发展之路 Microsoft Exchange Server 2010 介绍 Silverlight 3 —— 介绍 搭建基于MOSS的团队解决方案01——Microsoft Office SharePoint 2007 Server快速入门(Continued) 搭建基于MOSS的团队解决方案01——Microsoft Office SharePoint 2007 Server快速入门 Windows Workflow Foundation实验01——Windows Workflow Foundation快速入门(练习四) Windows Workflow Foundation 实验01 —— Windows Workflow Foundation 快速入门(练习三) Windows Workflow Foundation实验01——Windows Workflow Foundation 快速入门(练习二) Windows Workflow Foundation实验01——Windows Workflow Foundation快速入门(练习一) Windows Workflow Foundation实验——安装与准备 地图控件快速入门——控制地图 地图控件快速入门 - zhangdong - 博客园 WCF中的管道——管道类型
使用.NET平台工具操作Live Framework
zhangdong · 2010-01-13 · via 博客园 - zhangdong

目的

这个试验中展示了如何创建一个Windows窗体应用程序来查找和操作保存在Live Framework中的图片。由于这个示例的目的是展示Live Framework的.NET API,而并不是为了讲解构建一个高质量的应用程序,所以这里很少包含输入验证、异常处理、错误处理。这个示例中使用一套“Mesh Object”对象的实例。

准备

如果要设计如下示例必须下载并安装Live Framework SDK,而且需要使用Visual Studio 2008 SP1。

开始

在开始试验之前,请确认你的Windows Live ID和密码。

Live Framework 服务的URI:https://user-ctp.windows.net

注意!!!在使用https://user-ctp.windows.net 这个地址之前,必须登陆到“Azure Services Developer Portal”,在新项目页面中单击“Activate Live Framework CTP”来激活帐号。

任务一:创建一个新的Visual Studio项目,命名为MyPhotos

1. 打开Visual Studio。单击开始菜单,在所有程序列表中定位Visual Studio 2008,然后单击。

2. 点击文件菜单,选择新建-〉项目-〉Windows窗体应用程序。并选择C# 语言。

3. 输入MyPhotos作为项目名。

默认情况下,Visual Studio在Windows Vista系统下创建的项目在C:\Users\USERNAME\Documents\Visual Studio 2008\Projects目录下。这里的UserName是你登录到本机的帐户名。

clip_image002

4. 点击OK。

此时,你会进入窗体的设计界面(标签为Form1.cs[Design])。

5. 点击Form1,右键单击,选择属性,然后将窗体的名字修改为MyPhotos,大小设置为730,660,窗体的文本属性是My Photos。

6. 将鼠标移到解决方案资源管理器上,右键单击引用,选择添加引用。

7. 单击浏览按钮,定位到Live Framework SDK安装路径下的.NET Library目录(C:\Program Files\Microsoft SDKs\Live Framework\v0.91\API Toolkits\.Net Library)。

8. 选择其中全部DLL(Microsoft.LiveFX.Client.dll、Microsoft.LiveFX.ResourceModel.dll、Microsoft.Web.dll),然后将他们添加到引用。

9. 右键单击引用,选择添加引用,并选择.NET选项卡,然后添加对System.Runtime.Serialization的引用。

clip_image002[8]

任务二:使用全局变量和语句来添加连接字符串

1. 展开解决方案资源管理器中的属性节点,双击Resources.resx。然后添加一个URI到里面。这个URI指向Mesh服务器: https://user-ctp.windows.net

2. 保存并关闭现在的选项卡。此时你会返回窗体的设计视图。

3. 按F7转向窗体的代码视图。

4. 添加如下Using语句到代码文件的顶端。

   1:  using System.Collections;
   2:  using System.IO;
   3:  using System.Net;
   4:  using System.Runtime.Serialization;
   5:  using Microsoft.LiveFX.Client;
   6:  using Microsoft.LiveFX.ResourceModel;  // For RoleType
    • System.Collections 用来获得缓存Framework信息的列表。
    • System.IO 用作文件操作
    • System.Net用来创建连接到Framework的凭证。
    • System.Runtime.Serialization 用来添加用户数据信息到Framework。
    • Microsoft.LiveFX.Client用来提供Framework的运行时支持。
    • Microsoft.LiveFX.ResourceModel用来支持RoleType枚举。

5. 在MyPhotos类中添加如下声明。这是对Live Framework的引用。

任务三:添加控件来连接到Framework以及退出应用程序

  1. 按Shift+F7返回设计界面clip_image002[13]
  2. 拖拽一个Label控件到窗体,并将它放置在左上角。设置其字体为粗体。设置文本属性为Windows Live ID。
  3. 拖拽一个文本控件到窗体,并放置到Label控件的右侧。
  4. 设置其名称属性为LiveIDTextBox,并设置其大小为175,20。
  5. 拖拽一个Label控件到窗体上并放置在TextBox的右侧。
  6. 设置字体为粗体,文本属性为Passwork。
  7. 拖拽一个TextBox控件到窗体,并放置在Label控件的右侧。
  8. 设置名称属性为PasswordTextBox,大小为100,20。然后将UseSystemPasswordChar属性设置为Ture。
  9. 拖拽一个Button控件,放置在TextBox控件的右侧。
  10. 设置名称为ConnectButton,并且,文本属性为Connect。
  11. 拖拽一个Button控件到窗体的右下角。
  12. 设置其名称为ExitButton,文本属性为Exit。

任务四:添加连接Framework的代码,以及退出应用程序代码

  1. 双击Connect按钮。
  2. 添加如下代码到ConnectButton_Click方法以连接到Framework。这个方法获得了Uir资源实体的值,并且从界面上的两个文本框中获得用户的Windows Live ID以及密码。它创建一个FrameworkItemAccessOptions对象,当Framework加载时获取Framework的资源。它用Windows Live ID、密码、URI,创建一个用户代理。并使用这个用户代理、URI和FrameworkItemAccessOptions对象进行连接。
       1:  if (mesh != null)
       2:     {
       3:        return;
       4:     }
       5:   
       6:     LiveItemAccessOptions accessOptions = new LiveItemAccessOptions(true);
       7:   
       8:     try
       9:     {
      10:        string address = LiveIdTextBox.Text;
      11:   
      12:        if (string.IsNullOrEmpty(address))
      13:        {
      14:           MessageBox.Show("You must specify a Windows Live ID", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
      15:           return;
      16:        }
      17:   
      18:        string password = PasswordTextBox.Text;
      19:   
      20:        if (string.IsNullOrEmpty(password))
      21:        {
      22:           MessageBox.Show("You must enter your password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
      23:           return;
      24:        }
      25:   
      26:        string uri = Properties.Resources.Uri;
      27:   
      28:        if (string.IsNullOrEmpty(uri))
      29:        {
      30:           MessageBox.Show("No URI in the resources file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
      31:           return;
      32:        }
      33:   
      34:        // Create user token
      35:        String token = new NetworkCredential(address, password, uri).GetWindowsLiveAuthenticationToken();
      36:              
      37:        // Create URI for cloud Mesh
      38:        Uri theUri = new Uri(uri);
      39:   
      40:        env.Connect(token, AuthenticationTokenType.UserToken, theUri, accessOptions);
      41:   
      42:        mesh = env.Mesh;
      43:   
      44:        // Tell user they are connected
      45:        ConnectButton.Text = "connected";
      46:     }
      47:     catch (Exception ex)
      48:     {
      49:        MessageBox.Show("Caught exception trying to connect: " + ex.Message
      50:                                     , "Error
      51:                                     , MessageBoxButtons.OK
      52:                                     , MessageBoxIcon.Error);
      53:     }
  3. 返回设计界面。
  4. 双击Exit按钮。
  5. 在ExitButton_Click方法中添加如下语句。
       1:  System.Windows.Forms.Application.Exit();

任务五:保存,生成,并运行项目

  1. 按F5保存、生成、并以调试模式运行应用程序。
  2. 输入你的Windows Live ID 和密码。你也可以尝试输入错误的密码来看看应用程序会出现什么情况。
  3. 单击连接。当连接成功,按钮的文本从Connect变为connected。
  4. 单击Exit关闭应用程序。
  5. 注意:如果文本框的大小不足以显示你的Live ID或密码,可以对其进行调整。