コード例 #1
0
 public static void UpdateRun(this Run run, RunViewModel runVm)
 {
     run.BatchId   = runVm.BatchId;
     run.Direction = runVm.Direction;
     run.Sequence  = runVm.Sequence;
     run.TimeTaken = runVm.TimeTaken;
 }
コード例 #2
0
        public async Task <IActionResult> CpuSpike(RunViewModel runViewModel)
        {
            Task.Run(() => GenerateCpuSpike(runViewModel));

            TempData["CpuSpikeTriggered"] = true;
            return(View("Index"));
        }
コード例 #3
0
        public void NewProject(int defaultPage)
        {
            ProjectViewModel      projectViewModel      = new ProjectViewModel(_context);
            SetupViewModel        setupViewModel        = new SetupViewModel(_appModel.NewSetupModel(), _context);
            ParticipantsViewModel participantsViewModel = new ParticipantsViewModel(_appModel.NewParticipantsModel(), _context);
            PreferencesViewModel  preferencesViewModel  = new PreferencesViewModel(_appModel.NewPreferencesModel(), _context);
            AlgorithmViewModel    algorithmViewModel    = new AlgorithmViewModel(_appModel.NewAlgorithmModel(), _context);
            RunViewModel          runViewModel          = new RunViewModel(_appModel.NewRunModel(), _context);

            runViewModel.CheckSolution += new EventHandler <int>(OnNewResultWindow);

            _pages.Clear();
            _pages.Add(projectViewModel);
            _pages.Add(setupViewModel);
            _pages.Add(participantsViewModel);
            _pages.Add(preferencesViewModel);
            _pages.Add(algorithmViewModel);
            _pages.Add(runViewModel);

            foreach (IPageTurn page in _pages)
            {
                page.NextPage     += new EventHandler(Context_NextPage);
                page.PreviousPage += new EventHandler(Context_PreviousPage);
            }

            //_context.ReadyChanged += new EventHandler(Context_ReadyChanged);

            CurrentPage = _pages[defaultPage];
        }
コード例 #4
0
        public async Task <IActionResult> Edit(int id, [Bind("RunId,Name,TimeToRun")] RunViewModel runViewModel)
        {
            if (id != runViewModel.RunId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var run = await _runRepository.FindRunAsync(runViewModel.RunId);

                    run.Name      = runViewModel.Name;
                    run.TimeToRun = runViewModel.TimeToRun;
                    await _runRepository.EditRunAsync(run);
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(runViewModel));
        }
コード例 #5
0
        public void should_populate_tests_using_specified_filename_and_environment()
        {
            // given
            const string fileName = "Some file";
            var          testFile =
                Mock.Of <TestFile>(
                    c =>
                    c.Tests ==
                    new[]
            {
                new Test {
                    Description = "Desc1"
                },
                new Test {
                    Description = "Desc2"
                }
            });

            ITestService testService = Mock.Of <ITestService>(s => s.GetTestFile(fileName) == testFile);
            RunViewModel viewModel   = GivenARunViewModel(testService: testService);

            // when
            viewModel.Run(Mock.Of <IUserContext>(), fileName, null);

            // then
            Assert.That(viewModel.Tests, Is.Not.Null);
            Assert.That(viewModel.Tests.Select(c => new { Position = c.Position, c.Description }), Is.EquivalentTo(new[]
            {
                new { Position = 0, Description = "Desc1" },
                new { Position = 1, Description = "Desc2" }
            }));
        }
コード例 #6
0
 public MainViewModel()
 {
     _document = new Document();
     File      = new FileViewModel(_document);
     View      = new ViewModel(_document);
     Edit      = new EditViewModel(_document);
     Run       = new RunViewModel(_document);
 }
コード例 #7
0
        protected RunPage()
        {
            InitializeComponent();

            BindingContext = ViewModel = new RunViewModel();

            ViewModel.Stopped += ViewModel_Stopped;
        }
コード例 #8
0
        public void Remove()
        {
            Experiment experiment = project.Experiments.First() as Experiment;
            LabelingViewModel labelingViewModel = new LabelingViewModel(experiment.Labeling.First(), experiment.ProteinStates.First(), experiment);
            Assert.AreEqual(2, labelingViewModel.Children.Count);

            viewModel = labelingViewModel.Children.First();
            viewModel.Remove.Execute(viewModel);

            Assert.AreEqual(1, labelingViewModel.Children.Count);
        }
コード例 #9
0
        public void should_set_filename_to_specified_file()
        {
            // given
            const string fileName    = "Some file";
            ITestService testService = Mock.Of <ITestService>(s => s.GetTestFile(It.IsAny <string>()) == Mock.Of <TestFile>());
            RunViewModel viewModel   = GivenARunViewModel(testService: testService);

            // when
            viewModel.Run(Mock.Of <IUserContext>(), fileName, null);

            // then
            Assert.That(viewModel.FileName, Is.EqualTo(fileName));
        }
コード例 #10
0
        public async Task <IActionResult> Create([Bind("Name,TimeToRun")] RunViewModel runViewModel)
        {
            if (ModelState.IsValid)
            {
                var run = _mapper.Map <Run>(runViewModel);
                run.OwnerUserId = _userManager.GetUserId(User);
                run.runStatus   = RunStatus.Prepped;
                await _runRepository.CreateRunAsync(run);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(runViewModel));
        }
コード例 #11
0
        private RunViewModel CreateSequenceRun(RunViewModel run)
        {
            int[] numbers = Array.ConvertAll(run.Batch.Split(','), element => int.Parse(element));

            Stopwatch watch = new Stopwatch();

            watch.Start();
            Quicksort(numbers, 0, numbers.Length - 1);
            watch.Stop();

            run.Sequence  = (run.Direction == 0) ? string.Join(",", numbers.Select(x => x.ToString()).ToArray()) : string.Join(",", numbers.Reverse().Select(x => x.ToString()).ToArray());
            run.TimeTaken = Convert.ToDecimal(watch.Elapsed.Ticks);

            return(run);
        }
コード例 #12
0
        public ActionResult Index(int id)
        {
            var run   = _runRepo.GetRunDetails(id);
            var train = _trainRepo.GetTrainDetails(run.TrainId);
            var model = new RunViewModel()
            {
                RunDate          = run.Date,
                Carriages        = train.Carriages.ToDictionary(x => x.Number),
                PlacesByCarriage = run.Places.GroupBy(x => x.CarriageNumber).ToDictionary(x => x.Key, x => x.ToList()),
                ReservedPlaces   = run.Places.Where(p => _resServ.PlaceIsOccupied(p)).Select(p => p.Id).ToList(),
                Train            = train,
            };

            return(View(model));
        }
コード例 #13
0
ファイル: HomeController.cs プロジェクト: aiplugs/functions
        public async Task <IActionResult> Run([FromForm] RunViewModel model)
        {
            if (ModelState.IsValid == false)
            {
                return(RedirectToAction("Index"));
            }

            var id = await _jobService.ExclusiveCreateAsync(model.Name, new JObject());

            if (id.HasValue == false)
            {
                return(StatusCode((int)HttpStatusCode.Conflict));
            }

            return(RedirectToAction("Index", new { id }));
        }
コード例 #14
0
        private static void GenerateCpuSpike(RunViewModel viewmodel)
        {
            int cpuUsage = 99;
            int time     = viewmodel.Minutes * 60 * 1000;
            CancellationTokenSource cs = new CancellationTokenSource();
            CancellationToken       ct = cs.Token;

            for (int i = 0; i < Environment.ProcessorCount; i++)
            {
                var t = new Thread(
                    () => ConsumeCPU(cpuUsage, ct));

                t.Start();
            }
            Thread.Sleep(time);
            cs.Cancel();
        }
コード例 #15
0
        public HttpResponseMessage CreateRun(HttpRequestMessage request, RunViewModel run)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                run = CreateSequenceRun(run);

                Run newRun = new Run();
                newRun.UpdateRun(run);

                _runsRepository.Add(newRun);

                _unitOfWork.Commit();

                run = Mapper.Map <Run, RunViewModel>(newRun);
                response = request.CreateResponse <RunViewModel>(HttpStatusCode.Created, run);

                return response;
            }));
        }
コード例 #16
0
        public Window1()
        {
            InitializeComponent();
            runViewModel = new RunViewModel();
            DataContext  = runViewModel;

            List <ISearchStrategy> strategies = MyLocalSearches.GenerateSearchesTimeOut();

            cboOptions.ItemsSource   = strategies;
            cboOptions.SelectedIndex = strategies.Count - 1;
            graphViewModel           = new GraphViewModel()
            {
                BoundX    = 100,
                BoundY    = 100,
                NodeCount = 25,
                Seed      = 255
            };
            runViewModel.Graph = graphViewModel.ToGraph();

            ReadyToComputeCheck();
        }
コード例 #17
0
        public async Task <ActionResult> Patch(int id, [FromBody] JsonPatchDocument <RunViewModel> runPatch)
        {
            var run = await _runRepository.GetRun(id);

            if (run == null)
            {
                return(NotFound());
            }

            RunViewModel runViewModel = _mapper.Map <RunViewModel>(run);

            runPatch.ApplyTo(runViewModel);

            var patchedRun = _mapper.Map <Run>(runViewModel);

            if (await _runRepository.UpdateRun(patchedRun))
            {
                return(Ok(runViewModel));
            }
            return(BadRequest());
        }
コード例 #18
0
        public void should_start_task_using_current_user_context_and_file_name_when_running_tests()
        {
            // given
            const string fileName    = "MyFile";
            const string environment = "Chris loves a bit of environment if you know what I mean...";
            const string userName    = "******";

            ITestService testService  = Mock.Of <ITestService>(s => s.GetTestFile(fileName) == Mock.Of <TestFile>());
            var          tasksService = new Mock <ITasksService>();
            RunViewModel viewModel    = GivenARunViewModel(testService: testService, tasksService: tasksService.Object);

            // when
            viewModel.Run(Mock.Of <IUserContext>(c => c.FullName == userName), fileName, environment);

            // then
            tasksService.Verify(
                s =>
                s.Start(
                    It.Is <TaskRequest>(
                        r => r.Filename == fileName && r.Username == userName && r.Environment == environment)),
                "Should have requested for the correct task to start.");
        }
コード例 #19
0
        private void NewViewModel()
        {
            _context   = new ModelContext();
            _model     = new RunModel(_context);
            _viewModel = new RunViewModel(_model, _context);

            SetupModel setupModel = new SetupModel(_context);

            setupModel.Initialize();
            ParticipantsModel participantsModel = new ParticipantsModel(_context);

            participantsModel.Initialize();
            PreferencesModel preferencesModel = new PreferencesModel(_context);

            preferencesModel.Initialize();
            AlgorithmModel algorithmModel = new AlgorithmModel(_context);

            algorithmModel.Initialize();

            algorithmModel.CreateGaleShapleyAlgorithm();
            algorithmModel.CreateGeneticAlgorithm();

            _viewModel.RefreshPage();
        }
コード例 #20
0
 public Run()
 {
     InitializeComponent();
     BindingContext = new RunViewModel();
 }
コード例 #21
0
        public object Execute(RunArgs args)
        {
            Console.WriteLine("Resgrid Email Processor");
            Console.WriteLine("-----------------------------------------");

            Console.WriteLine("Starting Up");

            var _running = true;
            var model    = new RunViewModel();

            var config = _configService.LoadSettingsFromFile();

            _fileService.SetupDirectories();

            TelemetryConfiguration configuration   = null;
            TelemetryClient        telemetryClient = null;

            if (!String.IsNullOrWhiteSpace(config.DebugKey))
            {
                try
                {
                    configuration = TelemetryConfiguration.Active;
                    configuration.InstrumentationKey = config.DebugKey;
                    configuration.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer());
                    configuration.TelemetryInitializers.Add(new HttpDependenciesParsingTelemetryInitializer());
                    telemetryClient = new TelemetryClient();

                    System.Console.WriteLine("Application Insights Debug Key Detected and AppInsights Initialized");
                }
                catch { }
            }

            Logger log;

            if (config.Debug)
            {
                log = new LoggerConfiguration()
                      .MinimumLevel.Debug()
                      .WriteTo.Console()
                      .CreateLogger();
            }
            else
            {
                log = new LoggerConfiguration()
                      .MinimumLevel.Error()
                      .WriteTo.Console()
                      .CreateLogger();
            }

            using (InitializeDependencyTracking(configuration))
            {
                // Define the cancellation token.
                CancellationTokenSource source = new CancellationTokenSource();
                CancellationToken       token  = source.Token;

                Thread dataThread = new Thread(() => _dataService.Run(token, log, config));
                dataThread.Name = $"Data Service Thread";
                dataThread.Start();

                Thread emailThread = new Thread(() => _emailService.Run(token, log));
                emailThread.Name = $"Email Service Thread";
                emailThread.Start();

                Thread importThread = new Thread(() => _montiorService.Run(token, log));
                importThread.Name = $"Import Service Thread";
                importThread.Start();

                System.Console.WriteLine("Email Processor is Running...");
                System.Console.WriteLine("Press any key to stop");

                var line = Console.ReadLine();
                source.Cancel();
                System.Console.WriteLine("Shutting down, please wait...");
                Task.Delay(2000).Wait();

                _running = false;
            }

            if (telemetryClient != null)
            {
                telemetryClient.Flush();
                Task.Delay(5000).Wait();
            }

            return(View("Run", model));
        }
コード例 #22
0
 public void TestInitialize()
 {
     project = TestHelper.CreateTestProject();
     viewModel = new RunViewModel(((Experiment)project.Experiments.First()).Runs.First());
 }