private void Start()
        {
            while ((_udpClient != null) && (_remoteEndPoint != null))
            {
                try
                {
                    byte[] buffer       = _udpClient.Receive(ref _remoteEndPoint);
                    string loggingEvent = Encoding.UTF8.GetString(buffer);

                    //Console.WriteLine(loggingEvent);
                    //  Console.WriteLine("Count: " + count++);

                    if (Notifiable == null)
                    {
                        continue;
                    }

                    LogMessage logMsg = ReceiverUtils.ParseLog4JXmlLogEvent(loggingEvent, "UdpLogger");
                    logMsg.RootLoggerName = _remoteEndPoint.Address.ToString().Replace(".", "-");
                    logMsg.LoggerName     = string.Format("{0}_{1}", _remoteEndPoint.Address.ToString().Replace(".", "-"), logMsg.LoggerName);
                    Notifiable.Notify(logMsg);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    return;
                }
            }
        }
        void Start(object newSocket)
        {
            try
            {
                using (var socket = (Socket)newSocket)
                    using (var ns = new NetworkStream(socket, FileAccess.Read, false))
                        while (_socket != null)
                        {
                            var logMsg = ReceiverUtils.ParseLog4JXmlLogEvent(ns, "TcpLogger");
                            logMsg.RootLoggerName = logMsg.LoggerName;
                            logMsg.LoggerName     = string.Format(":{1}.{0}", logMsg.LoggerName, _port);

                            if (Notifiable != null)
                            {
                                Notifiable.Notify(logMsg);
                            }
                        }
            }
            catch (IOException)
            {
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Beispiel #3
0
        private void EventLogOnEntryWritten(object sender, EntryWrittenEventArgs entryWrittenEventArgs)
        {
            var logMsg = new LogMessage
            {
                RootLoggerName = _baseLoggerName,
                LoggerName     = string.IsNullOrEmpty(entryWrittenEventArgs.Entry.Source)
                    ? _baseLoggerName
                    : $"{_baseLoggerName}.{entryWrittenEventArgs.Entry.Source}",
                Message    = entryWrittenEventArgs.Entry.Message,
                TimeStamp  = entryWrittenEventArgs.Entry.TimeGenerated,
                Level      = LogUtils.GetLogLevelInfo(GetLogLevel(entryWrittenEventArgs.Entry.EntryType)),
                ThreadName = entryWrittenEventArgs.Entry.InstanceId.ToString()
            };


            if (!string.IsNullOrEmpty(entryWrittenEventArgs.Entry.Category))
            {
                logMsg.Properties.Add("Category", entryWrittenEventArgs.Entry.Category);
            }

            if (!string.IsNullOrEmpty(entryWrittenEventArgs.Entry.UserName))
            {
                logMsg.Properties.Add("User Name", entryWrittenEventArgs.Entry.UserName);
            }

            Notifiable.Notify(logMsg);
        }
        private void EventLogOnEntryWritten(object sender, EntryWrittenEventArgs entryWrittenEventArgs)
        {
            LogMessage logMsg = new LogMessage();

            logMsg.RootLoggerName = _baseLoggerName;
            logMsg.LoggerName     = String.IsNullOrEmpty(entryWrittenEventArgs.Entry.Source)
                                    ? _baseLoggerName
                                    : String.Format("{0}.{1}", _baseLoggerName, entryWrittenEventArgs.Entry.Source);

            logMsg.Message    = entryWrittenEventArgs.Entry.Message;
            logMsg.TimeStamp  = entryWrittenEventArgs.Entry.TimeGenerated;
            logMsg.Level      = LogUtils.GetLogLevelInfo(GetLogLevel(entryWrittenEventArgs.Entry.EntryType));
            logMsg.ThreadName = entryWrittenEventArgs.Entry.InstanceId.ToString();

            if (!String.IsNullOrEmpty(entryWrittenEventArgs.Entry.Category))
            {
                logMsg.Properties.Add("Category", entryWrittenEventArgs.Entry.Category);
            }
            if (!String.IsNullOrEmpty(entryWrittenEventArgs.Entry.UserName))
            {
                logMsg.Properties.Add("User Name", entryWrittenEventArgs.Entry.UserName);
            }

            Notifiable.Notify(logMsg);
        }
Beispiel #5
0
 /// <summary>
 /// Verifica se o contrato possue notificações, caso sim, lança uma DomainException.
 /// </summary>
 public static void ThrowExceptionIfInvalid(this Notifiable contract)
 {
     if (contract.Invalid)
     {
         throw new DomainException(contract.Notifications);
     }
 }
Beispiel #6
0
        private void DebugMonitor_OnOutputDebugString(int pid, string text)
        {
            // Trim ending newline (if any)
            if (text.EndsWith(Environment.NewLine))
            {
                text = text.Substring(0, text.Length - Environment.NewLine.Length);
            }

            // Replace dots by "middle dots" to preserve Logger namespace
            var processName = GetProcessName(pid);

            processName = processName.Replace('.', '·');

            var logMsg = new LogMessage
            {
                Message    = text,
                LoggerName = processName
            };

            logMsg.LoggerName = $"{processName}.{pid}";
            logMsg.Level      = LogLevels.Instance[LogLevel.Debug];
            logMsg.ThreadName = pid.ToString();
            logMsg.TimeStamp  = DateTime.Now;
            Notifiable.Notify(logMsg);
        }
Beispiel #7
0
        private void Start()
        {
            while (_udpClient != null && _remoteEndPoint != null)
            {
                try
                {
                    var buffer       = _udpClient.Receive(ref _remoteEndPoint);
                    var loggingEvent = Encoding.UTF8.GetString(buffer);

                    if (Notifiable == null)
                    {
                        continue;
                    }

                    var logMsg = ReceiverUtils.ParseLog4JXmlLogEvent(loggingEvent, "UdpLogger");
                    logMsg.RootLoggerName = _remoteEndPoint.Address.ToString().Replace(".", "-");
                    logMsg.LoggerName     = $"{_remoteEndPoint.Address.ToString().Replace(".", "-")}_{logMsg.LoggerName}";
                    Notifiable.Notify(logMsg);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    return;
                }
            }
        }
Beispiel #8
0
        protected override void ProcessFileData()
        {
            int    temp;
            Parser parser = new Parser();

            while ((temp = fileReader.Read()) != -1)
            {
                var log = parser.parse((char)temp);
                if (log != null)
                {
                    if (Notifiable != null)
                    {
                        Notifiable.Notify(log);
                    }
                }
            }
            var logLast = parser.GetLog();

            if (logLast != null)
            {
                if (Notifiable != null)
                {
                    Notifiable.Notify(logLast);
                }
            }
        }
Beispiel #9
0
        private void ReadFile()
        {
            if ((_fileReader == null))
            {
                return;
            }

            if (_fileReader.BaseStream.Position > _fileReader.BaseStream.Length)
            {
                _fileReader.BaseStream.Seek(0, SeekOrigin.Begin);
                _fileReader.DiscardBufferedData();
            }

            // Get last added lines
            var           logMsgs = new List <LogMessage>();
            List <string> fields;

            while ((fields = ReadLogEntry()) != null)
            {
                var logMsg = new LogMessage {
                    ThreadName = string.Empty
                };

                if (fields.Count == FieldList.Length)
                {
                    ParseFields(ref logMsg, fields);
                    logMsgs.Add(logMsg);
                }
            }

            // Notify the UI with the set of messages
            Notifiable.Notify(logMsgs.ToArray());
        }
        /// <summary>
        /// 接受消息
        /// </summary>
        private void ReceiveMessage()
        {
            while (IsContinueToListenToUDP)
            {
                try
                {
                    byte[] buffer = _udpClient.Receive(ref _remoteEndPoint);

                    if (Notifiable == null)
                    {
                        continue;
                    }

                    //获取LogMessage
                    LogMessage logMsg = ParserHelper.ParseLayout(buffer, LogLayoutType);

                    //检查等级过滤
                    if (!string.IsNullOrWhiteSpace(LevelFilterStr) &&
                        !LevelFilterStr.Contains(logMsg.Level))
                    {
                        //需要过滤,且配置中不包含该等级名称
                        continue;
                    }

                    //保存日志到数据库
                    Notifiable.Notify(logMsg);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }
        }
        private void ParseEventLogEntry(EventLog eventLog, EventLogEntry entry)
        {
            LogMessage logMsg   = new LogMessage();
            var        baseName = "EventLog." + eventLog.Log;

            if (AppendHostNameToLogger)
            {
                baseName = "EventLog_" + (this.MachineName == "." ? "local" : this.MachineName) + "." + eventLog.Log;
            }
            logMsg.RootLoggerName = baseName;
            logMsg.LoggerName     = String.IsNullOrEmpty(entry.Source)
                                    ? baseName
                                    : String.Format("{0}.{1}", baseName, entry.Source);

            logMsg.Message    = entry.Message;
            logMsg.TimeStamp  = entry.TimeGenerated;
            logMsg.Level      = LogUtils.GetLogLevelInfo(GetLogLevel(entry.EntryType));
            logMsg.ThreadName = entry.InstanceId.ToString();

            if (!String.IsNullOrEmpty(entry.Category))
            {
                logMsg.Properties.Add("Category", entry.Category);
            }
            if (!String.IsNullOrEmpty(entry.UserName))
            {
                logMsg.Properties.Add("User Name", entry.UserName);
            }

            if (Notifiable != null)
            {
                Notifiable.Notify(logMsg);
            }
        }
Beispiel #12
0
 public INotifyEnumerable <ModelTreeItem> AsNotifiable()
 {
     if (notifiable == null)
     {
         notifiable = new Notifiable(Element);
     }
     return(notifiable);
 }
 public DataProcessor(IInvokable invoke, INotifiable notify, ILobby lobby) {
     if(invoke != null)
         _invokable = new Invokable(invoke);
     if(notify != null)
         _notifiable = new Notifiable(notify);
     if (lobby != null)
         _lobby = new Lobby(lobby);
 }
Beispiel #14
0
 public INotifyEnumerable <IModelElement> AsNotifiable()
 {
     if (notifiable == null)
     {
         notifiable = new Notifiable(Element);
     }
     return(notifiable);
 }
Beispiel #15
0
        public ValidationContract Concat(Notifiable notifiable)
        {
            if (notifiable.Invalid)
            {
                AddNotifications(notifiable.Notifications);
            }

            return(this);
        }
Beispiel #16
0
 protected void AddNotifications(Notifiable notifiable)
 {
     if (notifiable != null && notifiable.Invalid)
     {
         foreach (var notify in notifiable.Notifications)
         {
             Notification.Add(notify.Property, notify.Message);
         }
     }
 }
Beispiel #17
0
        /// <summary>
        ///
        /// </summary>
        private void Start()
        {
            _queue = new MessageQueue(QueueName);

            _queue.ReceiveCompleted += delegate(Object source, ReceiveCompletedEventArgs asyncResult)
            {
                try
                {
                    // End the asynchronous receive operation.
                    Message m = ((MessageQueue)source).EndReceive(asyncResult.AsyncResult);

                    if (Notifiable != null)
                    {
                        string     loggingEvent = Encoding.ASCII.GetString(((MemoryStream)m.BodyStream).ToArray());
                        LogMessage logMsg       = ReceiverUtils.ParseLog4JXmlLogEvent(loggingEvent, "MSMQLogger");
                        logMsg.LoggerName     = string.Format("{0}_{1}", QueueName.TrimStart('.'), logMsg.LoggerName);
                        logMsg.RootLoggerName = QueueName;
                        Notifiable.Notify(logMsg);
                    }


                    if (BulkProcessBackedUpMessages)
                    {
                        Message[] all = ((MessageQueue)source).GetAllMessages();
                        if (all.Length > 0)
                        {
                            int numberofmessages = all.Length > 1000 ? 1000 : all.Length;

                            LogMessage[] logs = new LogMessage[numberofmessages];

                            for (int i = 0; i < numberofmessages; i++)
                            {
                                Message thisone = ((MessageQueue)source).Receive();

                                string loggingEvent =
                                    Encoding.ASCII.GetString(((MemoryStream)thisone.BodyStream).ToArray());
                                LogMessage logMsg = ReceiverUtils.ParseLog4JXmlLogEvent(loggingEvent, "MSMQLogger");
                                logMsg.LoggerName = string.Format("{0}_{1}", QueueName.TrimStart('.'), logMsg.LoggerName);
                                logs[i]           = logMsg;
                            }

                            Notifiable.Notify(logs);
                        }
                    }

                    ((MessageQueue)source).BeginReceive();
                }
                catch (MessageQueueException)
                {
                    // Handle sources of MessageQueueException.
                }
            };

            _queue.BeginReceive();
        }
Beispiel #18
0
    public void Unsubscribe(Notification.Type type, Notifiable notifiable)
    {
        if (!m_types.ContainsKey(type))
        {
            return;
        }

        List <Notifiable> notifiables = m_types[type];

        notifiables.Remove(notifiable);
    }
        private static Task <TResponse> Errors(IEnumerable <ValidationFailure> failures)
        {
            var notifiable = new Notifiable();

            foreach (var failure in failures)
            {
                notifiable.AddError(new NotifiableError(failure.ErrorMessage));
            }

            return(Task.FromResult(notifiable as TResponse));
        }
        private void NotifyWebSocketStateChange(WebSocketState state)
        {
            var logMsg = ReceiverUtils.ParseLog4JXmlLogEvent($"WebSocket state changed: {state}", "wssLogger");

            logMsg.Level = LogLevels.Instance[LogLevel.Info];

            var loggerName = WebSocketServerUri.Replace("wss://", "wss-").Replace(":", "-").Replace(".", "-");

            logMsg.RootLoggerName = loggerName;
            logMsg.LoggerName     = $"{loggerName}_{logMsg.LoggerName}";
            Notifiable.Notify(logMsg);
        }
Beispiel #21
0
        public static string GetAllMessages(this Notifiable notifiable)
        {
            var messages = new StringBuilder();

            if (notifiable.Invalid)
            {
                foreach (var item in notifiable.Notifications)
                {
                    messages.AppendLine(item.Message);
                }
            }
            return(messages.ToString());
        }
Beispiel #22
0
 public bool Commit(Notifiable entity)
 {
     if (entity.IsNotification())
     {
         _uow.Commit();
         return(true);
     }
     else
     {
         _uow.Rollback();
         return(false);
     }
 }
Beispiel #23
0
        private void ReadFile()
        {
            if ((_fileReader == null) || (_fileReader.BaseStream.Length == _lastFileLength))
            {
                return;
            }

            // Seek to the last file length
            _fileReader.BaseStream.Seek(_lastFileLength, SeekOrigin.Begin);

            // Get last added lines
            string            line;
            var               sb      = new StringBuilder();
            List <LogMessage> logMsgs = new List <LogMessage>();

            while ((line = _fileReader.ReadLine()) != null)
            {
                if (_fileFormat == FileFormatEnums.Flat)
                {
                    LogMessage logMsg = new LogMessage();
                    logMsg.RootLoggerName = _loggerName;
                    logMsg.LoggerName     = _fullLoggerName;
                    logMsg.ThreadName     = "NA";
                    logMsg.Message        = line;
                    logMsg.TimeStamp      = DateTime.Now;
                    logMsg.Level          = LogLevels.Instance[LogLevel.Info];

                    logMsgs.Add(logMsg);
                }
                else
                {
                    sb.Append(line);

                    // This condition allows us to process events that spread over multiple lines
                    if (line.Contains("</log4j:event>"))
                    {
                        LogMessage logMsg = ReceiverUtils.ParseLog4JXmlLogEvent(sb.ToString(), _fullLoggerName);
                        logMsgs.Add(logMsg);
                        sb = new StringBuilder();
                    }
                }
            }

            // Notify the UI with the set of messages
            Notifiable.Notify(logMsgs.ToArray());

            // Update the last file length
            _lastFileLength = _fileReader.BaseStream.Position;
        }
        private static IEnumerable <Notifiable> GetModels(Notifiable aggregate)
        {
            GuardAgainst.Null(aggregate, nameof(aggregate));

            var models = aggregate
                         .GetType()
                         .GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)
                         .Where(p => typeof(Notifiable).IsAssignableFrom(p.PropertyType))
                         .Select(p => (Notifiable)p.GetValue(aggregate))
                         .ToList();

            models.Insert(0, aggregate);

            return(models);
        }
Beispiel #25
0
        public void LogEvents(LoggingEvent[] events)
        {
            if ((events == null) || (events.Length == 0) || (Notifiable == null))
            {
                return;
            }

            LogMessage[] logMsgs = new LogMessage[events.Length];
            for (int i = 0; i < events.Length; i++)
            {
                logMsgs[i] = CreateLogMessage(events[i]);
            }

            Notifiable.Notify(logMsgs);
        }
Beispiel #26
0
    // PUBLIC METHODS
    // -------------------------------------------------------------------------

    public void Subscribe(Notification.Type type, Notifiable notifiable)
    {
        if (!m_types.ContainsKey(type))
        {
            m_types[type] = new List <Notifiable>();
        }

        List <Notifiable> notifiables = m_types[type];

        if (notifiables.Contains(notifiable))
        {
            return;
        }

        notifiables.Add(notifiable);
    }
        public void LogEvents(LoggingEvent[] events)
        {
            if (events == null || events.Length == 0 || Notifiable == null)
            {
                return;
            }

            var logMsgs = new LogMessage[events.Length];

            for (var i = 0; i < events.Length; i++)
            {
                logMsgs[i] = CreateLogMessage(events[i]);
            }

            Notifiable.Notify(logMsgs);
        }
Beispiel #28
0
        public async void um_comando_valido_nao_notifica_mock()
        {
            //mocks
            var mediatorHandlerMock = new Mock <IMediatorHandler>();
            var notificationsMock   = new Mock <INotifications>();
            var commandMock         = new Mock <ICommandBase>();

            //setups
            commandMock.Setup(x => x.ValidationResult).Returns(new ValidationResult());

            var notifiable = new Notifiable(mediatorHandlerMock.Object, notificationsMock.Object);

            await notifiable.ValidateAndNotifyValidationErrors(commandMock.Object);

            _ = notifiable.IsValid();

            mediatorHandlerMock.Verify(x => x.RaiseEvent(It.IsAny <DomainNotification>(), It.IsAny <CancellationToken>()), Times.Never);
            notificationsMock.Verify(x => x.HasNotifications(), Times.Once);
        }
        public static ObjectId ObjectIdCast(this Notifiable notifiable, string id)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                notifiable.AddNotification(new Notification(null, "Obirgatório informar o id"));
                return(ObjectId.Empty);
            }

            if (ObjectId.TryParse(id, out var objectId))
            {
                return(objectId);
            }
            else
            {
                notifiable.AddNotification(new Notification(null, "Obirgatório informar o id"));
            }

            return(ObjectId.Empty);
        }
Beispiel #30
0
        private void StartUdp()
        {
            while ((_udpClient != null) && (_remoteEndPoint != null))
            {
                try
                {
                    byte[] buffer       = _udpClient.Receive(ref _remoteEndPoint);
                    string loggingEvent = this.EncodingObject.GetString(buffer);

                    //Console.WriteLine(loggingEvent);
                    //  Console.WriteLine("Count: " + count++);

                    if (Notifiable == null)
                    {
                        continue;
                    }

                    LogMessage logMsg = ReceiverUtils.ParseLog4JXmlLogEvent(loggingEvent, "UdpLogger");
                    if (_useRemoteIPAsNamespacePrefix)
                    {
                        logMsg.RootLoggerName = _remoteEndPoint.Address.ToString().Replace(".", "-");
                        logMsg.LoggerName     = string.Format("{0}_{1}", _remoteEndPoint.Address.ToString().Replace(".", "-"), logMsg.LoggerName);
                    }

                    if (Notifiable != null)
                    {
                        Notifiable.Notify(logMsg);
                    }
                }
                catch (ThreadAbortException ex)
                {
                    Utils.log.Error("StartUdp " + ex.Message);
                    Thread.ResetAbort();
                    break;
                }
                catch (Exception ex)
                {
                    Utils.log.Error(ex.Message, ex);
                    return;
                }
            }
        }
Beispiel #31
0
        protected override void ProcessFileData()
        {
            int temp;

            while ((temp = fileReader.Read()) != -1)
            {
                // < ImmediateFlush value = "false" /> Óдí, ³¢ÊÔtcpreceiverµÄ·½·¨.
                sb.Append((char)temp);

                // This condition allows us to process events that spread over multiple lines
                if (IsEndWith(sb, log4jEndTag))
                {
                    LogMessage logMsg = ReceiverUtils.ParseLog4JXmlLogEvent(sb.ToString(), _fullLoggerName);
                    // Notify the UI with the set of messages
                    if (Notifiable != null)
                    {
                        Notifiable.Notify(logMsg);
                    }
                    sb = new StringBuilder();
                }
            }
        }