Ejemplo n.º 1
0
        private void ProccessLogTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            StopTimer();

            QueueLog.Where(ql => ql.LogId == 0).All(ql =>
            {
                try
                {
                    ql.LogId = DAL.Controller.LogDataController.Instance.LogCreate
                                   (ql.User,
                                   ql.Application,
                                   ql.Source,
                                   ql.IsSuccess,
                                   ql.Message);

                    if (ql.RelatedLogInfo != null)
                    {
                        ql.RelatedLogInfo.All(qli =>
                        {
                            DAL.Controller.LogDataController.Instance.LogInfoCreate
                                (ql.LogId,
                                qli.LogInfoType,
                                qli.Value);

                            return(true);
                        });
                    }

                    if (ql.LogInfoObject != null)
                    {
                        ql.LogInfoObject.All(qlo =>
                        {
                            DAL.Controller.LogDataController.Instance.LogInfoCreate
                                (ql.LogId,
                                qlo.LogInfoType,
                                qlo.Value);

                            return(true);
                        });
                    }
                }
                catch { }

                return(true);
            });

            QueueLog = QueueLog.Where(lg => lg.LogId == 0).Select(lg => lg).ToList();

            InitTimer();
        }
Ejemplo n.º 2
0
        public ServerController()
        {
            Log = new QueueLog(
                new ConsoleLog(),
                new SimpleFileLog(
                    Path.Combine(
                        Path.GetTempPath(),
                        AppName)));

            Log.Open();

            AppDomain.CurrentDomain.UnhandledException += (s, e) => ReportIssue(e.ExceptionObject);
            OperationMode = (OperationMode)Enum.Parse(typeof(OperationMode), ConfigurationManager.AppSettings["OperationMode"], true);

            if (OperationMode == OperationMode.Debug)
            {
                _interceptor = new DebugInterceptor();
            }
            Model = new ServerModel(_interceptor);
        }
Ejemplo n.º 3
0
        public static async Task Run([EventHubTrigger("%EMP_EVENT_HUB_NAME%", Connection = "EMP_EVENTHUB_CONNECTION_STRING")] EventData[] events, ILogger log, ExecutionContext executionContext)
        {
            var    exceptions = new List <Exception>();
            string infoMessage;
            string errorMessage;

            string jsonSettingsPath = executionContext.FunctionAppDirectory;

            //App Settings from local.settings.json
            string storageConnectionString = ApSettings.LoadAppSettings(jsonSettingsPath, log).EMP_STORAGE_ACCOUNT_CONNECTION_STRING;
            string teamsQueueName          = ApSettings.LoadAppSettings(jsonSettingsPath, log).EMP_STORAGE_ACCOUNT_TEAMS_QUEUE_NAME;
            string errorQueueName          = ApSettings.LoadAppSettings(jsonSettingsPath, log).EMP_STORAGE_ACCOUNT_ERROR_QUEUE_NAME;
            string trigramTableName        = ApSettings.LoadAppSettings(jsonSettingsPath, log).EMP_TRIGRAM_TABLE_NAME;
            string elasticSearchClusterURI = ApSettings.LoadAppSettings(jsonSettingsPath, log).EMP_ELASTIC_SEARCH_CLUSTER_URI;
            string elasticSearchAPIId      = ApSettings.LoadAppSettings(jsonSettingsPath, log).EMP_ELASTIC_SEARCH_API_ID;
            string elasticSearchAPIKey     = ApSettings.LoadAppSettings(jsonSettingsPath, log).EMP_ELASTIC_SEARCH_API_KEY;

            foreach (EventData eventData in events)
            {
                JsonLogEntry logEntry     = null;
                string       webhookUrl   = null;
                bool         validTrigram = false;
                string       messageBody  = null;

                try
                {
                    messageBody = Encoding.UTF8.GetString(eventData.Body.Array, eventData.Body.Offset, eventData.Body.Count);
                    log?.LogInformation($"FROM EVENTHUB {messageBody}");
                    if (string.IsNullOrEmpty(messageBody))
                    {
                        infoMessage = $"Task Run: Event is null";
                        log?.LogInformation(infoMessage);
                    }
                    else
                    {
                        // Validate semantically the json schema
                        logEntry = JsonLogEntry.DeserializeJsonLogEntry(messageBody, log);
                        var(validJson, errorValidation) = JsonLogEntry.ValidateJsonLogEntry(messageBody, log);
                        //Validate Trigram - compare entry from the json log with the trigram azure table storage
                        (validTrigram, webhookUrl) = Trigram.ValidateTrigram(storageConnectionString, logEntry, trigramTableName, log);

                        if (validJson)
                        {
                            infoMessage = $"Task Run: Json Schema valid: {messageBody}";
                            log?.LogInformation(infoMessage);
                            if (validTrigram)
                            {
                                //Insert into ElasticSearch Cluster
                                var elasticLowLevelClient = emp_elastic_operations.ElasticConnect(elasticSearchClusterURI, elasticSearchAPIId, elasticSearchAPIKey, log);
                                await emp_elastic_operations.ElasticPutAsync(elasticLowLevelClient, logEntry, log);
                            }
                            else
                            {
                                // If not successful send to the Azure Storage  Teams queue
                                log?.LogInformation($"Task Run: Application Trigram NOT valid: {messageBody}");
                                CloudQueue cloudQueue = AzureStorageQueueOperations.CreateAzureQueue(storageConnectionString, teamsQueueName, log);
                                var        logQueue   = new QueueLog()
                                {
                                    ErrorMessage = $"Invalid trigram", LogEntry = logEntry, WebhookUrl = webhookUrl
                                };
                                AzureStorageQueueOperations.InsertMessageQueue(cloudQueue, JsonConvert.SerializeObject(logQueue), log);
                            }
                        }
                        else
                        {
                            // If not valid  send to the Azure Storage Teams queue
                            infoMessage = $"Task Run: Json Schema NOT valid: {messageBody}";
                            log?.LogInformation(infoMessage);
                            CloudQueue cloudQueue = AzureStorageQueueOperations.CreateAzureQueue(storageConnectionString, teamsQueueName, log);
                            var        logQueue   = new QueueLog()
                            {
                                ErrorMessage = errorValidation, LogEntry = logEntry, WebhookUrl = webhookUrl
                            };
                            AzureStorageQueueOperations.InsertMessageQueue(cloudQueue, JsonConvert.SerializeObject(logQueue), log);
                        }
                        await Task.Yield();
                    }
                }
                catch (Exception ex)
                {
                    if (logEntry != null)
                    {
                        // send to the Azure Storage teams queue
                        log?.LogInformation($"Task Run: exception raised {ex}");
                        CloudQueue cloudQueue = AzureStorageQueueOperations.CreateAzureQueue(storageConnectionString, teamsQueueName, log);
                        var        logQueue   = new QueueLog()
                        {
                            ErrorMessage = $"{ex}", LogEntry = logEntry, WebhookUrl = webhookUrl
                        };
                        AzureStorageQueueOperations.InsertMessageQueue(cloudQueue, JsonConvert.SerializeObject(logQueue), log);

                        // send to the Azure Storage Error queue
                        log?.LogInformation($"Task Run: exception raised {ex}");
                        cloudQueue = AzureStorageQueueOperations.CreateAzureQueue(storageConnectionString, errorQueueName, log);
                        AzureStorageQueueOperations.InsertMessageQueue(cloudQueue, messageBody, log);
                    }
                }
            }
            // Once processing of the batch is complete, if any messages in the batch failed processing throw an exception so that there is a record of the failure.
            if (exceptions.Count > 1)
            {
                throw new AggregateException(exceptions);
            }

            if (exceptions.Count == 1)
            {
                throw exceptions.Single();
            }
        }
Ejemplo n.º 4
0
 internal void AddQueueLog(LogModel oLogToAdd)
 {
     QueueLog.Add(oLogToAdd);
 }