コード例 #1
0
ファイル: Program.cs プロジェクト: zachary-kaelan/CSharp
        public static void PostServiceOrders(string path)
        {
            Console.Write("Enter the number of the batch you want to post to: ");
            int batchNum = Convert.ToInt32(Console.ReadLine().Trim());
            var loop     = new LoopManager <PostedOrder>(
                path,
                "FinishedPostedOrders.txt",
                "ErroredPostedOrders.txt",
                o => o.OrderID
                );

            loop.EndLoop(
                Parallel.ForEach(
                    loop.Updates, LoopManager.PARALLEL_OPTS, postedOrder =>
            {
                try
                {
                    var responseCode = Postman.PostServiceOrder(postedOrder.OrderID, postedOrder.Tech, batchNum);
                    if (responseCode.IsOK())
                    {
                        loop.LogUpdate(postedOrder.OrderID, "OK", UpdateType.Finished);
                    }
                    else
                    {
                        loop.LogUpdate(postedOrder.OrderID, responseCode.ToString(), UpdateType.Error);
                    }
                }
                catch (Exception e)
                {
                    loop.LogUpdate(postedOrder.OrderID, e.Message, UpdateType.Error);
                }
            }
                    )
                );
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: zachary-kaelan/CSharp
        public static void SkipMonths(string path, bool clearErrors = false)
        {
            var loop = new LoopManager <Location_CodeOnly>(
                path,
                PATH_LOGGING + "SetupSkipMonthsFinished.txt",
                PATH_LOGGING + "SetupSkipMonthsErrored.txt",
                l => l.Location.ToString(),
                clearErrors
                );
            var skipFields = Enumerable.Range(1, 12).Select(m => "Skip" + m.ToString()).ToArray();

            loop.EndLoop(
                Parallel.ForEach(
                    loop.Updates,
                    PARALLEL_OPTS,
                    location =>
            {
                try
                {
                    int locID   = Postman.GetLocationIDFromCode(location.Location);
                    var setupID = Postman.GetLocationServiceSetup(locID, s => s.ServiceCode == "MONTHLY MOSQ").SetupID.Value.ToString();
                    PPWebLib.PestPac.EditServiceSetup(setupID, null, skipFields);
                    loop.LogUpdate(location.Location.ToString(), setupID);
                }
                catch (Exception e)
                {
                    loop.LogUpdate(location.Location, e.Message, UpdateType.Error);
                }
            }
                    ),
                false
                );
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: zachary-kaelan/CSharp
        static void Main(string[] args)
        {
            Console.Write("Enter the number of the batch you want to post to: ");
            int batchNum = Convert.ToInt32(Console.ReadLine().Trim());

            OpenFileDialog dialog = new OpenFileDialog()
            {
                CheckFileExists              = true,
                CheckPathExists              = true,
                DefaultExt                   = "csv",
                AddExtension                 = true,
                Filter                       = "CSV UTF-8 (Comma delimited) (*.csv)|*.csv|Text files (*.prn;*.txt;*.csv)|*.prn;*.txt;*.csv|All files (*.*)|*.*",
                InitialDirectory             = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\Downloads",
                SupportMultiDottedExtensions = true,
                Title = "PostServiceOrders - Open File"
            };

            Console.Write("Pick a file: ");
            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            Console.WriteLine(dialog.FileName);

            PostedOrder[] postedOrders = null;
            try
            {
                postedOrders = LoopManager.StartLoop <PostedOrder>(
                    dialog.FileName,
                    "FinishedPostedOrders.txt",
                    "ErroredPostedOrders.txt",
                    o => o.OrderID
                    );
            }
            catch (Exception err)
            {
                if (err.Message.StartsWith("The process cannot access the file"))
                {
                    Console.WriteLine("Please close the Excel file and try again.");
                }
                else if (err.Message.StartsWith("No members are mapped"))
                {
                    Console.WriteLine("Please make sure that the Excel file has 'OrderID' and 'Tech' fields.");
                }
                else
                {
                    Console.WriteLine(err.Message);
                }
                Console.Write("Press Enter to exit...");
                Console.ReadLine();
                return;
            }

            LoopManager.EndLoop(
                Parallel.ForEach(
                    postedOrders, LoopManager.PARALLEL_OPTS, postedOrder =>
            {
                try
                {
                    if (Postman.PostServiceOrder(postedOrder.OrderID, postedOrder.Tech, batchNum))
                    {
                        LoopManager.LogUpdate(postedOrder.OrderID + " - true", UpdateType.Finished);
                    }
                    else
                    {
                        LoopManager.LogUpdate(postedOrder.OrderID + " - false", UpdateType.Error);
                    }
                }
                catch
                {
                    LoopManager.LogUpdate(postedOrder.OrderID + " - ERROR");
                }
            }
                    )
                );
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: zachary-kaelan/CSharp
        static void Main(string[] args)
        {
            var proc = Process.GetCurrentProcess();

            proc.PriorityBoostEnabled     = true;
            proc.PriorityClass            = ProcessPriorityClass.AboveNormal;
            Thread.CurrentThread.Priority = ThreadPriority.Highest;

            LogManager.AddLog(new Log(LogType.FolderFilesByDate, "BatchPayments")
            {
                LogFileEntries = true
            });
            LogManager.Start(ThreadPriority.AboveNormal, false);

            OpenFileDialog dialog = new OpenFileDialog()
            {
                CheckFileExists              = true,
                CheckPathExists              = true,
                DefaultExt                   = "csv",
                AddExtension                 = true,
                Filter                       = "CSV UTF-8 (Comma delimited) (*.csv)|*.csv|Text files (*.prn;*.txt;*.csv)|*.prn;*.txt;*.csv|All files (*.*)|*.*",
                InitialDirectory             = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\Downloads",
                SupportMultiDottedExtensions = true,
                Title = "PostServiceOrders - Open File"
            };

            Console.Write("Pick a file: ");
            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            Console.WriteLine(dialog.FileName);

            var loop = new LoopManager <BillToPaymentModel>(
                dialog.FileName,
                "FinishedBatchPayments.txt",
                "ErroredBatchPayments.txt",
                b => b.LocationCode
                );

            loop.EndLoop(
                Parallel.ForEach(
                    loop.Updates,
                    new ParallelOptions()
            {
                MaxDegreeOfParallelism = 32
            },
                    billto =>
            {
                CardOnFileListModel[] accounts = null;
                CardOnFileListModel account    = null;
                PaymentProcessorTransactionModel transaction = null;
                try
                {
                    accounts = Postman.GetPaymentAccounts(billto.BillToID);
                    if (accounts.Length == 0)
                    {
                        loop.LogUpdate(billto, billto.LocationCode + ", " + billto.BillToID + " - No payment accounts found", UpdateType.Nonexistant);
                    }
                    else
                    {
                        if (accounts.Count() > 1)
                        {
                            accounts = accounts.Where(a => a.ExpirationDate.Value > Utils.Now).ToArray();
                            if (accounts.Count() > 1)
                            {
                                accounts = accounts.Where(a => a.AutoBilledServices.Any()).ToArray();
                            }
                        }
                        account = accounts.Count() == 1 ?
                                  accounts[0] :
                                  accounts.First(a => a.IsPrimary.Value);

                        transaction = Postman.Charge(
                            account.CardID.Value,
                            billto.Balance.StartsWith("$") ?
                            billto.Balance.Substring(1) :
                            billto.Balance,
                            false
                            );

                        string loopLogEntry = (transaction.Payment != null ? transaction.Payment.BatchNumber + " - " : "") +
                                              (transaction.TransactionResponse.TransactionResult.HasValue ?
                                               transaction.TransactionResponse.TransactionResult.Value.ToString() + ": " : "") +
                                              transaction.TransactionResponse.Message;
                        string loopLogKey = billto.BillToID;

                        switch (transaction.TransactionResponse.TransactionResult.Value)
                        {
                        case TransactionResponseModel.TransactionResultEnum.Error:
                            loop.LogUpdate(loopLogKey, loopLogEntry, UpdateType.Error);
                            LogManager.Enqueue(
                                "BatchPayments",
                                loopLogKey,
                                new object[] {
                                loopLogKey,
                                transaction.TransactionResponse.Message
                            },
                                new object[]
                            {
                                billto,
                                account,
                                transaction.TransactionResponse
                            },
                                true
                                );
                            break;

                        case TransactionResponseModel.TransactionResultEnum.Approved:
                            loop.LogUpdate(loopLogKey, loopLogEntry, UpdateType.Finished);
                            LogManager.Enqueue(
                                "BatchPayments",
                                EntryType.DEBUG,
                                loopLogKey + " has been charged " + billto.Balance.ToString(),
                                "Batch " + transaction.Payment.BatchNumber.Value.ToString()
                                );

                            break;
                        }
                    }
                }
                catch (Exception e)
                {
                    loop.LogUpdate(billto, e.Message, UpdateType.Error);
                    LogManager.Enqueue(
                        "BatchPayments",
                        billto.BillToID,
                        true,
                        "Code - " + billto.BillToID,
                        e, true
                        );
                }
            }
                    )
                );
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: zachary-kaelan/CSharp
        public static void UpdateEmployeeAccess(string path)
        {
            List <int> branchIDs = new List <int>();

            do
            {
                Console.Write("Enter branch name(s): ");
                var      branchesStr = Console.ReadLine().Trim();
                string[] branches    = branchesStr.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var branch in branches)
                {
                    if (Postman.TryGetBranch(branch, out int branchID))
                    {
                        branchIDs.Add(branchID);
                    }
                    else
                    {
                        Console.WriteLine("\"" + branch + "\" is an invalid branch");
                    }
                }

                if (branchIDs.Count > 0)
                {
                    if (branchIDs.Count < branches.Length)
                    {
                        Console.Write("Would you like to add more branches? (y/n)");
                        var key = Console.ReadKey();
                        if (key.KeyChar == 'N' || key.KeyChar == 'n')
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("Try again, fat-fingers.");
                }
            } while (true);

            string access = null;

            Console.Write("Enter new access template: ");
            access = Console.ReadLine().Trim();

            var loop = new LoopManager(
                path,
                PATH_LOGGING + "FinishedEmployeeAccessUpdates.txt",
                PATH_LOGGING + "ErroredEmployeeAccessUpdates.txt",
                s => !s.Contains('.')
#if DEBUG
                , true
#endif
                );

            loop.EndLoop(
                Parallel.ForEach(
                    loop.Updates,
                    PARALLEL_OPTS,
                    username =>
            {
                try
                {
                    var employee = Postman.GetEmployee(username);
                    var id       = employee.EmployeeID.Value.ToString();
                    List <int> erroredBranchIDs = new List <int>();
                    foreach (var branchID in branchIDs)
                    {
                        if (!Postman.UpdateEmployeeAccess(id, branchID, access))
                        {
                            erroredBranchIDs.Add(branchID);
                        }
                    }
                    if (erroredBranchIDs.Any())
                    {
                        loop.LogUpdate(username, "Failed branches: " + erroredBranchIDs.ToArrayString(), UpdateType.Error);
                    }
                    else
                    {
                        loop.LogUpdate(username, id);
                    }
                }
                catch (Exception e)
                {
                    loop.LogUpdate(username, e.Message, UpdateType.Error);
                }
            }
                    )
                );
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: zachary-kaelan/CSharp
        public static void BatchPayments(string path)
        {
            var loop = new LoopManager <BillToPaymentModel>(
                path,
                PATH_LOGGING + "FinishedBatchPayments.txt",
                PATH_LOGGING + "ErroredBatchPayments.txt",
                b => b.LocationCode
                );

            loop.EndLoop(
                Parallel.ForEach(
                    loop.Updates,
                    new ParallelOptions()
            {
                MaxDegreeOfParallelism = 32
            },
                    billto =>
            {
                CardOnFileListModel[] accounts = null;
                CardOnFileListModel account    = null;
                PaymentProcessorTransactionModel transaction = null;
                try
                {
                    accounts = Postman.GetPaymentAccounts(billto.BillToID);
                    if (accounts.Length == 0)
                    {
                        loop.LogUpdate(billto, billto.LocationCode + ", " + billto.BillToID + " - No payment accounts found", UpdateType.Nonexistant);
                    }
                    else
                    {
                        if (accounts.Count() > 1)
                        {
                            accounts = accounts.Where(a => a.ExpirationDate.Value > Utils.Now).ToArray();
                            if (accounts.Count() > 1)
                            {
                                accounts = accounts.Where(a => a.AutoBilledServices.Any()).ToArray();
                            }
                        }
                        account = accounts.Count() == 1 ?
                                  accounts[0] :
                                  accounts.First(a => a.IsPrimary.Value);

                        transaction = Postman.Charge(
                            account.CardID.Value,
                            billto.Balance.StartsWith("$") ?
                            billto.Balance.Substring(1) :
                            billto.Balance,
                            false
                            );

                        string loopLogEntry = (transaction.Payment != null ? transaction.Payment.BatchNumber + " - " : "") +
                                              (transaction.TransactionResponse.TransactionResult.HasValue ?
                                               transaction.TransactionResponse.TransactionResult.Value.ToString() + ": " : "") +
                                              transaction.TransactionResponse.Message;
                        int loopLogKey = billto.BillToID;

                        switch (transaction.TransactionResponse.TransactionResult.Value)
                        {
                        case TransactionResponseModel.TransactionResultEnum.Error:
                            loop.LogUpdate(loopLogKey, loopLogEntry, UpdateType.Error);
                            LogManager.Enqueue(
                                "BatchPayments",
                                loopLogKey.ToString(),
                                new object[] {
                                loopLogKey,
                                transaction.TransactionResponse.Message
                            },
                                new object[]
                            {
                                billto,
                                account,
                                transaction.TransactionResponse
                            },
                                true
                                );
                            break;

                        case TransactionResponseModel.TransactionResultEnum.Approved:
                            loop.LogUpdate(loopLogKey, loopLogEntry, UpdateType.Finished);
                            LogManager.Enqueue(
                                "BatchPayments",
                                EntryType.DEBUG,
                                loopLogKey + " has been charged " + billto.Balance,
                                "Batch " + transaction.Payment.BatchNumber.Value.ToString()
                                );

                            break;
                        }
                    }
                }
                catch (Exception e)
                {
                    loop.LogUpdate(billto, e.Message, UpdateType.Error);
                    LogManager.Enqueue(
                        "BatchPayments",
                        billto.BillToID.ToString(),
                        true,
                        "Code - " + billto.BillToID,
                        e, true
                        );
                }
            }
                    ),
                false
                );
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: zachary-kaelan/CSharp
        public static void TimeRanges(string path)
        {
            var loop = new LoopManager <Location_CodeAndOrder>(
                @"C:\Users\ZACH-GAMING\Downloads\Time Range Updates Oct.18.2018.csv",
                @"E:\Work Programming\Insight Program Files\PPInternal\Logging\TimerangeChangesFinished.txt",
                @"E:\Work Programming\Insight Program Files\PPInternal\Logging\TimerangeChangesErrored.txt",
                t => t.Location
                );

            loop.EndLoop(
                Parallel.ForEach(
                    loop.Updates,
                    LoopManager.PARALLEL_OPTS,
                    l =>
            {
                string location = l.Location.ToString();
                try
                {
                    int id            = Postman.GetLocationIDFromCode(l.Location);
                    var serviceSetups = Postman.GetLocationServiceSetups(id).Where(s => !String.IsNullOrWhiteSpace(s.TimeRange));
                    var serviceOrder  = Postman.GetServiceOrderByNumber(id, l.Order);

                    foreach (var serviceSetup in serviceSetups)
                    {
                        PPWebLib.PestPac.EditServiceSetup(serviceSetup.SetupID.Value.ToString(), new Dictionary <string, string>()
                        {
                            { "TimeRange", "" }
                        });
                    }

                    if (serviceOrder == null || !serviceOrder.OrderID.HasValue)
                    {
                        loop.LogUpdate(l.Location, l.Location + " has no matching orders.", UpdateType.Nonexistant);
                    }
                    else
                    {
                        Postman.Patch(
                            EntityType.ServiceOrders,
                            serviceOrder.OrderID.Value.ToString(),
                            new PatchOperation(
                                "replace",
                                "/constraints/latesttime",
                                "07:00 PM"
                                )
                            );
                    }

                    loop.LogUpdate(l.Location, null);
                }
                catch (Exception e)
                {
                    loop.LogUpdate(
                        l.Location,
                        l.Location + " met with error: " + e.Message,
                        UpdateType.Error
                        );
                }
            }
                    ),
                false
                );
        }