/// <summary> /// Initializes a new instance of the <see cref="FrmEditMediaPath"/> class. /// </summary> public FrmEditMediaPath(MediaPathActionType type, MediaPathModel mediaPathModel) { this.InitializeComponent(); this.actionType = type; this.editingMediaPathModel = mediaPathModel; this.SetupBindings(); }
/// <summary> /// Scans the media path. /// </summary> /// <param name="mediaPathModel"> /// The media path model. /// </param> public static void ScanMediaPath(MediaPathModel mediaPathModel) { var bgw = new BackgroundWorker(); bgw.DoWork += BgwDoWork; bgw.RunWorkerCompleted += BgwRunWorkerCompleted; importInProgress = true; bgw.RunWorkerAsync(mediaPathModel); do { Thread.Sleep(50); }while (importInProgress); }
/// <summary> /// Adds the new entries. /// </summary> /// <param name="mediaPathModel"> /// The media path model. /// </param> /// <param name="files"> /// The files. /// </param> private static void AddNewEntries(MediaPathModel mediaPathModel, string[] files) { if (files == null) { return; } foreach (string f in files) { MediaPathFileModel.MediaPathFileType type = DetectType.FindType( f, mediaPathModel.ContainsTv, mediaPathModel.ContainsMovies); AddFolderType importType; if (type == MediaPathFileModel.MediaPathFileType.Movie) { importType = mediaPathModel.NameFileBy; } else { importType = AddFolderType.NotApplicable; } MediaPathFileModel obj = MediaPathFileModel.Add( f, type, importType, mediaPathModel.ScraperGroup, mediaPathModel.DefaultSource); string f1 = f; try { var check = mediaPathModel.FileCollection.Any(file => file.PathAndFileName == f1); if (!check) { mediaPathModel.FileCollection.Add(obj); } } catch { } } }
/// <summary> /// Handles the DoWork event of the bgwSaveMediaPathDb control. /// </summary> /// <param name="sender"> /// The source of the event. /// </param> /// <param name="e"> /// The <see cref="System.ComponentModel.DoWorkEventArgs"/> instance containing the event data. /// </param> private static void bgwSaveMediaPathDb_DoWork(object sender, DoWorkEventArgs e) { SavingCount++; string path = Get.FileSystemPaths.PathDatabases + OutputName.MediaPathDb + Path.DirectorySeparatorChar; Directory.CreateDirectory(path); Folders.DeleteFilesInFolder(path); int count = 0; for (int index = 0; index < MediaPathDBFactory.MediaPathDB.Count; index++) { MediaPathModel mediaPath = MediaPathDBFactory.MediaPathDB[index]; string json = JsonConvert.SerializeObject(mediaPath); Gzip.CompressString(json, path + count + ".MediaPath.gz"); count++; } SavingCount--; }
/// <summary> /// Remove a MediaPathModel from the MediaPathDB /// </summary> /// <param name="mediaPathModel">The media path model.</param> public static void RemoveFromDatabase(MediaPathModel mediaPathModel) { EnsureMediaPathDatabaseExists(); // Remove movies from db for (int index = 0; index < mediaPathModel.FileCollection.Count; index++) { MediaPathFileModel filePath = mediaPathModel.FileCollection[index]; if (filePath.Type == MediaPathFileModel.MediaPathFileType.Movie) { string p = filePath.Path.TrimEnd('\\'); if (! MovieDBFactory.MovieDatabase.Remove( (from m in MovieDBFactory.MovieDatabase where m.GetBaseFilePath == p select m). SingleOrDefault()) ) { MovieDBFactory.HiddenMovieDatabase.Remove( (from m in MovieDBFactory.HiddenMovieDatabase where m.GetBaseFilePath == p select m). SingleOrDefault()); } } if (filePath.Type == MediaPathFileModel.MediaPathFileType.TV) { if (MasterMediaDBFactory.TvDatabaseContains(filePath.PathAndFileName)) { MasterMediaDBFactory.MasterTvMediaDatabase.Remove(filePath.PathAndFileName); } } } // Remove media path MediaPathDB.Remove(mediaPathModel); // Update master MasterMediaDBFactory.PopulateMasterMovieMediaDatabase(); }
/// <summary> /// Create new record at CurrentMediaPathEdit /// </summary> public static void AddNewRecord() { CurrentMediaPathEdit = new MediaPathModel(); }
/// <summary> /// Remove a MediaPathModel from the MediaPathDB /// </summary> /// <param name="mediaPathModel">The media path model.</param> public static void RemoveFromDatabase(MediaPathModel mediaPathModel) { EnsureMediaPathDatabaseExists(); MediaPathDB.Remove(mediaPathModel); }
/// <summary> /// Get a MediaPathModel ready to edit. /// </summary> /// <param name="mediaPathModel">The media path model.</param> public static void EditRecord(MediaPathModel mediaPathModel) { CurrentMediaPathEdit = mediaPathModel; SaveMediaPathDB(); }
/// <summary> /// Add a MediaPathModel to the MediaPathDB Collection /// </summary> /// <param name="mediaPathModel">The MediaPathModel to add.</param> public static void AddToDatabase(MediaPathModel mediaPathModel) { EnsureMediaPathDatabaseExists(); MediaPathDB.Add(mediaPathModel); }