Select Git revision
EnvironmentConfiguration.cs
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
EnvironmentConfiguration.cs 3.93 KiB
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Coscine.Configuration
{
public class EnvironmentConfiguration : IConfiguration
{
private readonly EnvironmentVariableTarget target;
public EnvironmentConfiguration()
{
target = EnvironmentVariableTarget.Machine;
}
public EnvironmentConfiguration(EnvironmentVariableTarget target)
{
this.target = target;
}
public bool Delete(string key)
{
try
{
Environment.SetEnvironmentVariable(key, null, target);
}
catch (Exception)
{
return false;
}
return true;
}
public bool DeleteAndWait(string key)
{
return Delete(key);
}
public Task<bool> DeleteAsync(string key)
{
return Task.Factory.StartNew(() =>
{
return Delete(key);
});
}
public byte[] Get(string key)
{
var result = GetString(key);
if (result != null)
{
return new System.Text.ASCIIEncoding().GetBytes(result);
}
else
{
return null;
}
}
public byte[] GetAndWait(string key)
{
return Get(key);
}
public Task<byte[]> GetAsync(string key)
{
return Task.Factory.StartNew(() =>