Exemplo n.º 1
0
        public static CASCConfig LoadOnlineStorageConfig()
        {
            var    config      = new CASCConfig();
            string usingRegion = null;

            try
            {
                usingRegion = Constants.CDN_REGIONS[0];

                using (var stream = CDNIndexHandler.OpenFileDirect(string.Format(Constants.CDN_CONFIG_URL, usingRegion)))
                    config.CDNData = VerBarConfig.ReadVerBarConfig(stream);

                using (Stream stream = CDNIndexHandler.OpenFileDirect(string.Format(Constants.CDN_VERSION_URL, usingRegion)))
                    config.VersionsData = VerBarConfig.ReadVerBarConfig(stream);
            }
            catch
            {
                usingRegion = Constants.CDN_REGIONS[1];

                using (var stream = CDNIndexHandler.OpenFileDirect(string.Format(Constants.CDN_CONFIG_URL, usingRegion)))
                    config.CDNData = VerBarConfig.ReadVerBarConfig(stream);

                using (Stream stream = CDNIndexHandler.OpenFileDirect(string.Format(Constants.CDN_VERSION_URL, usingRegion)))
                    config.VersionsData = VerBarConfig.ReadVerBarConfig(stream);
            }

            if (usingRegion == null)
            {
                throw new Exception("Unable to access default CDN servers for config/versioning.");
            }

            for (int i = 0; i < config.VersionsData.Count; i++)
            {
                if (config.VersionsData[i]["Region"] == usingRegion)
                {
                    config.versionIndex = i;
                    break;
                }
            }

            string cdnKey = config.VersionsData[config.versionIndex]["CDNConfig"].ToLower();

            using (Stream stream = CDNIndexHandler.OpenConfigFileDirect(config, cdnKey))
                config.CDNConfig = KeyValueConfig.ReadKeyValueConfig(stream);

            config.ActiveBuild = 0;
            config.Builds      = new List <KeyValueConfig>();

            string buildKey = config.VersionsData[config.versionIndex]["BuildConfig"].ToLower();

            using (Stream stream = CDNIndexHandler.OpenConfigFileDirect(config, buildKey))
            {
                KeyValueConfig buildConfig = KeyValueConfig.ReadKeyValueConfig(stream);
                config.Builds.Add(buildConfig);
            }

            return(config);
        }