public async Task Import(IMusicImporter iIMusicImporter,IImportExportProgress iIImportExportProgress) { var imp = new ImporterItem(iIMusicImporter); _Importers.Add(imp); await imp.RunAsync(iIImportExportProgress); _Importers.Remove(imp); }
public Task SynchronizeAsync(bool DeleteBrokenItunes, IImportExportProgress iIImportExportProgress, CancellationToken? iCancellationToken) { return Task.Factory.StartNew( () => { PrivateSynchronize(DeleteBrokenItunes,iIImportExportProgress, iCancellationToken.HasValue ? iCancellationToken.Value : CancellationToken.None); }, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default); }
public Task ExportAsync(IImportExportProgress iIImportExportProgress, CancellationToken? iCancellationToken=null) { return Task.Factory.StartNew( () => { PrivateExport(iIImportExportProgress, iCancellationToken.HasValue ? iCancellationToken.Value : CancellationToken.None); }, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default); }
protected override void PrivateExport(IImportExportProgress iIImportExportProgress = null, CancellationToken? iCancelationToken = null) { if (AlbumToExport == null) return; _IIC.Error += ((o, e) => iIImportExportProgress.SafeReport(e)); _sem.Wait(); iIImportExportProgress.SafeReport(new ConnectingToWindowsPhone()); IDeviceManager idm = DeviceManager.CreateInstance(new SettingsPhone()); idm.Startup(_Ims.MainWindow); _IImportExportProgress = iIImportExportProgress; idm.DeviceEnumerationEnded += new EventHandler<EventArgs>(idm_DeviceEnumerationEnded); if (!_AutoResetEvent.WaitOne(TimeSpan.FromSeconds(40))) { bool Copy = false; lock (_CopyingLocker) Copy = _IsCopying; if (Copy) { //le transfer a commence j'attend la fin _AutoResetEvent.WaitOne(); } else { _IsCancelled.Cancel(); //j'ai pas de reponse de la part de device manager //j'arrete tout Trace.WriteLine("Time out during export to windows phone"); iIImportExportProgress.SafeReport(new UnknowErrorWindowsPhone()); } } //idm.Dispose(); _IIC.FireFactorizedEvents(); iIImportExportProgress.SafeReport(new EndExport(AlbumToExport)); _sem.Release(); _AutoResetEvent.Dispose(); }
protected override void PrivateExport(IImportExportProgress iIImportExportProgress, CancellationToken? iCancellationToken) { if (AlbumToExport == null) return; if (AlbumToExport.Count() == 0) return; if (!Directory.Exists(FileDirectory)) return; using (IImportContext Context = _msi.GetNewSessionContext()) { using (Context.SessionLock()) { Context.Error += (o, e) => iIImportExportProgress.SafeReport(e); iIImportExportProgress.SafeReport(new BeginningMove()); using (IMusicTransaction imut = Context.CreateTransaction()) { bool res = false; AlbumToExport.Apply(a => { bool r = (a as Album).Reroot(FileDirectory, Context, true); if (r) res = true; }); if (res) { imut.Commit(); } else imut.Cancel(); } iIImportExportProgress.SafeReport(new EndExport(_Alls)); } } }
public void Export(IImportExportProgress iIImportExportProgress=null) { PrivateExport(iIImportExportProgress, CancellationToken.None); }
private Task UniversalLoadAsync(IImportExportProgress iIImportProgress, CancellationToken? iCancelationToken, ThreadProperties tp) { return Task.Factory.StartNew( () => { using (tp.GetChanger()) { SecureImport(iIImportProgress, iCancelationToken); } }, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default); }
Task IMusicImporter.LoadAsync(IImportExportProgress iIImportProgress, CancellationToken? iCancelationToken) { return UniversalLoadAsync(iIImportProgress, iCancelationToken,null); }
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()); } } }
void IMusicImporter.Load(IImportExportProgress iIImportProgress) { SecureImport(iIImportProgress, null); }
public Task RunAsync(IImportExportProgress iIImportExportProgress) { return Importer.LoadAsync(iIImportExportProgress, _CancellationTokenSource.Token); }
private void PrivateExportToItunes(IImportExportProgress iIImportExportProgress, CancellationToken? iCancellationToken) { TrackError(iIImportExportProgress); try { iTunesApp iTunesApp = new iTunesApp(); if (iTunesApp == null) return; IITLibraryPlaylist mainLibrary = iTunesApp.LibraryPlaylist; List<IITTrack> list = new List<IITTrack>(); foreach (string p in from al in AlbumToExport from tr in al.Tracks select tr.Path) { IITOperationStatus iops = mainLibrary.AddFile(p); list.AddCollection(iops.Tracks.Cast<IITTrack>()); } if (!Exporttoipod) return; bool Transfer = false; IITSourceCollection _sources = iTunesApp.Sources; foreach (IITSource s in _sources) { if (s.Kind == ITSourceKind.ITSourceKindIPod) { Transfer = true; IITPlaylist l = s.Playlists.get_ItemByName(s.Name); IITLibraryPlaylist lpl = l as IITLibraryPlaylist; foreach (IITTrack track in list) { IITTrack itt = lpl.AddTrack(track); if (itt == null) _IIC.OnFactorisableError<ImpossibleToTransferMusicToIPod>(track.Name); } IITIPodSource ipod = s as IITIPodSource; if (ipod != null) ipod.UpdateIPod(); break; } } if (Transfer == false) { //OnError(new iPodNotFound()); iIImportExportProgress.SafeReport(new iPodNotFound()); return; } _IIC.FireFactorizedEvents(); //OnProgress(new EndExport(AlbumToExport)); iIImportExportProgress.SafeReport(new EndExport(AlbumToExport)); } catch (Exception e) { Trace.WriteLine("Problem to connect to iPod " + e.ToString()); if (e.Message == "The playlist is not modifiable.") //OnError(new ITunesIPodPlaylistreadonly()); iIImportExportProgress.SafeReport(new ITunesIPodPlaylistreadonly()); else //OnError(new ITunesNotResponding()); iIImportExportProgress.SafeReport(new ITunesNotResponding()); } }
public void Export(IImportExportProgress iIImportExportProgress) { PrivateExportToItunes(iIImportExportProgress, CancellationToken.None); }
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)); }
protected abstract void PrivateExport(IImportExportProgress iIImportProgress = null, CancellationToken? iCancelationToken = null);
private void PrivateSynchronize(bool DeleteBrokenItunes, IImportExportProgress iIImportExportProgress, CancellationToken? iCancellationToken) { TrackError(iIImportExportProgress); try { var MyMusicCollect = (from al in _MSI.Albums from t in al.Tracks let fi = new FileInfo(t.Path) where fi.Exists select fi.FullName ).ToList(); iTunesApp iTunesApp = new iTunesApp(); if (iTunesApp == null) return; IITLibraryPlaylist mainLibrary = iTunesApp.LibraryPlaylist; //OnProgress(new ITunesIdentifyingProgessEventArgs()); iIImportExportProgress.SafeReport(new ITunesIdentifyingProgessEventArgs()); var ItunesCollect = (from track in mainLibrary.Tracks.Cast<IITTrack>() let filetrack = track as IITFileOrCDTrack where ((filetrack != null) && (filetrack.Kind == ITTrackKind.ITTrackKindFile)) select new { Location = filetrack.Location, TunesTrack = filetrack }).ToList(); var cleanitunescollect = (from tunetrack in ItunesCollect where tunetrack.Location != null select tunetrack.Location).ToHashSet(); var hashedcollect = MyMusicCollect.ToHashSet(); var ToAdd = MyMusicCollect.Where(path => (!cleanitunescollect.Contains(path)) && (Path.GetExtension(path) != ".wma")); var ToRemove = from tunetrack in ItunesCollect let rem = (DeleteBrokenItunes ? ((tunetrack.Location == null) || !(hashedcollect.Contains(tunetrack.Location))) : ((tunetrack.Location != null) && !(hashedcollect.Contains(tunetrack.Location)))) where rem select tunetrack.TunesTrack; //OnProgress(new ITunesExportingProgessEventArgs(0)); iIImportExportProgress.SafeReport(new ITunesExportingProgessEventArgs(0)); foreach (string res in ToAdd) { try { mainLibrary.AddFile(res); } catch(Exception e) { Trace.WriteLine(string.Format("Export error to itunes {0}", e)); _IIC.OnFactorisableError<ExportFileError>(res); } } foreach (IITFileOrCDTrack res in ToRemove) { res.Delete(); } //OnProgress(new ITunesExportingProgessEventArgs(100)); iIImportExportProgress.SafeReport(new ITunesExportingProgessEventArgs(100)); //OnProgress(new EndExport("Collection Synchronised with iTunes")); iIImportExportProgress.SafeReport(new EndExport("Collection Synchronised with iTunes")); } catch (Exception e) { Trace.WriteLine("Problem to connect to iPod "+e.ToString()); iIImportExportProgress.SafeReport(new ITunesNotResponding()); //OnError(new ITunesNotResponding()); } }
private void TrackError(IImportExportProgress iIImportExportProgress) { _IIC.Error += ((o, e) => iIImportExportProgress.SafeReport(e)); }