コード例 #1
0
        private void StartImport(int pluginID)
        {
            Cursor = Cursors.WaitCursor;
            this.Refresh();

            OMLPlugin plugin = new OMLPlugin();

            plugin = _importPlugins[pluginID];
            //plugin.FileFound += new OMLPlugin.FileFoundEventHandler(FileFound);
            //if (plugin.CanCopyImages) AskIfShouldCopyImages();
            plugin.CopyImages = true;// Program._copyImages;

            string[] work = plugin.GetWork();
            if (work != null)
            {
                plugin.DoWork(work);
                LoadTitlesIntoDatabase(plugin);
            }

            Cursor = Cursors.Default;
            this.Refresh();
            string[] nonFatalErrors = plugin.GetErrors;
            if (nonFatalErrors.Length > 0)
            {
                ShowNonFatalErrors(nonFatalErrors);
            }
        }
コード例 #2
0
        public Importer(OMLPlugin _importer)
        {
            InitializeComponent();

            sbOK.Enabled     = false;
            sbCancel.Enabled = false;

            importer = _importer;

            // Present the folder/file select dialog.
            work = importer.GetWork();


            if (work != null)
            {
                backgroundWorker1.WorkerReportsProgress      = true;
                backgroundWorker1.WorkerSupportsCancellation = true;
                backgroundWorker1.RunWorkerAsync();
                sbCancel.Enabled = true;
            }
            else
            {
                lbStatus.Text = "Cancelled";
                sbOK.Enabled  = true;
            }
        }
コード例 #3
0
        private static void LoadPlugins()
        {
            List <PluginServices.AvailablePlugin> pluginz =
                PluginServices.FindPlugins(FileSystemWalker.PluginsDirectory, typeof(IOMLPlugin).Name);

            // Loop through available plugins, creating instances and adding them
            foreach (PluginServices.AvailablePlugin oPlugin in pluginz)
            {
                OMLPlugin objPlugin = (OMLPlugin)PluginServices.CreateInstance(oPlugin);
                objPlugin.FileFound += new OMLPlugin.FileFoundEventHandler(FileFound);
                plugins.Add(objPlugin);
            }
        }
コード例 #4
0
        public static DialogResult GetFile(ref string file_to_import, OMLPlugin plugin)
        {
            OpenFileDialog ofDiag = new OpenFileDialog();

            ofDiag.InitialDirectory   = "c:\\";
            ofDiag.Filter             = "Xml files (*.xml)|*.xml|DVR-MS Files (*.dvr-ms)|*.dvr-ms|All files (*.*)|*.*";
            ofDiag.FilterIndex        = 1;
            ofDiag.RestoreDirectory   = true;
            ofDiag.AutoUpgradeEnabled = true;
            ofDiag.CheckFileExists    = true;
            ofDiag.CheckPathExists    = true;
            ofDiag.Multiselect        = false;
            ofDiag.Title = "Select " + plugin.Name + " file to import";
            DialogResult dlgRslt = ofDiag.ShowDialog();

            if (dlgRslt == DialogResult.OK)
            {
                Utilities.DebugLine("[OMLImporter] Valid file found (" + ofDiag.FileName + ")");
                file_to_import = ofDiag.FileName;
            }
            return(dlgRslt);
        }
コード例 #5
0
        public void LoadTitlesIntoDatabase(OMLPlugin plugin)
        {
            try
            {
                Utilities.DebugLine("[OMLImporter] Titles loaded, beginning Import process");
                //TitleCollection tc = new TitleCollection();
                IList <Title> titles = plugin.GetTitles();
                Utilities.DebugLine("[OMLImporter] " + titles.Count + " titles found in input file");
                //Console.WriteLine("Found " + titles.Count + " titles");

                int  numberOfTitlesAdded   = 0;
                int  numberOfTitlesSkipped = 0;
                bool YesToAll = true;// false;

                //if (Console.In.Peek() > 0)
                //    Console.In.ReadToEnd(); // flush out anything still in there

                foreach (Title t in titles)
                {
                    if (_titleCollection.ContainsDisks(t.Disks))
                    {
                        //Console.WriteLine("Title {0} skipped because already in the collection", t.Name);
                        numberOfTitlesSkipped++;
                        continue;
                    }


                    //Console.WriteLine("Adding: " + t.Name);
                    if (YesToAll == false)
                    {
                        /*Console.WriteLine("Would you like to add this title? (y/n/a)");
                         * string response = Console.ReadLine();
                         * switch (response.ToUpper())
                         * {
                         *  case "Y":
                         *      mainTitleCollection.Add(t);
                         *      numberOfTitlesAdded++;
                         *      break;
                         *  case "N":
                         *      numberOfTitlesSkipped++;
                         *      break;
                         *  case "A":
                         *      YesToAll = true;
                         *      mainTitleCollection.Add(t);
                         *      numberOfTitlesAdded++;
                         *      break;
                         *  default:
                         *      break;
                         * }*/
                    }
                    else
                    {
                        OMLPlugin.BuildResizedMenuImage(t);
                        _titleCollection.Add(t);
                        numberOfTitlesAdded++;
                        tvSourceList_AddItem(t.Name, t.InternalItemID.ToString(), "Movies");
                    }
                }

                MessageBox.Show("Added " + numberOfTitlesAdded + " titles\nSkipped " + numberOfTitlesSkipped + " titles\n", "Import Results");

                plugin.GetTitles().Clear();

                /*if (numberOfTitlesAdded > 0) isDirty = true;
                 * Console.WriteLine();
                 * Console.WriteLine("Added " + numberOfTitlesAdded + " titles");
                 * Console.WriteLine("Skipped " + numberOfTitlesSkipped + " titles");*/
            }
            catch (Exception e)
            {
                MessageBox.Show("Exception in LoadTitlesIntoDatabase: %1", e.Message);
                //Console.WriteLine("Exception in LoadTitlesIntoDatabase: %1", e.Message);
            }
            //tc.saveTitleCollection();
            //Console.WriteLine("Complete");
        }
コード例 #6
0
        public void LoadTitlesIntoDatabase(OMLPlugin plugin)
        {
            bool Cancelled = false;

            try
            {
                Utilities.DebugLine("[OMLImporter] Titles loaded, beginning Import process");
                IList <Title> titles = OMLSDK.SDKUtilities.ConvertOMLSDKTitlesToTitles(plugin.GetTitles());
                Utilities.DebugLine("[OMLImporter] " + titles.Count + " titles found in input file");

                int totalNumberOfTitles   = 0;
                int numberOfTitlesAdded   = 0;
                int numberOfTitlesSkipped = 0;

                bool YesToAll = true;// false;

                foreach (Title t in titles)
                {
                    if (backgroundWorker1.CancellationPending)
                    {
                        // Abort the operation
                        Cancelled = true;
                        break;
                    }

                    backgroundWorker1.ReportProgress(100 * totalNumberOfTitles / titles.Count, "Saving title : " + t.Name);

                    totalNumberOfTitles++;

                    if (TitleCollectionManager.ContainsDisks(t.Disks))
                    {
                        numberOfTitlesSkipped++;
                        continue;
                    }

                    if (!YesToAll)
                    {
                        //TODO: Need to show a UI that let's the User decide whether to import all titles or be selective about it

                        /*Console.WriteLine("Would you like to add this title? (y/n/a)");
                         * string response = Console.ReadLine();
                         * switch (response.ToUpper())
                         * {
                         *  case "Y":
                         *      mainTitleCollection.Add(t);
                         *      numberOfTitlesAdded++;
                         *      break;
                         *  case "N":
                         *      numberOfTitlesSkipped++;
                         *      break;
                         *  case "A":
                         *      YesToAll = true;
                         *      mainTitleCollection.Add(t);
                         *      numberOfTitlesAdded++;
                         *      break;
                         *  default:
                         *      break;
                         * }*/
                    }
                    else
                    {
                        TitleCollectionManager.AddTitle(t);
                        numberOfTitlesAdded++;
                    }
                }

                backgroundWorker1.ReportProgress(100, "Finalising...");

                TitleCollectionManager.SaveTitleUpdates();

                if (Cancelled)
                {
                    backgroundWorker1.ReportProgress(100, "Cancelled : Added " + numberOfTitlesAdded + "  Skipped " + numberOfTitlesSkipped);
                }
                else
                {
                    backgroundWorker1.ReportProgress(100, "Complete : Added " + numberOfTitlesAdded + "  Skipped " + numberOfTitlesSkipped);
                }

                plugin.GetTitles().Clear();
            }
            catch (Exception e)
            {
                XtraMessageBox.Show("Exception in LoadTitlesIntoDatabase: {0}", e.Message);
                Utilities.DebugLine("[OMLImporter] Exception in LoadTitlesIntoDatabase: " + e.Message);
            }
        }
コード例 #7
0
        public void BeginLoading()
        {
            OMLApplication.DebugLine("Start loading new titles");
            plugin = GetPlugin();

            Application.DeferredInvokeOnWorkerThread(delegate
            {
                OMLApplication.DebugLine("[Setup UI] _BeginLoading called");
                LoadStarted = true;
                try
                {
                    for (int i = 0; i <= _treeView.CheckedNodes.Count - 1; i++)
                    {
                        OMLApplication.DebugLine("[Setup UI] Found a node");
                        TreeNode node = (TreeNode)_treeView.CheckedNodes[i];
                        if (node != null)
                        {
                            OMLApplication.DebugLine("[Setup UI] Scanning node: " + node.FullPath);
                            if (plugin.IsSingleFileImporter())
                            {
                                string fileNameToFind = plugin.DefaultFileToImport();
                                if (fileNameToFind != null)
                                {
                                    OMLApplication.DebugLine("[Setup UI] Looking for file: " + fileNameToFind);
                                    if (Directory.Exists(node.FullPath))
                                    {
                                        DirectoryInfo dirInfo = new DirectoryInfo(node.FullPath);
                                        if (dirInfo != null)
                                        {
                                            FileInfo[] fileInfos = dirInfo.GetFiles(fileNameToFind, SearchOption.TopDirectoryOnly);
                                            foreach (FileInfo fInfo in fileInfos)
                                            {
                                                OMLApplication.DebugLine("[Setup UI] File Found: " + fInfo.Name);
                                                plugin.DoWork(new string[] { fInfo.FullName });
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                OMLApplication.DebugLine("[Setup UI] Processing path: " + node.FullPath);
                                plugin.DoWork(new string[] { node.FullPath });
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    OMLApplication.DebugLine("[Setup UI] Error finding file: " + e.Message);
                }
            },
                                                     delegate
            {
                OMLApplication.DebugLine("[Setup UI] _LoadingComplete called");
                LoadComplete = true;
                _titles      = plugin.GetTitles();

                if (_titles.Count > 0)
                {
                    TotalTitlesFound  = _titles.Count;
                    CurrentTitleIndex = 0;
                    CurrentTitle      = _titles[CurrentTitleIndex];
                }
            }, null);
        }
コード例 #8
0
        public static void Menu()
        {
            OMLPlugin plugin         = null;
            string    file_to_import = string.Empty;

            Console.WriteLine("Loading current titles...");
            //mainTitleCollection.loadTitleCollection();
            IEnumerable <Title> allTitles = TitleCollectionManager.GetAllTitles();

            while (true)
            {
                plugin = null;
                Console.Clear();
                PrintHeader();
                Console.WriteLine("OML Importer: Current {0} titles in the database", allTitles.Count());
                Console.WriteLine("Which Importer would you like to use:");
                int ii;
                for (ii = 0; ii < plugins.Count; ii++)
                {
                    OMLPlugin pi   = plugins[ii];
                    string    sFmt = "{0}) {1} (v{2})";
                    Console.WriteLine(string.Format(sFmt, (ii + 1), pi.Menu, pi.Version));
                }
                //foreach (OMLPlugin pi in plugins)
                //{
                //    Console.WriteLine(string.Format("{0}) {1} (v{2})", ii++, pi.Name, pi.Version));
                //}
                ii++;
                //Console.WriteLine(String.Format("{0}) Save the New Titles", ii++));
                Console.WriteLine(String.Format("{0}) Quit", ii++));
                Console.WriteLine(String.Format("{0}) Remove all titles from the database (be carefull!!!)", ii++));
                Console.WriteLine();
                Console.Write("Choice: ");

                string response = Console.ReadLine();
                if (response.Length == 0)
                {
                    continue;
                }

                //response = response.Substring(0, 1);
                Int32 iResp;
                if (!Int32.TryParse(response, out iResp))
                {
                    continue;
                }
                if (!(0 < iResp && iResp < ii))
                {
                    continue;
                }
                --iResp;
                if (iResp < plugins.Count)
                {
                    plugin = plugins[iResp];

                    DateTime startTime = DateTime.Now;
                    Console.WriteLine("Begin time: " + startTime);

                    plugin.DoWork(plugin.GetWork());
                    LoadTitlesIntoDatabase(plugin, true, true);

                    Console.WriteLine("End time: " + DateTime.Now.ToString() + " Total seconds: " + (DateTime.Now - startTime).TotalSeconds);

                    Console.WriteLine("Done!");
                    Console.ReadLine();
                }

                /*else if (iResp == (plugins.Count))
                 * {
                 *  if (isDirty)
                 *  {
                 *      Console.WriteLine("Adding Titles ...");
                 *      isDirty = !mainTitleCollection.saveTitleCollection();
                 *  }
                 *  Console.WriteLine("Complete!");
                 * } */
                else if (iResp == (plugins.Count))
                {
                    /*if (isDirty)
                     * {
                     *  Console.WriteLine("You have not saved your changes. Do you want to save before quitting? (y/n)");
                     *  string answer = Console.ReadLine();
                     *  if (answer.ToUpper() == "Y")
                     *  {
                     *      Console.WriteLine("Adding Titles ...");
                     *      mainTitleCollection.saveTitleCollection();
                     *      isDirty = false;
                     *  }
                     * }*/
                    Console.WriteLine("Complete!");
                    return;
                }
                else if (iResp == (plugins.Count + 1))
                {
                    Console.WriteLine("This option will delete all titles from the database immediately! This operation CANNOT be undone!");
                    Console.WriteLine("Are you sure you want to delete all the titles from the database? (please type YES)");
                    string deleteAllAnswer = Console.ReadLine();
                    if (deleteAllAnswer == "YES")
                    {
                        Console.WriteLine("Removing all entries...(this can take awhile)");
                        //mainTitleCollection = new TitleCollection();
                        //mainTitleCollection.saveTitleCollection();
                        TitleCollectionManager.DeleteAllDBData();
                        //isDirty = false;
                        Console.WriteLine("Done!");
                    }
                    else
                    {
                        Console.WriteLine("Operation aborted. No titles have been deleted!");
                    }
                }
                else
                {
                    Usage();
                }
            }
        }
コード例 #9
0
        public static void LoadTitlesIntoDatabase(OMLPlugin plugin, bool flushInputBuffer, bool autoYesToAll)
        {
            try
            {
                Utilities.DebugLine("[OMLImporter] Titles loaded, beginning Import process");
                //TitleCollection tc = new TitleCollection();
                IList <Title> titles = OMLSDK.SDKUtilities.ConvertOMLSDKTitlesToTitles(plugin.GetTitles());
                Utilities.DebugLine("[OMLImporter] " + titles.Count + " titles found in input file");
                Console.WriteLine("Found " + titles.Count + " titles");

                int  numberOfTitlesAdded   = 0;
                int  numberOfTitlesSkipped = 0;
                bool YesToAll = autoYesToAll;

                if (flushInputBuffer && Console.In.Peek() > 0)
                {
                    Console.In.ReadToEnd(); // flush out anything still in there
                }
                foreach (Title t in titles)
                {
                    if (TitleCollectionManager.ContainsDisks(t.Disks))
                    {
                        Console.WriteLine("Title {0} skipped because already in the collection", t.Name);
                        numberOfTitlesSkipped++;
                        continue;
                    }


                    Console.WriteLine("Adding: " + t.Name);
                    if (YesToAll == false)
                    {
                        Console.WriteLine("Would you like to add this title? (y/n/a)");
                        string response = Console.ReadLine();
                        switch (response.ToUpper())
                        {
                        case "Y":
                            TitleCollectionManager.AddTitle(t);
                            numberOfTitlesAdded++;
                            break;

                        case "N":
                            numberOfTitlesSkipped++;
                            break;

                        case "A":
                            YesToAll = true;
                            TitleCollectionManager.AddTitle(t);
                            numberOfTitlesAdded++;
                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        TitleCollectionManager.AddTitle(t);
                        numberOfTitlesAdded++;
                    }
                }

                // save all the image updates
                TitleCollectionManager.SaveTitleUpdates();

                plugin.GetTitles().Clear();

                //if (numberOfTitlesAdded > 0) isDirty = true;
                Console.WriteLine();
                Console.WriteLine("Added " + numberOfTitlesAdded + " titles");
                Console.WriteLine("Skipped " + numberOfTitlesSkipped + " titles");
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception in LoadTitlesIntoDatabase: {0}", e.Message);
            }
            //tc.saveTitleCollection();
            //Console.WriteLine("Complete");
        }
コード例 #10
0
 public static bool ImportFile(OMLPlugin plugin, string fileName)
 {
     return(plugin.Load(fileName));
 }
コード例 #11
0
        private static void FileFound(object sender, OMLSDK.PlugInFileEventArgs e)
        {
            OMLPlugin plugin = (OMLPlugin)sender;

            Console.WriteLine("Loading file " + e.FileName + " using " + plugin.Name + " importer");
        }
コード例 #12
0
        private static bool ProcessCommandLine(string [] args)
        {
            OMLPlugin pluginToUse       = null;
            string    pluginName        = args[0].Trim();
            bool      copyImages        = true;
            string    path              = null;
            bool      clearBeforeImport = false;

            if (args.Length > 1)
            {
                path = args[1];
            }
            else
            {
                return(false);
            }

            for (int i = 2; i < args.Length; i++)
            {
                if (args[i].StartsWith(COPY_IMAGES_KEY, StringComparison.OrdinalIgnoreCase))
                {
                    if (!bool.TryParse(args[i].Substring(COPY_IMAGES_KEY.Length), out copyImages))
                    {
                        return(false);
                    }
                }
                else if (args[i].StartsWith(CLEAR_BEFORE_IMPORT_KEY, StringComparison.OrdinalIgnoreCase))
                {
                    if (!bool.TryParse(args[i].Substring(CLEAR_BEFORE_IMPORT_KEY.Length), out clearBeforeImport))
                    {
                        return(false);
                    }
                }
                else // command line argument not understood
                {
                    return(false);
                }
            }

            // Loop through available plugins to find the new we need to create
            foreach (PluginServices.AvailablePlugin plugin in
                     PluginServices.FindPlugins(FileSystemWalker.PluginsDirectory, "OMLSDK.IOMLPlugin"))
            {
                if (plugin.ClassName.Equals(pluginName, StringComparison.OrdinalIgnoreCase))
                {
                    pluginToUse            = (OMLPlugin)PluginServices.CreateInstance(plugin);
                    pluginToUse.FileFound += new OMLPlugin.FileFoundEventHandler(FileFound);
                }
            }

            if (pluginToUse == null)
            {
                Console.WriteLine(pluginName + " was not found as a plugin. The valid plugins are:");
                Console.WriteLine("");
                foreach (PluginServices.AvailablePlugin plugin in
                         PluginServices.FindPlugins(FileSystemWalker.PluginsDirectory, typeof(IOMLPlugin).Name))
                {
                    Console.WriteLine(plugin.ClassName);
                }
            }
            else
            {
                // use the found plugin
                if (pluginToUse.IsSingleFileImporter() && !File.Exists(path))
                {
                    Console.WriteLine(pluginToUse.Name + " requires an import file which it can't find (" + path + ")");
                }
                else if (!pluginToUse.IsSingleFileImporter() && !Directory.Exists(path))
                {
                    Console.WriteLine(pluginToUse.Name + " requires an import directory which can't be found (" + path + ")");
                }
                else
                {
                    if (clearBeforeImport)
                    {
                        Console.WriteLine("Clearing out old data before import ( this can take awhile )");
                        TitleCollectionManager.DeleteAllDBData();
                    }

                    Console.WriteLine("Beginning to import titles...");

                    pluginToUse.DoWork(new string[] { path });
                    LoadTitlesIntoDatabase(pluginToUse, false, true);
                }
            }

            return(true);
        }