public static bool Save() { if (listVideoInfos == null) { return(false); } Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); MyLog.Add("Saving VideoItems -->"); foreach (ConfigSettings.Source settingsSource in Config.settings.sources) { string dataFile = MyFile.EnsureDataFile("videos", Config.settings.exportExt, "data", settingsSource.alias); if (dataFile == null) { continue; } List <VideoInfo> saveVideoInfos = new List <VideoInfo>(listVideoInfos.Count()); saveVideoInfos = listVideoInfos.Where(x => x.sourceAlias == settingsSource.alias && x.videoItem != null && x.videoItem.title != null).OrderBy(x => x.videoItem.title).ToList(); if (saveVideoInfos == null) { continue; } int nbrVideoInfos = saveVideoInfos.Count(); if (nbrVideoInfos == 0) { continue; } MyLog.RotateFiles(dataFile); MySerialize.ToFile(Config.settings.exportFormat, dataFile, saveVideoInfos); FileInfo fileInfo = MyFile.FileInfo(dataFile); string toFile = "to " + dataFile.Replace(MyFile.exeDirectory, ""); if (fileInfo != null) { toFile += " " + MyFile.FormatSize(fileInfo.Length); } MyLog.Add("Saved " + nbrVideoInfos + " VideoItems " + toFile); } stopWatch.Stop(); MyLog.AddElapsed("<-- in ", stopWatch.Elapsed); return(true); }
protected void BackgroundWorkerCalcStats_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { stopwatchCalcStats.Stop(); MyLog.AddElapsed(stopwatchCalcStats.Elapsed); VideoInfoStats videoInfoStatsResults = (VideoInfoStats)sender; if (videoInfoStatsResults != null) { CalcVideoInfoStats.Save(); } LoadVideos_Completed(sender, e); }
public static bool Load() { bool ret = false; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); // MyLog.Add("Loading VideoItemStats"); string dataFile = MyFile.EnsureDataFile("stats", Config.settings.exportExt, "stats"); if (dataFile == null) { return(false); } // keep a backup of settings if (File.Exists(dataFile)) { videoInfoStats = new VideoInfoStats(); videoInfoStats = (VideoInfoStats)MyDeserialize.FromFile(Config.settings.exportFormat, dataFile, videoInfoStats); string fromFIle = "from " + dataFile.Replace(MyFile.exeDirectory, ""); FileInfo fileInfo = MyFile.FileInfo(dataFile); if (fileInfo != null) { fromFIle += " " + MyFile.FormatSize(fileInfo.Length); } MyLog.Add("Loaded VideoInfoStats " + fromFIle); if (videoInfoStats != null && videoInfoStats.year != null && videoInfoStats.year.Count() > 0) { ret = true; } } else { // MyLog.Add("No VideoInfoStats to load "); } stopWatch.Stop(); if (ret) { MyLog.AddElapsed(stopWatch.Elapsed); } return(ret); }
private void LoadVideos_Completed(object sender, EventArgs e) { subFormProgress.Value(0); subFormProgress.Text("Ready"); MyLog.Add("Ready"); stopwatch.Stop(); MyLog.AddElapsed("<-- in ", stopwatch.Elapsed); subFormFilterForm.Enabled = true; subFormListView.Enabled = true; subFormVideoForm.Enabled = true; subFormGallery.Enabled = true; // bubble the event up var handler = loadVideos_Completed; if (handler != null) { handler(this, e); } }
protected void BackgroundWorkerBuildGalleryImages_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { // result of scan .. continue processing .. stopwatchBuildGalleryImages.Stop(); MyLog.AddElapsed(stopwatchBuildGalleryImages.Elapsed); List <VideoInfo> videoInfos = (List <VideoInfo>)sender; if (videoInfos != null) { // set list again so get gallery thumbnails ListVideoInfo.SetList(videoInfos); MyLog.Add("Setting Gallery"); subFormProgress.Value(0); subFormProgress.Text("Setting Gallery.."); subFormGallery.SetPosters(ListVideoInfo.GetList()); } RunCalcStats(sender, e); }
public static bool Load() { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); MyLog.Add("Loading VideoItems -->"); int nbrVideoInfos; FileInfo fileInfo; CreateList(); foreach (ConfigSettings.Source source in Config.settings.sources) { string dataFile = MyFile.EnsureDataFile("videos", Config.settings.exportExt, "data", source.alias); if (dataFile == null) { continue; } // keep a backup of settings if (File.Exists(dataFile)) { fileInfo = MyFile.FileInfo(dataFile); List <VideoInfo> loadVideoInfos = (List <VideoInfo>)MyDeserialize.FromFile(Config.settings.exportFormat, dataFile, listVideoInfos); if (loadVideoInfos == null) { MyLog.Add("Unable to load VideoInfos from " + dataFile); continue; } AddItems(loadVideoInfos); string fromFile = "from " + dataFile.Replace(MyFile.exeDirectory, ""); if (fileInfo != null) { fromFile += " " + MyFile.FormatSize(fileInfo.Length); } if (loadVideoInfos == null) { nbrVideoInfos = 0; } else { nbrVideoInfos = loadVideoInfos.Count(); } MyLog.Add("Loaded " + nbrVideoInfos + " VideoItems " + fromFile); } } EnsureVideoInfos(); stopWatch.Stop(); if (listVideoInfos == null) { nbrVideoInfos = 0; } else { nbrVideoInfos = listVideoInfos.Count(); } MyLog.AddElapsed("<-- in ", stopWatch.Elapsed); bool loaded = nbrVideoInfos > 0 ? true : false; return(loaded); }
/// <summary> /// background process getting VideoInfos completed /// used for ScanSource and FilterSource /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void VideoInfos_RunWorkerCompleted(string action, string message, object sender, RunWorkerCompletedEventArgs e) { // First, handle the case where an exception was thrown. if (e.Error != null) { MyLog.Add(e.Error.ToString()); subFormProgress.Text(e.Error.Message); } else if (e.Cancelled) { // Next, handle the case where the user canceled the operation. // Note that due to a race condition in the DoWork event handler, the Cancelled // flag may not have been set, even though CancelAsync was called. subFormProgress.Text("Canceled"); } else { // Finally, handle the case where the operation succeeded. if (action == "scan") { List <VideoInfosScanSource> videoInfosScanSources = (List <VideoInfosScanSource>)e.Result; if (videoInfosScanSources == null) { MyLog.Add(message + " Null VideoItems"); MyLog.AddElapsed(stopwatch.Elapsed); LoadVideos_Completed(sender, e); return; } MyLog.Add(message); MyLog.AddElapsed(stopwatch.Elapsed); subFormProgress.Text("Applying.."); subFormProgress.Value(0); int nbrAppliedSources = 0; int nbrSourcesToApply = videoInfosScanSources.Count(); foreach (VideoInfosScanSource videoInfosScanSource in videoInfosScanSources) { MyLog.Add("Applying " + videoInfosScanSource.sourceAlias + " with " + videoInfosScanSource.videoInfos.Count().ToString() + " VideoItems"); int progress = (int)Math.Floor((decimal)(nbrSourcesToApply - nbrAppliedSources) / nbrSourcesToApply * 100); subFormProgress.Text("Applying " + videoInfosScanSource.sourceAlias + ".."); subFormProgress.Value(progress); // sources scanned less than settings, // so remove scanned sources from existing list // and replace with scanned list List <VideoInfo> currentVideoInfos = ListVideoInfo.GetList(); if (currentVideoInfos == null) { ListVideoInfo.SetList(videoInfosScanSource.videoInfos); } else { currentVideoInfos.RemoveAll(s => s.sourceAlias == videoInfosScanSource.sourceAlias); currentVideoInfos.AddRange(videoInfosScanSource.videoInfos); ListVideoInfo.SetList(currentVideoInfos); } // videoInfos = videoInfos.Union(currentVideoInfos).ToList(); nbrAppliedSources++; } } else // filter { List <VideoInfo> videoInfos = (List <VideoInfo>)e.Result; if (videoInfos == null) { MyLog.Add(message + " Null VideoItems"); MyLog.AddElapsed(stopwatch.Elapsed); LoadVideos_Completed(sender, e); return; } MyLog.Add(message + " " + videoInfos.Count().ToString() + " VideoItems"); MyLog.AddElapsed(stopwatch.Elapsed); subFormProgress.Text("Applying.."); subFormProgress.Value(0); ListVideoInfo.SetList(videoInfos); } MyLog.Add("Setting List"); subFormProgress.Value(0); subFormProgress.Text("Setting List.."); subFormListView.SetListViewInfos(ListVideoInfo.GetList()); Application.DoEvents(); // meh, not needed but allow ui redraw if (Config.settings.gallery.enable) { MyLog.Add("Building Gallery"); subFormProgress.Text("Building Gallery.."); subFormProgress.Value(0); stopwatchBuildGalleryImages = Stopwatch.StartNew(); // stopped when background worker completed // build to either create thumbnails or get existing thumbnails // will call LoadVideos_Completed() via RunCalcStats() when done buildGalleryImages.Build(ListVideoInfo.GetList()); } else { RunCalcStats(sender, e); } } }