操作方法:在模拟器上创建角色实例
如何使用 Azure 模拟器通过 C# 创建某个角色的新实例?有一些关于这方面的指南吗?有一些关于在云中而不是在模拟器中创建实例的手册。
到目前为止我知道:
- 我需要更改配置文件。它是在 sln 文件中还是在某个临时部署文件夹中配置的?
- 我需要使用 csrun 工具。如何选择参数?
UPD 知道了。
要更改模拟器上的计数或实例,您必须:
- 更新 bin 文件夹中的“ServiceConfiguration.cscfg”文件
- 使用参数运行“csrun”工具:
string.Format("/update:{0};\"{1 }\“”,deploymentId,“
”)
其中deploymentId:
// get id from RoleEnvironment with regex
var patternt = Regex.Escape("(") + @"\d+" + Regex.Escape(")");
var input = RoleEnvironment.DeploymentId;
var m = Regex.Match(input, patternt);
var deploymentId = m.ToString().Replace("(", string.Empty).Replace(")", string.Empty);
如果您在通过代码运行csrun时遇到问题,请阅读以下内容: http://social.msdn.microsoft.com/Forums/en/windowsazuredevelopment/thread/62ca1372-2388-4181-9dbd-8fbba470ea77
How do I create new instances of some role via C# using Azure emulator? Is there some guide about that? There are some manuals about creating instances in the cloud, not in emulator.
So far I know that:
- I need to change config-file. Is it config in sln-file or in some temp-delpoyment folder?
- I need to use csrun tool. How to pick params?
UPD
Got it.
To change count or instances on emulator, you have to:
- update 'ServiceConfiguration.cscfg' file in bin-folder
- run 'csrun' tool with params:
string.Format("/update:{0};\"{1}\"", deploymentId, "<path to ServiceConfiguration.cscfg>")
where deploymentId:
// get id from RoleEnvironment with regex
var patternt = Regex.Escape("(") + @"\d+" + Regex.Escape(")");
var input = RoleEnvironment.DeploymentId;
var m = Regex.Match(input, patternt);
var deploymentId = m.ToString().Replace("(", string.Empty).Replace(")", string.Empty);
If you have troubles running csrun via code, read this:
http://social.msdn.microsoft.com/Forums/en/windowsazuredevelopment/thread/62ca1372-2388-4181-9dbd-8fbba470ea77
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在本地模拟器中,您需要修改部署 .csx 文件夹(而不是源代码文件夹)下的 CSCFG 文件,因为本地模拟器将从该文件夹启动您的应用程序。
修改保存的 CSCFG 文件后,例如实例计数,您可以立即从代码中检索新值。但如果您希望本地模拟器检测到此更改并执行相关操作,例如增加虚拟机或调用 Configuration_Changed 方法,则需要执行
csrun /更新:;
您可以从计算模拟器 UI 检索部署 ID。
In local emulator, you need to modify the CSCFG file under the deployment .csx folder, instead of your source code folder, since the local emulator will fire your application up from that folder.
Once you modified the saved your CSCFG file, for example the count of the instances you can retrieve the new value from your code immediately. But if you want the local emulator detect this changes and perform the related actions, such as increase the VMs or invoke the Configuration_Changed method, you need to execute
csrun /update:;
You can retrieve the deployment id from the compute emulator UI.
您可以在 Azure 项目的 ServiceConfiguration.cscfg 中找到实例计数
You can find the instance count in the ServiceConfiguration.cscfg in your Azure project