public async Task <string> Handle(CreateOptimizedExperimentCommand request, CancellationToken cancellationToken)
        {
            // Use Optimizer

            var command = new SingleCloudOptimizedCommand
            {
                BenchmarkCloudProvier = request.BenchmarkCloudProvier,
                HostCloudProvider     = request.HostCloudProvider,
                BenchmarkTimeLength   = request.BenchmarkTimeLength,
                ConcurrentUsers       = request.ConcurrentUsers,
                MaxCost = request.MaxCost
            };

            var optimizedResults = await _mediatr.Send(command);

            //loop through each experiment
            var experiments = new List <Core.Entities.BenchmarkExperiment>();

            foreach (var result in optimizedResults)
            {
                //create host vm

                var host = result.HostVM.CloudProvider == Optimizer.Enums.CloudProvider.AWS ? await CreateAWSHost(request, result.HostVM.CloudTemplateId) : await CreateAzureHost(request, result.HostVM.CloudTemplateId);

                var benchmarkHost = result.BenchmarkVM.CloudProvider == Optimizer.Enums.CloudProvider.AWS ? await CreateAWSHost(request, result.BenchmarkVM.CloudTemplateId) : await CreateAzureHost(request, result.BenchmarkVM.CloudTemplateId);

                var experiment = await CreateExperiment(host, benchmarkHost, request);

                experiments.Add(experiment);
                //create benchmark vm
            }
            //Create Experiments

            return(await Task.FromResult(string.Empty));
        }
        public Task <IEnumerable <OptimisedResult> > Handle(SingleCloudOptimizedCommand request, CancellationToken cancellationToken)
        {
            var benchmarkVMSize = SetBenchmarkVMSize(request.ConcurrentUsers);

            CloudServiceProvider benchmarkProvider;

            if (request.BenchmarkCloudProvier == CloudProvider.AWS)
            {
                var vm = _awsTemplate.FindBy(c => c.VMSizeType == benchmarkVMSize && c.Active).OrderBy(c => c.PricePerHour).FirstOrDefault();

                if (vm == null)
                {
                    throw new Exception("No VM found for AWS");
                }

                benchmarkProvider = new CloudServiceProvider
                {
                    CloudTemplateId = vm.Id,
                    CloudProvider   = Optimizer.Enums.CloudProvider.AWS,
                    Name            = vm.Name,
                    Time            = request.ExperimentLengthInSeconds,
                    CostPerHour     = vm.PricePerHour,
                    VMSize          = (Optimizer.Enums.VMSize)benchmarkVMSize
                };
            }
            else
            //if (request.BenchmarkProvider == CloudProvider.Azure)
            {
                var vm = _azureTemplate.FindBy(c => c.VMSizeType == benchmarkVMSize && c.Active).OrderBy(c => c.PricePerHour).FirstOrDefault();

                if (vm == null)
                {
                    throw new Exception("No VM found for Azure");
                }

                benchmarkProvider = new CloudServiceProvider
                {
                    CloudTemplateId = vm.Id,
                    CloudProvider   = Optimizer.Enums.CloudProvider.Azure,
                    Name            = vm.Name,
                    Time            = request.ExperimentLengthInSeconds,
                    CostPerHour     = vm.PricePerHour,
                    VMSize          = (Optimizer.Enums.VMSize)benchmarkVMSize
                };
            }

            List <CloudServiceProvider> vmHosts = new List <CloudServiceProvider>();

            if (request.HostCloudProvider == CloudProvider.AWS)
            {
                var vms = _awsTemplate.FindBy(c => c.Active).OrderBy(c => c.PricePerHour);

                if (vms == null)
                {
                    throw new Exception("No VMs found for AWS");
                }

                foreach (var vm in vms)
                {
                    vmHosts.Add(new CloudServiceProvider
                    {
                        CloudTemplateId = vm.Id,
                        CloudProvider   = Optimizer.Enums.CloudProvider.AWS,
                        CostPerHour     = vm.PricePerHour,
                        Name            = vm.Name,
                        Time            = request.ExperimentLengthInSeconds,
                        VMSize          = (Optimizer.Enums.VMSize)vm.VMSizeType
                    });
                }
            }

            if (request.HostCloudProvider == CloudProvider.Azure)
            {
                var vms = _azureTemplate.FindBy(c => c.Active).OrderBy(c => c.PricePerHour);

                if (vms == null)
                {
                    throw new Exception("No VMs found for Azure");
                }

                foreach (var vm in vms)
                {
                    vmHosts.Add(new CloudServiceProvider
                    {
                        CloudTemplateId = vm.Id,
                        CloudProvider   = Optimizer.Enums.CloudProvider.Azure,
                        CostPerHour     = vm.PricePerHour,
                        Name            = vm.Name,
                        Time            = request.ExperimentLengthInSeconds,
                        VMSize          = (Optimizer.Enums.VMSize)vm.VMSizeType
                    });
                }
            }

            decimal estimateCost  = 0;
            var     optimizedList = _optimizer.SingleProvider(vmHosts, benchmarkProvider, request.MaxCost, out estimateCost);

            return(Task.FromResult <IEnumerable <OptimisedResult> >(optimizedList));
        }