public Entities.Problem GetEntity(string username) { var item = new Entities.Problem() { Eventid = eventid, Source = source, @Object = @object, Objectid = objectid, Clock = clock, Ns = ns, R_eventid = r_eventid, R_clock = r_clock, R_ns = r_ns, Correlationid = correlationid, Userid = userid, Name = name, Acknowledged = acknowledged, Severity = severity, Opdata = opdata, //Acknowledges = BsonArray.Create(acknowledges), //Suppression_data = BsonArray.Create(suppression_data), Suppressed = suppressed, Urls = urls, //Tags = BsonArray.Create(tags), Id = $"{username}_{eventid}" }; return(item); }
private void UpdateProblemInfo(Bacs.Problem.Problem internalProblem, Entities.Problem problem, ProblemsDbContext problemsDbContext, ITestsFetcher testsFetcher, IArchiveClient archiveClient) { var name = internalProblem.Info.Name.First().Value; var maintainers = string.Join(", ", internalProblem.Info.Maintainer); var revision = internalProblem.System.Revision.Value.ToBase64(); var extensionValue = internalProblem.Profile.First().Extension.Value; var testsCount = ProfileExtension.Parser.ParseFrom(extensionValue) .TestGroup .Sum(x => x.Tests.Query.Count); var statement = $"http://bacs.cs.istu.ru/problem/{problem.InternalId}"; problem.Maintainers = maintainers; problem.Name = name; problem.Revision = revision; problem.Statement = statement; problem.TestsCount = testsCount; var testGroups = problemsDbContext.TestGroups .Where(x => string.Equals(x.ProblemId, problem.InternalId)) .ToArray(); problemsDbContext.TestGroups.RemoveRange(testGroups); var internalTestGroups = ProfileExtension.Parser.ParseFrom(extensionValue).TestGroup; var tests = internalTestGroups .SelectMany(x => x.Tests.Query.Select(y => y.Id)) .ToArray(); var testInfos = testsFetcher .FetchTests(archiveClient, problem.InternalId, tests) .DistinctBy(x => x.Id) .ToDictionary(x => x.Id); var newTestGroups = internalTestGroups.Select(x => new TestGroup { InternalId = x.Id, Score = x.Score, ProblemId = problem.InternalId, ContinueCondition = x.Tests.ContinueCondition.ToString(), Tests = x.Tests.Query.OrderBy(y => y.Id).Select(y => testInfos[y.Id]) .Select(y => new Test { Input = y.Input, Output = y.Output, InternalId = y.Id }).ToArray() }).OrderBy(y => y.Id); problemsDbContext.TestGroups.AddRange(newTestGroups); }
private bool TryAddProblem(IArchiveClient archiveClient, ITestsFetcher testsFetcher, string notCachedProblem, ProblemsDbContext problemsDbContext) { if (!TryGetInternalProblem(archiveClient, notCachedProblem, out var internalProblem)) { return(false); } var problem = new Entities.Problem { InternalId = notCachedProblem }; UpdateProblemInfo(internalProblem, problem, problemsDbContext, testsFetcher, archiveClient); problemsDbContext.Add(problem); return(true); }