Пример #1
0
        /// <summary>
        /// This is the header host.
        /// </summary>
        public virtual string HeaderSingle(string keyValue)
        {
            if (keyValue == null)
            {
                throw new ArgumentNullException("keyValue", "keyValue cannot be null.");
            }

            if (!mHeaderCollectionAlreadyBuilt)
            {
                return(null);
            }

            string key = keyValue.Trim().ToLower();

            int[] values = mHeaderCollection[key];

            if (values.Length > 1)
            {
                throw new ArgumentOutOfRangeException("keyValue", "There are multiple headers for " + keyValue);
            }

            HeaderFragment frag = mMessageParts[values[0]] as HeaderFragment;

            if (frag == null)
            {
                return(null);
            }
            return(frag.FieldData);
        }
Пример #2
0
        /// <summary>
        /// This method extracts the header value for the particular key.
        /// </summary>
        /// <param name="keyValue">The key to retrieve.</param>
        /// <returns>The collection of strings.</returns>
        public virtual IEnumerable <string> Headers(string keyValue)
        {
            if (keyValue == null)
            {
                throw new ArgumentNullException("keyValue", "keyValue cannot be null.");
            }

            if (!mHeaderCollectionAlreadyBuilt)
            {
                yield break;
            }

            string key = keyValue.Trim().ToLower();

            if (mHeaderCollection.ContainsKey(key))
            {
                int[] values = mHeaderCollection[key];

                if (values.Length > 0)
                {
                    foreach (int i in values)
                    {
                        HeaderFragment frag = mMessageParts[i] as HeaderFragment;
                        if (frag != null)
                        {
                            yield return(frag.FieldData);
                        }
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// This method extracts the header value for the particular key.
        /// </summary>
        /// <returns>The collection of strings.</returns>
        public virtual IEnumerable <HeaderFragment> HeaderFragments()
        {
            if (!mHeaderCollectionAlreadyBuilt)
            {
                yield break;
            }

            foreach (string key in mHeaderCollection.Keys)
            {
                if (mHeaderCollection.ContainsKey(key))
                {
                    int[] values = mHeaderCollection[key];

                    if (values.Length == 0)
                    {
                        continue;
                    }

                    foreach (int i in values)
                    {
                        HeaderFragment frag = mMessageParts[i] as HeaderFragment;
                        if (frag != null)
                        {
                            yield return(frag);
                        }
                    }
                }
            }
        }
Пример #4
0
        public virtual void HeaderAdd(Type headerType, string Header, string HeaderData)
        {
            if (!Initializing)
            {
                throw new MessageException("The HeaderAdd instruction can only be called when the message is initializing.");
            }

            HeaderFragment newFrag = Activator.CreateInstance(headerType) as HeaderFragment;

            newFrag.BeginInit();
            newFrag.Field     = Header;
            newFrag.FieldData = HeaderData ?? "";
            HeaderAdd(newFrag);
        }