Ejemplo n.º 1
0
        public override void RunCommissions(CompanyConfig config, RunQueueItem item, MakoAdmin makoAdmin, string connStr, QueueManagement queueManager)
        {
            try
            {
                //
                if (item.RunTy != 4)
                {
                    LoggingHelpers.InsertIntoLog(connStr, config.CompanyId, item.QueueId, $"{DateTime.UtcNow:G} [Info] Now Processing Real Time -  QueueId {item.QueueId}");
                }
                else
                {
                    LoggingHelpers.InsertIntoLog(connStr, config.CompanyId, item.QueueId, $"{DateTime.UtcNow:G} [Info] Now Processing Run -  QueueId {item.QueueId}");
                }

                //
                LoggingHelpers.InsertIntoLog(connStr, config.CompanyId, item.QueueId, $"{DateTime.UtcNow:G} RunTy({item.RunTy}), PlanId({item.QueueId}), RevisionId({item.RevisionId})");


                // Assembly assm, string typesXML, string bonusXML, string glossaryXML,
                // string overrideXML, string rankXML, string volumeXML
                var myschema = new MakoXMLSchemas(
                    makoAdmin.ProjectAssembly,
                    makoAdmin.ProjectAssembly.GetName().Name + ".MakoTypes.xml",
                    makoAdmin.ProjectAssembly.GetName().Name + ".MakoBonuses.xml",
                    "",
                    makoAdmin.ProjectAssembly.GetName().Name + ".MakoOverrides.xml",
                    makoAdmin.ProjectAssembly.GetName().Name + ".MakoRanks.xml",
                    makoAdmin.ProjectAssembly.GetName().Name + ".MakoVolumes.xml"
                    );

                MakoConfig comConfig = new MakoConfig()
                {
                    CompanyID = config.CompanyId,
                    PeriodID  = item.PeriodId,
                    PeriodTy  = item.PeriodTy,
                    QueueID   = item.QueueId,
                    RunDescr  = item.RunDescr,
                    RunID     = item.RunId,
                    RunTy     = item.RunTy,
                    XMLSchema = myschema,
                    PlanID    = item.PlanId,
                    RevisonID = item.RevisionId
                };

                LoggingHelpers.InsertIntoLog(connStr, config.CompanyId, item.QueueId, $"{DateTime.UtcNow.ToString("G")} [Info] Commission complete");

                //
                makoAdmin.ProcessCommissions(comConfig);

                //
                if (comConfig.RunID != 0 && comConfig.RunTy != 4)
                {
                    LoggingHelpers.UpdateRunLog(connStr, config.CompanyId, item.QueueId, comConfig.RunID);
                }
                //
                queueManager.DeleteQueueItem(item.QueueId);
            }
            catch (AggregateException e)
            {
                //
                foreach (var ex in e.InnerExceptions)
                {
                    LoggingHelpers.InsertIntoLog(connStr, config.CompanyId, item.QueueId, $"{DateTime.UtcNow:G} [Error] " + ex.Message);
                    LoggingHelpers.InsertIntoLog(connStr, config.CompanyId, item.QueueId, $"{DateTime.UtcNow:G} [Error] " + ex.StackTrace);
                }
                //
                LoggingHelpers.LogQueueError(connStr, config.CompanyId, item, e);

#if DEVELOPMENT
#else
                Common.API.SendGrid.SendGridHelper.SendAlertAsync("Mako Runner Exception", $"Company {config.CompanyName}, RunTy {item.RunTy}, Description {item.RunDescr} {Environment.NewLine} {e}",
                                                                  $"Company {config.CompanyName}, RunTy {item.RunTy}, Description {item.RunDescr} {Environment.NewLine} {e}");
#endif

                throw;
            }
            catch (Exception ex)
            {
                //
                LoggingHelpers.InsertIntoLog(connStr, config.CompanyId, item.QueueId, $"{DateTime.UtcNow:G} [Error] " + ex.Message);
                LoggingHelpers.InsertIntoLog(connStr, config.CompanyId, item.QueueId, $"{DateTime.UtcNow:G} [Error] " + ex.StackTrace);

                //
                LoggingHelpers.LogQueueError(connStr, config.CompanyId, item, ex);

#if DEVELOPMENT
#else
                if (!_isDevelopment)
                {
                    Common.API.SendGrid.SendGridHelper.SendAlertAsync("Mako Runner Exception", $"Company {config.CompanyName}, RunTy {item.RunTy}, Description {item.RunDescr} {Environment.NewLine} {ex}",
                                                                      $"Company {config.CompanyName}, RunTy {item.RunTy}, Description {item.RunDescr} {Environment.NewLine} {ex}");
                }
#endif
                throw;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="appContract"></param>
        /// <param name="makoLogger"></param>
        /// <param name="makoCache"></param>
        /// <param name="queueManager"></param>
        private void ProcessQueueItem(ApplicationContract appContract, DelegateLogProvider makoLogger, SqlCacheRepo makoCache, QueueManagement queueManager)
        {
            // TODO: Find a smart way to check to see if there are changes to the connection strings and so forth

            //
            while (queueManager.FindNextQueueItem(out RunQueueItem item))             // TODO: Write authentication for app
            {
                //
                var startTime = DateTimeOffset.Now;
                _logRunTy      = item.RunTy;
                ConnectString  = appContract.GenerateConnectionStr();
                _logCompanyId  = Config.CompanyId;
                _logQueueId    = item.QueueId;
                _logPeriodType = item.PeriodTy;
                _logPeriodId   = item.PeriodId;

                try
                {
                    //
                    UpdateMakoAdmin(item, makoCache, makoLogger);

                    //
                    _listLog = new List <string>();
                    _listLog.Add("");
                    _listLog.Add($"{DateTime.UtcNow.ToString("G")} ------------------------------------------");
                    _listLog.Add(
                        $"{DateTime.UtcNow.ToString("G")} Now Processing Real Time -  QueueId {item.QueueId}");
                    _listLog.Add(
                        $"{DateTime.UtcNow.ToString("G")} RunTy({item.RunTy}), PlanId({item.PlanId}), RevisionId({item.RevisionId})");
                    _listLog.Add($"{DateTime.UtcNow.ToString("G")} ------------------------------------------");
                    _listLog.Add("");

                    // Assembly assm, string typesXML, string bonusXML, string glossaryXML,
                    // string overrideXML, string rankXML, string volumeXML
                    var myschema = new MakoXMLSchemas(
                        Assembly,
                        PlanName + ".MakoTypes.xml",
                        PlanName + ".MakoBonuses.xml",
                        "",
                        PlanName + ".MakoOverrides.xml",
                        PlanName + ".MakoRanks.xml",
                        PlanName + ".MakoVolumes.xml"
                        );
                    //
                    MakoConfig comConfig = new MakoConfig()
                    {
                        PeriodID  = item.PeriodId,
                        PeriodTy  = item.PeriodTy,
                        QueueID   = item.QueueId,
                        RunDescr  = item.RunDescr,
                        RunID     = item.RunId,
                        RunTy     = item.RunTy,
                        XMLSchema = myschema,
                        PlanID    = item.PlanId,
                        RevisonID = item.RevisionId
                    };
                    //
                    Admin.ProcessCommissions(comConfig);

                    //
                    var endTime = DateTimeOffset.Now;

                    //
                    if (comConfig.RunID != 0 && comConfig.RunTy != 4)
                    {
                        LoggingHelpers.UpdateRunLog(appContract.GenerateConnectionStr(), Config.CompanyId, item.QueueId,
                                                    comConfig.RunID);
                        queueManager.UpdateRunStartAndEndDate(appContract.GenerateConnectionStr(), Config.CompanyId, item.RunId,
                                                              startTime, endTime);
                    }

                    queueManager.DeleteQueueItem(item.QueueId);

                    var log = new FileLogger(Config.CompanyKey, item.QueueId, item.RunTy);
                    log.GenerateLog(_listLog);
                    _listLog.Clear();

                    //
                    if (!IsRunning)
                    {
                        break;
                    }
                }
                catch (Exception ex)
                {
                    var log = new FileLogger(Config.CompanyKey, item.QueueId, item.RunTy);
                    _listLog.Add($"{DateTime.UtcNow.ToString("G")} [Error] " + ex.Message);
                    _listLog.Add($"{DateTime.UtcNow.ToString("G")} [Error] " + ex.StackTrace);
                    log.GenerateLog(_listLog);
                    _listLog.Clear();

                    //
                    queueManager.LogQueueError(appContract.GenerateConnectionStr(), Config.CompanyId, item.QueueId, ex);
                }
            }
            //
            Thread.Sleep(TimeSpan.FromSeconds(1));
        }