private void SecureImport(IImportExportProgress iIImportProgress, CancellationToken? iCancelationToken) { if (_Done) return; _Transaction.Error += ((o, e) => iIImportProgress.SafeReport(e)); _Transaction.Progress += ((o, e) => iIImportProgress.SafeReport(e)); CancellationToken ct = (iCancelationToken != null) ? iCancelationToken.Value : CancellationToken.None; var listener = new IEventListenerAdaptor(iIImportProgress, _Transaction); bool Cancelled = false; using (_Transaction.SessionLock()) { if (IsCancelled(ct)) return; try { _Importers = _Const(listener); iIImportProgress.SafeReport(new BeginImport()); bool donesemething = false; foreach (IImporter Importer in _Importers) { if (Cancelled = IsCancelled(ct)) break; IImporter CurrentImporter = Importer; while (CurrentImporter != null) { donesemething = true; CurrentImporter.Context = _Transaction; CurrentImporter = CurrentImporter.Import(listener, ct); } } Cancelled = IsCancelled(ct); _Transaction.FireFactorizedEvents(); if (!donesemething) iIImportProgress.SafeReport(new NullMusicImportErrorEventArgs()); else if (!Cancelled) _Transaction.Commit(); else if (!_IInternalMusicSession.IsEnded) iIImportProgress.SafeReport(new CancelledImportEventArgs()); _Done = true; if (!_IInternalMusicSession.IsEnded) iIImportProgress.SafeReport(new EndImport()); } catch (ImportExportException iee) { iIImportProgress.SafeReport(iee.Error); _Transaction.FireFactorizedEvents(); iIImportProgress.SafeReport(new EndImport()); } catch (Exception e) { Trace.WriteLine(e); iIImportProgress.SafeReport(new UnknowError()); _Transaction.FireFactorizedEvents(); iIImportProgress.SafeReport(new EndImport()); } } }
protected override void PrivateExport(IImportExportProgress iIImportExportProgress, CancellationToken? iCancellationToken) { if (!Directory.Exists(FileDirectory)) { iIImportExportProgress.SafeReport(new ExportDirectoryNotFound(FileDirectory)); return; } _IIC.Error += ((o, e) => iIImportExportProgress.SafeReport(e)); using (_IIC.SessionLock()) { SizeChecker sc = new SizeChecker(FileDirectory); foreach (IInternalAlbum Al in AlbumToExport) { Al.Visit(sc); } if (!sc.End()) { iIImportExportProgress.SafeReport(new NotEnougthSpace(sc.Checker.ToString())); return; } var listener = new IEventListenerAdaptor(iIImportExportProgress, _IIC); IAlbumVisitor exp = null; if (CompactFiles == MusicExportType.Directory) exp = new SimpleExporter(this, FileDirectory, listener); else exp = new FileCompactor(this, FileDirectory, (CompactFiles == MusicExportType.Custo), listener); foreach (IInternalAlbum Al in AlbumToExport) { Al.Visit(exp); } if (!exp.End()) { iIImportExportProgress.SafeReport(new UnableToCreateFile(string.Join(Environment.NewLine, AlbumToExport))); return; } } _IIC.FireFactorizedEvents(); iIImportExportProgress.SafeReport(new EndExport(AlbumToExport)); }