/// <summary> /// /// </summary> /// <param name="appContract"></param> private void ProcessQueue(ApplicationContract appContract) { if (appContract != null) { // Retrieve the connection string for this Application Contract. var connString = appContract.GenerateConnectionStr(); // Retrieve the company data for the specified ID. CompanySettingsForId = new CompanySettings(connString, Config.CompanyId); // Create a new SQL Cache. MakoCache = new SqlCacheRepo(appContract.GenerateConnectionStr(), MakoLogger); // Create a new Queue management object. var queueManager = new QueueManagement(Config.CompanyId, appContract.GenerateConnectionStr()); // Clear the queue for this Company ID. queueManager.ClearQueue(); // IsRunning = true; // while (IsRunning) { // ProcessQueueItem(appContract, MakoLogger, MakoCache, queueManager); } } }
public GeneralQueueRegistrationTests(ApplicationFixture application) { string?connectionString = _connectionString.Resolve(application.PropertyResolver); _serviceBusConnection = new ServiceBusConnection(connectionString !); _queueManagement = new QueueManagement(_serviceBusConnection); }
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; } }
public new static void RunCommissionsStatic(CompanyConfig config, RunQueueItem item, MakoAdmin makoAdmin, string connStr, QueueManagement queueManager) { }
/// <summary> /// A placeholder for the method implemented in the derived classes. /// </summary> /// <param name="config"></param> /// <param name="item"></param> /// <param name="makoAdmin"></param> /// <param name="connStr"></param> /// <param name="queueManager"></param> /// <remarks> /// Derived classes must declare the RunCommissions as: /// public override void RunCommissions(...) /// </remarks> public virtual void RunCommissions(CompanyConfig config, RunQueueItem item, MakoAdmin makoAdmin, string connStr, QueueManagement queueManager) { throw new NotImplementedException( "Error in RunCommissions. The method must have a new implementation in derived classes."); }
/// <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)); }
/// <summary> /// /// </summary> /// <param name="infoCompanyId"></param> /// <returns></returns> private Dictionary <string, object> GetCompanyRunnerInfo(string infoCompanyId) { // Dictionary <string, object> dict; try { // Retrieve the encoded Company Configuration data from the Settings. var encodedCompanyConfig = Settings.Default["CompanyId" + infoCompanyId].ToString(); // Convert the encoded company configuration value to a byte array. var data = Convert.FromBase64String(encodedCompanyConfig); // Decode the byte array to a string. var decodedString = Encoding.UTF8.GetString(data); // Deserialize the decoded string to a CompanyConfig object. var config = JsonConvert.DeserializeObject <CompanyConfig>(decodedString); // Create the object used for user and application authentication and authorization. var api = new AuthenticateAndAuthorize(); // Create an authentication token for the user encoded in the configuration file for the current Company ID. // TODO: Look into better ways of doing this. Try to use GetTokenForUser by adding to it the additional code found in this method call. Token = api.GetTokenForAzureUser(config.Username, config.Pwd); // Retrieve the encrypted data that is returned from the user-specific URL. var encryptStr = AuthenticateAndAuthorize.GetApplication(Token); // Authenticate and decrypt the data returned from the user-specific URL. var decrypt = AesThenHmac.SimpleDecrypt(encryptStr, Convert.FromBase64String(config.CryptKey), Convert.FromBase64String(config.AuthKey)); // Retrieve the List of application configurations. var list = JsonConvert.DeserializeObject <List <ApplicationContract> >(decrypt); // Select the First item in the List of application configuration objects. var appContract = list.FirstOrDefault(listItem => listItem.CompanyId == config.CompanyId && listItem.ApplicationTy == 1); if (appContract != null) { // Retrieve the connection string for this Application Contract. ConnectString = appContract.GenerateConnectionStr(); // Retrieve the company data for the specified ID. CompanySettingsForId = new CompanySettings(ConnectString, config.CompanyId); // Create a new SQL Cache. MakoCache = new SqlCacheRepo(appContract.GenerateConnectionStr(), MakoLogger); // Create a new Queue management object. QueueManager = new QueueManagement(config.CompanyId, appContract.GenerateConnectionStr()); // Clear the queue for this Company ID. QueueManager.ClearQueue(); // Create a Dictionary of values that will be used on the call to RunCommissions. // NOTE: 'item' and 'makoAdmin' values will be populated on each read from the queue. dict = new Dictionary <string, object> { { "config", config }, { "item", null }, { "makoAdmin", null }, { "connStr", ConnectString }, { "queueManager", QueueManager } }; } else { throw new ApplicationException("Invalid ApplicationContract in GetCompanyRunnerInfo."); } // return(dict); } catch (Exception e) { // TODO: Instead of throwing an exception and breaking the loop, log the error and continue. throw new ApplicationException("Error starting Windows Service for company ID" + infoCompanyId, e); } }