예제 #1
0
        public void Log(string content, int level = LogLevel.Information)
        {
            try
            {
                if (level == LogLevel.Information)
                {
                    _logger.Info(content);
                }
                if (level == LogLevel.Debug)
                {
                    _logger.Debug(content);
                }
                if (level == LogLevel.Error)
                {
                    _logger.Error(content);
                }

                var logEntry = new ExecutionLog();
                logEntry.LogContent  = content;
                logEntry.LogLevel    = level;
                logEntry.DateCreated = DateTime.UtcNow;
                Entities.ExecutionLogs.Add(logEntry);
                Entities.SaveChanges();
            }
            catch (Exception ex)
            {
                // Swallow the exception! - this is a logger
                //
                _logger.Info($"Failed attempt to add Execution Log ({level}) {content}");
                _logger.Error(ex);
            }
        }
예제 #2
0
        public void Run()
        {
            var instanceId = Guid.Parse("51AA413D-E679-4F38-BA47-68129B3F9212");

            _connection.Initialize(instanceId);
            var testCustomerJson = System.IO.File.ReadAllText("Testing/Feeder/TestCustomers.json");
            var testCustomers    = testCustomerJson.DeserializeFromJson <List <TestCustomerDto> >();
            var count            = 0;

            foreach (var customer in testCustomers)
            {
                var standardizedEmail
                    = customer.Email.Substring(0, customer.Email.IndexOf("@") + 1)
                      + "logicautomated.com";

                var payload = new OrderPayload
                {
                    CustomerEmail     = standardizedEmail,
                    CustomerFirstName = customer.FirstName,
                    CustomerLastName  = customer.LastName,
                    LineItemVariantId = 31975123484717, // TAX ROUNDING BEAST
                    UnitPrice         = 50,
                    Quantity          = 3,
                };
                PushCustomerOrderTransaction(payload);
                _logger.Info($"Created Customer+Order+Transaction - {++count}");
            }
        }
 public void Run()
 {
     while (true)
     {
         _logger.Info($"Sound off from RiffRaff: {Id} - {_persist.Id}");
         System.Threading.Thread.Sleep(1000);
     }
 }
예제 #4
0
        public void PopulateRolesAndAdmin()
        {
            // Check to see if Role Exists, if not create it
            if (!_roleManager.RoleExists(SecurityConfig.AdminRole))
            {
                _logger.Info($"Role {SecurityConfig.AdminRole} does not exist - adding to Roles");
                var result = _roleManager.Create(new IdentityRole(SecurityConfig.AdminRole));
                if (result.Succeeded == false)
                {
                    throw new Exception($"RoleManager.Create (Admin) failed: {result.Errors.JoinByNewline()}");
                }
            }

            if (!_roleManager.RoleExists(SecurityConfig.UserRole))
            {
                _logger.Info($"Role {SecurityConfig.UserRole} does not exist - adding to Roles");
                var result = _roleManager.Create(new IdentityRole(SecurityConfig.UserRole));
                if (result.Succeeded == false)
                {
                    throw new Exception($"RoleManager.Create (User) failed: {result.Errors.JoinByNewline()}");
                }
            }

            var adminUser = _userManager.FindByName(SecurityConfig.DefaultAdminEmail);

            if (adminUser == null)
            {
                using (var transaction = _dbContext.Database.BeginTransaction())
                {
                    _logger.Info(
                        $"Unable to locate default Sys Admin: {SecurityConfig.DefaultAdminEmail} - "
                        + @"creating new Sys Admin");

                    var newAdminUser = new ApplicationUser()
                    {
                        UserName = SecurityConfig.DefaultAdminEmail,
                        Email    = SecurityConfig.DefaultAdminEmail,
                    };

                    var result = _userManager.Create(newAdminUser, SecurityConfig.DefaultAdminPassword);
                    if (result.Succeeded == false)
                    {
                        throw new Exception(
                                  $"UserManager.Create failed: {result.Errors.JoinByNewline()}");
                    }

                    var resultAddToAdmin = _userManager.AddToRole(newAdminUser.Id, SecurityConfig.AdminRole);
                    if (resultAddToAdmin.Succeeded == false)
                    {
                        throw new Exception(
                                  $"UserManager.AddToRole (Admin) failed: {resultAddToAdmin.Errors.JoinByNewline()}");
                    }

                    transaction.Commit();
                }
            }
        }
        public void SavePayoutHeaders(
            PayoutList payouts, long?shopifyPayoutId)
        {
            foreach (var payout in payouts.payouts)
            {
                var persistedPayout =
                    _persistRepository.RetrievePayout(payout.id);

                if (shopifyPayoutId.HasValue && payout.id != shopifyPayoutId.Value)
                {
                    continue;
                }

                if (persistedPayout != null)
                {
                    _persistRepository
                    .UpdatePayoutHeaderStatus(payout.id, payout.status);

                    _logger.Info($"Shopify Payout {payout.id} found - updating status and skipping!");
                    continue;
                }

                _logger.Info(
                    $"Creating Header for Shopify Payout {payout.id}");

                var newPayout = new UsrShopifyPayout()
                {
                    ShopifyPayoutId   = payout.id,
                    ShopifyLastStatus = payout.status,
                    Json        = payout.SerializeToJson(),
                    CreatedDate = DateTime.UtcNow,
                    UpdatedDate = DateTime.UtcNow,
                    AllShopifyTransDownloaded = false,
                };

                _persistRepository.InsertPayoutHeader(newPayout);
            }
        }
예제 #6
0
        public bool Log(LogLevel logLevel, Func <string> messageFunc, Exception exception = null)
        {
            if (_logger == null)
            {
                return(false);
            }
            if (messageFunc == null && exception == null)
            {
                return(true);
            }


            if (logLevel == LogLevel.Trace && _logger.IsTraceEnabled)
            {
                _logger.Trace(messageFunc());
            }
            if (logLevel == LogLevel.Debug && _logger.IsDebugEnabled)
            {
                _logger.Debug(messageFunc());
            }
            if (logLevel == LogLevel.Info && _logger.IsInfoEnabled)
            {
                _logger.Info(messageFunc());
            }
            if (logLevel == LogLevel.Warn && _logger.IsWarnEnabled)
            {
                _logger.Warn(messageFunc());
            }
            if (logLevel == LogLevel.Error && _logger.IsErrorEnabled)
            {
                var message = messageFunc();
                if (!message.IsNullOrEmpty())
                {
                    _logger.Error(message);
                }
                _logger.Error(exception);
            }
            if (logLevel == LogLevel.Fatal && _logger.IsFatalEnabled)
            {
                _logger.Fatal(messageFunc());
            }
            return(true);
        }
        public void RunPayoutTransactions(long payoutId)
        {
            _logger.Info($"Importing Transactions for Shopify Payout: {payoutId}");

            // Read first batch
            var firstBatch =
                _payoutApi
                .RetrievePayoutDetail(
                    payout_id: payoutId,
                    limit: PayoutTransactionPagingLimit)
                .DeserializeFromJson <PayoutDetail>();

            UpsertPayoutTransactions(firstBatch, payoutId);

            // Identify transaction id
            var lastTranscationId = firstBatch.transactions.Last().id;

            while (true)
            {
                // Grab the next Batch
                var nextBatch =
                    _payoutApi
                    .RetrievePayoutDetail(
                        since_id: lastTranscationId,
                        limit: PayoutTransactionPagingLimit)
                    .DeserializeFromJson <PayoutDetail>();

                UpsertPayoutTransactions(nextBatch, payoutId);

                // If there are no transactions, then break!
                if (nextBatch.transactions.Count == 0)
                {
                    break;
                }

                // We stop iterating when we see type = "payout" or a null payout id
                if (nextBatch
                    .transactions
                    .Any(x => x.type == "payout" ||
                         x.payout_id == null ||
                         x.payout_id != payoutId))
                {
                    break;
                }

                // Else, grab the last transaction id and keep going!
                lastTranscationId = nextBatch.transactions.Last().id;
            }
        }
예제 #8
0
        public void WritePayoutToAcumatica(long shopifyPayoutId)
        {
            var persistedPayout = _persistRepository.RetrievePayout(shopifyPayoutId);
            var schema          = PX.Soap.Helper.GetSchema <CA306500Content>(_screen);

            if (persistedPayout.AcumaticaRefNumber.IsNullOrEmpty())
            {
                // Get data staged
                var preferences = _persistRepository.RetrievePayoutPreferences();

                var payoutObject = persistedPayout.Json.DeserializeFromJson <Payout>();

                var payoutDate
                    = new DateTime(
                          payoutObject.date.Year,
                          payoutObject.date.Month,
                          payoutObject.date.Day)
                      .ToShortDateString();

                var commands
                    = new List <Command>()
                      .AddCommand(schema.CashAccount.CashAccount, preferences.AcumaticaCashAccount)
                      .AddCommand(schema.Actions.Insert)
                      .AddCommand(schema.CashAccount.StartBalanceDate, payoutDate)
                      .AddCommand(schema.CashAccount.EndBalanceDate, payoutDate)
                      .AddCommand(schema.CashAccount.StatementDate, payoutDate)
                      .AddCommand(schema.Actions.Save)
                      .AddCommand(schema.CashAccount.CashAccount)
                      .AddCommand(schema.CashAccount.ReferenceNbr);

                var results = _screen.CA306500Submit(commands.ToArray())[0];

                var cashAccount  = results.CashAccount.CashAccount.Value;
                var referenceNbr = results.CashAccount.ReferenceNbr.Value;

                _logger.Info(
                    $"Created Shopify Payout : {persistedPayout.ShopifyPayoutId} " +
                    $"in Acumatica with Ref Number: {referenceNbr}");

                _persistRepository
                .UpdatePayoutHeaderAcumaticaImport(
                    persistedPayout.ShopifyPayoutId,
                    cashAccount,
                    referenceNbr,
                    DateTime.UtcNow);
            }
            else
            {
                _logger.Info(
                    $"Shopify Payout : {persistedPayout.ShopifyPayoutId} " +
                    $"already exists in Acumatica with Ref Number: {persistedPayout.AcumaticaRefNumber}");
            }

            var navigateCommands
                = new List <Command>()
                  .AddCommand(schema.CashAccount.CashAccount, persistedPayout.AcumaticaCashAccount)
                  .AddCommand(schema.CashAccount.ReferenceNbr, persistedPayout.AcumaticaRefNumber)
                  .AddCommand(schema.Actions.Cancel);

            var resultnavs = _screen.CA306500Submit(navigateCommands.ToArray());

            WritePayoutTransactions(shopifyPayoutId);
        }