Exemple #1
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();
                }
            }
        }
Exemple #2
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);
        }