Пример #1
0
        public static CdsConfig GetCdsConfig()
        {
            var assemblyLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
            var directory        = new System.IO.FileInfo(assemblyLocation).Directory;

            while (true)
            {
                var configDirectory = directory.GetDirectories(ConfigDirectoryName).FirstOrDefault();
                if (configDirectory != null)
                {
                    var configFile = configDirectory.GetFiles(ConfigFileName).FirstOrDefault();
                    if (configFile != null)
                    {
                        var configDictionary = System.IO.File.ReadAllLines(configFile.FullName).
                                               Select(line => line.Split(',')).
                                               ToDictionary(splitLine => splitLine[0], splitLine => splitLine[1]);
                        return(new CdsConfig
                        {
                            User = configDictionary["user"],
                            Password = configDictionary["password"],
                            UriString = configDictionary["uriString"],
                            NativeAppId = configDictionary["nativeAppId"]
                        });
                    }
                    else
                    {
                        throw new InvalidOperationException($"{ConfigFileName} file was not found inside '{configDirectory.FullName}'.");
                    }
                }
                directory = directory.Parent;
                if (directory == null)
                {
                    throw new InvalidOperationException($"{ConfigDirectoryName} file was not found.");
                }
            }
        }