public CommandOutput OnExecute(CommandInput arguments) { var output = new CommandOutput {PostAction = CommandOutput.PostCommandAction.None}; var name = arguments["name"]; long userId = arguments.GetUserId(); if (string.IsNullOrEmpty(name)) { output.DisplayMessage = "Suite Name missing"; output.PostAction = CommandOutput.PostCommandAction.ShowCommandHelp; output.MessageType = CommandOutput.DisplayMessageType.Error; } else { var keys = EncryptionEngine.Default.CreateKeys(); var model = new SuiteCreateModel { SuiteName = name, SuiteType = SuiteTypes.PersonalWithMultiEnvironment, PrivateKey = keys.Item1, UsesSysEncryption = true, PublicKey = keys.Item2, UserId = userId }; model.Environments.Add(new EnvironmentModel { EnvironmentName = "*", EnvironmentType = EnvironmentType.PROD }); model.Applications.Add(new ApplicationModel { ApplicationName = "*", Description = "All Applications in Suite " + name }); model.Regions.Add(new RegionModel { RegionName = "*", Description = "All Regions in Suite " + name }); model.Servers.Add(new ServerModel { ServerName = "*", Description = "All Servers in Suite " + name }); var suite = CurrentHostContext.Default.Provider.ConfigurationStore.AddSuite(model); output.Data = suite; output.DisplayMessage = "Success"; output.PostAction = CommandOutput.PostCommandAction.None; } return output; }
public CommandOutput OnExecute(CommandInput arguments) { var output = new CommandOutput { PostAction = CommandOutput.PostCommandAction.None }; var name = arguments["name"]; long userId = arguments.GetUserId(); if (string.IsNullOrEmpty(name)) { output.DisplayMessage = "Suite Name missing"; output.PostAction = CommandOutput.PostCommandAction.ShowCommandHelp; output.MessageType = CommandOutput.DisplayMessageType.Error; } else { var keys = EncryptionEngine.Default.CreateKeys(); var model = new SuiteCreateModel { SuiteName = name, SuiteType = SuiteTypes.PersonalWithMultiEnvironment, PrivateKey = keys.Item1, UsesSysEncryption = true, PublicKey = keys.Item2, UserId = userId }; model.Environments.Add(new EnvironmentModel { EnvironmentName = "*", EnvironmentType = EnvironmentType.PROD }); model.Applications.Add(new ApplicationModel { ApplicationName = "*", Description = "All Applications in Suite " + name }); model.Regions.Add(new RegionModel { RegionName = "*", Description = "All Regions in Suite " + name }); model.Servers.Add(new ServerModel { ServerName = "*", Description = "All Servers in Suite " + name }); var suite = CurrentHostContext.Default.Provider.ConfigurationStore.AddSuite(model); output.Data = suite; output.DisplayMessage = "Success"; output.PostAction = CommandOutput.PostCommandAction.None; } return(output); }
public SuiteModel AddSuite(SuiteCreateModel suiteModel) { Suite suiteReturn; using (var unitOfWork = new UnitOfWork(_connectionString)) { if (unitOfWork.Context.Suites.Any(x => x.SuiteName == suiteModel.SuiteName)) throw new InvalidOperationException("Suite already exists with name:" + suiteModel.SuiteName); var suiteDB = suiteModel.ToNewDbObject(); unitOfWork.Add(suiteDB); suiteReturn = suiteDB; //if (unitOfWork.Context.SuiteUsers.Any(x => x.UserId == suiteModel.UserId && x.SuiteId == suiteDB.SuiteId)) return; //var userMapping = new SuiteUser() //{ // SuiteId = suiteDB.SuiteId, // UserId = suiteModel.UserId //}; //unitOfWork.Add(userMapping); foreach (var environment in suiteModel.Environments) { environment.SuiteId = suiteDB.SuiteId; environment.IsActive = true; unitOfWork.Add(environment.ToNewDbObject()); } foreach (var application in suiteModel.Applications) { application.SuiteId = suiteDB.SuiteId; application.IsActive = true; unitOfWork.Add(application.ToNewDbObject()); } foreach (var region in suiteModel.Regions) { region.SuiteId = suiteDB.SuiteId; region.IsActive = true; unitOfWork.Add(region.ToNewDbObject()); } foreach (var server in suiteModel.Servers) { server.SuiteId = suiteDB.SuiteId; server.IsActive = true; unitOfWork.Add(server.ToNewDbObject()); } unitOfWork.Add(new SuiteUser { SuiteId = suiteReturn.SuiteId, UserId = (int) suiteModel.UserId, RoleId = (int) RoleType.Admin }); } return GetSuite(suiteModel.UserId, suiteReturn.SuiteId); }