Пример #1
0
        /// <summary>
        /// Quick mode. Input from cmd line args.
        /// </summary>
        /// <param name="argsIn">cmd line args</param>
        /// <returns>0 if successful</returns>
        public static int RunWithArgs(string[] argsIn)
        {
            // User requests help info
            if(Regex.IsMatch(argsIn[0], "help"))
            {
                PrintHelp();
            }
            // Parse arguments from cmdline
            else
            {
                StringBuilder singlePid = new StringBuilder();
                string[] pids = {};
                StringBuilder singleOrder = new StringBuilder();
                string[] orders = {};
                StringBuilder lowDate = new StringBuilder();
                StringBuilder highDate = new StringBuilder();
                StringBuilder customRoot = new StringBuilder();
                bool isFba = true;
                bool isVerbose = false;

                bool allInputValid = true;

                for(int i = 0; i < argsIn.Length; i++)
                {
                    // PIDs
                    if (singlePid.Length < 1 & pids.Length < 1 && Regex.IsMatch(argsIn[i], "-p|-pids"))
                    {
                        if (Regex.IsMatch(argsIn[i + 1], @"^[0-9]{8}$"))
                            singlePid.Append(argsIn[i + 1]);
                        else if (Regex.IsMatch(argsIn[i + 1], @".*\.txt"))
                            pids = File.ReadAllLines(string.Concat(Directory.GetCurrentDirectory(), @"\", argsIn[i + 1]));
                        else
                        {
                            allInputValid = false;
                            Console.WriteLine("PARAMETER ERROR: Invalid PID");
                        }
                    }
                    // Orders
                    else if (singleOrder.Length < 1 & orders.Length < 1 && Regex.IsMatch(argsIn[i], "-o|-orders"))
                    {
                        if (Regex.IsMatch(argsIn[i + 1], @"^[0-9]{3}-[0-9]{7}-[0-9]{7}$"))
                            singleOrder.Append(argsIn[i + 1]); //broken single order input doesn't work
                        else if (Regex.IsMatch(argsIn[i + 1], @".*\.txt"))
                            orders = File.ReadAllLines(string.Concat(Directory.GetCurrentDirectory(), @"\", argsIn[i + 1]));
                        else
                        {
                            allInputValid = false;
                            Console.WriteLine(@"PARAMETER ERROR: Invalid order(s)");
                        }
                    }
                    // Dates
                    else if (lowDate.Length < 1 & highDate.Length < 1 && Regex.IsMatch(argsIn[i], "-d|-dates"))
                    {
                        if (Regex.IsMatch(argsIn[i + 1], @"^(0[1-9]|1[0-2])(0[1-9]|1[0-9]|2[0-9]|3[01])[0-9]{4}$") && Regex.IsMatch(argsIn[i + 2], @"^(0[1-9]|1[0-2])(0[1-9]|1[0-9]|2[0-9]|3[01])[0-9]{4}$"))
                        {
                            lowDate.Append(argsIn[i + 1]);
                            highDate.Append(argsIn[i + 2]);
                        }
                        else
                        {
                            allInputValid = false;
                            Console.WriteLine(@"PARAMETER ERROR: Invalid date(s). Use MMDDYYYY.");
                        }
                    }
                    // Custom root
                    else if (Regex.IsMatch(argsIn[i], "-r|-root"))
                    {
                        if (Directory.Exists(argsIn[i + 1]))
                        {
                            customRoot.Append(new DirectoryInfo(argsIn[i + 1].ToString()).FullName);
                        }
                        else
                        {
                            allInputValid = false;
                            Console.WriteLine(@"PARAMETER ERROR: Invalid path for root.");
                        }
                    }
                    // FBA check
                    else if (Regex.IsMatch(argsIn[i], "-nofba"))
                        isFba = false;
                    // Verbose
                    else if (Regex.IsMatch(argsIn[i], "-v"))
                        isVerbose = true;
                }

                if (allInputValid)
                {
                    // Local directory to store the retrieved files
                    string dest = String.Concat(
                        DateTime.Now.Day, "-",
                        DateTime.Now.Month, "-",
                        DateTime.Now.Year, " ",
                        DateTime.Now.Hour, "h",
                        DateTime.Now.Minute, "m",
                        DateTime.Now.Second, "s");

                    Retriever r;
                    Searcher s;

                    // Custom root
                    if (customRoot.Length > 0)
                    {
                        if (singlePid.Length > 0)
                        {
                            string[] p = new string[] { singlePid.ToString() };
                            r = new Retriever(customRoot.ToString(), p, isFba, lowDate.ToString(), highDate.ToString(), isVerbose, dest);
                        }
                        else
                        {
                            r = new Retriever(customRoot.ToString(), pids, isFba, lowDate.ToString(), highDate.ToString(), isVerbose, dest);
                        }
                    }
                    // Default root
                    else
                    {
                        if (singlePid.Length > 0)
                        {
                            string[] p = new string[] { singlePid.ToString() };
                            r = new Retriever(p, isFba, lowDate.ToString(), highDate.ToString(), isVerbose, dest);
                        }
                        else
                        {
                            r = new Retriever(pids, isFba, lowDate.ToString(), highDate.ToString(), isVerbose, dest);
                        }
                    }

                    s = new Searcher(pids, orders, dest, isVerbose);

                    PrintResults(s.OrderFindChecklist);
                }

                Console.WriteLine("\n");
            }

            return 0;
        }
Пример #2
0
        /// <summary>
        /// Default more. No cmd line args.
        /// </summary>
        /// <returns>0 if successful</returns>
        public static int RunWithoutArgs()
        {
            // Get input
            Console.WriteLine("Specify target root directory");
            Console.Write(@"(Leave blank and press ENTER for default \\rdu-isilon-01.auctionrover.com\cads\profiles): ");
            // Root path
            string root = Console.ReadLine();
            Console.Write("Provide list of PIDs (filename): ");
            // List of pids
            string[] pids = File.ReadAllLines(string.Concat(Directory.GetCurrentDirectory(), @"\", Console.ReadLine()));
            Console.Write("Provide list of Amazon orders (filename): ");
            // List of orders
            string[] orders = File.ReadAllLines(string.Concat(Directory.GetCurrentDirectory(), @"\", Console.ReadLine()));
            // Search for FBA orders?
            Console.Write("Does order list possibly contain FBA orders? (Y/N): ");
            bool isFba;
            if (Console.ReadKey().KeyChar == 'y')
                isFba = true;
            else
                isFba = false;
            // Low date in range
            Console.Write("\nProvide low date (MMDDYYYY): ");
            string lowDate = Console.ReadLine();
            // High date in range
            Console.Write("Provide high date (MMDDYYYY): ");
            string highDate = Console.ReadLine();

            // Local directory to store the retrieved files
            string dest = String.Concat(
                DateTime.Now.Day, "-",
                DateTime.Now.Month, "-",
                DateTime.Now.Year, " ",
                DateTime.Now.Hour, "h",
                DateTime.Now.Minute, "m",
                DateTime.Now.Second, "s");

            Retriever r;
            Searcher s;

            if (root.Length == 0)
                r = new Retriever(pids, isFba, lowDate, highDate, true, dest);
            else
                r = new Retriever(root, pids, isFba, lowDate, highDate, true, dest);

            s = new Searcher(pids, orders, dest, true);

            PrintResults(s.OrderFindChecklist);

            Console.WriteLine("\n");

            return 0;
        }