private void buttonRemoveSource_Click(object sender, EventArgs e) { MyFormField.DelayButtonClick(buttonRemoveSource); if (currentSource == null) { return; } string message = "Are you sure you want to remove this Video Source?" + Environment.NewLine; message += "Alias: " + currentSource.alias + Environment.NewLine; message += "Type: " + currentSource.type + Environment.NewLine; message += "Directory: " + currentSource.directory + Environment.NewLine; string lastScanned = currentSource.lastScanned.ToLocalTime().ToString(); if (currentSource.lastScanned == DateTime.MinValue) { lastScanned = "Not yet"; } message += "Last Scanned: " + lastScanned + Environment.NewLine; if (MessageBox.Show(message, "Confirm Removal", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes) { listViewSource.SelectedItems[0].Remove(); // remove entry from settings Config.settings.sources.Remove(currentSource); List <VideoInfo> currentVideoInfos = ListVideoInfo.GetList(); int nbrOrigVideoInfos = currentVideoInfos.Count(); currentVideoInfos.RemoveAll(s => s.sourceAlias == currentSource.alias); int nbrRemovedVideoInfos = nbrOrigVideoInfos - currentVideoInfos.Count(); ListVideoInfo.SetList(currentVideoInfos); // meh, but works FormMain formMain = (FormMain)this.Owner; SubFormListView subFormListView = formMain.GetSubFormListView(); subFormListView.SetListViewInfos(ListVideoInfo.GetList()); MyLog.Add("Removed " + currentSource.alias + " and it's " + nbrRemovedVideoInfos + " VideoItems"); // datatable xml will be updated on main form close // settings xml will be updated on main form close currentSource = null; buttonRemoveSource.Enabled = false; } }
public void RunCalcStats(object sender, RunWorkerCompletedEventArgs e) { MyLog.Add("Setting Stats"); subFormProgress.Value(0); subFormProgress.Text("Setting Stats.."); if (!CalcVideoInfoStats.Load()) { stopwatchCalcStats = Stopwatch.StartNew(); // stopped when background worker completed calcVideoInfoStats.Calc(ListVideoInfo.GetList()); } else { LoadVideos_Completed(sender, e); } }
private int CalcStatsForSource(string sourceAlias) { List <VideoInfo> listVideoInfos = ListVideoInfo.GetList(); if (listVideoInfos == null) { return(0); } listVideoInfos = listVideoInfos.FindAll(x => x.sourceAlias == sourceAlias).ToList(); if (listVideoInfos == null) { return(0); } int nbrVideos = listVideoInfos.Where(x => x.files != null && x.files.video != null).Count(); return(nbrVideos); }
/// <summary> /// load videos from disk into list /// </summary> public void FilterListView() { stopwatch = Stopwatch.StartNew(); // stopped when background worker completed FilterInfo filterInfo = subFormFilterForm.GetFilterForm(); subFormListView.listViewColumnSorter.sortColumnIndex = FilterEnums.sortColumn.GetValueByKey(filterInfo.sortColumn); subFormListView.listViewColumnSorter.sortOrderIndex = filterInfo.sortOrderIndex; subFormFilterForm.Enabled = false; subFormListView.Enabled = false; subFormVideoForm.Enabled = false; subFormGallery.Enabled = false; MyLog.Add("Filter sources -->"); // since static, no need to pass in .. but has allowed for conatiner to be replaced .. tree, datatabel, etc backgroundWorkerFilterSource.Run(ListVideoInfo.GetList(), filterInfo); }
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); }
private void CalcStatsForSource(ConfigSettings.Source source) { List <VideoInfo> listVideoInfos = ListVideoInfo.GetList(); if (listVideoInfos == null) { return; } listVideoInfos = listVideoInfos.FindAll(x => x.sourceAlias == source.alias).ToList(); if (listVideoInfos == null) { return; } int nbrVideos = listVideoInfos.Where(x => x.files != null && x.files.video != null).Count(); // int nbrPosters = listVideoInfos.Where(x => x.files != null && x.files.poster != null).Count(); // int nbrFanarts = listVideoInfos.Where(x => x.files != null && x.files.fanart != null).Count(); // int nbrImages = listVideoInfos.Where(x => x.files != null && x.files.images != null).Count(); // int nbrMBs = listVideoInfos.Where(x => x.files != null && x.files.mb != null).Count(); // int nbrMVEs = listVideoInfos.Where(x => x.files != null && x.files.mve != null).Count(); // int nbrXBMCs = listVideoInfos.Where(x => x.files != null && x.files.xbmc != null).Count(); // int nbrOthers = listVideoInfos.Where(x => x.files != null && x.files.others != null).Count(); int nbrFiles = listVideoInfos.Where(x => x.files != null).Sum(x => x.files.qty); // int nbrNonVideos = nbrImages + nbrMBs + nbrMVEs + nbrXBMCs + nbrOthers; int nbrNonVideos = nbrFiles - nbrVideos; labelVideoFileQty.Text = nbrVideos.ToString(); labelOtherFilesQty.Text = nbrNonVideos.ToString(); }
public static bool ThumbnailsAlreadySet() { List <VideoInfo> videoInfos = ListVideoInfo.GetList(); int nbrThumbnails = videoInfos.Where(x => x.files.posterThumbnail != null).Count(); long thumbnailCachesize = MyFile.DirectorySize(@"cache\gallery", "poster*.jpg"); bool thumbnailsSet; // if thumbnails set in list (nbrThumbnails > 0), but cache empty (thumbnailCachesize == 0) // assume intent is to rebuild app thumbnails, so thumbnailsSet = false // so thumbnails set only if set in list and set in cache if (nbrThumbnails > 0 && thumbnailCachesize > 0) { thumbnailsSet = true; } else { thumbnailsSet = false; } return(thumbnailsSet); }
/// <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); } } }