/// <summary>
 ///     Notifys when Download is finished ||
 ///     lastWriteTime.Subtract(LastDownload).Ticks > 0 because the FileSystemWatcher gets called 2 times read here
 ///     http://stackoverflow.com/questions/1764809/filesystemwatcher-changed-event-is-raised-twice?answertab=votes#tab-top
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="fileSystemEventArgs"></param>
 private void FileSystemDownloadWatcherOnCreated(object sender, FileSystemEventArgs fileSystemEventArgs)
 {
     try {
         var lastWriteTime = File.GetLastWriteTime(fileSystemEventArgs.FullPath);
         if (lastWriteTime.Subtract(LastDownload).Ticks > 0)
         {
             if (ConvertService == null)
             {
                 ConvertService = new ConvertService(ApplicationModel)
                 {
                     SongFileName = fileSystemEventArgs.FullPath
                 };
                 ConvertService.StartFFmpeg();
             }
             else
             {
                 ConvertService.SongFileName = fileSystemEventArgs.FullPath;
                 ConvertService.StartFFmpeg();
             }
         }
     }
     catch (Exception ex) {
         new LogException(ex);
     }
 }
Exemple #2
0
        /// <summary>
        /// Notifys when File Converted and Done
        /// lastWriteTime.Subtract(LastDownload).Ticks > 0 because the FileSystemWatcher gets called 2 times read here
        /// http://stackoverflow.com/questions/1764809/filesystemwatcher-changed-event-is-raised-twice?answertab=votes#tab-top
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="fileSystemEventArgs"></param>
        private void FileSystemMusicWatcherOnCreated(object sender, FileSystemEventArgs fileSystemEventArgs)
        {
            var lastWriteTime = File.GetLastWriteTime(fileSystemEventArgs.FullPath);

            if (lastWriteTime.Subtract(LastMusic).Ticks > 0)
            {
                var finishedSong =
                    ApplicationModel.DownloadCollection.FirstOrDefault(
                        x => x.FileName.Contains(Path.GetFileNameWithoutExtension(
                                                     fileSystemEventArgs.Name), StringComparison.OrdinalIgnoreCase));
                if (finishedSong == null)
                {
                    return;
                }

                Application.Current.Dispatcher.Invoke(() => {
                    ConvertService.KillFFmpegProcess();

                    var fullPath          = Path.Combine(MusicPath, Path.GetFileName(fileSystemEventArgs.FullPath));
                    finishedSong.FullPath = fullPath;
                    finishedSong.Status   = Finished;
                    ApplicationModel.DownloadCollection.Remove(finishedSong);
                    ApplicationModel.SongCollection.Add(finishedSong);

                    //if (File.Exists(fullPath)) {
                    //    File.Delete(fullPath);
                    //}
                });
            }
        }
        /// <summary>
        ///     Notifys when File Converted and Done
        ///     lastWriteTime.Subtract(LastDownload).Ticks > 0 because the FileSystemWatcher gets called 2 times read here
        ///     http://stackoverflow.com/questions/1764809/filesystemwatcher-changed-event-is-raised-twice?answertab=votes#tab-top
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="fileSystemEventArgs"></param>
        private void FileSystemMusicWatcherOnCreated(object sender, FileSystemEventArgs fileSystemEventArgs)
        {
            try {
                var lastWriteTime = File.GetLastWriteTime(fileSystemEventArgs.FullPath);
                if (lastWriteTime.Subtract(LastMusic).Ticks > 0)
                {
                    var finishedSong = ApplicationModel.DownloadCollection.FirstOrDefault(
                        x =>
                        x.FileName.Contains(Path.GetFileNameWithoutExtension(fileSystemEventArgs.Name),
                                            StringComparison.OrdinalIgnoreCase));
                    if (finishedSong == null)
                    {
                        return;
                    }

                    Application.Current.Dispatcher.Invoke(() => {
                        ConvertService.KillFFmpegProcess();

                        var fullPath          = Path.Combine(MusicPath, Path.GetFileName(fileSystemEventArgs.FullPath));
                        finishedSong.FullPath = fullPath;
                        SetStatus(finishedSong, Status.Done);

                        if (ApplicationModel.DownloadCollection.Count == 1)
                        {
                            ApplicationModel.StatusText = "Ready...";

                            if (ApplicationModel.Settings.RemoveSongsFromList)
                            {
                                ApplicationModel.DownloadCollection.Remove(finishedSong);
                            }
                            ApplicationModel.SongCollection.Add(finishedSong);
                            NavigationService.ContentWindow = NavigationService.SpotifyView;
                        }
                        else
                        {
                            if (ApplicationModel.Settings.RemoveSongsFromList)
                            {
                                ApplicationModel.DownloadCollection.Remove(finishedSong);
                            }
                            ApplicationModel.StatusText = $"Downloading {ApplicationModel.DownloadCollection.Count}/" +
                                                          $"{ApplicationModel.DroppedSongs.Count}";
                            ApplicationModel.SongCollection.Add(finishedSong);
                        }
                    });
                }
            }
            catch (Exception ex) {
                Debug.Write(ex.Message);
                Debug.Write(ex.StackTrace);
            }
        }