Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("AnalysisName,UserIsNetworkSeed,UserGivenNetworkGeneration,UserGivenNodes,UserGivenTarget,UserGivenDrugTarget,AlgorithmType,GeneticRandomSeed,GeneticMaxIteration,GeneticMaxIterationNoImprovement,GeneticMaxPathLength,GeneticPopulationSize,GeneticElementsRandom,GeneticPercentageRandom,GeneticPercentageElite,GeneticProbabilityMutation,GreedyRandomSeed,GreedyMaxIteration,GreedyMaxIterationNoImprovement,GreedyMaxPathLength,GreedyRepeats,GreedyHeuristics")] AnalysisModel analysisModel)
        {
            ApplicationUser user = await _userManager.GetUserAsync(HttpContext.User);

            analysisModel.User = user;

            // If the model is valid and the user is logged in.
            if (ModelState.IsValid && user != null)
            {
                // If the network is generated successfully.
                if (AlgorithmFunctions.GenerateNetwork(analysisModel))
                {
                    // Save the new analysis to the database.
                    _context.Add(analysisModel);
                    await _context.SaveChangesAsync();

                    // Calling on a Hangfire background task the analysis run.
                    var analysisRun = new AnalysisRun(_context);
                    BackgroundJob.Enqueue(() => analysisRun.RunAnalysis(analysisModel.AnalysisId));

                    // This also seems to be working. The only problem is that it's not implmeneted on a background task.
                    // await AlgorithmFunctions.RunAnalysis(_context, analysisModel);

                    // Return to Dashboard.
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    return(View(analysisModel));
                }
            }
            return(View(analysisModel));
        }