-
-
Save iwate/9898117fb6e106b87b44 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace WebApplication27 | |
{ | |
public static class WebsiteEnvironment | |
{ | |
public static bool IsAvailable | |
{ | |
get { return !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME")); } | |
} | |
public static string InstanceId | |
{ | |
get { return Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID"); } | |
} | |
public static string Name | |
{ | |
get { return Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME"); } | |
} | |
public static WebsiteComputeMode? ComputeMode | |
{ | |
get { return EnumHelper.Convert<WebsiteComputeMode>(Environment.GetEnvironmentVariable("WEBSITE_COMPUTE_MODE")); } | |
} | |
public static WebsiteMode? Mode | |
{ | |
get { return EnumHelper.Convert<WebsiteMode>(Environment.GetEnvironmentVariable("WEBSITE_SITE_MODE")); } | |
} | |
public static WebsiteSku? Sku | |
{ | |
get { return EnumHelper.Convert<WebsiteSku>(Environment.GetEnvironmentVariable("WEBSITE_SKU")); } | |
} | |
public static IDictionary<string, string> AppSettings | |
{ | |
get { return EnvironmentHelper.GetVariables("APPSETTING_"); } | |
} | |
public static IDictionary<string, string> MySqlConnections | |
{ | |
get { return EnvironmentHelper.GetVariables("MYSQLCONNSTR_"); } | |
} | |
public static IDictionary<string, string> SqlServerConnections | |
{ | |
get { return EnvironmentHelper.GetVariables("SQLAZURECONNSTR_"); } | |
} | |
public class EnvironmentHelper | |
{ | |
public static IDictionary<string, string> GetVariables(string prefix) | |
{ | |
return Environment.GetEnvironmentVariables() | |
.Cast<DictionaryEntry>() | |
.Where(p => ((string)p.Key).StartsWith(prefix)) | |
.ToDictionary(p => ((string)p.Key).Substring(prefix.Length), p => (string)p.Value); | |
} | |
} | |
public class EnumHelper | |
{ | |
public static TEnum? Convert<TEnum>(string name) where TEnum : struct | |
{ | |
TEnum result; | |
if (Enum.TryParse(name, true, out result)) | |
{ | |
return result; | |
} | |
return null; | |
} | |
} | |
} | |
public enum WebsiteComputeMode | |
{ | |
Shared, | |
Dedicated, | |
} | |
public enum WebsiteMode | |
{ | |
Limited, | |
Basic | |
} | |
public enum WebsiteSku | |
{ | |
Free, | |
Shared, | |
Basic, | |
Standard, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment