示例#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();
        }
        /// <summary>
        ///     Creates an incident and a report.
        /// </summary>
        public void CreateReportAndIncident(out int reportId, out int incidentId)
        {
            ErrorReportEntity report;

            using (var uow = CreateUnitOfWork())
            {
                CreateUserAndApplication(uow, out var accountId, out var applicationId);

                report = new ErrorReportEntity(applicationId, Guid.NewGuid().ToString("N"), DateTime.UtcNow,
                                               new ErrorReportException(new Exception("mofo")),
                                               new List <ErrorReportContext>
                {
                    new ErrorReportContext("Maps", new Dictionary <string, string>())
                })
                {
                    Title = "Missing here"
                };
                report.Init(report.GenerateHashCodeIdentifier());

                uow.SaveChanges();
            }

            using (var dbContext = new AnalysisDbContext(CreateUnitOfWork()))
            {
                var incident = new IncidentBeingAnalyzed(report);
                var incRepos = new AnalyticsRepository(dbContext, ConfigStore);
                incRepos.CreateIncident(incident);
                incidentId = incident.Id;

                report.IncidentId = incident.Id;
                incRepos.CreateReport(report);
                reportId = report.Id;

                dbContext.SaveChanges();
            }
        }
 public void Add(CMSAnalysis entity)
 {
     _cmsAnalysisDbContext.CMSAnalysis.Add(entity);
     _cmsAnalysisDbContext.SaveChanges();
 }