Exemple #1
0
 public async Task Add(QueueIds queueId, string itemId)
 {
     db.WorkQueueItems.Add(new WorkQueueItem {
         QueueId = queueId, ItemId = itemId
     });
     await db.SaveChangesAsync().ConfigureAwait(false);
 }
Exemple #2
0
        public async Task <Snippet> AddSnippetAsync(int tokensCount, SnippetType type, int hash)
        {
            var snippet = new Snippet
            {
                TokensCount = tokensCount,
                SnippetType = type,
                Hash        = hash
            };
            await db.Snippets.AddAsync(snippet);

            await db.SaveChangesAsync();

            return(snippet);
        }
        public async Task SetManualSuspicionLevelsAsync(ManualSuspicionLevels manualSuspicionLevels)
        {
            using (var ts = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromSeconds(30), TransactionScopeAsyncFlowOption.Enabled))
            {
                db.AddOrUpdate(manualSuspicionLevels, p => p.TaskId == manualSuspicionLevels.TaskId);
                await db.SaveChangesAsync().ConfigureAwait(false);

                ts.Complete();
            }
        }
        public async Task SaveMostSimilarSubmissionAsync(MostSimilarSubmission mostSimilarSubmission)
        {
            using (var ts = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromSeconds(30), TransactionScopeAsyncFlowOption.Enabled))
            {
                db.AddOrUpdate(mostSimilarSubmission, p => p.SubmissionId == mostSimilarSubmission.SubmissionId);
                await db.SaveChangesAsync().ConfigureAwait(false);

                ts.Complete();
            }
        }
Exemple #5
0
        public async Task SaveTaskStatisticsParametersAsync(TaskStatisticsParameters parameters)
        {
            using (var transaction = db.Database.BeginTransaction())
            {
                db.AddOrUpdate(parameters, p => p.TaskId == parameters.TaskId);
                await db.SaveChangesAsync();

                transaction.Commit();
            }
        }
Exemple #6
0
        private async Task TrySaveTaskStatisticsParametersAsync(TaskStatisticsParameters parameters)
        {
            using (var transaction = await db.Database.BeginTransactionAsync(IsolationLevel.Serializable).ConfigureAwait(false))
            {
                db.AddOrUpdate(parameters, p => p.TaskId == parameters.TaskId);
                await db.SaveChangesAsync().ConfigureAwait(false);

                transaction.Commit();
            }
        }
Exemple #7
0
        private async Task TrySaveTaskStatisticsParametersAsync(TaskStatisticsParameters parameters)
        {
            using (var ts = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromSeconds(30), TransactionScopeAsyncFlowOption.Enabled))
            {
                db.AddOrUpdate(parameters, p => p.TaskId == parameters.TaskId);
                await db.SaveChangesAsync().ConfigureAwait(false);

                ts.Complete();
            }
        }
Exemple #8
0
 public async Task SetManualSuspicionLevelsAsync(ManualSuspicionLevels manualSuspicionLevels)
 {
     var executionStrategy = new NpgsqlRetryingExecutionStrategy(db, 3);
     await executionStrategy.ExecuteAsync(async() =>
     {
         using (var ts = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromSeconds(30), TransactionScopeAsyncFlowOption.Enabled))
         {
             db.AddOrUpdate(manualSuspicionLevels, p => p.TaskId == manualSuspicionLevels.TaskId && p.Language == manualSuspicionLevels.Language);
             await db.SaveChangesAsync().ConfigureAwait(false);
             ts.Complete();
         }
     });
 }
Exemple #9
0
        public async Task <Submission> AddSubmissionAsync(int clientId, Guid taskId, Guid authorId, Language language, string code, int tokensCount, string additionalInfo = "")
        {
            var submission = new Submission
            {
                ClientId = clientId,
                TaskId   = taskId,
                AuthorId = authorId,
                Language = language,
                Program  = new Code
                {
                    Text = code,
                },
                TokensCount    = tokensCount,
                AdditionalInfo = additionalInfo,
                AddingTime     = DateTime.Now,
            };

            db.Submissions.Add(submission);
            await db.SaveChangesAsync();

            return(submission);
        }
Exemple #10
0
 public async Task SaveMostSimilarSubmissionAsync(MostSimilarSubmission mostSimilarSubmission)
 {
     await FuncUtils.TrySeveralTimesAsync(async() =>
     {
         using (var ts = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromSeconds(30), TransactionScopeAsyncFlowOption.Enabled))
         {
             db.AddOrUpdate(mostSimilarSubmission, p => p.SubmissionId == mostSimilarSubmission.SubmissionId);
             await db.SaveChangesAsync().ConfigureAwait(false);
             ts.Complete();
             return(0);
         }
     }, 3, () => Task.Delay(30));
 }
Exemple #11
0
        private async Task TrySaveTaskStatisticsParametersAsync(TaskStatisticsParameters parameters, List <TaskStatisticsSourceData> sourceData)
        {
            using (var ts = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromSeconds(30), TransactionScopeAsyncFlowOption.Enabled))
            {
                await db.TaskStatisticsSourceData
                .Where(d => d.Submission1.TaskId == parameters.TaskId)
                .DeleteAsync();

                db.AddOrUpdate(parameters, p => p.TaskId == parameters.TaskId);
                db.TaskStatisticsSourceData.AddRange(sourceData);
                await db.SaveChangesAsync().ConfigureAwait(false);

                ts.Complete();
            }
        }
Exemple #12
0
 /* It's very important that SaveTaskStatisticsParametersAsync() works with disabled EF's Change Tracker */
 public async Task SaveTaskStatisticsParametersAsync(TaskStatisticsParameters parameters, List <TaskStatisticsSourceData> sourceData)
 {
     var executionStrategy = new NpgsqlRetryingExecutionStrategy(db, 5);
     await executionStrategy.ExecuteAsync(async() =>
     {
         using (var ts = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromSeconds(30), TransactionScopeAsyncFlowOption.Enabled))
         {
             await db.TaskStatisticsSourceData
             .Where(d => d.Submission1.TaskId == parameters.TaskId && d.Submission1.Language == parameters.Language)
             .DeleteAsync();
             db.AddOrUpdate(parameters, p => p.TaskId == parameters.TaskId && p.Language == parameters.Language);
             db.TaskStatisticsSourceData.AddRange(sourceData);
             await db.SaveChangesAsync().ConfigureAwait(false);
             ts.Complete();
         }
     });
 }
Exemple #13
0
        private static async Task WriteNewAuthorsCounts(DateTime @from, DateTime to, Guid taskId, AntiPlagiarismDb db,
                                                        List <SnippetStatistics> snippetsStatistics, Dictionary <int, int> snippet2AuthorsCount)
        {
            foreach (var snippetStatistics in snippetsStatistics)
            {
                // snippet2AuthorsCount не содержит ключа, если с момента to не было посылок c этим сниппетом
                snippetStatistics.AuthorsCount    = snippet2AuthorsCount.GetValueOrDefault(snippetStatistics.SnippetId);
                db.Entry(snippetStatistics).State = EntityState.Modified;
            }

            await db.SaveChangesAsync();

            foreach (var snippetStatistics in snippetsStatistics)
            {
                db.Entry(snippetStatistics).State = EntityState.Unchanged;
            }
            log.Info($"New authors count are written for {snippetsStatistics.Count} snippets for task {taskId} from {@from.ToSortable()} to {to.ToSortable()}");
        }
Exemple #14
0
 public async Task TrySaveMostSimilarSubmissionAsync(MostSimilarSubmission mostSimilarSubmission)
 {
     try
     {
         var executionStrategy = new NpgsqlRetryingExecutionStrategy(db, 3);
         await executionStrategy.ExecuteAsync(async() =>
         {
             using (var ts = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromSeconds(30), TransactionScopeAsyncFlowOption.Enabled))
             {
                 db.AddOrUpdate(mostSimilarSubmission, p => p.SubmissionId == mostSimilarSubmission.SubmissionId);
                 await db.SaveChangesAsync().ConfigureAwait(false);
                 ts.Complete();
                 return(0);
             }
         });
     } catch (InvalidOperationException ex)
     {
         log.Warn(ex);
     }
 }