public GetArg ( string argument1, string argument2 ) : string | ||
argument1 | string | |
argument2 | string | |
return | string |
/// <summary> /// Executes the event sub-command. /// </summary> static void EventCommand(string[] args) { string id = OptionLast(args); string[] options = OptionTrim(args); ArgvParser parser = new ArgvParser(options); if (!GlobalParametersLoad(parser)) { return; } Vuzit.OptionList list = new Vuzit.OptionList(); if (parser.GetArg("e", "event") != null) { list.Add("event", parser.GetArg("e", "event")); } if (parser.GetArg("c", "custom") != null) { list.Add("custom", parser.GetArg("c", "custom")); } if (parser.GetArg("l", "limit") != null) { list.Add("limit", parser.GetArg("l", "limit")); } if (parser.GetArg("o", "offset") != null) { list.Add("offset", parser.GetArg("o", "offset")); } Vuzit.Event[] events = null; try { events = Vuzit.Event.FindAll(id, list); } catch(Exception ex) { Console.WriteLine("Load failed: " + ex.Message); return; } int i = 1; Console.WriteLine("{0} events found", events.Length); Console.WriteLine(""); string format = "{0:yyyy-MM-dd HH:mm:ss}"; foreach (Vuzit.Event e in events) { Console.Write("[" + String.Format(format, e.RequestedAt) + "] "); if (e.EventType == "page_view") { Console.Write(e.Duration + "s -"); } Console.Write(e.EventType); if (e.Page != -1) { Console.Write(", p" + e.Page); } if (e.Custom != null) { Console.Write(" (" + e.Custom + ")"); } if (e.Referer != null) { Console.Write(" - " + e.Referer.Substring(7, 8)); } Console.Write(" - " + e.RemoteHost); Console.Write(" - " + e.UserAgent.Substring(0, 8)); Console.WriteLine(""); i++; } }
/// <summary> /// Executes the search sub-command. /// </summary> static void SearchCommand(string[] args) { string[] options = OptionRemoveFirst(args); ArgvParser parser = new ArgvParser(options); if (!GlobalParametersLoad(parser)) { return; } Vuzit.OptionList list = new Vuzit.OptionList(); if (parser.GetArg("q", "query") != null) { list.Add("query", parser.GetArg("q", "query")); } if (parser.GetArg("l", "limit") != null) { list.Add("limit", parser.GetArg("l", "limit")); } if (parser.GetArg("o", "offset") != null) { list.Add("offset", parser.GetArg("o", "offset")); } if (parser.GetArg("O", "output") != null) { list.Add("output", parser.GetArg("O", "output")); } Vuzit.Document[] documents = Vuzit.Document.FindAll(list); int i = 1; Console.WriteLine("{0} documents found", documents.Length); Console.WriteLine(""); foreach (Vuzit.Document document in documents) { Console.WriteLine("LOADED [{0}]: {1}", i, document.Id); if (document.PageCount != -1) { Console.WriteLine("title: {0}", document.Title); Console.WriteLine("pages: {0}", document.PageCount); Console.WriteLine("size: {0}", document.FileSize); Console.WriteLine("excerpt: {0}", document.Excerpt); Console.WriteLine("Download URL: {0}", Vuzit.Document.DownloadUrl(document.Id, "pdf")); Console.WriteLine(""); } i++; } }
/// <summary> /// Loads the global parameters. If they were not correctly added then it fails. /// </summary> /// <param name="parser"></param> /// <returns></returns> static bool GlobalParametersLoad(ArgvParser parser) { string key = parser.GetArg("k", "keys"); if (key == null) { Console.WriteLine("Must provide the --key parameter"); return false; } string[] keys = key.Split(','); if (keys.Length != 2) { Console.WriteLine("ERROR: Please provide both --key parameters (PUBLIC,PRIVATE)"); Console.WriteLine(""); PrintUsageGeneral(); } Vuzit.Service.PublicKey = keys[0]; Vuzit.Service.PrivateKey = keys[1]; Vuzit.Service.UserAgent = "VuzitCL .NET 2.1.0"; if(parser.GetArg("u", "service-url") != null) { Vuzit.Service.ServiceUrl = parser.GetArg("u", "service-url"); } return true; }
/// <summary> /// Executes the page sub-command. /// </summary> static void PageCommand(string[] args) { string id = OptionLast(args); string[] options = OptionTrim(args); ArgvParser parser = new ArgvParser(options); if (!GlobalParametersLoad(parser)) { return; } Vuzit.OptionList list = new Vuzit.OptionList(); if (parser.GetArg("i", "included") != null) { list.Add("included_pages", parser.GetArg("i", "included")); } if (parser.GetArg("l", "limit") != null) { list.Add("limit", parser.GetArg("l", "limit")); } if (parser.GetArg("o", "offset") != null) { list.Add("offset", parser.GetArg("o", "offset")); } Vuzit.Page[] pages = null; try { pages = Vuzit.Page.FindAll(id, list); } catch (Exception ex) { Console.WriteLine("Load failed: " + ex.Message); return; } Console.WriteLine("{0} pages found", pages.Length); Console.WriteLine(""); foreach (Vuzit.Page page in pages) { Console.WriteLine("Page: " + page.Number); Console.WriteLine(page.Text); Console.WriteLine(""); } }