zoukankan      html  css  js  c++  java
  • Skipping Windows Azure Startup Tasks When Running in the Emulator

     http://blog.smarx.com/posts/skipping-windows-azure-startup-tasks-when-running-in-the-emulator

    Startup tasks are often used in Windows Azure to install things or make other configuration changes to the virtual machine hosting your role code. Sometimes those setup steps are things you don’t want to execute when you’re running and testing locally via the compute emulator. (For example, you may want to skip a lengthy download or an installation of something you already have on your computer.)

    With SDK 1.5, there are a few supported ways for code to determine whether or not it’s running emulated. From .NET code, there’s the new RoleEnvironment.IsEmulated static property. From other code (like a batch file startup task), SDK 1.5 adds a nice way to put the value of IsEmulated into an environment variable. Here’s the definition of a startup task that will get an EMULATED environment variable telling it whether or not the role is running under the compute emulator.

        <Startup>
          <Task executionContext="elevated" commandLine="startup\startup.cmd">
            <Environment>
              <Variable name="EMULATED">
                <RoleInstanceValue xpath="/RoleEnvironment/Deployment/@emulated" />
              </Variable>
            </Environment>
          </Task>
        </Startup>

    Note the xpath attribute. There are many useful paths you can provide that will help you get at things like the port for an endpoint, the location of a local storage resource, or configuration setting values. See the MSDN documentation for the full details: “xPath Values in Windows Azure” and “WebRole Schema”.

    Now all we need to do is make use of this environment variable in our startup task. The first line of startup.cmd simply checks the environment variable and immediately exit if it’s set to true:

                 
    if "%EMULATED%"=="true" goto :EOF

    I used to write all sorts of tests in my startup tasks to try to avoid rerunning installers on my laptop, and this nice feature is going to save me the effort.

  • 相关阅读:
    第六周作业----测试自动化工具
    第六周作业----内聚耦合
    HTML 滚动条实现
    mysql练习(一)
    flume本地调试
    -Dmaven.multiModuleProjectDirectory system propery is not set
    Cannot read property 'substring' of undefined
    JVM的几个介绍
    storm(二)消息的可靠处理
    storm(一)
  • 原文地址:https://www.cnblogs.com/RobotTech/p/2387483.html
Copyright © 2011-2022 走看看