Exemplo n.º 1
0
        public static HipChatMessage Create(agsXMPP.protocol.client.Message message)
        {
            var xmppMessage = new HipChatMessage {ReplyEntity = new Entity()};

            xmppMessage.ReplyEntity.ReplyTo = ExtractReplyTo(message);

            if (message.From.ToString().Contains("conf.hipchat.com"))
            {
                xmppMessage.MessageType = MessageType.RoomMessage;
                xmppMessage.ReplyEntity.FromUser = ExtractFromUser(message);
            }

            else if (message.From.ToString().Contains("chat.hipchat.com"))
                xmppMessage.MessageType = MessageType.DirectMessage;
            else
                xmppMessage.MessageType = MessageType.UnKnown;

            xmppMessage.Body = message.Body;
            return xmppMessage;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Writes the logging event out to hipchat with the specified details.
        /// </summary>
        /// <param name="loggingEvent">The event to append.</param>
        protected override void Append(LoggingEvent loggingEvent)
        {
            try
            {
                var content = this.GetMessage(loggingEvent);
                var color = GetBackgroundColor(loggingEvent.Level.Name);
                var message = new HipChatMessage(content, color);

                if (this.Synchronous)
                {
                    SendMessageRequest(message.Content, this.AuthToken, this.RoomId, this.SenderName, message.Color, this.Notify);
                }
                else
                {
                    var thread = new Thread(this.SendMessage);
                    thread.IsBackground = true;
                    thread.Start(message);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }