中国的互联网是开放的
杯具啊! Bookmark Sync被墙了
使用魅族M8的一些体会
挣钱要低调啊!
http://www.cse.umich.edu/~jhalderm/pub/gd/
Conclusion
Our brief testing proves that Green Dam contains very serious security vulnerabilities. Unfortunately, these problems seem to reflect systemic flaws in the code. The software makes extensive use of programming techniques that are known to be unsafe, such as deprecated C string processing functions including sprintf and fscanf. These problems are compounded by the design of the program, which creates a large attack surface: since Green Dam filters and processes all Internet traffic, large parts of its code are exposed to attack.
If Green Dam is deployed in its current form, it will significantly weaken China’s computer security. While the flaws we discovered can be quickly patched, correcting all the problems in the Green Dam software will likely require extensive rewriting and thorough testing. This will be difficult to achieve before China’s July 1 deadline for deploying Green Dam nationwide.
Microsoft 收购列表
如何在Workflow项目中使用web service(2)
17. 在Solution Explorer中双击Workflow1.cs回到设计版面。从Toolbox拖放一个Code activity到ifElseActivity1的右边分支ifElseBranchActivity2中,并改名为GuessIncorrect。然后鼠标右键点击GuessIncorrect,选择Generate Handles。在 handler中添加代码显示猜错信息,结果如下:
private void GuessIncorrect_ExecuteCode(object sender, EventArgs e)
{
Console.WriteLine("Your Guess was incorrect…");
}
18. 在Solution Explorer中双击Workflow1.cs回到设计版面。从Toolbox拖放一个Code activity到ifElseActivity1下面。并改名为PlayAgain。这个activity接受用户输入,决定是否退出程序。然后鼠标右键点击PlayAgain,选择Generate Handles。在 handler中添加代码接受用户输入是否继续,结果如下:
private void PlayAgain_ExecuteCode(object sender, EventArgs e)
{
Console.Write("Do you want to play again (y/n)?");
bPlayAgain = Console.ReadKey().Key == ConsoleKey.Y;
Console.WriteLine();
}
19. 在Solution Explorer中双击Workflow1.cs回到设计版面。从Toolbox拖放一个Code activity到whileActivity1下面。并改名为GameOver。这个activity用来显示结束信息。然后鼠标右键点击GameOver,选择Generate Handles。在 handler中添加代码,结果如下:
private void GameOver_ExecuteCode(object sender, EventArgs e)
{
Console.WriteLine("Game Over");
int nPercent = (int)((double)nCorrectGuesses / nTurns * 100);
Console.WriteLine("You played {0} time(s) and were correct {1} time(s).", nTurns, nCorrectGuesses);
Console.WriteLine("Your accuracy was {0}%", nPercent);
}
20. 从菜单上选Build — > Build Solution确保编译成功。
21. 在Solution Explorer里鼠标右击CoinFlipWorkflow.Workflow1_WebService.asmx然后选择View in Browser,这样asp.net development server会启动并且监听在2149端口上。
22. 在Solution Explorer里鼠标右击CoinToss项目,选择Set as Startup Project。然后按 F5 开始程序,运行状况如图5:
如何在Workflow项目中使用web service(1)
在Solution Explorer里鼠标右击.asmx (在这个例子里是CoinFlipWorkflow.Workflow1_WebService.asmx) 然后选择View in Browser。
我们应该能正确访问这个web service。记住浏览器里地址栏里的URL. 在这个例子里是
http://localhost:2149/CoinFlipWorkflow_WebService/CoinFlipWorkflow.Workflow1_WebService.asmx
然后我们需要创建一个猜硬币正反面的程序。这个程序会调用刚产生的web service来获得模拟扔硬币正反面的结果。
- 在Visual Studio 2005菜单 上点击 File – > Add — > New Project。Add New Project对话框弹出。从Project types里选Visual C# — > Workflow。在templates列表里选Sequential Workflow Console Application。设置Name为CoinToss作为新的项目名。点击OK创建了新的workflow project。
- 从Toolbox上把一个Code activity拖到设计版面上。改名为Welcome。
- 然后鼠标右键点击Welcome,选择Generate Handles在 handler中添加提示代码,结果如下:
private void Welcome_ExecuteCode(object sender, EventArgs e)
{
Console.WriteLine("Welcome to Coin Toss");
Console.WriteLine("To play, enter either H for Heads or T for Tails.");
}
- 然后在Workflow1 class里添加一个变量作为判断是否结束程序的条件:
bool bPlayAgain = true;
- 在Solution Explorer中双击Workflow1.cs回到设计版面。从Toolbox中把一个While activity拖放到Welcome下面。在属性窗口里设置Condition为”Declarative Rule Condition”。展开 Condition设置ConditionName为GameLoopCondition。选中Expression属性,点击右边的省略号按钮,弹出”Rule Condition Editor”。输入(图3):
点击OK关闭。
- 因为While activity只允许包含一个activity,我们需要找另外的容器来包含多个activity。从Toolbox中把一个Sequence activity拖放到刚创建的whileActivity1中。
- 然后从Toolbox中把一个InvokeWebService activity拖放到刚创建的sequenceActivity1中。”Add web reference”对话框会弹出。在URL文本框中输入web service的URL。在这个例子里是
http://localhost:2149/CoinFlipWorkflow_WebService/CoinFlipWorkflow.Workflow1_WebService.asmx
点击Go按钮。然后再点击Add Reference加入这个web reference。
- 鼠标右键点击设计版面然后选择 View Code切换到代码试图。在namespace中加入一个enum代码硬币的正反面:
enum CoinFlipValue
{
cfHeads = 1,
cfTails = 2
}
- 在Workflow1类中创建一个成员变量cfCoinToss
CoinFlipValue cfCoinToss;
和一个公共属性CoinToss来存储扔硬币的结果
public int CoinToss
{
get { return (int)cfCoinToss; }
set
{
cfCoinToss = (CoinFlipValue)value;
}
}
- 在Solution Explorer中双击Workflow1.cs回到设计版面。
- 将刚创建的invokeWebServiceActivity1改名为invokeCoinFlipService。在它的属性窗口里设置MethodName为FlipCoin。然后选中(ReturnValue)属性点击右边的省略号按钮。在Bind to an existing member中选择刚创建的公共属性CoinToss。点击OK。这样invokeCoinFlipService会调用web service并将返回值赋予成员变量 cfCoinToss。
- 从Toolbox中把一个Code activity拖到invokeCoinFlipService下面。改名为GetGuess。这个activity用来获取用户的输入。
- 然后鼠标右键点击GetGuess,选择Generate Handles。在 handler中添加获取用户输入的代码:
private void GetGuess_ExecuteCode(object sender, EventArgs e)
{
// Increment Turn Counter
nTurns++;
bool bValidEntry = false;
while (!bValidEntry)
{
bValidEntry = true;
Console.Write("Enter your guess: H for Heads, T for Tails: ");
ConsoleKey cGuess = Console.ReadKey().Key;
Console.WriteLine();
if (cGuess == ConsoleKey.H)
{
cfGuess = CoinFlipValue.cfHeads;
}
else if(cGuess == ConsoleKey.T)
{
cfGuess = CoinFlipValue.cfTails;
}
else
{
Console.WriteLine("Invalid Entry.");
bValidEntry = false;
}
}
}
- 添加Workflow1类的成员变量nTurns用来记录猜硬币的次数和cfGuess用来记录用户的输入:
int nTurns = 0;
CoinFlipValue cfGuess;
- 在Solution Explorer中双击Workflow1.cs回到设计版面。从Toolbox把一个IfElse activity拖放到GetGuess下面。选中这个ifElseActivity1左边分支ifElseBranchActivity1,将它改名为IfCorrect。然后在属性窗口里设置Condition为”Code Condition”。然后展开Condition。在下面的Condition属性输入CheckGuessRule,然后回车。 如图:
成员函数CheckGuessRule会被自动产生,我们添加如下代码用来判断是否猜对硬币:
private void CheckGuessRule(object sender, ConditionalEventArgs e)
{
e.Result = cfGuess == cfCoinToss;
}
- 在Solution Explorer中双击Workflow1.cs回到设计版面。从Toolbox拖放一个Code activity到IfCorrect中,并改名为GuessCorrect。然后鼠标右键点击GuessCorrect,选择Generate Handles。在 handler中添加代码显示猜对信息,结果如下:
private void GuessCorrect_ExecuteCode(object sender, EventArgs e)
{
nCorrectGuesses++;
Console.WriteLine("Your Guess was correct!");
}
再添加一个Workflow1类的成员变量nCorrectGuesses用来记录猜中的次数:
int nCorrectGuesses = 0;
如何把Workflow项目发布成web service
这里讲的workflow指的是Windows Workflow Foundation (WF) 生成的workflow。
将一个workflow发布成web service需要以下的额外步骤:
- 定义一个interface作为web service的interface.
- 将WebServiceInputActivity 和WebServiceOutputActivity拖到你的workflow上并且和你所定义的web service interface绑定。
- 将WebServiceInputActivity 和WebServiceOutputActivity属性里的输入参数和返回值和workflow里的变量绑定。
- 运行向导把你的 workflow项目发布为web service。
我们以一个翻硬币的程序作为例子。
Task 1 — 创建一个 workflow project
- 打开 Visual Studio 2005。
- 从菜单选择 File — > New — > Project。出现 New project对话框。
- 在 Project types 树中选择 Visual C# — > Workflow。在templates列表中选Sequential Workflow Library。输入项目名字 CoinFlipWorkflow。
- 然后点击OK产生一个空的workflow project。
Task 2 – 编辑一个翻硬币的workflow
- 在Solution Explorer里鼠标右键选择Workflow1.cs,然后选择View Code
- 将下面的interface定义添加到namespace中
//Webservice interface definition for the workflow
public interface ICoinFlipService
{
int FlipCoin();
}
- 这个interface作为web service的接口。
- 在Solution Explorer里双击Workflow1.cs 回到Design View。从Toolbox中把一个WebServiceInput activity拖到设计版面上Sequential Workflow绿色箭头下面。改名为 webServiceReceive。
- 从Toolbox中把一个WebServiceOutput activity拖到webServiceReceive activity下面。并改名为webServiceResponse。
- 在设计版面上选中webServiceReceive,在Property窗口里选择Interface Type,然后点击旁边的省略号按钮。在弹出的”Browse and Select a .Net type”窗口中,选中我们刚刚定义的接口ICoinFlipService。点击OK按钮。
- 在Property窗口里设置如下的属性:
- IsActivating: True
- MethodName: FlipCoin
- 在设计版面上选中webServiceResponse。在Property窗口里将InputActivityName设置为webServiceReceive。然后选择(ReturnValue)属性,点击点击旁边的省略号按钮。选择”Bind to a new member”分页。再选择”Create Field”,将New member name改为nFlipValue。最后点击OK。这样一个新的成员变量被产生在Workflow1里。鼠标右键点击设计版面然后选择”View Code”。下面的代码已经被添加在类Workflow1里:
public Int32 nFlipValue = default(System.Int32);
- 在Solution Explorer里双击Workflow1.cs 回到Design View。从Toolbox里把一个Code activity拖曳到webServiceReceive和webServiceResponse中间。
- 鼠标右键点击codeActivity1,选择Generate Handles。以下的成员函数会被自动创建:
private void codeActivity1_ExecuteCode(object sender, EventArgs e)
{
}
- 在上面的成员函数里添加代码,随机产生整数1或2。1代表硬币的正面,2代表反面。并将结果赋予成员变量nFlipValue。最终代码如下:
private void codeActivity1_ExecuteCode(object sender, EventArgs e)
{
// 1 for Heads, 2 for Tails
nFlipValue = new Random().Next(1, 3);
}
Task 3 – 把workflow发布为一个web service
- 从菜单上选Build — > Build Solution确保这个workflow能编译成功。
- 在Solution Explorer里鼠标右键点击CoinFlipWorkflow项目然后选择”Publish as Web Service”。
- 一个新的project CoinFlipWorkflow_WebService被产生于同一个solution下面。
- 你会注意到:
- 一个新的.asmx文件指出这个web service是从CoinFlipWorkflow.Workflow1_WebService继承下来。
<%@WebService Class="CoinFlipWorkflow.Workflow1_WebService" %>
- 在web.config 中修改HTTPPipeline来运行workflow。
<httpModules>
<add type="System.Workflow.Runtime.Hosting.WorkflowWebHostingModule, System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="WorkflowHost"/>
</httpModules>
- 在web.config中加入workflow runtime services的配置
<configSections>
<section name="WorkflowRuntime" type="System.Workflow.Runtime.Configuration.WorkflowRuntimeSection, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</configSections>
<WorkflowRuntime Name="WorkflowServiceContainer">
<Services>
<add type="System.Workflow.Runtime.Hosting.ManualWorkflowSchedulerService, System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add type="System.Workflow.Runtime.Hosting.DefaultWorkflowCommitWorkBatchService, System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</Services>
</WorkflowRuntime>
- 当web service被成功创建后,一个确认对话框会弹出(图2)。点击OK关闭。
6. 在Solution Explorer里选中刚产生的web service project,在属性窗口把”Use Dynamic ports”改为false,然后设置Port number。在这个例子里我们设置端口号为2149。