Exemple #1
0
        public static Disposition Parse(string text)
        {
            try
            {
                string[] segments = text.Split(SEPARATOR,
                                               StringSplitOptions.RemoveEmptyEntries);

                var disp = new Disposition {
                    value = segments[0].Trim()
                };
                for (int i = 1; i < segments.Length; i++)
                {
                    string[] nameValue = segments[i].Split('=');

                    string paramValue = RemoveDoubleQuote(nameValue[1].Trim());
                    disp.parameters.Add(nameValue[0].Trim(), paramValue);
                }

                return(disp);
            }
            catch (Exception e)
            {
                throw new FormatException(
                          "Incorrect content disposition format: " + text, e);
            }
        }
Exemple #2
0
        public Part(ArraySegment <byte> data, NameValueCollection headers)
        {
            if (data == null || headers == null)
            {
                throw new ArgumentNullException();
            }

            this.data    = data;
            this.bytes   = data;
            this.headers = headers;

            if (headers["content-disposition"] != null)
            {
                disposition = Disposition.Parse(headers["content-disposition"]);
            }
        }
Exemple #3
0
        //public Part(string data)
        //{
        //    if (data == null)
        //        throw new ArgumentNullException();

        //    this.data = Encoding.UTF8.GetBytes(data);
        //    this.start = 0;
        //    this.len = this.data.Length;
        //    this.headers = new NameValueCollection();
        //}

        public Part(string data, NameValueCollection headers)
        {
            if (data == null || headers == null)
            {
                throw new ArgumentNullException();
            }

            byte[] dataUtf8 = Encoding.UTF8.GetBytes(data);

            this.data    = new ArraySegment <byte>(dataUtf8);
            this.headers = headers;

            if (headers["content-disposition"] != null)
            {
                disposition = Disposition.Parse(headers["content-disposition"]);
            }
        }