Skip to content

Instantly share code, notes, and snippets.

@Segment0895
Created January 23, 2018 11:26
Show Gist options
  • Save Segment0895/26cf14ce215e2c41b0dd64915e60e088 to your computer and use it in GitHub Desktop.
Save Segment0895/26cf14ce215e2c41b0dd64915e60e088 to your computer and use it in GitHub Desktop.
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