Dav*_*gon 22
RoleEnvironment.IsAvailable 告诉您是否在Windows Azure中运行,但它没有区分真正的Windows Azure和本地开发模拟器.
我写了一篇博客文章,展示了一个技巧,可以确定你是在真实模拟和模拟Windows Azure中运行RoleEnvironment.IsAvailable == true- 希望这可以提供你正在寻找的东西.
编辑:如果你想要我在上述帖子中描述的下行代码,不解释为什么该技术有效:
private bool IsRunningInDevFabric()
{
// easiest check: try translate deployment ID into guid
Guid guidId;
if (Guid.TryParse(RoleEnvironment.DeploymentId, out guidId))
return false; // valid guid? We're in Azure Fabric
return true; // can't parse into guid? We're in Dev Fabric
}
Run Code Online (Sandbox Code Playgroud)
编辑2:我的回答有点过时了.现在RoleEnvironment.IsEmulated,使用起来要简单得多.MSDN文档在这里
Cra*_*aig 14
这就是我使用的
public static class Azure
{
private static bool m_IsRunningAzure = GetIsRunningInAzure();
private static bool GetIsRunningInAzure()
{
Guid guidId;
if (RoleEnvironment.IsAvailable && Guid.TryParse(RoleEnvironment.DeploymentId, out guidId))
return true;
return false;
}
public static bool IsRunningInAzure()
{
return m_IsRunningAzure;
}
private static bool m_IsRunningAzureOrDevFabric = GetIsRunningInAzureOrDevFabric();
private static bool GetIsRunningInAzureOrDevFabric()
{
return RoleEnvironment.IsAvailable;
}
public static bool IsRunningInAzureOrDevFabric()
{
return m_IsRunningAzureOrDevFabric;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7103 次 |
| 最近记录: |