Exemple #1
0
 public Task ForEachAsync <T>(
     BlockingCollection <ILogMessage> messages,
     IEnumerable <T> source,
     int numberOfThreads,
     Func <T, Task> iterate)
 {
     return(Task.WhenAll(
                from partition in Partitioner.Create(source).GetPartitions(numberOfThreads)
                select Task.Run(async delegate
     {
         using (partition)
             while (partition.MoveNext())
             {
                 try
                 {
                     await iterate(partition.Current);
                     messages.Add(_formatter.Format(partition.Current));
                 }
                 catch (Exception ex)
                 {
                     messages.Add(_formatter.Format(partition.Current, LogLevel.Error, ex));
                 }
             }
     })));
 }
Exemple #2
0
        public void Write(ILogMessage message)
        {
            if (message.LevelOfSeverity < MinimumLevel)
            {
                return;
            }
            var formattedMessage = Formatter.Format(message);

            foreach (var module in OutputModules)
            {
                module.Write(formattedMessage);
            }
        }
Exemple #3
0
        /*----------------------------------------------------------------------------------------*/
        #region Protected Methods
        /// <summary>
        /// Writes the specified message to the stream.
        /// </summary>
        /// <param name="severity">The severity of the message.</param>
        /// <param name="format">The message format.</param>
        /// <param name="args">Arguments to the message format.</param>
        protected virtual void WriteMessage(LogSeverity severity, string format, params object[] args)
        {
            string message;

            if (args.Length > 0)
            {
                message = String.Format(format, args);
            }
            else
            {
                message = format;
            }

            _writer.WriteLine(_formatter.Format(this, severity, message));
        }
Exemple #4
0
        public async Task OutputMessageAsync(string partitionId, string pipelineName, int index, Message msg)
        {
            var serializedMessage = $"{_serializer.Format(msg)}{Environment.NewLine}";

            var filePath = GetFilePath(partitionId, pipelineName, index, msg);

            var key = $"{pipelineName}_{msg.Type}_{msg.Version}_{partitionId}";

            var semaphore = s_semaphores.GetOrAdd(key, new SemaphoreSlim(1, 1));
            await semaphore.WaitAsync();

            try
            {
                if (_serializer.IncludeHeaders)
                {
                    await AppendMessageToFileWithHeaderAsync(serializedMessage, filePath);
                }
                else
                {
                    await AppendMessageToFileWithoutHeaderAsync(serializedMessage, filePath);
                }
            }
            finally
            {
                semaphore.Release();
            }
        }
Exemple #5
0
        public void Write(Message message, MessageContext messageContext)
        {
            var text = _formatter.Format(message, messageContext);

            switch (message.Type)
            {
            case MessageType.Trace:
                UnityEngine.Debug.Log(text);
                break;

            case MessageType.Debug:
                UnityEngine.Debug.Log(text);
                break;

            case MessageType.Warning:
                UnityEngine.Debug.LogWarning(text);
                break;

            case MessageType.Error:
                UnityEngine.Debug.LogError(text);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemple #6
0
 /// <summary>
 /// Convierte a un array de bytes los datos del mensaje.
 /// </summary>
 /// <returns>
 /// Un array de bytes.
 /// </returns>
 public override byte[] GetBytes()
 {
     byte[] data = null;
     if (_formatter != null)
     {
         FormatterContext formatterContext = new FormatterContext(FormatterContext.DefaultBufferSize);
         _formatter.Format(this, ref formatterContext);
         data = formatterContext.GetData();
     }
     return(data);
 }
Exemple #7
0
        public Task OutputMessageAsync(string partitionId, string pipelineName, int index, Message msg)
        {
            if (_enabled)
            {
                var str = _serializer.Format(msg);

                Console.WriteLine(str);
            }

            return(Task.CompletedTask);
        }
Exemple #8
0
        public Task OutputMessageAsync(string partitionId, string pipelineName, int index, Message msg)
        {
            // the output expects a new line each time we write something, so we can
            // just append the new line at the end of the serialized output
            var serializedMessage = $"{_serializer.Format(msg)}{Environment.NewLine}";

            var filePath = GetFilePath(partitionId, pipelineName, index, msg);

            _buffers.Append(partitionId, filePath, serializedMessage);

            return(Task.CompletedTask);
        }
        public Task OutputMessageAsync(string partitionId, string pipelineName, int index, Message msg)
        {
            string payload = _serializer.Format(msg);

            if (_serializer.IncludeHeaders)
            {
                payload = $"{_serializer.Header}{Environment.NewLine}{payload}";
            }

            var eventData = new EventData(Encoding.UTF8.GetBytes(payload));

            return(Client.SendAsync(eventData));
        }
 public void OnNext(IList <ILogEntry> value)
 {
     messageLogView.ClearAllEntries();
     foreach (var logEntry in value)
     {
         var entryView = messageLogView.CreateNewEntry();
         entryView.Speaker = logEntry.Speaker;
         StringBuilder stringBuilder = new StringBuilder();
         foreach (var msgBuff in logEntry.MessageBuffers)
         {
             stringBuilder.Append(messageFormatter.Format(msgBuff.Message, msgBuff.FontData));
         }
         entryView.Message = stringBuilder.ToString();
     }
 }
Exemple #11
0
        public override Task OnConnected()
        {
            var message = _formatter.Format("New connection!");

            return(Clients.All.Message(message));
        }
        string MarkupMessage(MessageBuffer messageBuffer, int renderLen)
        {
            string message = messageBuffer.Message.Substring(0, renderLen);

            return(messageFormatter.Format(message, messageBuffer.FontData));
        }
Exemple #13
0
 public string SayHello(string name)
 {
     return(formatter.Format("Hi, {0}!", name));
 }
Exemple #14
0
        public void Send(string message)
        {
            string format = _formatter.Format(message);

            Console.WriteLine("EmailSender: \"{0}\" has been sent.", format);
        }