示例#1
0
        public async Task ExecuteAsync()
        {
            var sw = Stopwatch.StartNew();

            while (sw.ElapsedMilliseconds < 2000)
            {
                var collections = await GetInboundCollections();

                foreach (var collection in collections)
                {
                    var contexts = EntitySerializer.Deserialize <ErrorReportContext[]>(collection.JsonData);
                    _importer.AddContextCollections(collection.ReportId, contexts);
                }

                if (!collections.Any())
                {
                    break;
                }

                await DeleteImportedRows(collections);

                await _importer.Execute();

                _importer.Clear();
            }

            _dbContext.SaveChanges();
        }
        public async Task ExecuteAsync()
        {
            var sw = Stopwatch.StartNew();

            while (sw.ElapsedMilliseconds < 2000)
            {
                var reportIds = new List <int>();
                using (var cmd = _analysisDbContext.UnitOfWork.CreateDbCommand())
                {
                    cmd.CommandText = "SELECT TOP(10) Id, ContextInfo FROM ErrorReports WHERE cast([ContextInfo] as nvarchar(max)) != ''";
                    using (var reader = await cmd.ExecuteReaderAsync())
                    {
                        while (await reader.ReadAsync())
                        {
                            var reportId = reader.GetInt32(0);
                            var json     = reader.GetString(1);
                            var contexts = EntitySerializer.Deserialize <ErrorReportContext[]>(json);
                            _importer.AddContextCollections(reportId, contexts);
                            reportIds.Add(reportId);
                        }
                    }
                }

                if (!reportIds.Any())
                {
                    break;
                }

                await _importer.Execute();

                _importer.Clear();

                using (var cmd = _analysisDbContext.UnitOfWork.CreateDbCommand())
                {
                    var idStr = string.Join(",", reportIds);
                    cmd.CommandText = $"UPDATE ErrorReports SET ContextInfo='' WHERE Id IN({idStr})";
                    using (var reader = await cmd.ExecuteReaderAsync())
                    {
                        while (await reader.ReadAsync())
                        {
                            var reportId = reader.GetInt32(0);
                            var json     = reader.GetString(1);
                            var contexts = EntitySerializer.Deserialize <ErrorReportContext[]>(json);
                            _importer.AddContextCollections(reportId, contexts);
                        }
                    }
                }
            }

            _analysisDbContext.SaveChanges();
        }