Пример #1
0
        private void OnMessageArrived(object sender, IdleEventArgs args)
        {
            foreach (var message in args.Messages)
            {
                message.Seen = true;
                OutageMailMessage outageMessage = mapper.MapMail(message);
                Console.WriteLine(outageMessage);

                OutageTracingModel tracingModel = parser.Parse(outageMessage);

                if (tracingModel.IsValidReport)
                {
                    dispatcher.Dispatch(tracingModel.Gid);
                }

                try
                {
                    publisher.Publish(new OutageEmailPublication(Topic.OUTAGE_EMAIL, new EmailToOutageMessage(tracingModel.Gid)), MicroserviceNames.OmsEmailService).Wait();
                }
                catch (Exception e)
                {
                    Console.WriteLine($"[ImapIdleEmailClient::OnMessageArrived] Sending to PubSub Engine failed. Exception message: {e.Message}");
                }
            }

            ReregisterIdleHandler();
        }
Пример #2
0
        public OutageTracingModel Parse(OutageMailMessage message)
        {
            string searchQuery = "gid";
            int    gidIndex    = message.Body.ToLower().IndexOf(searchQuery);

            if (gidIndex < 0)
            {
                Logger.LogWarning("Gid Index is less than 0. Invalid model will be build.");
                return(BuildInvalidModel());
            }

            long gid = 0;

            try
            {
                // we should consider everything
                string gidText = message.Body.Split('[')[1].Split(']')[0];

                if (gidText.ToLower().Contains("0x"))
                {
                    gid = long.Parse(gidText.ToLower().Split('x')[1], NumberStyles.HexNumber);
                }
                else
                {
                    gid = long.Parse(gidText);
                }
            }
            catch (Exception e)
            {
                Logger.LogError($"Exception on parsing outage email, invalid model will be build. Message: {e.Message}");
                return(BuildInvalidModel());
            }

            return(BuildValidModel(gid));
        }
        private void OnMessageArrived(object sender, IdleEventArgs args)
        {
            foreach (var message in args.Messages)
            {
                message.Seen = true;
                OutageMailMessage outageMessage = _mapper.MapMail(message);
                Console.WriteLine(outageMessage);

                OutageTracingModel tracingModel = _parser.Parse(outageMessage);

                if (tracingModel.IsValidReport)
                {
                    _dispatcher.Dispatch(tracingModel.Gid);
                }

                try
                {
                    _publisher.Publish(
                        publication: new OutageEmailPublication(Topic.OUTAGE_EMAIL, new EmailToOutageMessage(tracingModel.Gid)),
                        publisherName: "ImapIdleEmailClient"
                        );
                }
                catch (Exception)
                {
                    Console.WriteLine("[ImapIdleEmailClient::OnMessageArrived] Sending to PubSub Engine failed.");
                }
            }

            ReregisterIdleHandler();
        }
Пример #4
0
        public OutageTracingModel Parse(OutageMailMessage message)
        {
            string searchQuery = "gid";
            int    gidIndex    = message.Body.ToLower().IndexOf(searchQuery);

            if (gidIndex < 0)
            {
                return(BuildInvalidModel());
            }

            long gid = 0;

            try
            {
                // we should consider everything
                string gidText = message.Body.Split('[')[1].Split(']')[0];

                if (gidText.ToLower().Contains("0x"))
                {
                    gid = long.Parse(gidText.ToLower().Split('x')[1], NumberStyles.HexNumber);
                }
                else
                {
                    gid = long.Parse(gidText);
                }
            }
            catch (Exception)
            {
                return(BuildInvalidModel());
            }

            return(BuildValidModel(gid));
        }
        public IEnumerable <OutageMailMessage> GetUnreadMessages()
        {
            if (!_client.IsConnected)
            {
                throw new NullReferenceException("ImapClient is a null value (not connected).");
            }

            Message[] messages = _client.Folders["INBOX"].Search("UNSEEN", MessageFetchMode.Full);

            List <OutageMailMessage> outageMailMessages = new List <OutageMailMessage>();

            foreach (Message message in messages)
            {
                OutageMailMessage outageMessage = _mapper.MapMail(message);
                outageMailMessages.Add(outageMessage);
                message.Seen = true;

                OutageTracingModel tracingModel = _parser.Parse(outageMessage);

                if (tracingModel.IsValidReport)
                {
                    _dispatcher.Dispatch(tracingModel.Gid);
                }

                try
                {
                    _publisher.Publish(
                        publication: new OutageEmailPublication(Topic.OUTAGE_EMAIL, new EmailToOutageMessage(tracingModel.Gid)),
                        publisherName: "Email Service"
                        );
                }
                catch (Exception)
                {
                    Console.WriteLine("[ImapEmailClient::GetUnreadMessages] Sending to PubSub Engine failed.");
                }
            }

            return(outageMailMessages);
        }
        private void OnMessageArrived(object sender, IdleEventArgs args)
        {
            try
            {
                foreach (var message in args.Messages)
                {
                    message.Seen = true;
                    OutageMailMessage outageMessage = mapper.MapMail(message);
                    Logger.LogInformation($"{baseLogString} OnMessageArrived => Message: {outageMessage}");

                    OutageTracingModel tracingModel = parser.Parse(outageMessage);

                    publisher.Publish(new OutageEmailPublication(Topic.OUTAGE_EMAIL, new EmailToOutageMessage(tracingModel.Gid)), MicroserviceNames.OmsEmailService).Wait();
                }

                ReregisterIdleHandler();
            }
            catch (Exception e)
            {
                Logger.LogError($"{baseLogString} OnMessageArrived => Exception: {e.Message}", e);
            }
        }
        public IEnumerable <OutageMailMessage> GetUnreadMessages()
        {
            var outageMailMessages = new List <OutageMailMessage>();

            try
            {
                if (!client.IsConnected)
                {
                    if (!client.Connect())
                    {
                        Logger.LogError($"{baseLogString} GetUnreadMessages => client could not connect to the email server.");
                        return(outageMailMessages);
                    }
                }

                Message[] messages = client.Folders["INBOX"].Search("UNSEEN", MessageFetchMode.Full);

                foreach (Message message in messages)
                {
                    OutageMailMessage outageMessage = mapper.MapMail(message);

                    outageMailMessages.Add(outageMessage);
                    message.Seen = true;

                    OutageTracingModel tracingModel = parser.Parse(outageMessage);

                    publisher.Publish(new OutageEmailPublication(Topic.OUTAGE_EMAIL, new EmailToOutageMessage(tracingModel.Gid)), MicroserviceNames.OmsEmailService).Wait();
                }
            }
            catch (Exception e)
            {
                Logger.LogError($"{baseLogString} GetUnreadMessages => Message: {e.Message}", e);
            }

            return(outageMailMessages);
        }