예제 #1
0
        /// <summary>
        /// Decodes an object.
        /// </summary>
        /// <param name="ContentType">Internet Content Type.</param>
        /// <param name="Data">Encoded object.</param>
        /// <param name="Encoding">Any encoding specified. Can be null if no encoding specified.</param>
        /// <param name="Fields">Any content-type related fields and their corresponding values.</param>
        ///	<param name="BaseUri">Base URI, if any. If not available, value is null.</param>
        /// <returns>Decoded object.</returns>
        /// <exception cref="ArgumentException">If the object cannot be decoded.</exception>
        public object Decode(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair <string, string>[] Fields, Uri BaseUri)
        {
            List <object> List = new List <object>();

            FormDataDecoder.Decode(Data, Fields, null, List, BaseUri);

            return(List);
        }
예제 #2
0
        /// <summary>
        /// Decodes an object.
        /// </summary>
        /// <param name="ContentType">Internet Content Type.</param>
        /// <param name="Data">Encoded object.</param>
        /// <param name="Encoding">Any encoding specified. Can be null if no encoding specified.</param>
        /// <param name="Fields">Any content-type related fields and their corresponding values.</param>
        ///	<param name="BaseUri">Base URI, if any. If not available, value is null.</param>
        /// <returns>Decoded object.</returns>
        /// <exception cref="ArgumentException">If the object cannot be decoded.</exception>
        public object Decode(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair <string, string>[] Fields, Uri BaseUri)
        {
            List <EmbeddedContent> List = new List <EmbeddedContent>();

            FormDataDecoder.Decode(Data, Fields, null, List, BaseUri);

            return(new MixedContent(List.ToArray()));
        }
예제 #3
0
 /// <summary>
 /// Encodes an object.
 /// </summary>
 /// <param name="Object">Object to encode.</param>
 /// <param name="Encoding">Desired encoding of text. Can be null if no desired encoding is speified.</param>
 /// <param name="ContentType">Content Type of encoding. Includes information about any text encodings used.</param>
 /// <param name="AcceptedContentTypes">Optional array of accepted content types. If array is empty, all content types are accepted.</param>
 /// <returns>Encoded object.</returns>
 /// <exception cref="ArgumentException">If the object cannot be encoded.</exception>
 public byte[] Encode(object Object, Encoding Encoding, out string ContentType, params string[] AcceptedContentTypes)
 {
     if (Object is MixedContent Mixed &&
         InternetContent.IsAccepted(ContentTypes, AcceptedContentTypes))
     {
         string Boundary = Guid.NewGuid().ToString();
         ContentType = MixedCodec.ContentType + "; boundary=\"" + Boundary + "\"";
         return(FormDataDecoder.Encode(Mixed.Content, Boundary));
     }
예제 #4
0
 /// <summary>
 /// Encodes an object.
 /// </summary>
 /// <param name="Object">Object to encode.</param>
 /// <param name="Encoding">Desired encoding of text. Can be null if no desired encoding is speified.</param>
 /// <param name="ContentType">Content Type of encoding. Includes information about any text encodings used.</param>
 /// <param name="AcceptedContentTypes">Optional array of accepted content types. If array is empty, all content types are accepted.</param>
 /// <returns>Encoded object.</returns>
 /// <exception cref="ArgumentException">If the object cannot be encoded.</exception>
 public byte[] Encode(object Object, Encoding Encoding, out string ContentType, params string[] AcceptedContentTypes)
 {
     if (Object is RelatedContent Related &&
         InternetContent.IsAccepted(ContentTypes, AcceptedContentTypes))
     {
         string Boundary = Guid.NewGuid().ToString();
         ContentType = RelatedCodec.ContentType + "; boundary=\"" + Boundary + "\"; type=\"" + Related.Type.Replace("\"", "\\\"") + "\"";
         return(FormDataDecoder.Encode(Related.Content, Boundary));
     }
예제 #5
0
        /// <summary>
        /// Decodes an object.
        /// </summary>
        /// <param name="ContentType">Internet Content Type.</param>
        /// <param name="Data">Encoded object.</param>
        /// <param name="Encoding">Any encoding specified. Can be null if no encoding specified.</param>
        /// <param name="Fields">Any content-type related fields and their corresponding values.</param>
        ///	<param name="BaseUri">Base URI, if any. If not available, value is null.</param>
        /// <returns>Decoded object.</returns>
        /// <exception cref="ArgumentException">If the object cannot be decoded.</exception>
        public object Decode(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair <string, string>[] Fields, Uri BaseUri)
        {
            List <EmbeddedContent> List = new List <EmbeddedContent>();

            FormDataDecoder.Decode(Data, Fields, null, List, BaseUri);
            string Type = string.Empty;

            foreach (KeyValuePair <string, string> P in Fields)
            {
                switch (P.Key.ToUpper())
                {
                case "TYPE":
                    Type = P.Value.Trim();
                    break;
                }
            }

            return(new RelatedContent(List.ToArray(), Type));
        }