/// <summary> /// This is the entry point into the DLL. It parses the command line and /// delegates the work out to each program. /// </summary> /// <param name="commandLine">The commandline that invoked the program. Usually /// this corresponds to System.Environment.CommandLine</param> /// <returns></returns> public static void DllMain(string commandLine) { CommandLine = new CommandLine(); Parser parser = new Parser(commandLine, CommandLine); parser.Parse(); if(CommandLine.Help) { Console.WriteLine("This program is used to import blog data from other blogging programs."); Console.WriteLine(" Note that this program will modify your content directory so back it up."); Console.WriteLine(" Also, the program will require an internet connection in some instances, "); Console.WriteLine(" like importing comments from an external server."); Console.WriteLine( parser.GetHelpText() ); } else { switch(CommandLine.Source) { case BlogSourceType.Radio: if(CommandLine.SourceDirectory != null && CommandLine.SourceDirectory.Length > 0 && CommandLine.ContentDirectory != null && CommandLine.ContentDirectory.Length > 0) { Console.WriteLine("Importing entries from Radio..."); DasBlog.Import.Radio.EntryImporter.Import( CommandLine.SourceDirectory, CommandLine.ContentDirectory); } else { Console.WriteLine("Entries from Radio not imported because either source directory or content directory were not specified."); } if(CommandLine.UserID != null && CommandLine.UserID.Length > 0 && CommandLine.ContentDirectory != null && CommandLine.ContentDirectory.Length > 0) { if(CommandLine.CommentServer != null && CommandLine.CommentServer.Length > 0) { Console.WriteLine("Defaulting to comment server {0}. You may need to check your radio source. radiocomments2, etc",DasBlog.Import.Radio.CommentImporter.DefaultCommentServer); } Console.WriteLine("BETA: Importing comments from Radio..."); DasBlog.Import.Radio.CommentImporter.Import( CommandLine.UserID, CommandLine.ContentDirectory, CommandLine.CommentServer ); } else { Console.WriteLine("Comments from Radio not imported because comment server, userid or content directory were not specified."); } break; case BlogSourceType.none: goto default; default: throw new ApplicationException( string.Format("The source option was not specified or else was invalid.")); } } }
public void GetHelpText() { string expectedText = "DummyProgramName.exe [/SourceType:Radio] [/{ContentDir|to}] [/{SourceDir|from}] [/Help] \n\n" + " /SourceType -Specify the blog program from which to import content.\n" + " /ContentDir -The DasBlog content directory into which the entries are placed.\n" + " Aliases: to\n" + " /SourceDir -The source directory from which content will be imported.\n" + " Aliases: from\n" + " /Help -Displays the command line help.\n"; CommandLine commandLine= new CommandLine(); Parser parser = new Parser("DummyProgramName.exe /Help", commandLine); parser.Parse(); Console.WriteLine("Actual:\n" + parser.GetHelpText()); Console.WriteLine("\nExpected:\n" + expectedText); Assert.IsTrue(commandLine.Help, "The CommandLine was unexpectedly not set to true when using the '/Help' parameters."); Assert.AreEqual( expectedText, parser.GetHelpText(), "The help text returned was not as expected."); }