/// <summary> /// <see cref="SifService{UI, DB}.Create(UI, string, string)"/> /// </summary> public override Guid Create(environmentType item, string zoneId = null, string contextId = null) { EnvironmentRegister environmentRegister = (new EnvironmentRegisterService()).RetrieveByUniqueIdentifiers (item.applicationInfo.applicationKey, item.instanceId, item.userToken, item.solutionId); if (environmentRegister == null) { string errorMessage = string.Format("Environment with application key of {0}, solution ID of {1}, instance ID of {2} and user token of {3} does NOT exist.", item.applicationInfo.applicationKey, (item.solutionId == null ? "[null]" : item.solutionId), (item.instanceId == null ? "[null]" : item.instanceId), (item.userToken == null ? "[null]" : item.userToken)); throw new AlreadyExistsException(errorMessage); } string sessionToken = AuthenticationUtils.GenerateSessionToken(item.applicationInfo.applicationKey, item.instanceId, item.userToken, item.solutionId); environmentType environmentType = RetrieveBySessionToken(sessionToken); if (environmentType != null) { string errorMessage = string.Format("A session token already exists for environment with application key of {0}, solution ID of {1}, instance ID of {2} and user token of {3}.", item.applicationInfo.applicationKey, (item.solutionId == null ? "[null]" : item.solutionId), (item.instanceId == null ? "[null]" : item.instanceId), (item.userToken == null ? "[null]" : item.userToken)); throw new AlreadyExistsException(errorMessage); } IDictionary <InfrastructureServiceNames, InfrastructureService> infrastructureServices = CopyInfrastructureServices(environmentRegister.InfrastructureServices); IDictionary <string, ProvisionedZone> provisionedZones = CopyProvisionedZones(environmentRegister.ProvisionedZones); Environment repoItem = MapperFactory.CreateInstance <environmentType, Environment>(item); if (environmentRegister.DefaultZone != null) { repoItem.DefaultZone = CopyDefaultZone(environmentRegister.DefaultZone); } if (infrastructureServices.Count > 0) { repoItem.InfrastructureServices = CopyInfrastructureServices(environmentRegister.InfrastructureServices); } if (provisionedZones.Count > 0) { repoItem.ProvisionedZones = CopyProvisionedZones(environmentRegister.ProvisionedZones); } repoItem.SessionToken = sessionToken; Guid environmentId = repository.Save(repoItem); if (repoItem.InfrastructureServices.Count > 0) { InfrastructureService infrastructureService = repoItem.InfrastructureServices[InfrastructureServiceNames.environment]; if (infrastructureService != null) { infrastructureService.Value = infrastructureService.Value + "/" + environmentId; repository.Save(repoItem); } } return(environmentId); }
/// <summary> /// <see cref="SifService{UI, DB}.Create(UI, string, string)"/> /// </summary> public override Guid Create(environmentType item, string zoneId = null, string contextId = null) { var environmentRegisterService = new EnvironmentRegisterService(); EnvironmentRegister environmentRegister = environmentRegisterService.RetrieveByUniqueIdentifiers( item.applicationInfo.applicationKey, item.instanceId, item.userToken, item.solutionId); if (environmentRegister == null) { var errorMessage = $"Environment with [applicationKey:{item.applicationInfo.applicationKey}|solutionId:{item.solutionId ?? "<null>"}|instanceId:{item.instanceId ?? "<null>"}|userToken:{item.userToken ?? "<null>"}] does NOT exist."; throw new AlreadyExistsException(errorMessage); } string sessionToken = AuthenticationUtils.GenerateSessionToken( item.applicationInfo.applicationKey, item.instanceId, item.userToken, item.solutionId); environmentType environmentType = RetrieveBySessionToken(sessionToken); if (environmentType != null) { var errorMessage = $"A session token already exists for environment with [applicationKey:{item.applicationInfo.applicationKey}|solutionId:{item.solutionId ?? "<null>"}|instanceId:{item.instanceId ?? "<null>"}|userToken:{item.userToken ?? "<null>"}]."; throw new AlreadyExistsException(errorMessage); } IDictionary <InfrastructureServiceNames, InfrastructureService> infrastructureServices = CopyInfrastructureServices(environmentRegister.InfrastructureServices); IDictionary <string, ProvisionedZone> provisionedZones = CopyProvisionedZones(environmentRegister.ProvisionedZones); Environment repoItem = MapperFactory.CreateInstance <environmentType, Environment>(item); if (environmentRegister.DefaultZone != null) { repoItem.DefaultZone = CopyDefaultZone(environmentRegister.DefaultZone); } if (infrastructureServices.Count > 0) { repoItem.InfrastructureServices = CopyInfrastructureServices(environmentRegister.InfrastructureServices); } if (provisionedZones.Count > 0) { repoItem.ProvisionedZones = CopyProvisionedZones(environmentRegister.ProvisionedZones); } repoItem.SessionToken = sessionToken; Guid environmentId = repository.Save(repoItem); if (repoItem.InfrastructureServices != null && repoItem.InfrastructureServices.Count > 0) { InfrastructureService infrastructureService = repoItem.InfrastructureServices[InfrastructureServiceNames.environment]; if (infrastructureService != null) { infrastructureService.Value = infrastructureService.Value + "/" + environmentId; repository.Save(repoItem); } } return(environmentId); }