Skip to content

Commit

Permalink
removing local run-time dependency on Azure SDK (hopefully for real t…
Browse files Browse the repository at this point in the history
…his time)
  • Loading branch information
half-ogre committed Dec 9, 2011
1 parent 8a4e79d commit 82f36c3
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions Website/App_Start/Configuration.cs
Expand Up @@ -10,6 +10,7 @@ public class Configuration : IConfiguration
{
private static readonly Dictionary<string, Lazy<object>> configThunks = new Dictionary<string, Lazy<object>>();
private readonly Lazy<string> siteRoot = new Lazy<string>(GetSiteRoot);
static readonly Lazy<bool> runningInAzure = new Lazy<bool>(RunningInAzure);

public static string ReadAppSetting(string key)
{
Expand All @@ -19,11 +20,7 @@ public static string ReadAppSetting(string key)

public static string ReadAzureSetting(string key)
{
if (!RoleEnvironment.IsAvailable)
return null;

var value = RoleEnvironment.GetConfigurationSettingValue(key);
return value;
return RoleEnvironment.GetConfigurationSettingValue(key);
}

public static string ReadConfiguration(string key)
Expand All @@ -42,20 +39,30 @@ public static string ReadConfiguration(string key)
{
string value = null;
try
{
if (runningInAzure.Value)
value = ReadAzureSetting(key);
}
catch (RoleEnvironmentException) { }
if (value == null)
value = ReadAppSetting(key);
return valueThunk(value);
}));

return (T)configThunks[key].Value;
}

static bool RunningInAzure()
{
try
{
return RoleEnvironment.IsAvailable;
}
catch (RoleEnvironmentException) { }
catch (TypeInitializationException) { }

return false;
}

public string SiteRoot
{
get
Expand Down

0 comments on commit 82f36c3

Please sign in to comment.