protected override void PrepareRoutine() { if (_profile.CleanBeforeImport) { ImportToolkit.DropTransaction(_profile.TransactionIdentificator); } _importIdentificator = ImportToolkit.CreateImportIdentificator(_profile); if (_profile.EmbedSource) { var blob = BlobToolkit.CreateFromFile(_profile.Source.File, _importIdentificator); _profile = new EmbeddedSourceProfile { BlobName = blob.Name, CleanBeforeImport = _profile.CleanBeforeImport, EmbedSource = _profile.EmbedSource, Guid = Guid.NewGuid(), RuleIdentificatorString = _profile.Rule.Identificator, TransactionIdentificator = _profile.TransactionIdentificator, Distributor = _profile.Distributor }; _importIdentificator = ImportToolkit.CreateImportIdentificator(_profile); } // ToDo: не только ITableRule! _sourceReader = new BufferedSourceReader(_profile.Source, _profile.Rule as ITableRule); _sourceReader.Open(); _itemsWriter = new BufferedItemsWriter(_importIdentificator); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); }
public static EmbeddedBlob CreateFromFile(string file, ImportIdentificator importIdentificator) { if (importIdentificator.IsNew) { throw new Exception("Идентификатор импорта должен быть предварительно записан"); } var blob = EmbeddedBlob.FromFile(file); blob.ImportIdentificatorId = importIdentificator.Id; using (var context = new Context()) { context.EmbeddedBlobs.AddOrAttach(blob); context.SaveChanges(); } return(blob); }
public static ImportIdentificator CreateImportIdentificator(ISourceProfile target) { using (var context = new Context()) { var idName = target.TransactionIdentificator + "_"; idName += context.ImportIdentificators.Count(i => i.Identificator.StartsWith(idName)); var id = new ImportIdentificator { DateTime = DateTime.Now, Identificator = idName, SourceLocation = target.Source.Location, Distributor = target.Distributor }; context.ImportIdentificators.AddOrAttach(id); context.SaveChanges(); return(id); } }
public BufferedItemsWriter(ImportIdentificator importIdentificator) { _importIdentificator = importIdentificator; _buffer = new ManagedCircleBuffer <CatalogImportItem>(ItemsBufferSize, ItemsBufferIoTimeoutMsec); }