/// <summary>
        /// Converts the SubscriptionResponse to a list of headers
        /// </summary>
        /// <returns><see cref="HeaderCollection"/></returns>
        public override HeaderCollection ToHeaders()
        {
            HeaderCollection headers = new HeaderCollection();

            Header hTTL = new Header(Header.SUBSCRIPTION_TTL, this.ttl.ToString());
            headers.AddHeader(hTTL);

            HeaderCollection baseHeaders = base.ToHeaders();
            headers.AddHeaders(baseHeaders);

            return headers;
        }
Example #2
0
        /// <summary>
        /// Converts the Error to a list of headers
        /// </summary>
        /// <returns><see cref="HeaderCollection"/></returns>
        public virtual HeaderCollection ToHeaders()
        {
            Header hErrorCode = new Header(Header.ERROR_CODE, this.ErrorCode.ToString());
            Header hDescription = new Header(Header.ERROR_DESCRIPTION, this.ErrorDescription);

            HeaderCollection headers = new HeaderCollection();
            headers.AddHeader(hErrorCode);
            headers.AddHeader(hDescription);

            this.AddInheritedAttributesToHeaders(headers);
            return headers;
        }
Example #3
0
        protected override bool OnBeforeSend(Growl.Connector.MessageBuilder mb)
        {
            //from <hostname> by <hostname> [with Growl] [id <identifier>]; <ISO 8601 date>

            foreach (Header header in this.RequestInfo.PreviousReceivedHeaders)
            {
                mb.AddHeader(header);
            }

            string received = String.Format("from {0} by {1}{2}{3}; {4}", this.RequestInfo.ReceivedFrom, this.RequestInfo.ReceivedBy, (this.RequestInfo.ReceivedWith != null ? String.Format(" with {0}", this.RequestInfo.ReceivedWith) : String.Empty), (this.RequestInfo.RequestID != null ? String.Format(" id {0}", this.RequestInfo.RequestID) : String.Empty), this.RequestInfo.TimeReceived.ToString("u"));
            Header receivedHeader = new Header("Received", received);
            mb.AddHeader(receivedHeader);

            return base.OnBeforeSend(mb);
        }
Example #4
0
        /// <summary>
        /// Converts the object to a list of headers
        /// </summary>
        /// <returns><see cref="HeaderCollection"/></returns>
        public HeaderCollection ToHeaders()
        {
            Header hName = new Header(Header.APPLICATION_NAME, this.name);
            Header hIcon = new Header(Header.APPLICATION_ICON, this.Icon);

            HeaderCollection headers = new HeaderCollection();
            headers.AddHeader(hName);

            if (this.Icon != null && this.Icon.IsSet)
            {
                headers.AddHeader(hIcon);
                headers.AssociateBinaryData(this.Icon);
            }

            this.AddInheritedAttributesToHeaders(headers);
            return headers;
        }
Example #5
0
        /// <summary>
        /// Creates a <see cref="Header"/> from a message line
        /// </summary>
        /// <param name="line">The individual message line</param>
        /// <returns><see cref="Header"/></returns>
        public static Header ParseHeader(string line)
        {
            Header header = null;

            if (line != null)
            {
                line = line.Trim();
                if(String.IsNullOrEmpty(line))
                {
                    header = new Header();
                }
                else
                {
                    // move this to static member variable
                    Match m = regExHeader.Match(line);
                    if (m.Success)
                    {
                        header = new Header(m.Groups[HEADER_NAME_REGEX_GROUP_NAME].Value.Trim(), m.Groups[HEADER_VALUE_REGEX_GROUP_NAME].Value.Trim());
                    }
                }
            }
            return header;
        }
        /// <summary>
        /// When converting an <see cref="ExtensibleObject"/> to a list of headers,
        /// this method adds the common attributes to the list of headers.
        /// </summary>
        /// <param name="headers">The <see cref="HeaderCollection"/> to add the custom headers to</param>
        protected void AddCommonAttributesToHeaders(HeaderCollection headers)
        {
            if (headers != null)
            {
                //Header hRequestID = new Header("RequestID", requestID);
                Header hMachineName = new Header(Header.ORIGIN_MACHINE_NAME, machineName);
                Header hSoftwareName = new Header(Header.ORIGIN_SOFTWARE_NAME, softwareName);
                Header hSoftwareVersion = new Header(Header.ORIGIN_SOFTWARE_VERSION, softwareVersion);
                Header hPlatformName = new Header(Header.ORIGIN_PLATFORM_NAME, platformName);
                Header hPlatformVersion = new Header(Header.ORIGIN_PLATFORM_VERSION, platformVersion);

                //headers.Add(hRequestID);
                headers.AddHeader(hMachineName);
                headers.AddHeader(hSoftwareName);
                headers.AddHeader(hSoftwareVersion);
                headers.AddHeader(hPlatformName);
                headers.AddHeader(hPlatformVersion);
            }
        }
Example #7
0
        /// <summary>
        /// Converts the Response to a list of headers
        /// </summary>
        /// <returns><see cref="HeaderCollection"/></returns>
        public override HeaderCollection ToHeaders()
        {
            HeaderCollection headers = new HeaderCollection();

            if (this.IsOK && !this.IsCallback)
            {
                Header hResponseAction = new Header(Header.RESPONSE_ACTION, this.InResponseTo);

                headers.AddHeader(hResponseAction);
            }

            if (this.IsError)
            {
                Header hErrorCode = new Header(Header.ERROR_CODE, this.ErrorCode.ToString());
                Header hDescription = new Header(Header.ERROR_DESCRIPTION, this.ErrorDescription);

                headers.AddHeader(hErrorCode);
                headers.AddHeader(hDescription);
            }

            if (this.IsCallback)
            {
                Header hNotificationID = new Header(Header.NOTIFICATION_ID, this.callbackData.NotificationID);
                Header hCallbackResult = new Header(Header.NOTIFICATION_CALLBACK_RESULT, Enum.GetName(typeof(CallbackResult), this.callbackData.Result));
                Header hCallbackContext = new Header(Header.NOTIFICATION_CALLBACK_CONTEXT, this.callbackData.Data);
                Header hCallbackContextType = new Header(Header.NOTIFICATION_CALLBACK_CONTEXT_TYPE, this.callbackData.Type);
                //Header hCallbackTimestamp = new Header(Header.NOTIFICATION_CALLBACK_TIMESTAMP, DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ"));
                Header hCallbackTimestamp = new Header(Header.NOTIFICATION_CALLBACK_TIMESTAMP, DateTime.UtcNow.ToString("u"));

                headers.AddHeader(hNotificationID);
                headers.AddHeader(hCallbackResult);
                headers.AddHeader(hCallbackContext);
                headers.AddHeader(hCallbackContextType);
                headers.AddHeader(hCallbackTimestamp);
            }

            this.AddInheritedAttributesToHeaders(headers);
            return headers;
        }
        /// <summary>
        /// Adds a <see cref="Header"/> to the section.
        /// </summary>
        /// <remarks>
        /// Headers are added to the message output in the same order that they are added via this method.
        /// If the header is a pointer to a binary resource, the binary data is also handled.
        /// </remarks>
        /// <param name="header">The <see cref="Header"/> to add</param>
        public void AddHeader(Header header)
        {
            if (header != null)
            {
                if (header.IsGrowlResourcePointer)
                    this.binaryData.Add(header.GrowlResource);

                if (header.IsBlankLine) AddBlankLine();
                else AddHeader(header.Name, header.Value);
            }
        }
        /// <summary>
        /// Converts the object to a list of headers
        /// </summary>
        /// <returns><see cref="HeaderCollection"/></returns>
        public HeaderCollection ToHeaders()
        {
            Header hAppName = new Header(Header.APPLICATION_NAME, this.ApplicationName);
            Header hName = new Header(Header.NOTIFICATION_NAME, this.Name);
            Header hID = new Header(Header.NOTIFICATION_ID, this.ID);
            Header hTitle = new Header(Header.NOTIFICATION_TITLE, this.Title);
            Header hText = new Header(Header.NOTIFICATION_TEXT, this.Text);
            Header hSticky = new Header(Header.NOTIFICATION_STICKY, this.Sticky);
            Header hPriority = new Header(Header.NOTIFICATION_PRIORITY, ((int) this.Priority).ToString());
            Header hIcon = new Header(Header.NOTIFICATION_ICON, this.Icon);
            Header hCoalescingID = new Header(Header.NOTIFICATION_COALESCING_ID, this.CoalescingID);

            HeaderCollection headers = new HeaderCollection();
            headers.AddHeader(hAppName);
            headers.AddHeader(hName);
            headers.AddHeader(hID);
            headers.AddHeader(hTitle);
            headers.AddHeader(hText);
            headers.AddHeader(hSticky);
            headers.AddHeader(hPriority);
            headers.AddHeader(hCoalescingID);

            if (this.Icon != null && this.Icon.IsSet)
            {
                headers.AddHeader(hIcon);
                headers.AssociateBinaryData(this.Icon);
            }

            this.AddInheritedAttributesToHeaders(headers);
            return headers;
        }
        /// <summary>
        /// Converts the object to a list of headers
        /// </summary>
        /// <returns><see cref="HeaderCollection"/></returns>
        public HeaderCollection ToHeaders()
        {
            Header hName = new Header(Header.NOTIFICATION_NAME, this.Name);
            Header hDisplayName = new Header(Header.NOTIFICATION_DISPLAY_NAME, this.DisplayName);
            Header hIcon = new Header(Header.NOTIFICATION_ICON, this.Icon);
            Header hEnabled = new Header(Header.NOTIFICATION_ENABLED, this.Enabled.ToString());

            HeaderCollection headers = new HeaderCollection();
            headers.AddHeader(hName);
            headers.AddHeader(hEnabled);

            if(this.displayName != null)
                headers.AddHeader(hDisplayName);

            if (this.Icon != null && this.Icon.IsSet)
            {
                headers.AddHeader(hIcon);
                headers.AssociateBinaryData(this.Icon);
            }

            this.AddCustomAttributesToHeaders(headers); // NOTE: dont call AddInheritedAttributesToHeaders because we want to ignore the common attributes
            return headers;
        }
Example #11
0
        /// <summary>
        /// Converts the object to a list of headers
        /// </summary>
        /// <returns><see cref="HeaderCollection"/></returns>
        public HeaderCollection ToHeaders()
        {
            Header hID = new Header(Header.SUBSCRIBER_ID, this.id);
            Header hName = new Header(Header.SUBSCRIBER_NAME, this.name);

            HeaderCollection headers = new HeaderCollection();
            headers.AddHeader(hID);
            headers.AddHeader(hName);
            // only pass the port if different than the standard port
            if (this.port != GrowlConnector.TCP_PORT)
            {
                Header hPort = new Header(Header.SUBSCRIBER_PORT, this.port.ToString());
                headers.AddHeader(hPort);
            }

            this.AddInheritedAttributesToHeaders(headers);
            return headers;
        }