Created
January 23, 2018 11:26
-
-
Save Segment0895/26cf14ce215e2c41b0dd64915e60e088 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.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Domain.Logic | |
{ | |
public class FeatureToggleHelper | |
{ | |
static public bool GetCreateFeatureToggleVal(string NAME) | |
{ | |
try | |
{ | |
if (System.IO.File.Exists(System.IO.Path.Combine(AssemblyDirectory, $"{NAME}_ENABLED"))) | |
{ | |
return true; | |
} | |
else | |
{ | |
System.IO.File.Create(System.IO.Path.Combine(AssemblyDirectory, $"{NAME}_DISABLED")).Dispose(); | |
return false; | |
} | |
} | |
catch (Exception) | |
{ return false; } | |
} | |
static public bool? GetFeatureToggleVal(string NAME) | |
{ | |
try | |
{ | |
if (System.IO.File.Exists(System.IO.Path.Combine(AssemblyDirectory, $"{NAME}_ENABLED"))) | |
{ | |
return true; | |
} | |
else if (System.IO.File.Exists(System.IO.Path.Combine(AssemblyDirectory, $"{NAME}_DISABLED"))) | |
{ | |
return false; | |
} | |
else | |
{ | |
return null; | |
} | |
} | |
catch (Exception) | |
{ return null; } | |
} | |
static public void SetFeatureToggleVal(string NAME, bool val) | |
{ | |
var enabled = System.IO.Path.Combine(AssemblyDirectory, $"{NAME}_ENABLED"); | |
var disabled = System.IO.Path.Combine(AssemblyDirectory, $"{NAME}_DISABLED"); | |
try | |
{ | |
if (val) | |
{ | |
System.IO.File.Create(enabled).Dispose(); | |
System.IO.File.Delete(disabled); | |
} | |
else | |
{ | |
System.IO.File.Create(disabled).Dispose(); | |
System.IO.File.Delete(enabled); | |
} | |
} | |
catch (Exception) | |
{ } | |
} | |
public static string AssemblyDirectory | |
{ | |
get | |
{ | |
string codeBase = System.Reflection.Assembly.GetExecutingAssembly().CodeBase; | |
UriBuilder uri = new UriBuilder(codeBase); | |
string path = Uri.UnescapeDataString(uri.Path); | |
return System.IO.Path.GetDirectoryName(path); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment