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;
            }
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        /// <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);
                }
            }
        }