/// <summary>
 /// Constructor that accepts AppSettings and ConnectionStrings XML data in array form
 /// This method is to support ConfigurationManagerFull() construction
 /// </summary>
 /// <param name="appSettings">ConfigurationManager.AppSettings.ToArraySafe()</param>
 /// <param name="connectionStrings">ConfigurationManager.ConnectionStrings.ToArraySafe()</param>
 public ConfigurationManagerSafe(string[,] appSettings, string[,] connectionStrings) : this()
 {
     connectionStrings = connectionStrings ?? new string[0, 2];
     for (var itemCount = 0; itemCount < connectionStrings.GetLength(0); itemCount++)
     {
         ConnectionStrings.Add(connectionStrings[itemCount, 0], connectionStrings[itemCount, 1]);
     }
     appSettings = appSettings ?? new string[0, 2];
     for (var itemCount = 0; itemCount < appSettings.GetLength(0); itemCount++)
     {
         AppSettings.Add(appSettings[itemCount, 0], appSettings[itemCount, 1]);
     }
 }
        /// <summary>
        /// Add a connection string
        /// </summary>
        /// <param name="type">Type of connection string</param>
        /// <param name="key">Name of key</param>
        /// <param name="value">Connection string</param>
        public void AddConnectionString(AppServiceWebAppConnectionStringType type, string key, string value)
        {
            if (ConnectionStrings == null)
            {
                ConnectionStrings = new List <AppServiceWebAppConnectionString>();
            }

            ConnectionStrings.Add(
                new AppServiceWebAppConnectionString()
            {
                Type  = type,
                Name  = key,
                Value = value
            }
                );;
        }
Пример #3
0
        static ConfigurationManager()
        {
#if !NETSTANDARD2_0 && !NET5_0 && !NET6_0
            try
            {
                _settings = System.Configuration.ConfigurationManager.AppSettings;
                foreach (System.Configuration.ConnectionStringSettings item in System.Configuration.ConfigurationManager.ConnectionStrings)
                {
                    ConnectionStrings.Add(item.Name, new ConnectionStringSettings(item));
                }
            }
            catch (Exception ex)
            {
                throw new ConfigurationErrorsException(ex.Message, ex);
            }
#endif
        }
Пример #4
0
        protected void Initialise()
        {
            string groupID = settings.VariableKey1;

            TalentAccessDetailList = new List <TalentDataAccess>();
            try
            {
                TalentAccessDetailList = objAudit.GetCommandsByGroupId(int.Parse(groupID));
                DESQLParameter currBusinessUnit = null;
                foreach (TalentDataAccess sqlAccess in TalentAccessDetailList)
                {
                    currBusinessUnit = sqlAccess.CommandElements.CommandParameter.Find(x => x.ParamName.Contains(BUSINESS_UNIT));
                    if (!(currBusinessUnit == null))
                    {
                        HasBusinessUnit = true;
                    }
                }
                if (HasBusinessUnit)
                {
                    string[] items = TalentSystemDefaults.Utilities.GetBusinessUnits(settings);
                    foreach (string item in items)
                    {
                        bool selected = string.Compare(currBusinessUnit.ParamValue.ToString(), item, true) == 0;
                        BusinessUnits.Add(new SelectListItem {
                            Text = item, Value = item, Selected = selected
                        });
                    }
                }
                ConnectionStrings.Add(new SelectListItem {
                    Text = "TALENTEBUSINESS", Value = "SQL2005", Selected = true
                });
                ConnectionStrings.Add(new SelectListItem {
                    Text = "TALENT CONFIGURATION", Value = "TALENT_CONFIG", Selected = false
                });
                if (!string.IsNullOrEmpty(settings.SearchText))
                {
                    BackURL += "&searchText={1}";
                }
                BackURL        = string.Format(BackURL, settings.Module_Name, settings.SearchText);
                AuditGroupInfo = objAudit.RetrieveAuditGroupInfo(int.Parse(groupID));
            }
            catch (Exception)
            {
            }
        }
Пример #5
0
        /// <summary>
        /// Loads from JSON data
        ///  Use: Configuration["subsection:suboption1"]
        /// </summary>
        public void Load()
        {
            IConfigurationRoot    configuration;
            IConfigurationBuilder configBuilder;
            var currentEnvironment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Development";

            configBuilder = new ConfigurationBuilder()
                            .AddJsonFile($@"{RootPath.AddLast(@"\")}{FileNames.AppSettingsJson}", optional: true)
                            .AddJsonFile($@"{RootPath.AddLast(@"\")}{string.Format(FileNames.AppSettingsEnvironmentJson, currentEnvironment)}");
            configuration = configBuilder.Build();

            foreach (var Item in configuration?.GetSection("AppSettings").GetChildren())
            {
                AppSettings.Add(new AppSettingSafe(Item.Key, Item.Value));
            }
            foreach (var Item in configuration.GetSection("ConnectionStrings").GetChildren())
            {
                ConnectionStrings.Add(new ConnectionStringSafe(Item.Key, Item.Value));
            }
        }
Пример #6
0
        public ConfigFile LoadConnectionStrings()
        {
            var xpath = @"//connectionStrings/add";

            this.ConnectionStrings = new List <ConnEntity>();
            if (File.Exists(FileName))
            {
                try
                {
                    var xmlDoc = new XmlDocument();
                    xmlDoc.Load(this.FileName);
                    var connNodes = xmlDoc.SelectNodes(xpath);
                    if (connNodes.Count > 0)
                    {
                        foreach (XmlNode node in connNodes)
                        {
                            var cfg = ConnEntity.LoadFromXmlNode(node);
                            if (cfg != null)
                            {
                                ConnectionStrings.Add(cfg);
                            }
                        }
                    }
                    else
                    {
                        this.Message = "Can't find connectionstring by xpath " + xpath;
                    }
                }
                catch (Exception exp)
                {
                    this.Message = exp.ToString();
                }
            }
            else
            {
                this.Message = "File is not exists.";
            }
            return(this);
        }
        /// <summary>
        /// Loads from JSON data
        ///  Use: Configuration["subsection:suboption1"]
        /// </summary>
        private void Load(IEnumerable <string> configFiles)
        {
            IConfigurationRoot    configuration;
            IConfigurationBuilder configBuilder = new ConfigurationBuilder();

            // Load files
            foreach (var file in configFiles)
            {
                configBuilder.AddJsonFile(file, optional: true);
            }
            configuration = configBuilder.Build();
            // Add AppSettings node
            foreach (var Item in configuration?.GetSection("AppSettings").GetChildren())
            {
                AppSettings.Add(new AppSettingSafe(Item.Key, Item.Value));
            }
            // Add ConnectionStrings node
            foreach (var Item in configuration.GetSection("ConnectionStrings").GetChildren())
            {
                ConnectionStrings.Add(new ConnectionStringSafe(Item.Key, Item.Value));
            }
        }
Пример #8
0
 private void SetConnectionString(string name, string connString, string providerName = null)
 {
     ConnectionStrings.Add(new ConnectionStringSettings(name, connString, providerName));
 }
Пример #9
0
using JetBrains.Annotations;