コード例 #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
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            backgroundWorker1.ReportProgress(0, "Starting");

            //string[] work = importer.GetWork();
            if (work != null)
            {
                backgroundWorker1.ReportProgress(0, "Scanning titles");
                importer.DoWork(work);
                backgroundWorker1.ReportProgress(0, "Saving titles");
                LoadTitlesIntoDatabase(importer);
            }
        }
コード例 #3
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();
                }
            }
        }
コード例 #4
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);
        }
コード例 #5
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);
        }