public IList<Loadtest> ConvertToDomain(IEnumerable<LoadtestViewModel> viewModels) { List<Loadtest> loadtests = new List<Loadtest>(); LoadTestingContext context = new LoadTestingContext(); foreach (LoadtestViewModel vm in viewModels) { Guid id = vm.Id; LoadtestParameters ltParams = new LoadtestParameters(vm.StartDateUtc, vm.UserCount, vm.DurationSec); Agent agent = (from a in context.Agents where a.Location.City.Equals(vm.AgentCity, StringComparison.InvariantCultureIgnoreCase) && a.Location.Country.ToLower() == vm.AgentCountry.ToLower() select a).FirstOrDefault(); if (agent == null) throw new ArgumentException("There is no agent with the given properties."); Customer customer = (from c in context.Customers where c.Name.Equals(vm.CustomerName, StringComparison.InvariantCultureIgnoreCase) select c).FirstOrDefault(); if (customer == null) throw new ArgumentException("There is no customer with the given properties."); Guid? engineerId = null; if (!string.IsNullOrEmpty(vm.EngineerName)) { Engineer engineer = (from e in context.Engineers where e.Name.Equals(vm.EngineerName, StringComparison.InvariantCultureIgnoreCase) select e).FirstOrDefault(); if (engineer == null) throw new ArgumentException("There is no engineer with the given properties."); engineerId = engineer.Id; } LoadtestType ltType = (from t in context.LoadtestTypes where t.Description.ShortDescription.Equals(vm.LoadtestTypeShortDescription, StringComparison.InvariantCultureIgnoreCase) select t).FirstOrDefault(); if (ltType == null) throw new ArgumentException("There is no load test type with the given properties."); Project project = (from p in context.Projects where p.Description.ShortDescription.ToLower() == vm.ProjectName.ToLower() select p).FirstOrDefault(); if (project == null) throw new ArgumentException("There is no project with the given properties."); Scenario scenario = (from s in context.Scenarios where s.UriOne.Equals(vm.ScenarioUriOne, StringComparison.InvariantCultureIgnoreCase) && s.UriTwo.Equals(vm.ScenarioUriTwo, StringComparison.InvariantCultureIgnoreCase) && s.UriThree.Equals(vm.ScenarioUriThree, StringComparison.InvariantCultureIgnoreCase) select s).FirstOrDefault(); if (scenario == null) { List<Uri> uris = new List<Uri>(); Uri firstUri = string.IsNullOrEmpty(vm.ScenarioUriOne) ? null : new Uri(vm.ScenarioUriOne); Uri secondUri = string.IsNullOrEmpty(vm.ScenarioUriTwo) ? null : new Uri(vm.ScenarioUriTwo); Uri thirdUri = string.IsNullOrEmpty(vm.ScenarioUriThree) ? null : new Uri(vm.ScenarioUriThree); if (firstUri != null) uris.Add(firstUri); if (secondUri != null) uris.Add(secondUri); if (thirdUri != null) uris.Add(thirdUri); scenario = new Scenario(Guid.NewGuid(), uris); context.Scenarios.Add(scenario); context.SaveChanges(); } Loadtest converted = new Loadtest(id, ltParams, agent.Id, customer.Id, engineerId, ltType.Id, project.Id, scenario.Id); loadtests.Add(converted); } return loadtests; }
public static Loadtest ConvertToDomain(this LoadtestMongoDb loadtestDbModel) { LoadtestParametersMongoDb ltParamsDb = loadtestDbModel.Parameters; LoadtestParameters ltParamsDomain = new LoadtestParameters(ltParamsDb.StartDateUtc, ltParamsDb.UserCount, ltParamsDb.DurationSec); return new Loadtest( loadtestDbModel.DomainId, ltParamsDomain, loadtestDbModel.AgentId, loadtestDbModel.CustomerId, loadtestDbModel.EngineerId, loadtestDbModel.LoadtestTypeId, loadtestDbModel.ProjectId, loadtestDbModel.ScenarioId); }
public static Loadtest ConvertToDomain(this LoadtestMongoDb loadtestDbModel) { LoadtestParametersMongoDb ltParamsDb = loadtestDbModel.Parameters; LoadtestParameters ltParamsDomain = new LoadtestParameters(ltParamsDb.StartDateUtc, ltParamsDb.UserCount, ltParamsDb.DurationSec); return(new Loadtest( loadtestDbModel.DomainId, ltParamsDomain, loadtestDbModel.AgentId, loadtestDbModel.CustomerId, loadtestDbModel.EngineerId, loadtestDbModel.LoadtestTypeId, loadtestDbModel.ProjectId, loadtestDbModel.ScenarioId)); }
public void AddOrUpdateLoadtests(AddOrUpdateLoadtestsValidationResult addOrUpdateLoadtestsValidationResult) { LoadTestingContext context = LoadTestingContext.Create(base.ConnectionStringRepository); if (addOrUpdateLoadtestsValidationResult.ValidationComplete) { if (addOrUpdateLoadtestsValidationResult.ToBeInserted.Any()) { IEnumerable <LoadtestMongoDb> toBeInserted = addOrUpdateLoadtestsValidationResult.ToBeInserted.PrepareAllForInsertion(); context.Loadtests.InsertMany(toBeInserted); } if (addOrUpdateLoadtestsValidationResult.ToBeUpdated.Any()) { foreach (Loadtest toBeUpdated in addOrUpdateLoadtestsValidationResult.ToBeUpdated) { Guid existingLoadtestId = toBeUpdated.Id; var loadtestInDbQuery = context.Loadtests.Find <LoadtestMongoDb>(lt => lt.DomainId == existingLoadtestId); LoadtestMongoDb loadtestInDb = loadtestInDbQuery.SingleOrDefault(); loadtestInDb.AgentId = toBeUpdated.AgentId; loadtestInDb.CustomerId = toBeUpdated.CustomerId; loadtestInDb.EngineerId = toBeUpdated.EngineerId; loadtestInDb.LoadtestTypeId = toBeUpdated.LoadtestTypeId; LoadtestParameters ltDomainParameters = toBeUpdated.Parameters; loadtestInDb.Parameters.DurationSec = ltDomainParameters.DurationSec; loadtestInDb.Parameters.ExpectedEndDateUtc = ltDomainParameters.StartDateUtc.AddSeconds(ltDomainParameters.DurationSec); loadtestInDb.Parameters.StartDateUtc = ltDomainParameters.StartDateUtc; loadtestInDb.Parameters.UserCount = ltDomainParameters.UserCount; loadtestInDb.ProjectId = toBeUpdated.ProjectId; loadtestInDb.ScenarioId = toBeUpdated.ScenarioId; context.Loadtests.FindOneAndReplace <LoadtestMongoDb>(lt => lt.DbObjectId == loadtestInDb.DbObjectId, loadtestInDb); } } } else { throw new InvalidOperationException("Validation is not complete. You have to call the AddOrUpdateLoadtests method of the Timetable class first."); } }
public IList<Loadtest> ConvertToDomain(IEnumerable<LoadtestViewModel> viewModels) { List<Loadtest> loadtests = new List<Loadtest>(); LoadTestingContext context = LoadTestingContext.Create(base.ConnectionStringRepository); foreach (LoadtestViewModel vm in viewModels) { Guid id = vm.Id; LoadtestParameters ltParams = new LoadtestParameters(vm.StartDateUtc, vm.UserCount, vm.DurationSec); var agentQueryBuilder = Builders<AgentMongoDb>.Filter; var agentCityFilter = agentQueryBuilder.Eq<string>(a => a.Location.City.ToLower(), vm.AgentCity.ToLower()); var agentCountryFilter = agentQueryBuilder.Eq<string>(a => a.Location.Country.ToLower(), vm.AgentCountry.ToLower()); var agentCompleteFilter = agentQueryBuilder.And(agentCityFilter, agentCountryFilter); AgentMongoDb agentDb = context.Agents.Find(agentCompleteFilter).FirstOrDefault(); if (agentDb == null) throw new ArgumentException("There is no agent with the given properties."); var customerQueryBuilder = Builders<CustomerMongoDb>.Filter; var customerQuery = customerQueryBuilder.Eq<string>(c => c.Name.ToLower(), vm.CustomerName.ToLower()); CustomerMongoDb custDb = context.Customers.Find(customerQuery).SingleOrDefault(); if (custDb == null) throw new ArgumentException("There is no customer with the given properties."); Guid? engineerId = null; if (!string.IsNullOrEmpty(vm.EngineerName)) { EngineerMongoDb engDb = context.Engineers.Find(e => e.Name.ToLower() == vm.EngineerName.ToLower()).SingleOrDefault(); if (engDb == null) throw new ArgumentException("There is no engineer with the given properties."); engineerId = engDb.DomainId; } LoadtestTypeMongoDb ltTypeDb = context.LoadtestTypes.Find(t => t.Description.ShortDescription.ToLower() == vm.LoadtestTypeShortDescription.ToLower()).SingleOrDefault(); if (ltTypeDb == null) throw new ArgumentException("There is no load test type with the given properties."); ProjectMongoDb projectDb = context.Projects.Find(p => p.Description.ShortDescription.ToLower() == vm.ProjectName.ToLower()).SingleOrDefault(); if (projectDb == null) throw new ArgumentException("There is no project with the given properties."); var scenarioQueryBuilder = Builders<ScenarioMongoDb>.Filter; var scenarioUriOneFilter = scenarioQueryBuilder.Eq<string>(s => s.UriOne.ToLower(), vm.ScenarioUriOne.ToLower()); var scenarioUriTwoFilter = scenarioQueryBuilder.Eq<string>(s => s.UriTwo.ToLower(), vm.ScenarioUriTwo.ToLower()); var scenarioUriThreeFilter = scenarioQueryBuilder.Eq<string>(s => s.UriThree.ToLower(), vm.ScenarioUriThree.ToLower()); var scenarioCompleteFilter = scenarioQueryBuilder.And(scenarioUriOneFilter, scenarioUriTwoFilter, scenarioUriThreeFilter); ScenarioMongoDb scenarioDb = context.Scenarios.Find(scenarioCompleteFilter).SingleOrDefault(); if (scenarioDb == null) { scenarioDb = new ScenarioMongoDb() { DbObjectId = ObjectId.GenerateNewId(), DomainId = Guid.NewGuid() }; if (!string.IsNullOrEmpty(vm.ScenarioUriOne)) { scenarioDb.UriOne = vm.ScenarioUriOne; } if (!string.IsNullOrEmpty(vm.ScenarioUriTwo)) { scenarioDb.UriTwo = vm.ScenarioUriTwo; } if (!string.IsNullOrEmpty(vm.ScenarioUriThree)) { scenarioDb.UriThree = vm.ScenarioUriThree; } context.Scenarios.InsertOne(scenarioDb); } Loadtest converted = new Loadtest(id, ltParams, agentDb.DomainId, custDb.DomainId, engineerId, ltTypeDb.DomainId, projectDb.DomainId, scenarioDb.DomainId); loadtests.Add(converted); } return loadtests; }
public IList <Loadtest> ConvertToDomain(IEnumerable <LoadtestViewModel> viewModels) { List <Loadtest> loadtests = new List <Loadtest>(); LoadTestingContext context = LoadTestingContext.Create(base.ConnectionStringRepository); foreach (LoadtestViewModel vm in viewModels) { Guid id = vm.Id; LoadtestParameters ltParams = new LoadtestParameters(vm.StartDateUtc, vm.UserCount, vm.DurationSec); var agentQueryBuilder = Builders <AgentMongoDb> .Filter; var agentCityFilter = agentQueryBuilder.Eq <string>(a => a.Location.City.ToLower(), vm.AgentCity.ToLower()); var agentCountryFilter = agentQueryBuilder.Eq <string>(a => a.Location.Country.ToLower(), vm.AgentCountry.ToLower()); var agentCompleteFilter = agentQueryBuilder.And(agentCityFilter, agentCountryFilter); AgentMongoDb agentDb = context.Agents.Find(agentCompleteFilter).FirstOrDefault(); if (agentDb == null) { throw new ArgumentException("There is no agent with the given properties."); } var customerQueryBuilder = Builders <CustomerMongoDb> .Filter; var customerQuery = customerQueryBuilder.Eq <string>(c => c.Name.ToLower(), vm.CustomerName.ToLower()); CustomerMongoDb custDb = context.Customers.Find(customerQuery).SingleOrDefault(); if (custDb == null) { throw new ArgumentException("There is no customer with the given properties."); } Guid?engineerId = null; if (!string.IsNullOrEmpty(vm.EngineerName)) { EngineerMongoDb engDb = context.Engineers.Find(e => e.Name.ToLower() == vm.EngineerName.ToLower()).SingleOrDefault(); if (engDb == null) { throw new ArgumentException("There is no engineer with the given properties."); } engineerId = engDb.DomainId; } LoadtestTypeMongoDb ltTypeDb = context.LoadtestTypes.Find(t => t.Description.ShortDescription.ToLower() == vm.LoadtestTypeShortDescription.ToLower()).SingleOrDefault(); if (ltTypeDb == null) { throw new ArgumentException("There is no load test type with the given properties."); } ProjectMongoDb projectDb = context.Projects.Find(p => p.Description.ShortDescription.ToLower() == vm.ProjectName.ToLower()).SingleOrDefault(); if (projectDb == null) { throw new ArgumentException("There is no project with the given properties."); } var scenarioQueryBuilder = Builders <ScenarioMongoDb> .Filter; var scenarioUriOneFilter = scenarioQueryBuilder.Eq <string>(s => s.UriOne.ToLower(), vm.ScenarioUriOne.ToLower()); var scenarioUriTwoFilter = scenarioQueryBuilder.Eq <string>(s => s.UriTwo.ToLower(), vm.ScenarioUriTwo.ToLower()); var scenarioUriThreeFilter = scenarioQueryBuilder.Eq <string>(s => s.UriThree.ToLower(), vm.ScenarioUriThree.ToLower()); var scenarioCompleteFilter = scenarioQueryBuilder.And(scenarioUriOneFilter, scenarioUriTwoFilter, scenarioUriThreeFilter); ScenarioMongoDb scenarioDb = context.Scenarios.Find(scenarioCompleteFilter).SingleOrDefault(); if (scenarioDb == null) { scenarioDb = new ScenarioMongoDb() { DbObjectId = ObjectId.GenerateNewId(), DomainId = Guid.NewGuid() }; if (!string.IsNullOrEmpty(vm.ScenarioUriOne)) { scenarioDb.UriOne = vm.ScenarioUriOne; } if (!string.IsNullOrEmpty(vm.ScenarioUriTwo)) { scenarioDb.UriTwo = vm.ScenarioUriTwo; } if (!string.IsNullOrEmpty(vm.ScenarioUriThree)) { scenarioDb.UriThree = vm.ScenarioUriThree; } context.Scenarios.InsertOne(scenarioDb); } Loadtest converted = new Loadtest(id, ltParams, agentDb.DomainId, custDb.DomainId, engineerId, ltTypeDb.DomainId, projectDb.DomainId, scenarioDb.DomainId); loadtests.Add(converted); } return(loadtests); }
public IList <Loadtest> ConvertToDomain(IEnumerable <LoadtestViewModel> viewModels) { List <Loadtest> loadtests = new List <Loadtest>(); LoadTestingContext context = new LoadTestingContext(); foreach (LoadtestViewModel vm in viewModels) { Guid id = vm.Id; LoadtestParameters ltParams = new LoadtestParameters(vm.StartDateUtc, vm.UserCount, vm.DurationSec); Agent agent = (from a in context.Agents where a.Location.City.Equals(vm.AgentCity, StringComparison.InvariantCultureIgnoreCase) && a.Location.Country.ToLower() == vm.AgentCountry.ToLower() select a).FirstOrDefault(); if (agent == null) { throw new ArgumentException("There is no agent with the given properties."); } Customer customer = (from c in context.Customers where c.Name.Equals(vm.CustomerName, StringComparison.InvariantCultureIgnoreCase) select c).FirstOrDefault(); if (customer == null) { throw new ArgumentException("There is no customer with the given properties."); } Guid?engineerId = null; if (!string.IsNullOrEmpty(vm.EngineerName)) { Engineer engineer = (from e in context.Engineers where e.Name.Equals(vm.EngineerName, StringComparison.InvariantCultureIgnoreCase) select e).FirstOrDefault(); if (engineer == null) { throw new ArgumentException("There is no engineer with the given properties."); } engineerId = engineer.Id; } LoadtestType ltType = (from t in context.LoadtestTypes where t.Description.ShortDescription.Equals(vm.LoadtestTypeShortDescription, StringComparison.InvariantCultureIgnoreCase) select t).FirstOrDefault(); if (ltType == null) { throw new ArgumentException("There is no load test type with the given properties."); } Project project = (from p in context.Projects where p.Description.ShortDescription.ToLower() == vm.ProjectName.ToLower() select p).FirstOrDefault(); if (project == null) { throw new ArgumentException("There is no project with the given properties."); } Scenario scenario = (from s in context.Scenarios where s.UriOne.Equals(vm.ScenarioUriOne, StringComparison.InvariantCultureIgnoreCase) && s.UriTwo.Equals(vm.ScenarioUriTwo, StringComparison.InvariantCultureIgnoreCase) && s.UriThree.Equals(vm.ScenarioUriThree, StringComparison.InvariantCultureIgnoreCase) select s).FirstOrDefault(); if (scenario == null) { List <Uri> uris = new List <Uri>(); Uri firstUri = string.IsNullOrEmpty(vm.ScenarioUriOne) ? null : new Uri(vm.ScenarioUriOne); Uri secondUri = string.IsNullOrEmpty(vm.ScenarioUriTwo) ? null : new Uri(vm.ScenarioUriTwo); Uri thirdUri = string.IsNullOrEmpty(vm.ScenarioUriThree) ? null : new Uri(vm.ScenarioUriThree); if (firstUri != null) { uris.Add(firstUri); } if (secondUri != null) { uris.Add(secondUri); } if (thirdUri != null) { uris.Add(thirdUri); } scenario = new Scenario(Guid.NewGuid(), uris); context.Scenarios.Add(scenario); context.SaveChanges(); } Loadtest converted = new Loadtest(id, ltParams, agent.Id, customer.Id, engineerId, ltType.Id, project.Id, scenario.Id); loadtests.Add(converted); } return(loadtests); }