Class for parsing command-line arguments.
Пример #1
0
        /// <summary>
        /// Executes the delete sub-command.  
        /// </summary>
        static void DeleteCommand(string[] args)
        {
            string id = OptionLast(args);
            string[] options = OptionTrim(args);
            ArgvParser parser = new ArgvParser(options);

            if (!GlobalParametersLoad(parser))
            {
                return;
            }

            Vuzit.Document.Destroy(id);
            Console.WriteLine("DELETED: {0}", id);
        }
Пример #2
0
        /// <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++;
            }
        }
Пример #3
0
        /// <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;
        }
Пример #4
0
        /// <summary>
        /// Executes the upload sub-command.  
        /// </summary>
        static void UploadCommand(string[] args)
        {
            string path = OptionLast(args);
            string[] options = OptionTrim(args);
            ArgvParser parser = new ArgvParser(options);

            if (!GlobalParametersLoad(parser))
            {
                return;
            }

            Vuzit.OptionList list = new Vuzit.OptionList();

            // TODO: Use GetArg function?
            if (parser["s"] != null || parser["secure"] != null)
            {
                list.Add("secure", true);
            }
            else
            {
                list.Add("secure", false);
            }

            if (parser["p"] != null || parser["download-pdf"] != null)
            {
                list.Add("download_pdf", true);
            }

            if (parser["d"] != null || parser["download-document"] != null)
            {
                list.Add("download_document", true);
            }

            Vuzit.Document document = Vuzit.Document.Upload(path, list);
            Console.WriteLine("UPLOADED: {0}", document.Id);
        }
Пример #5
0
        /// <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++;
            }
        }
Пример #6
0
        /// <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("");
            }
        }
Пример #7
0
        /// <summary>
        /// Executes the load command.  
        /// </summary>
        static void LoadCommand(string[] args)
        {
            string id = OptionLast(args);
            string[] options = OptionTrim(args);
            ArgvParser parser = new ArgvParser(options);

            if (!GlobalParametersLoad(parser))
            {
                return;
            }
            
            Vuzit.Document document = Vuzit.Document.Find(id);
            Console.WriteLine("LOADED: {0}", document.Id);
            Console.WriteLine("title: {0}", document.Title);
            Console.WriteLine("subject: {0}", document.Subject);
            Console.WriteLine("pages: {0}", document.PageCount);
            Console.WriteLine("width: {0}", document.PageWidth);
            Console.WriteLine("height: {0}", document.PageHeight);
            Console.WriteLine("size: {0}", document.FileSize);
            Console.WriteLine("status: {0}", document.Status);

            Console.WriteLine("Download URL: {0}", Vuzit.Document.DownloadUrl(id, "pdf"));
        }