public void SetSolution(JidType jidType, SolutionResult result, params MessageType[] messageTypes) { foreach (var messageType in messageTypes) { results[jidType.ToString() + messageType.ToString()] = result; } }
public IEnumerable <ProjectNuspecResult> ConsolidateSolution(SolutionResult solution) { var projectsToCheck = solution.Projects.Where(a => a.HasNuspec && a.References.Count() > 0); foreach (var project in projectsToCheck) { var docu = ProjectReader.GetDocument(project.NuspecInfo.FullName); var dependencies = NuspecUpdater.GetDependencies(docu); var missing = CheckMissingPackages(dependencies, ParseReferences(project.References)); var useless = CheckUselessPackages(dependencies, ParseReferences(project.References)); if (missing.Any() || useless.Any()) { yield return(new ProjectNuspecResult { Project = project, MissingPackages = missing, UselessPackages = useless }); } } }
public async Task <JsonResult> GetIsSolvedReport(string SDate, string EDate) { string TotalSolved = String.Empty; string TotalUnSolved = String.Empty; string Dates = String.Empty; List <SolutionProvidedReportValues> IsSolvedRecordJson = new List <SolutionProvidedReportValues>(); List <SolutionResult> ResultRecordJson = new List <SolutionResult>(); try { string a = Convert.ToString(CloudConfigurationManager.GetSetting("StorageConnectionString")); CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString")); Microsoft.WindowsAzure.Storage.Table.CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); table = tableClient.GetTableReference("SolutionProvidedReport"); await table.CreateIfNotExistsAsync(); string StartdateString = SDate; //"2018-10-25T00:00:00.000Z"; string EnddateString = EDate; // "2018-11-10T00:00:00.000Z"; DateTime StartDate = DateTime.Parse(StartdateString, System.Globalization.CultureInfo.InvariantCulture); DateTime EndDate = DateTime.Parse(EnddateString, System.Globalization.CultureInfo.InvariantCulture); List <SolutionProvidedReport> SutdentListObj = RetrieveEntity <SolutionProvidedReport>(); var SutdentListObj1 = SutdentListObj.Where(item => item.Timestamp >= StartDate && item.Timestamp <= EndDate).OrderByDescending(item => item.Timestamp).GroupBy(item => item.Timestamp.Date).ToList(); foreach (var singleData in SutdentListObj1) { SolutionProvidedReportValues DataList = new SolutionProvidedReportValues(); SolutionResult resultdata = new SolutionResult(); DataList.Timestamp1 = (singleData.Key).ToString(); foreach (var result in singleData) { if (result.IsSolved == true) { DataList.isSolvedTrue += 1; } else { DataList.isSolvedFalse += 1; } } resultdata.TotalSolved += DataList.isSolvedTrue; //+ ", "; resultdata.TotalUnSolved += DataList.isSolvedFalse; // + ", "; resultdata.Dates += Convert.ToDateTime(DataList.Timestamp1).ToString("dd MMM"); // + ", "; ResultRecordJson.Add(resultdata); //IsSolvedRecordJson.Add(DataList); } } catch (Exception ex) { Utility.Utility.GenrateLog(ex.Message); } finally { } var output = JsonConvert.SerializeObject(ResultRecordJson); return(Json(output, JsonRequestBehavior.AllowGet)); }
internal TestSolutionAnalysis GenerateSolutionResult(string solutionPath, SolutionResult analysisRunResult, PortSolutionResult solutionRunResult) { var result = new TestSolutionAnalysis(); var projectFiles = Utils.GetProjectPaths(solutionPath).ToList(); projectFiles.ForEach(projectFile => { result.ProjectResults.Add(new ProjectResult() { CsProjectPath = projectFile, ProjectDirectory = Directory.GetParent(projectFile).FullName, CsProjectContent = File.ReadAllText(projectFile) }); }); StringBuilder str = new StringBuilder(); foreach (var projectResult in analysisRunResult.ProjectResults) { StringBuilder projectResults = new StringBuilder(); projectResults.AppendLine(projectResult.ProjectFile); projectResults.AppendLine(projectResult.ProjectActions.ToString()); result.ProjectResults.Where(p => p.CsProjectPath == projectResult.ProjectFile).FirstOrDefault().ProjectAnalysisResult = projectResults.ToString(); str.Append(projectResults); } result.SolutionAnalysisResult = str.ToString(); result.SolutionRunResult = solutionRunResult; return(result); }
private static void PrintNLResult(NonlinearSystem system, SolutionResult r, double[] result, double[] expected, double prec) { string s = system.Print() + Environment.NewLine + "Solution"; s = s + Environment.NewLine + "Converged: " + r.Converged.ToString(); string s1 = "RESULT:"; string s2 = "EXPECT:"; int l = result.Length; bool b = true; for (int i = 0; i < l; i++) { s1 = s1 + " " + result[i].ToString(); s2 = s2 + " " + expected[i].ToString(); if (Math.Abs(result[i] - expected[i]) > prec) { b = false; } } s = s + Environment.NewLine + s1 + Environment.NewLine + s2 + Environment.NewLine; if (b) { s = s + "SUCCESS"; } else { s = s + "ERROR: " + r.Message; } Console.Out.WriteLine(Environment.NewLine + s); }
/// <summary> /// Initializes a new instance of SolutionRewriter, analyzing the solution path using the provided config. /// WARNING: This constructor will rebuild and reanalyze the solution, which will have a performance impact. If you /// have an already analyzed solution, use another constructor /// </summary> /// <param name="analyzerConfiguration">Configuration for code analyzer to be used (AnalyzerConfiguration)</param> /// <param name="solutionFilePath">Path to solution file</param> /// <param name="solutionConfiguration">Configuration for each project in solution to be built</param> public SolutionRewriter(string solutionFilePath, List <ProjectConfiguration> solutionConfiguration, IProjectRewriterFactory projectRewriterFactory = null) { DownloadResourceFiles(); _solutionResult = new SolutionResult(); _projectRewriterFactory = projectRewriterFactory ?? new DefaultProjectRewriterFactory(); AnalyzerConfiguration analyzerConfiguration = new AnalyzerConfiguration(LanguageOptions.CSharp) { MetaDataSettings = new MetaDataSettings() { Annotations = true, DeclarationNodes = true, MethodInvocations = true, ReferenceData = true, LoadBuildData = true, InterfaceDeclarations = true, MemberAccess = true, ElementAccess = true } }; _projectRewriters = new List <ProjectRewriter>(); CodeAnalyzer analyzer = CodeAnalyzerFactory.GetAnalyzer(analyzerConfiguration, LogHelper.Logger); var analyzerResults = analyzer.AnalyzeSolution(solutionFilePath).Result; InitializeProjectRewriters(analyzerResults, solutionConfiguration); }
/// <summary> /// Initializes a new instance of SolutionRewriter with an already analyzed solution /// </summary> /// <param name="analyzerResults">The solution analysis</param> /// <param name="solutionConfiguration">Configuration for each project in the solution</param> public SolutionRewriter(List <AnalyzerResult> analyzerResults, List <ProjectConfiguration> solutionConfiguration, IProjectRewriterFactory projectRewriterFactory = null) { DownloadResourceFiles(); _solutionResult = new SolutionResult(); _projectRewriterFactory = projectRewriterFactory ?? new DefaultProjectRewriterFactory(); _projectRewriters = new List <ProjectRewriter>(); InitializeProjectRewriters(analyzerResults, solutionConfiguration); }
public async Task <JsonResult> GetIntentNotunderstoodGrid(string SDate, string EDate) { string TotalSolved = String.Empty; string TotalUnSolved = String.Empty; string Dates = String.Empty; List <SolutionProvidedReportValues> IsSolvedRecordJson = new List <SolutionProvidedReportValues>(); List <SolutionResult> ResultRecordJson = new List <SolutionResult>(); try { string a = Convert.ToString(CloudConfigurationManager.GetSetting("StorageConnectionString")); CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString")); // Create the table client. Microsoft.WindowsAzure.Storage.Table.CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); // Retrieve a reference to the table. // CloudTable table = tableClient.GetTableReference("SolutionProvidedReport"); table = tableClient.GetTableReference("IntentNotunderstood"); await table.CreateIfNotExistsAsync(); string StartdateString = SDate; //"2018-10-25T00:00:00.000Z"; string EnddateString = EDate; // "2018-11-10T00:00:00.000Z"; DateTime StartDate = DateTime.Parse(StartdateString, System.Globalization.CultureInfo.InvariantCulture); DateTime EndDate = DateTime.Parse(EnddateString, System.Globalization.CultureInfo.InvariantCulture); List <SolutionProvidedReport> SutdentListObj = RetrieveEntity <SolutionProvidedReport>(); var SutdentListObj1 = SutdentListObj.Where(item => item.Timestamp >= StartDate && item.Timestamp <= EndDate).OrderByDescending(item => item.Timestamp).ToList(); foreach (var singleData in SutdentListObj1) { SolutionProvidedReportValues DataList = new SolutionProvidedReportValues(); SolutionResult resultdata = new SolutionResult(); //DataList.Timestamp1 = (singleData.Key).ToString(); //DataList.IntentNotunderstood = singleData.Count(); // resultdata.TotalNoRating += DataList.FailedTicket; //+ ", "; resultdata.FunctionLocation += singleData.FunctionLocation; resultdata.ExceptionMessage += singleData.ExceptionMessage; resultdata.Query += singleData.Query; resultdata.Dates += Convert.ToDateTime(singleData.Timestamp.DateTime).ToString("dd-MMM-yyyy");// + ", "; ResultRecordJson.Add(resultdata); //IsSolvedRecordJson.Add(DataList); } } catch (Exception ex) { Utility.Utility.GenrateLog(ex.Message); } finally { } var output = JsonConvert.SerializeObject(ResultRecordJson); // var resultData = new {TotalSolved = TotalSolved, TotalUnSolved = TotalUnSolved, Dates = Dates }; // return Json(resultData, JsonRequestBehavior.AllowGet); //return Json(c, JsonRequestBehavior.AllowGet); return(Json(output, JsonRequestBehavior.AllowGet)); }
public async Task <ISolutionResult> GetSolution( int id, bool fullRecord = true) { var result = new SolutionResult(); if (id == 0) { result.Success = false; result.Message = SolutionsMessages.SolutionNotFoundMessage; return(result); } try { var solutionResponse = await solutionsRepository.GetById(id, fullRecord); if (solutionResponse.Success) { var solution = (SudokuSolution)solutionResponse.Object; if (fullRecord && solution.Game != null) { solution.Game.SudokuMatrix.Difficulty.Matrices = null; } result.Success = solutionResponse.Success; result.Message = SolutionsMessages.SolutionFoundMessage; result.Solution = solution; return(result); } else if (!solutionResponse.Success && solutionResponse.Exception != null) { result.Success = solutionResponse.Success; result.Message = solutionResponse.Exception.Message; return(result); } else { result.Success = false; result.Message = SolutionsMessages.SolutionNotFoundMessage; return(result); } } catch (Exception exp) { result.Success = false; result.Message = exp.Message; return(result); } }
/// <summary> /// Initializes the Solution Port /// </summary> public SolutionResult AnalysisRun() { // If the solution was already analyzed, don't duplicate the results if (_solutionAnalysisResult != null) { return(_solutionAnalysisResult); } _solutionAnalysisResult = _solutionRewriter.AnalysisRun(); return(GenerateAnalysisResult()); }
/// <summary> /// Runs the Solution Port after creating an analysis /// </summary> public PortSolutionResult Run() { // Find actions to execute for each project var solutionAnalysisResult = AnalysisRun(); var projectActionsMap = solutionAnalysisResult.ProjectResults .ToDictionary(project => project.ProjectFile, project => project.ProjectActions); // Pass in the actions found to translate all files in each project _solutionRunResult = _solutionRewriter.Run(projectActionsMap); return(GenerateRunResult()); }
public async Task <SolutionResult> ScanSolution(string rootDirectory) { var solutions = GetSolutions(rootDirectory); if (!solutions.Any()) { return(null); } var solutionPath = solutions.First(); var result = new SolutionResult(new FileInfo(solutionPath), this); foreach (var projectPath in GetProjects(result.Info.DirectoryName)) { var projectInfo = new FileInfo(projectPath); var packagePaths = GetPackages(projectInfo.DirectoryName); ProjectResult projectResult; if (packagePaths.Count() != 0) // Projects contains package.config file { var packageInfo = new FileInfo(packagePaths.First()); projectResult = new ProjectResult(projectInfo, packageInfo); } else { projectResult = new ProjectResult(projectInfo); } var nuspecInfo = GetNuspec(projectInfo.DirectoryName).FirstOrDefault(); if (!string.IsNullOrEmpty(nuspecInfo)) { projectResult.NuspecInfo = new FileInfo(nuspecInfo); } result.Projects.Add(projectResult); } var gitPath = DirectoryTools.SearchDirectory(solutionPath, GetGitFolder); if (!string.IsNullOrEmpty(gitPath)) { result.GitInformation = _gitCtor(gitPath); await result.GitInformation.Init(false); } return(result); }
public async Task <ISolutionResult> Generate() { var result = new SolutionResult(); var continueLoop = true; do { var matrix = new SudokuMatrix(); matrix.GenerateSolution(); var response = (await solutionsRepository.GetSolvedSolutions()); var matrixNotInDB = true; if (response.Success) { foreach (var solution in response.Objects.ConvertAll(s => (SudokuSolution)s)) { if (solution.SolutionList.Count > 0 && solution.ToString().Equals(matrix)) { matrixNotInDB = false; } } } if (matrixNotInDB) { result.Solution = new SudokuSolution( matrix.ToIntList()); continueLoop = false; } } while (continueLoop); var solutionResponse = await solutionsRepository.Create((SudokuSolution)result.Solution); if (solutionResponse.Success) { result.Success = solutionResponse.Success; result.Message = SolutionsMessages.SolutionGeneratedMessage; return(result); } else { result.Success = solutionResponse.Success; result.Message = SolutionsMessages.SolutionNotGeneratedMessage; return(result); } }
private async Task <SolutionResult> ExecuteSolutionScan(string solutionPath, ICancelableProgress <ProgressMessage> progress, bool executeGitFetch) { var result = new SolutionResult(new FileInfo(solutionPath), this); foreach (var projectPath in GetProjects(result.Info.DirectoryName)) { if (progress.Token.IsCancellationRequested) { Log.Information("Cancelling scan"); throw new OperationCanceledException("Operation was canceled by user"); } var projectInfo = new FileInfo(projectPath); var packagePaths = GetPackages(projectInfo.DirectoryName); ProjectResult projectResult; if (packagePaths.Count() != 0) // Projects contains package.config file { var packageInfo = new FileInfo(packagePaths.First()); projectResult = new ProjectResult(projectInfo, packageInfo); } else { projectResult = new ProjectResult(projectInfo); } var nuspecInfo = GetNuspec(projectInfo.DirectoryName).FirstOrDefault(); if (!string.IsNullOrEmpty(nuspecInfo)) { projectResult.NuspecInfo = new FileInfo(nuspecInfo); } result.Projects.Add(projectResult); } var gitPath = DirectoryTools.SearchDirectory(solutionPath, GetGitFolder); if (!string.IsNullOrEmpty(gitPath)) { result.GitInformation = new GitInfo(gitPath, _gitEngine); await result.GitInformation.Init(executeGitFetch); } return(result); }
public async Task <JsonResult> GetTop10DetectedIntent(string SDate, string EDate) { string TotalSolved = String.Empty; string TotalUnSolved = String.Empty; string Dates = String.Empty; List <SolutionProvidedReportValues> IsSolvedRecordJson = new List <SolutionProvidedReportValues>(); List <SolutionResult> ResultRecordJson = new List <SolutionResult>(); try { string a = Convert.ToString(CloudConfigurationManager.GetSetting("StorageConnectionString")); CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString")); // Create the table client. Microsoft.WindowsAzure.Storage.Table.CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); // Retrieve a reference to the table. // CloudTable table = tableClient.GetTableReference("SolutionProvidedReport"); table = tableClient.GetTableReference("SolutionProvidedReport"); await table.CreateIfNotExistsAsync(); string StartdateString = SDate; string EnddateString = EDate; DateTime StartDate = DateTime.Parse(StartdateString, System.Globalization.CultureInfo.InvariantCulture); DateTime EndDate = DateTime.Parse(EnddateString, System.Globalization.CultureInfo.InvariantCulture); List <SolutionProvidedReport> SutdentListObj = RetrieveEntity <SolutionProvidedReport>(); var SutdentListObj1 = SutdentListObj.Where(item => item.Timestamp >= StartDate && item.Timestamp <= EndDate).OrderByDescending(item => item.Timestamp).GroupBy(item => item.DetectedIntent).Take(10).OrderByDescending(g => g.Count()).ToList(); foreach (var singleData in SutdentListObj1) { SolutionProvidedReportValues DataList = new SolutionProvidedReportValues(); SolutionResult resultdata = new SolutionResult(); DataList.DetectedIntent = (singleData.Key).ToString(); DataList.Values = singleData.Count(); resultdata.DetectedIntent += DataList.DetectedIntent; resultdata.DetectedIntentCount += DataList.Values; ResultRecordJson.Add(resultdata); } } catch (Exception ex) { Utility.Utility.GenrateLog(ex.Message); } finally { } var output = JsonConvert.SerializeObject(ResultRecordJson); return(Json(output, JsonRequestBehavior.AllowGet)); }
public SolutionPort(string solutionFilePath, ILogger logger = null) { if (logger != null) { LogHelper.Logger = logger; } _portSolutionResult = new PortSolutionResult(solutionFilePath); _solutionPath = solutionFilePath; _context = new MetricsContext(solutionFilePath); _solutionAnalysisResult = new SolutionResult(); _solutionRunResult = new SolutionResult(); SkipDownloadFiles = new ConcurrentDictionary <string, bool>(); _projectTypeFeatureResults = new Dictionary <string, FeatureDetectionResult>(); CheckCache(); }
public async Task <string> createSubmissionWithInputAsync(SubmissionWithInput httpBody) { httpBody.source_code = httpBody.source_code.Replace('"', '\"'); string URI = "https://api.judge0.com/submissions/?base64_encoded=false&wait=false"; HttpClient httpClient = new HttpClient(); HttpResponseMessage submissionResponse = await httpClient.PostAsJsonAsync(URI, httpBody); var content = submissionResponse.Content.ReadAsStringAsync(); JsonSerializer serializer = new JsonSerializer(); SolutionResult solutionResult = serializer.Deserialize <SolutionResult>(new JsonTextReader(new StringReader(content.Result))); string token = solutionResult.token; return(token); }
public float[] Solve() { NonlinearSystem system = new AnalyticalSystem(_variables, _functions); _options = new SolverOptions() { MaxIterationCount = 100, SolutionPrecision = 1e-5 }; _result = null; // solving the system double[] guess = Array.ConvertAll(_initGuess, x => (double)x); _actual = _solver.Solve(system, guess, _options, ref _result); return(Array.ConvertAll(_result, x => (float)x)); // expected values // printing solution result into console out }
/// <summary> /// Initializes a new instance of SolutionRewriter, analyzing the solution path using the provided config. /// WARNING: This constructor will rebuild and reanalyze the solution, which will have a performance impact. If you /// have an already analyzed solution, use another constructor /// </summary> /// <param name="analyzerConfiguration">Configuration for code analyzer to be used (AnalyzerConfiguration)</param> /// <param name="solutionFilePath">Path to solution file</param> /// <param name="solutionConfiguration">Configuration for each project in solution to be built</param> public SolutionRewriter(string solutionFilePath, List <ProjectConfiguration> solutionConfiguration) { _solutionResult = new SolutionResult(); AnalyzerConfiguration analyzerConfiguration = new AnalyzerConfiguration(LanguageOptions.CSharp); analyzerConfiguration.MetaDataSettings = new MetaDataSettings() { Annotations = true, DeclarationNodes = true, MethodInvocations = true, ReferenceData = true, LoadBuildData = true, InterfaceDeclarations = true }; _rulesRewriters = new List <ProjectRewriter>(); CodeAnalyzer analyzer = CodeAnalyzerFactory.GetAnalyzer(analyzerConfiguration, LogHelper.Logger); var analyzerResults = analyzer.AnalyzeSolution(solutionFilePath).Result; InitializeProjects(analyzerResults, solutionConfiguration); }
public JsonResult GetsessionsCount(string Timespan, string Interval) { var webAddr = "https://api.applicationinsights.io/v1/apps/" + AzureInsightsApplicationID + "/metrics/sessions/count?timespan=" + Timespan + "&interval=" + Interval + "";//&top=10 var httpWebRequest = (System.Net.HttpWebRequest)WebRequest.Create(webAddr); httpWebRequest.ContentType = "application/json"; httpWebRequest.Headers.Add("x-api-key", "" + AzureInsightsAppKey + ""); httpWebRequest.ContentLength = 0; httpWebRequest.Method = "GET"; var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); List <SolutionResult> ResultRecordJson = new List <SolutionResult>(); try { using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); result = result.Replace("sessions/count", "userscount"); var model = JsonConvert.DeserializeObject <RootObject>(result); foreach (var singleData in model.value.segments) { SolutionResult resultdata = new SolutionResult(); resultdata.Uniquecount = singleData.userscount.unique; resultdata.Date = TimeZoneInfo.ConvertTimeFromUtc(Convert.ToDateTime(singleData.end), INDIAN_ZONE).ToString("dd MMM, HH:MM"); ResultRecordJson.Add(resultdata); } } } catch (Exception ex) { Utility.Utility.GenrateLog(ex.Message); } finally { } var output = JsonConvert.SerializeObject(ResultRecordJson); return(Json(output, JsonRequestBehavior.AllowGet)); }
// To check whether infinite solutions // exists or no solution exists static SolutionResult CheckConsistency(float[,] a, int n) { int i, j; float sum; // flag == 2 for infinite solution // flag == 3 for No solution SolutionResult result = SolutionResult.NoSolution; for (i = 0; i < n; i++) { sum = 0; for (j = 0; j < n; j++) { sum = sum + a[i, j]; } if (sum == a[i, j]) { result = SolutionResult.InfiniteSolutions; } } return(result); }
public IEnumerable <ConsolidateProject> FindConsolidateReferences(SolutionResult solution) { foreach (var reference in solution.GetSolutionReferences().GroupBy(a => a.Id)) { var allVersions = reference.Select(a => a.Version).ToList(); if (AllAreSame(allVersions)) { continue; } var packageId = reference.First().Id; var ocurringProjects = solution.Projects.Where(a => a.References.Any(b => b.Id == packageId)); var dict = ocurringProjects.ToDictionary(a => a, b => b.References.First(c => c.Id == packageId).Version); yield return(new ConsolidateProject { Id = packageId, References = dict }); } }
/// <summary> /// Initializes a new instance of SolutionRewriter with an already analyzed solution /// </summary> /// <param name="analyzerResults">The solution analysis</param> /// <param name="solutionConfiguration">Configuration for each project in the solution</param> public SolutionRewriter(List <AnalyzerResult> analyzerResults, List <ProjectConfiguration> solutionConfiguration) { _solutionResult = new SolutionResult(); _rulesRewriters = new List <ProjectRewriter>(); InitializeProjects(analyzerResults, solutionConfiguration); }
public async Task <ISolutionResult> Solve( ISolutionRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } var result = new SolutionResult(); try { var solvedSolutions = ((await solutionsRepository.GetSolvedSolutions()).Objects) .ConvertAll(s => (SudokuSolution)s); var intList = new List <int>(); intList.AddRange(request.FirstRow); intList.AddRange(request.SecondRow); intList.AddRange(request.ThirdRow); intList.AddRange(request.FourthRow); intList.AddRange(request.FifthRow); intList.AddRange(request.SixthRow); intList.AddRange(request.SeventhRow); intList.AddRange(request.EighthRow); intList.AddRange(request.NinthRow); var sudokuSolver = new SudokuMatrix(intList); await sudokuSolver.Solve(); if (sudokuSolver.IsValid()) { var solution = new SudokuSolution(sudokuSolver.ToIntList()); var addResultToDataContext = true; if (solvedSolutions.Count > 0) { foreach (var solvedSolution in solvedSolutions) { if (solvedSolution.ToString().Equals(solution.ToString())) { addResultToDataContext = false; } } } if (addResultToDataContext) { solution = (SudokuSolution)(await solutionsRepository.Create(solution)).Object; } else { solution = solvedSolutions.Where(s => s.SolutionList.IsThisListEqual(solution.SolutionList)).FirstOrDefault(); } result.Success = true; result.Solution = solution; result.Message = SolutionsMessages.SudokuSolutionFoundMessage; } else { intList = sudokuSolver.ToIntList(); if (solvedSolutions.Count > 0) { var solutonInDB = false; foreach (var solution in solvedSolutions) { var possibleSolution = true; for (var i = 0; i < intList.Count - 1; i++) { if (intList[i] != 0 && intList[i] != solution.SolutionList[i]) { possibleSolution = false; break; } } if (possibleSolution) { solutonInDB = possibleSolution; result.Success = possibleSolution; result.Solution = solution; result.Message = SolutionsMessages.SudokuSolutionFoundMessage; break; } } if (!solutonInDB) { result.Success = false; result.Solution = null; result.Message = SolutionsMessages.SudokuSolutionNotFoundMessage; } } else { result.Success = false; result.Solution = null; result.Message = SolutionsMessages.SudokuSolutionNotFoundMessage; } } return(result); } catch (Exception exp) { result.Success = false; result.Message = exp.Message; return(result); } }
public static string FormatPart(int part, SolutionResult result) => $" - Part{part} => " + (string.IsNullOrEmpty(result.Answer) ? "Unsolved" : $"{result.Answer} ({result.Time.TotalMilliseconds}ms)");