Skip to content
Snippets Groups Projects
Select Git revision
  • 217d7fdf48067d8f859563fec762fe945bf85cf5
  • master default protected
  • gitkeep
  • dev protected
  • Issue/2309-docs
  • Issue/1910-MigrationtoNET6.0
  • Hotfix/1796-projectDdos
  • Experiment/NewBuild
  • Sprint/2022-01
  • Sprint/2021-03
  • Product/1287-dotnet5Sharepoint
  • Topic/1334-dotnet5migration
  • Product/407-net5migration
  • Topic/1226-configLibraryMigration
  • Sprint/2021-01
  • v2.1.1
  • v2.1.0
  • v2.0.0
  • v1.6.0
  • v1.5.0
  • v1.4.0
  • v1.3.1
  • v1.3.0
  • v1.2.1
  • v1.2.0
  • v1.1.0
  • v1.0.0
27 results

EnvironmentConfiguration.cs

Blame
  • 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(() =>