Пример #1
0
        void scanBackgroundWorkerI_DoWork(object sender, DoWorkEventArgs e)
        {
            //do work
            scanBackgroundWorkerI.ReportProgress(0, "Loading iTunes COM object...");
            using (iTunesCOM iTCOM = new iTunesCOM())
            {
                iTCOM.iTunesQuit += new _IiTunesEvents_OnQuittingEventEventHandler(iTCOM_iTunesQuit);
                iTCOM.iTunesAboutToPromptUser += new _IiTunesEvents_OnAboutToPromptUserToQuitEventEventHandler(iTCOM_iTunesAboutToPromptUser);
                scanBackgroundWorkerI.ReportProgress(0, "Connected to iTunes.");
                int totalitems = iTCOM.TVShowPlaylist.Tracks.Count + iTCOM.MoviePlaylist.Tracks.Count + iTCOM.Tracks.Count;
                int currentitem = 1;
                if (scanBackgroundWorkerI.CancellationPending)
                {
                    return;
                }
                scanBackgroundWorkerI.ReportProgress(CalcPercentage(currentitem, totalitems), iTCOM.Tracks.Count + " \"tracks\" found.");
                scanBackgroundWorkerI.ReportProgress(CalcPercentage(currentitem, totalitems), iTCOM.Playlists.Count + " \"playlists\" found.");
                scanBackgroundWorkerI.ReportProgress(CalcPercentage(currentitem, totalitems), iTCOM.MoviePlaylist.Name + " contains movies.");
                scanBackgroundWorkerI.ReportProgress(CalcPercentage(currentitem, totalitems), iTCOM.TVShowPlaylist.Name + " contains TV shows.");
                if (scanBackgroundWorkerI.CancellationPending)
                {
                    return;
                }
                if (iTCOM.MoviePlaylist.Tracks.Count > 0)
                {
                    scanBackgroundWorkerI.ReportProgress(CalcPercentage(currentitem, totalitems), "\nMovies:");
                    foreach (IITTrack Track in iTCOM.MoviePlaylist.Tracks)
                    {

                        scanBackgroundWorkerI.ReportProgress(CalcPercentage(currentitem++, totalitems), "\t- " + Track.Name + " (" + Track.Year + ")");
                        if (scanBackgroundWorkerI.CancellationPending)
                        {
                            return;
                        }
                    }
                }
                else
                {
                    scanBackgroundWorkerI.ReportProgress(CalcPercentage(currentitem, totalitems), "\nNo Movies found.");
                }
                if (scanBackgroundWorkerI.CancellationPending)
                {
                    return;
                }
                if (iTCOM.TVShowPlaylist.Tracks.Count > 0)
                {
                    scanBackgroundWorkerI.ReportProgress(CalcPercentage(currentitem, totalitems), "\nTV Shows:");
                    foreach (IITTrack Track in iTCOM.TVShowPlaylist.Tracks)
                    {
                        if (scanBackgroundWorkerI.CancellationPending)
                        {
                            return;
                        }
                        scanBackgroundWorkerI.ReportProgress(CalcPercentage(currentitem++, totalitems), "\t- " + Track.Name + " (" + Track.Year + ")");
                    }
                }
                else
                {
                    scanBackgroundWorkerI.ReportProgress(CalcPercentage(currentitem, totalitems), "\nNo TV Shows found.");
                }
                iTCOM.iTunesQuit -= new _IiTunesEvents_OnQuittingEventEventHandler(iTCOM_iTunesQuit);
                iTCOM.iTunesAboutToPromptUser -= new _IiTunesEvents_OnAboutToPromptUserToQuitEventEventHandler(iTCOM_iTunesAboutToPromptUser);
            }
        }
Пример #2
0
        BackgroundWorker updaterBackgroudWorker = new BackgroundWorker(); //Updater BackgroundWorker

        #endregion Fields

        #region Constructors

        public MainWindow()
        {
            InitializeComponent();
            Directory.SetCurrentDirectory(currentAssemblyDirectoryName);
            Application.Current.Exit += new ExitEventHandler(Current_Exit);
            writeLine("Welcome to the " + assemblyName.Name + " v" + assemblyName.Version.Major + "." + assemblyName.Version.Minor + "." + assemblyName.Version.Build);
            #region Workers Init
            scanBackgroundWorkerF.WorkerReportsProgress = true;
            scanBackgroundWorkerF.WorkerSupportsCancellation = true;
            scanBackgroundWorkerF.DoWork += new DoWorkEventHandler(scanBackgroundWorkerF_DoWork);
            scanBackgroundWorkerF.ProgressChanged += new ProgressChangedEventHandler(scanBackgroundWorkerF_ProgressChanged);
            scanBackgroundWorkerF.RunWorkerCompleted += new RunWorkerCompletedEventHandler(scanBackgroundWorkerF_RunWorkerCompleted);
            scanBackgroundWorkerI.WorkerReportsProgress = true;
            scanBackgroundWorkerI.WorkerSupportsCancellation = true;
            scanBackgroundWorkerI.DoWork += new DoWorkEventHandler(scanBackgroundWorkerI_DoWork);
            scanBackgroundWorkerI.ProgressChanged += new ProgressChangedEventHandler(scanBackgroundWorkerI_ProgressChanged);
            scanBackgroundWorkerI.RunWorkerCompleted += new RunWorkerCompletedEventHandler(scanBackgroundWorkerI_RunWorkerCompleted);
            updaterBackgroudWorker.WorkerReportsProgress = true;
            updaterBackgroudWorker.WorkerSupportsCancellation = false;
            updaterBackgroudWorker.DoWork += new DoWorkEventHandler(updaterBackgroudWorker_DoWork);
            updaterBackgroudWorker.ProgressChanged += new ProgressChangedEventHandler(updaterBackgroudWorker_ProgressChanged);
            updaterBackgroudWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(updaterBackgroudWorker_RunWorkerCompleted);
            #endregion
            #region Config Init
            OpenConfigurationToFile();
            #endregion
            #region Windows Init
            configurationWindow = new ConfigurationWindow();
            aboutWindow = new AboutWindow();
            #endregion
            #region Config UI creation
            foreach (Entities.Tab tab in config.Tabs)
            {
                Grid grid = new Grid();
                grid.Name = "ConfigurationGrid" + tab.Identifier;
                StackPanel stackpanel = new StackPanel();
                stackpanel.Name = "ConfigurationStackpanel" + tab.Identifier;
                stackpanel.HorizontalAlignment = HorizontalAlignment.Stretch;
                stackpanel.VerticalAlignment = VerticalAlignment.Stretch;
                grid.Children.Add(stackpanel);
                foreach (Entities.Group group in tab.Groups)
                {
                    GroupBox groupbox = new GroupBox();
                    groupbox.Name = "ConfigurationGroupBox" + group.Identifier;
                    groupbox.Header = group.Name;
                    groupbox.HorizontalAlignment = HorizontalAlignment.Stretch;
                    groupbox.VerticalAlignment = VerticalAlignment.Top;
                    Grid groupgrid = new Grid();
                    groupbox.Content = groupgrid;
                    StackPanel groupstackpanel = new StackPanel();
                    groupstackpanel.Name = "ConfigurationGroupStackpanel" + tab.Identifier;
                    groupstackpanel.HorizontalAlignment = HorizontalAlignment.Stretch;
                    groupstackpanel.VerticalAlignment = VerticalAlignment.Stretch;
                    groupgrid.Children.Add(groupstackpanel);
                    foreach (Entities.Setting setting in group.Settings)
                    {
                        //add extra types of controls here
                        if (setting.Type == typeof(String))
                        {
                            Label label = new Label();
                            label.HorizontalAlignment = HorizontalAlignment.Stretch;
                            label.Content = setting.Name;
                            label.Height = 28;
                            label.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                            groupstackpanel.Children.Add(label);
                            System.Windows.Controls.TextBox textbox = new System.Windows.Controls.TextBox();
                            textbox.HorizontalAlignment = HorizontalAlignment.Stretch;
                            textbox.Text = setting.Value.ToString();
                            textbox.Name = "ConfigurationSetting" + setting.Identifier;
                            RegisterName(textbox.Name, textbox);
                            textbox.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                            groupstackpanel.Children.Add(textbox);
                            label.Target = textbox;
                        }
                        else if (setting.Type == typeof(Boolean))
                        {
                            CheckBox checkbox = new CheckBox();
                            checkbox.HorizontalAlignment = HorizontalAlignment.Stretch;
                            checkbox.Content = setting.Name;
                            checkbox.IsChecked = (Boolean)setting.Value;
                            checkbox.Name = "ConfigurationSetting" + setting.Identifier;
                            checkbox.Margin = new Thickness(5, 5, 5, 5);
                            RegisterName(checkbox.Name, checkbox);
                            checkbox.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                            groupstackpanel.Children.Add(checkbox);
                        }

                    }
                    stackpanel.Children.Add(groupbox);
                }

                TabItem tabitem = new TabItem();

                tabitem.Name = "ConfigurationTabItem" + tab.Identifier;
                tabitem.Header = tab.Name;
                tabitem.Content = grid;
                configurationWindow.ConfigurationTabs.Items.Add(tabitem);
            }
            #endregion
            #region Config Event Subscription
            configurationWindow.ButtonOK.Click += new RoutedEventHandler(ConfigurationWindow_ButtonOK_Click);
            configurationWindow.ButtonCancel.Click += new RoutedEventHandler(ConfigurationWindow_ButtonCancel_Click);

            #endregion
            #region About Event Subscription
            aboutWindow.Loaded += new RoutedEventHandler(aboutWindow_Loaded);
            #endregion
            #region Library loading
            if ((String)config.GetSetting(Setting.iTunesMediaXMLPath) == "")
            {
                using (iTunesCOM iTCOM = new iTunesCOM())
                {
                    config.SetSetting(Setting.iTunesMediaXMLPath, iTCOM.GetiTunesMediaXMLPath());
                }
            }
            OpenLibrary();
            writeLine(String.Format("{0} Movies; {1} TVShows; {2} Mediafiles;", library.Movies.Rows.Count, library.TVShows.Rows.Count, library.MediaFileTargets.Rows.Count));
            #endregion
        }