Ejemplo n.º 1
0
 /// <summary>
 /// Method: DeserializeJsonLogEntry
 /// Goal: Converts a json string event coming from EventHub to a emp_json_log_entry object.
 /// </summary>
 /// <param name="jsonFromEventHubMessage">The json string event coming from the eventhub</param>
 /// <param name="log">The ILogger object to log information and errors</param>
 /// <returns>logEntry -> emp_json_log_entry object</returns>
 /// <exception cref="JsonException"> </exception>
 /// When <paramref name="jsonFromEventHubMessage"/> is invalid  OR
 /// When <paramref returnType="emp_json_log_entry"/> not compatible with the json OR
 /// When <paramref name="jsonFromEventHubMessage"/> There is remaining data in the span beyond a single JSON value
 /// <exception cref="ArgumentNullException"> </exception>
 /// When <paramref name="jsonFromEventHubMessage"/> is null
 /// </exception>
 public static JsonLogEntry DeserializeJsonLogEntry(string jsonFromEventHubMessage, ILogger log)
 {
     try
     {
         JsonLogEntry logEntry = JsonConvert.DeserializeObject <JsonLogEntry>(jsonFromEventHubMessage);
         log?.LogInformation($"DeserializeJsonLogEntry: Json was deserialized successfully: {jsonFromEventHubMessage}");
         return(logEntry);
     }
     catch (Newtonsoft.Json.JsonException e)
     {
         log?.LogError($"DeserializeJsonLogEntry: JsonException: {e.Message}");
         throw;
     }
     catch (ArgumentNullException e)
     {
         log?.LogError($"DeserializeJsonLogEntry: ArgumentNullException: {e.Message}");
         throw;
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Method: ValidateTrigram
 /// Goal: Validates if a trigram entry from the log is present in the emp-trigram storage table (single source of true) in Azure.
 /// </summary>
 /// <param name="storageConnectionString">The azure storage account connection string to access the azure trigram table</param>
 /// <param name="logEntry">The log entry</param>
 /// <param name="trigramTableName">The azure trigram table name</param>
 /// <param name="log">The ILogger object to log information and errors</param>
 /// <returns>validTrigram -> a boolean that reflects if the trigram is valid = true or if the trigram is not valid = false and the webhook url</returns>
 /// <exception cref="ArgumentException">The exception that is thrown when one of the arguments provided to a method is not valid</exception>
 public static (Boolean isValid, string webhookUrl) ValidateTrigram(string storageConnectionString, JsonLogEntry logEntry, string trigramTableName, ILogger log)
 {
     try
     {
         //Get the json string from the EventHub and converts to upper case - as Triagram table is stored as upper case
         string triagramFromLogEntry = logEntry.Trigram.ToUpper();
         //Retrieve Azure Cloud Table Entity that holds the information for the Application Trigrams
         CloudTable cloudTable = emp_azure_storage_table_operations.RetrieveTableObject(storageConnectionString, trigramTableName, log);
         //Query Azure Cloud Table with Partition and Row Key
         Task <Trigram> triagramFromAzureTable = emp_azure_storage_table_operations.RetrieveEntityUsingPointQueryAsync(cloudTable, triagramFromLogEntry, triagramFromLogEntry, log);
         if (triagramFromAzureTable.Result is null)
         {
             //Trigram not present in the Azure Storage Trigram Table
             log?.LogInformation($"ValidateTrigram: Trigram entry doesn't exist on the Trigram table: {triagramFromLogEntry}");
             return(false, null);
         }
         else
         {
             //Compare Trigram in the Log entry with the Azure Trigram table
             //If equal return true, if not returns false
             string stringTrigramFromAzureTable = triagramFromAzureTable.Result.ApplicationTrigram;
             bool   validTrigram = String.Equals(stringTrigramFromAzureTable, triagramFromLogEntry);
             log?.LogInformation($"ValidateTrigram: Trigram entry is valid: {triagramFromLogEntry}");
             return(validTrigram, triagramFromAzureTable.Result.WebHook);
         }
     }
     catch (ArgumentException e)
     {
         log?.LogError($"ValidateTrigram: Exception: {e.Message}");
         throw;
     }
 }