예제 #1
0
        /// <summary>
        /// Removes the attachment.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="nickname">The nickname.</param>
        /// <returns></returns>
        public static bool RemoveAttachment(this AgentMessage message, string nickname)
        {
            var decorator = message.FindDecorator <AttachDecorator>("attach") ?? new AttachDecorator();
            var result    = decorator.Remove(decorator[nickname]);

            message.SetDecorator(decorator, "attach");

            return(result);
        }
예제 #2
0
        /// <summary>
        /// Adds an attachment to the message using the ~attach attachment
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="attachment">The attachment.</param>
        /// <param name="overrideExisting">if set to <c>true</c> [override existing].</param>
        public static void AddAttachment(this AgentMessage message, Attachment attachment, bool overrideExisting = true)
        {
            var decorator = message.FindDecorator <AttachDecorator>("attach") ?? new AttachDecorator();
            var existing  = decorator[attachment];

            if (existing != null && !overrideExisting)
            {
                throw new ArgumentException($"Attachment {attachment.Nickname} already exists.");
            }
            if (existing != null)
            {
                decorator.Remove(existing);
            }
            decorator.Add(attachment);
            message.AddDecorator(decorator, "attach");
        }
예제 #3
0
        /// <summary>
        /// Adds return routing to message
        /// </summary>
        /// <param name="message">The message to add return routing</param>
        public static bool ReturnRoutingRequested(this AgentMessage message)
        {
            try
            {
                var transportDecorator = message.FindDecorator <TransportDecorator>(DecoratorNames.TransportDecorator);

                if (transportDecorator != null)
                {
                    return(true);
                }
                return(false);
            }
            catch (Exception)
            {
                return(false);
            }
        }
예제 #4
0
        /// <summary>
        /// Gets the attachment.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="nickname">The nickname.</param>
        public static Attachment GetAttachment(this AgentMessage message, string nickname)
        {
            var decorator = message.FindDecorator <AttachDecorator>("attach") ?? new AttachDecorator();

            return(decorator[nickname]);
        }