Пример #1
0
        public void LoadFromConfiguration(IConfigurationRoot configuration, string section)
        {
            _configuration = configuration;
            _section       = section;

            string v;

            if (ConfigurationReader.GetCurrentValue(configuration, section, "SecretProtector:Enabled", false))
            {
                v = ConfigurationReader.GetCurrentValue(configuration, section, "SecretProtector:Type", null);
                if (!string.IsNullOrEmpty(v))
                {
                    var type = Type.GetType(v);
                    if (type != null && typeof(IConfigurationSecretProtector).IsAssignableFrom(type))
                    {
                        var secretProtectorSection = configuration.GetSection(section + ":SecretProtector");
                        try
                        {
                            SecretProtector = (IConfigurationSecretProtector)Activator.CreateInstance(type);
                            if (!SecretProtector.Init(secretProtectorSection))
                            {
                                SecretProtector = null;
                            }
                        }
                        catch (Exception ex)
                        {
                            var exception = new Exception("Can't initialize secret protector.", ex);
                            exception.Data.Add("FullyQualifiedTypeName", v);
                            throw exception;
                        }
                    }
                    else
                    {
                        var exception = new Exception("Secret protector type not found.");
                        exception.Data.Add("FullyQualifiedTypeName", v);
                        throw exception;
                    }
                }
            }

            ModulesFolder = ConfigurationReader.GetCurrentValue(configuration, section, "ModulesFolder", @".\modules", SecretProtector);

            CustomReferenceAssemblyFolder = ConfigurationReader.GetCurrentValue(configuration, section, "CustomReferenceAssemblyFolder", null, SecretProtector);

            GetCommandAliases(configuration, section);
        }
Пример #2
0
        public bool Init(IExecutionContext executionContext, IConfigurationSection configurationSection, IConfigurationSecretProtector configurationSecretProtector)
        {
            _sessionId   = executionContext.SessionId;
            _contextName = executionContext.Name;
            var url = ConfigurationReader.GetCurrentValue(configurationSection, "Url", null, configurationSecretProtector);

            if (url == null)
            {
                return(false);
            }

            _uri = new Uri(url);

            _client = new HttpClient
            {
                Timeout = TimeSpan.FromMilliseconds(10000),
            };

            SendWriter(null);

            _workerThread = new Thread(WorkerMethod);
            _workerThread.Start();
            return(true);
        }
Пример #3
0
        public static string GetCurrentValue(IConfigurationSection section, string key, string defaultValue, IConfigurationSecretProtector protector = null)
        {
            var isProtected = section.GetValue(key + "-protected", false);

            var value = section.GetValue <string>(key + "-" + Environment.MachineName, default);

            if (value != null)
            {
                if (isProtected && protector != null)
                {
                    value = protector.Decrypt(value);
                }

                return(value);
            }

            value = section.GetValue(key, defaultValue);
            if (value != null && isProtected && protector != null)
            {
                value = protector.Decrypt(value);
            }

            return(value);
        }
Пример #4
0
        public void LoadFromConfiguration(IConfigurationRoot configuration, string section)
        {
            _configuration = configuration;
            _section       = section;

            string v;

            if (ConfigurationReader.GetCurrentValue(configuration, section, "SecretProtector:Enabled", false))
            {
                v = ConfigurationReader.GetCurrentValue(configuration, section, "SecretProtector:Type", null);
                if (!string.IsNullOrEmpty(v))
                {
                    var type = Type.GetType(v);
                    if (type != null && typeof(IConfigurationSecretProtector).IsAssignableFrom(type))
                    {
                        var secretProtectorSection = configuration.GetSection(section + ":SecretProtector");
                        try
                        {
                            SecretProtector = (IConfigurationSecretProtector)Activator.CreateInstance(type);
                            if (!SecretProtector.Init(secretProtectorSection))
                            {
                                SecretProtector = null;
                            }
                        }
                        catch (Exception ex)
                        {
                            var exception = new Exception("Can't initialize secret protector.", ex);
                            exception.Data.Add("FullyQualifiedTypeName", v);
                            throw exception;
                        }
                    }
                    else
                    {
                        var exception = new Exception("Secret protector type not found.");
                        exception.Data.Add("FullyQualifiedTypeName", v);
                        throw exception;
                    }
                }
            }

            if (ConfigurationReader.GetCurrentValue(configuration, section, "Seq:Enabled", false))
            {
                SeqUrl    = ConfigurationReader.GetCurrentValue(configuration, section, "Seq:Url", null, SecretProtector);
                SeqApiKey = ConfigurationReader.GetCurrentValue(configuration, section, "Seq:ApiKey", null, SecretProtector);
            }

            RetainedLogFileCountLimitImportant = ConfigurationReader.GetCurrentValue(configuration, section, "RetainedLogFileCountLimit:Important", 30);
            RetainedLogFileCountLimitInfo      = ConfigurationReader.GetCurrentValue(configuration, section, "RetainedLogFileCountLimit:Info", 14);
            RetainedLogFileCountLimitLow       = ConfigurationReader.GetCurrentValue(configuration, section, "RetainedLogFileCountLimit:Low", 4);
            TransactionScopeTimeout            = TimeSpan.FromMinutes(ConfigurationReader.GetCurrentValue(configuration, section, "TransactionScopeTimeoutMinutes", 120));
            ModulesFolder = ConfigurationReader.GetCurrentValue(configuration, section, "ModulesFolder", @".\modules", SecretProtector);

            CustomReferenceAssemblyFolder = ConfigurationReader.GetCurrentValue(configuration, section, "DynamicCompilation:CustomReferenceAssemblyFolder", null, SecretProtector);

            v = ConfigurationReader.GetCurrentValue(configuration, section, "DynamicCompilation:Mode", "Default", SecretProtector);
            if (!string.IsNullOrEmpty(v) && Enum.TryParse(v, out DynamicCompilationMode mode))
            {
                DynamicCompilationMode = mode;
            }

            v = ConfigurationReader.GetCurrentValue(configuration, section, "MinimumLogLevel:Console", "Information", SecretProtector);
            if (!string.IsNullOrEmpty(v) && Enum.TryParse(v, out LogEventLevel level))
            {
                MinimumLogLevelOnConsole = level;
            }

            v = ConfigurationReader.GetCurrentValue(configuration, section, "MinimumLogLevel:File", "Debug", SecretProtector);
            if (!string.IsNullOrEmpty(v) && Enum.TryParse(v, out level))
            {
                MinimumLogLevelInFile = level;
            }

            v = ConfigurationReader.GetCurrentValue(configuration, section, "MinimumLogLevel:IoFile", "Verbose", SecretProtector);
            if (!string.IsNullOrEmpty(v) && Enum.TryParse(v, out level))
            {
                MinimumLogLevelIo = level;
            }

            GetCommandAliases(configuration, section);
        }
Пример #5
0
 public bool Init(IExecutionContext executionContext, IConfigurationSection configurationSection, IConfigurationSecretProtector configurationSecretProtector)
 {
     throw new NotImplementedException();
 }