public NewNiisDictionaryService( NiisWebContextMigration context, IDicTypeResolver dicTypeResolver) { _context = context; _dicTypeResolver = dicTypeResolver; }
public InsertRequestRelationsHandler(NiisWebContextMigration context, OldNiisRequestRelationService oldNiisRequestRelationService, OldNiisRequestService oldNiisRequestService) : base(context) { _oldNiisRequestRelationService = oldNiisRequestRelationService; _oldNiisRequestService = oldNiisRequestService; }
public InsertMainEntityRelationsHandler( NiisWebContextMigration context, OldNiisMainEntityRelationService oldNiisMainEntityRelationService, AppConfiguration appConfiguration) : base(context) { _oldNiisMainEntityRelationService = oldNiisMainEntityRelationService; _appConfiguration = appConfiguration; }
public DictionaryTypesHelper( NewNiisDictionaryService newNiisDictionaryService, OldNiisContext oldContext, NiisWebContextMigration newContext) { _newContext = newContext; _oldContext = oldContext; }
public InsertAllDictionariesHandler( NiisWebContextMigration context, OldNiisDictionaryService oldNiisDictionaryService, NewNiisDictionaryService newNiisDictionaryService) : base(context) { _oldNiisDictionaryService = oldNiisDictionaryService; _newNiisDictionaryService = newNiisDictionaryService; }
public InsertOnlyPaymentsHandler( NiisWebContextMigration context, OldNiisPaymentService oldNiisPaymentService, AppConfiguration appConfiguration) : base(context) { _oldNiisPaymentService = oldNiisPaymentService; _appConfiguration = appConfiguration; }
public InsertSecurityUsersHandler( NewNiisSecurityUserService newNiisSecurityUserService, OldNiisSecurityUserService oldNiisSecurityUserService, NiisWebContextMigration context) : base(context) { _newNiisSecurityUserService = newNiisSecurityUserService; _oldNiisSecurityUserService = oldNiisSecurityUserService; }
public void MigrateContractAttachments() { int lastContractId = 0; MigratedFilesCount = 0; using (_context = new NiisWebContextMigration(OptionsBuilder.Options)) { lastContractId = _context.Contracts.OrderByDescending(r => r.Id).First().Id; } while (lastContractId > LastMigratedContractId) { using (var _context = new NiisWebContextMigration(OptionsBuilder.Options)) { var contracts = _context.Contracts .Where(r => r.Id > LastMigratedContractId && r.MainAttachmentId.HasValue == false) .OrderBy(r => r.Id) .Take(_appConfiguration.PackageSizeForFile) .ToList(); if (contracts.Any() == false) { break; } foreach (var contract in contracts) { try { var mainAttachmentId = _attachmentFileHelper.GetMainAttachmentId(contract.Id, _context); if (mainAttachmentId.HasValue == true) { contract.MainAttachmentId = mainAttachmentId; _context.SaveChanges(); MigratedFilesCount++; } File.WriteAllText(ContractDataFilePath, contracts.Last().Id.ToString()); } catch (Exception ex) { var logErrorText = $"Ошибка при загрузки файла для договоров с Id: {contract.Id}. текст ошибки" + ex.Message; Log.LogError(logErrorText); Console.WriteLine(logErrorText); if (ex.InnerException != null) { Console.WriteLine(ex.InnerException); } } } Console.Write($"\rМигрировано {MigratedFilesCount} файлов. Затрачено времени: {StopwatchRequestFiels.Elapsed}"); } } }
public void Execute(List <int> documentIds, NiisWebContextMigration niisWebContext) { _newNiisDocumentRelationService = new NewNiisDocumentRelationService(niisWebContext); InsertDocumentEarlyRegs(documentIds); InsertDocumentCustomers(documentIds); InsertDocumentExecutors(documentIds); InsertGetPaymentRegistryDatas(documentIds); }
public OldNiisMainEntityRelationService( OldNiisContext context, NiisWebContextMigration newContext, DictionaryTypesHelper dictionaryTypesHelper) { _context = context; _newContext = newContext; _dictionaryTypesHelper = dictionaryTypesHelper; }
public InsertContractsHandler( NiisWebContextMigration context, OldNiisContractService oldNiisContractService, AppConfiguration appConfiguration, AttachmentFileHelper attachmentFileHelper) : base(context) { _oldNiisContractService = oldNiisContractService; _appConfiguration = appConfiguration; _attachmentFileHelper = attachmentFileHelper; }
public InsertDicCustomersHandler( NiisWebContextMigration context, OldNiisDictionaryService oldNiisDictionaryService, NewNiisDictionaryService newNiisDictionaryService, AppConfiguration appConfiguration) : base(context) { _oldNiisDictionaryService = oldNiisDictionaryService; _newNiisDictionaryService = newNiisDictionaryService; _appConfiguration = appConfiguration; }
public InsertProtectionDocsHandler( NiisWebContextMigration context, AppConfiguration appConfiguration, OldNiisProtectionDocService oldNiisProtectionDocService, InsertProtectionDocRelationsHandler insertProtectionDocRelationsHandler) : base(context) { _appConfiguration = appConfiguration; _oldNiisProtectionDocService = oldNiisProtectionDocService; _insertProtectionDocRelationsHandler = insertProtectionDocRelationsHandler; }
public void Execute(List <int> requestIds, NiisWebContextMigration niisWebContext) { _newNiisRequestRelationService = new NewNiisRequestRelationService(niisWebContext); InsertDicColorTZRequestRelations(requestIds); InsertRequestCustomers(requestIds); InsertDicIcfemRequestRelations(requestIds); InsertICGSRequests(requestIds); InsertICISRequests(requestIds); InsertIPCRequests(requestIds); InsertRequestEarlyRegs(requestIds); }
public void AttachFilesToDocuments(List <Document> documents, NiisWebContextMigration niisWebContext, ref int migratedFilesCount) { var documentFiles = _oldNiisDocumentDataService.GetDdDocumentDatas(documents.Select(r => r.Barcode).ToList()); if (documentFiles.Any() == false) { return; } foreach (var document in documents) { var documentData = documentFiles.SingleOrDefault(d => d.Id == document.Barcode); if (documentData == null) { continue; } if (documentData.FileName == null) { return; } var validFileName = $"{document.Barcode}.{Path.GetExtension(documentData.FileName)}"; var attachment = new Attachment { DocumentId = document.Id, AuthorId = _appConfiguration.AuthorAttachmentDocumentId, ContentType = FileTypeHelper.GetContentType(documentData.FileName), BucketName = $"old-document-{document.Barcode}", IsMain = true, DateCreate = documentData.DateCreate, DateUpdate = documentData.DateUpdate, OriginalName = documentData.FileName, Length = documentData.File.Length, ValidName = validFileName, Hash = _generateHash.GenerateFileHash(documentData.File) }; niisWebContext.Attachments.Add(attachment); niisWebContext.SaveChanges(); _fileStorage.AddAsync(attachment.BucketName, attachment.ValidName, documentData.File, attachment.ContentType).Wait(); document.MainAttachmentId = attachment.Id; niisWebContext.SaveChanges(); migratedFilesCount++; } }
public InsertDocumentsHandler( OldNiisDocumentService oldNiisDocumentService, NiisWebContextMigration context, AttachmentFileHelper attachmentFileHelper, AppConfiguration appConfiguration, InsertDocumentRelationsHandler insertDocumentRelationsHandler) : base(context) { _oldNiisDocumentService = oldNiisDocumentService; _attachmentFileHelper = attachmentFileHelper; _appConfiguration = appConfiguration; _insertDocumentRelationsHandler = insertDocumentRelationsHandler; }
public void Execute(List <int> protectionDocIds, NiisWebContextMigration niisWebContext) { _newNiisProtectionDocRelationService = new NewNiisProtectionDocRelationService(niisWebContext); InsertDicColorTZProtectionDocRelation(protectionDocIds); InsertProtectionDocCustomers(protectionDocIds); InsertProtectionDocIcfems(protectionDocIds); InsertProtectionDocIcgses(protectionDocIds); InsertProtectionDocIcises(protectionDocIds); InsertProtectionDocIpcs(protectionDocIds); InsertProtectionDocEarlyRegs(protectionDocIds); InsertProtectionDocRedefines(protectionDocIds); }
public void AttachFilesToRequests(List <Request> requests, NiisWebContextMigration niisWebContext, ref int migratedFilesCount) { var documentFiles = _oldNiisDocumentDataService.GetDdDocumentDatas(requests.Select(r => r.Barcode).ToList()); if (documentFiles.Any() == false) { return; } foreach (var request in requests) { var documentData = documentFiles.SingleOrDefault(d => d.Id == request.Barcode); if (documentData == null) { continue; } if (string.IsNullOrWhiteSpace(documentData.FileName)) { documentData.FileName = $"{request.Barcode}.{FileTypes.Pdf}"; } var attachment = new Attachment { AuthorId = request.UserId ?? _appConfiguration.AuthorAttachmentDocumentId, ContentType = FileTypeHelper.GetContentType(documentData.FileName), BucketName = $"old-request-{request.Barcode}", IsMain = true, CopyCount = request.CopyCount, PageCount = request.PageCount, DateCreate = documentData.DateCreate, DateUpdate = documentData.DateUpdate, OriginalName = documentData.FileName, Length = documentData.File.Length, ValidName = documentData.FileName.MakeValidFileName(), Hash = _generateHash.GenerateFileHash(documentData.File) }; _newNiisAttachmentFileService = new NewNiisAttachmentFileService(niisWebContext); _newNiisAttachmentFileService.CreateAttachment(attachment); _fileStorage.AddAsync(attachment.BucketName, attachment.ValidName, documentData.File, attachment.ContentType).Wait(); request.MainAttachmentId = attachment.Id; niisWebContext.SaveChanges(); migratedFilesCount++; } }
private void MigrateMainEntityRelations(Type newType, string entityName, Func <int, int, IEnumerable <object> > getOldData) { var optionsBuilder = new DbContextOptionsBuilder <NiisWebContextMigration>(); optionsBuilder.UseSqlServer(_appConfiguration.NiisConnectionString); var countIndex = 0; while (true) { using (var db = new NiisWebContextMigration(optionsBuilder.Options)) { _newNiisMainEntityRelationService = new NewNiisMainEntityRelationService(db); using (var transaction = NewNiisContext.Database.BeginTransaction()) { try { var lastBarcode = _newNiisMainEntityRelationService.GetLastBarcode(newType); var mainEntityRelations = getOldData(_appConfiguration.PackageSize, lastBarcode ?? 1); if (mainEntityRelations.Any() == false) { break; } //if (mainEntityRelations is List<DocumentDocumentRelation>) // Console.WriteLine(string.Join(",", ((List<DocumentDocumentRelation>)mainEntityRelations).Select(r => $"C:{r.ParentId} pd:{r.ChildId} ed{r.ExternalId}"))); _newNiisMainEntityRelationService.CreateRangeMainEntityRelations(mainEntityRelations); transaction.Commit(); countIndex += _appConfiguration.PackageSize; Console.Write($"\rМигрировано {countIndex} записей"); } catch (Exception ex) { Log.LogError(ex); if (ex.InnerException != null) { Console.WriteLine(ex.InnerException); } transaction.Rollback(); throw ex; } } } } Console.WriteLine($"{entityName}s migrated"); }
public InsertRequestsHandler( NiisWebContextMigration context, OldNiisRequestService oldNiisRequestService, AttachmentFileHelper attachmentFileHelper, AppConfiguration appConfiguration, InsertRequestRelationsHandler insertRequestRelationsHandler) : base(context) { _context = context; _oldNiisRequestService = oldNiisRequestService; _attachmentFileHelper = attachmentFileHelper; _appConfiguration = appConfiguration; _insertRequestRelationsHandler = insertRequestRelationsHandler; }
public void MigrateDocumentAttachments() { int lastDocumentId = 0; MigratedFilesCount = 0; using (_context = new NiisWebContextMigration(OptionsBuilder.Options)) { lastDocumentId = _context.Documents.OrderByDescending(r => r.Id).First().Id; } while (lastDocumentId > LastMigratedDocumentId) { using (var _context = new NiisWebContextMigration(OptionsBuilder.Options)) { var documents = _context.Documents .Where(r => r.Id > LastMigratedDocumentId && r.MainAttachmentId.HasValue == false) .OrderBy(r => r.Id) .Take(_appConfiguration.PackageSizeForFile) .ToList(); if (documents.Any() == false) { break; } try { _attachmentFileHelper.AttachFilesToDocuments(documents, _context, ref MigratedFilesCount); File.WriteAllText(DocumentDataFilePath, documents.Last().Id.ToString()); } catch (Exception ex) { var logErrorText = $"Ошибка при загрузки файла для документов с Id: {string.Join(",", documents.Select(r => r.Id))}. текст ошибки" + ex.Message; Log.LogError(logErrorText); Console.WriteLine(logErrorText); Console.WriteLine(ex.Message + ex.StackTrace); if (ex.InnerException != null) { Console.WriteLine(ex.InnerException.Message + ex.StackTrace); } } Console.Write($"\rМигрировано {MigratedFilesCount} файлов. Затрачено времени: {StopwatchRequestFiels.Elapsed}"); } } }
public int?GetMainAttachmentId(int oldDocumentId, NiisWebContextMigration niisWebContext) { var documentData = _oldNiisDocumentDataService.GetDocumentData(oldDocumentId); if (documentData == null) { return(null); } if (string.IsNullOrWhiteSpace(documentData.FileName)) { documentData.FileName = $"{oldDocumentId}.{FileTypes.Pdf}"; } var attachment = new Attachment { AuthorId = _appConfiguration.AuthorAttachmentDocumentId, ContentType = FileTypeHelper.GetContentType(documentData.FileName), BucketName = $"old-document-{oldDocumentId}", IsMain = true, DateCreate = documentData.DateCreate, DateUpdate = documentData.DateUpdate, OriginalName = documentData.FileName, Length = documentData.File.Length, ValidName = documentData.FileName.MakeValidFileName(), Hash = _generateHash.GenerateFileHash(documentData.File) }; _newNiisAttachmentFileService = new NewNiisAttachmentFileService(niisWebContext); _newNiisAttachmentFileService.CreateAttachment(attachment); _fileStorage.AddAsync(attachment.BucketName, attachment.ValidName, documentData.File, attachment.ContentType).Wait(); return(attachment.Id); }
public NewNiisDocumentRelationService(NiisWebContextMigration context) { _context = context; }
public NewNiisProtectionDocService(NiisWebContextMigration context) { _context = context; }
public static void SetTableIdentityInsertOn(NiisWebContextMigration context, string tableName) { context.Database.ExecuteSqlCommand(string.Format("SET IDENTITY_INSERT [dbo].[{0}] ON", tableName)); }
public InsertProtectionDocRelationsHandler( OldNiisProtectionDocRelationService oldNiisProtectionDocRelationService, NiisWebContextMigration context) : base(context) { _oldNiisProtectionDocRelationService = oldNiisProtectionDocRelationService; }
public NewNiisPaymentService(NiisWebContextMigration context) { _context = context; }
public BaseHandler(NiisWebContextMigration context) { NewNiisContext = context; }
public void Execute() { var packageIndex = 1; var allDocumentsCount = _oldNiisDocumentService.GetDocumentsCount(); var documentsCommited = 0; var documentNeedToTransfer = 0; var optionsBuilder = new DbContextOptionsBuilder <NiisWebContextMigration>(); optionsBuilder.UseSqlServer(_appConfiguration.NiisConnectionString); var stopwatch = Stopwatch.StartNew(); while (true) { using (var db = new NiisWebContextMigration(optionsBuilder.Options)) { _context = db; _newNiisDocumentService = new NewNiisDocumentService(db); if (documentsCommited == 0) { documentsCommited = _newNiisDocumentService.GetDocumentsCount(); documentNeedToTransfer = allDocumentsCount - documentsCommited; } using (var transaction = db.Database.BeginTransaction()) { try { var lastBarcode = _newNiisDocumentService.GetLastBarcodeOfDocument(); var documents = _oldNiisDocumentService.GetDocuments(_appConfiguration.PackageSize, lastBarcode ?? 0); if (documents.Any() == false) { break; } _newNiisDocumentService.CreateRangeDocuments(documents); //_attachmentFileHelper.AttachFilesToDocuments(documents); InsertDocumentWorkflows(documents); _newNiisDocumentService.UpdateRangeDocuments(documents); _insertDocumentRelationsHandler.Execute(documents.Select(d => d.Id).ToList(), db); transaction.Commit(); Console.Write($"\rDocuments commited - {packageIndex * _appConfiguration.PackageSize}/{documentNeedToTransfer}. Time elapsed: {stopwatch.Elapsed}"); packageIndex++; } catch (Exception ex) { Log.LogError(ex); if (ex.InnerException != null) { Console.WriteLine(ex.InnerException); } transaction.Rollback(); throw ex; } } } } }
public NewNiisRequestService(NiisWebContextMigration context) { _context = context; }