Пример #1
0
        public AppDeploymentConfig SetVersionConfig(VersionDeploymentConfig versionDeploymentConfig)
        {
            var versions = new Dictionary <string, VersionDeploymentConfig>(ToDictionary(Versions));

            versions[versionDeploymentConfig.Version] = versionDeploymentConfig;
            return(new AppDeploymentConfig(AppId, versions));
        }
Пример #2
0
        public DeploymentConfig RemoveApplication(AppIdentity appIdentity, string deploymentId)
        {
            string appId   = appIdentity.Id;
            string version = appIdentity.Version.ToString();
            var    apps    = GetAppsCopy();

            if (!apps.ContainsKey(appId))
            {
                throw new InvalidOperationException($"Cannot remove deployment because app {appId} was not found");
            }
            AppDeploymentConfig appDeploymentConfig = apps[appId];

            if (!appDeploymentConfig.Versions.ContainsKey(version))
            {
                throw new InvalidOperationException(
                          $"Cannot remove deployment because app {appId}, version {version} was not found");
            }
            VersionDeploymentConfig versionDeploymentConfig = appDeploymentConfig.Versions[version];

            if (!versionDeploymentConfig.DeploymentIds.Contains(deploymentId))
            {
                throw new InvalidOperationException(
                          $"Cannot remove deployment {deploymentId} from app {appId}, version {version} because it was not found");
            }
            versionDeploymentConfig = versionDeploymentConfig.RemoveDeployment(deploymentId);
            appDeploymentConfig     = appDeploymentConfig.SetVersionConfig(versionDeploymentConfig);
            apps[appId]             = appDeploymentConfig;
            DeploymentConfig dc = new DeploymentConfig(apps);

            if (!dc._apps[appId].Versions[version].DeploymentIds.Any())
            {
                dc = dc.RemoveApplication(appIdentity);
            }
            return(dc);
        }
Пример #3
0
        public string RawData()
        {
            var applicationsList = new List <ApplicationData>();

            foreach (KeyValuePair <string, AppDeploymentConfig> app in _apps)
            {
                string appId = app.Key;
                AppDeploymentConfig appDeploymentConfig = app.Value;
                foreach (KeyValuePair <string, VersionDeploymentConfig> v in appDeploymentConfig.Versions)
                {
                    string version = v.Key;
                    VersionDeploymentConfig versionDeploymentConfig = v.Value;
                    applicationsList.Add(new ApplicationData(appId, version,
                                                             versionDeploymentConfig.DeploymentIds.ToArray()));
                }
            }
            ApplicationsData applicationsData = new ApplicationsData(applicationsList.ToArray());

            return(JsonUtils.Serialize(applicationsData));
        }
Пример #4
0
        public DeploymentConfig AddApplication(AppIdentity appIdentity, string deploymentId)
        {
            string appId   = appIdentity.Id;
            string version = appIdentity.Version.ToString();
            Dictionary <string, AppDeploymentConfig> apps = GetAppsCopy();

            apps = AddAppConfigIfNoneExists(apps, appId);
            AppDeploymentConfig appDeploymentConfig = apps[appId];

            appDeploymentConfig = AddVersionConfigIfNoneExists(appDeploymentConfig, version);
            VersionDeploymentConfig versionDeploymentConfig = appDeploymentConfig.Versions[version];

            if (versionDeploymentConfig.DeploymentIds.Contains(deploymentId))
            {
                throw new InvalidOperationException(
                          $"Cannot add the deployment {deploymentId} to application {appId}, version {version} because it's already there");
            }
            versionDeploymentConfig = versionDeploymentConfig.AddDeployment(deploymentId);
            appDeploymentConfig     = appDeploymentConfig.SetVersionConfig(versionDeploymentConfig);
            apps[appId]             = appDeploymentConfig;
            return(new DeploymentConfig(apps));
        }
Пример #5
0
        private static Dictionary <string, AppDeploymentConfig> ParseDeploymentsConfig(string json)
        {
            Dictionary <string, AppDeploymentConfig> apps = new Dictionary <string, AppDeploymentConfig>();

            if (string.IsNullOrEmpty(json))
            {
                return(apps);
            }

            ApplicationsData appsData = JsonUtils.Deserialize <ApplicationsData>(json);

            foreach (ApplicationData appData in appsData.Applications)
            {
                VersionDeploymentConfig versionDeploymentConfig = new VersionDeploymentConfig(appData.Version,
                                                                                              appData.DeploymentIds);
                apps = AddAppConfigIfNoneExists(apps, appData.Id);
                AppDeploymentConfig appDeploymentConfig = apps[appData.Id];
                appDeploymentConfig = appDeploymentConfig.SetVersionConfig(versionDeploymentConfig);
                apps[appData.Id]    = appDeploymentConfig;
            }
            return(apps);
        }
Пример #6
0
 public AppDeploymentConfig SetVersionConfig(VersionDeploymentConfig versionDeploymentConfig)
 {
     var versions = new Dictionary<string, VersionDeploymentConfig>(ToDictionary(Versions));
     versions[versionDeploymentConfig.Version] = versionDeploymentConfig;
     return new AppDeploymentConfig(AppId, versions);
 }
Пример #7
0
        private static Dictionary<string, AppDeploymentConfig> ParseDeploymentsConfig(string json)
        {
            Dictionary<string, AppDeploymentConfig> apps = new Dictionary<string, AppDeploymentConfig>();
            if (string.IsNullOrEmpty(json))
            {
                return apps;
            }

            ApplicationsData appsData = JsonUtils.Deserialize<ApplicationsData>(json);
            foreach (ApplicationData appData in appsData.Applications)
            {
                VersionDeploymentConfig versionDeploymentConfig = new VersionDeploymentConfig(appData.Version,
                    appData.DeploymentIds);
                apps = AddAppConfigIfNoneExists(apps, appData.Id);
                AppDeploymentConfig appDeploymentConfig = apps[appData.Id];
                appDeploymentConfig = appDeploymentConfig.SetVersionConfig(versionDeploymentConfig);
                apps[appData.Id] = appDeploymentConfig;
            }
            return apps;
        }