예제 #1
0
 public virtual void CopyFrom(HTTPFormBase fields)
 {
     this.Fields       = new List <HTTPFieldData>(fields.Fields);
     this.IsChanged    = true;
     this.HasBinary    = fields.HasBinary;
     this.HasLongValue = fields.HasLongValue;
 }
예제 #2
0
        public override void CopyFrom(HTTPFormBase fields)
        {
            this.Fields    = fields.Fields;
            this.IsChanged = true;

            if (Form == null)
            {
                Form = new WWWForm();

                if (Fields != null)
                {
                    for (int i = 0; i < Fields.Count; ++i)
                    {
                        var field = Fields[i];

                        if (string.IsNullOrEmpty(field.Text) && field.Binary != null)
                        {
                            Form.AddBinaryData(field.Name, field.Binary, field.FileName, field.MimeType);
                        }
                        else
                        {
                            Form.AddField(field.Name, field.Text, field.Encoding);
                        }
                    }
                }
            }
        }
예제 #3
0
        public override void CopyFrom(HTTPFormBase fields)
        {
            this.Fields = fields.Fields;
            this.IsChanged = true;

            if (Form == null)
            {
                Form = new WWWForm();

                if (Fields != null)
                    for (int i = 0; i < Fields.Count; ++i)
                    {
                        var field = Fields[i];

                        if (string.IsNullOrEmpty(field.Text) && field.Binary != null)
                            Form.AddBinaryData(field.Name, field.Binary, field.FileName, field.MimeType);
                        else
                            Form.AddField(field.Name, field.Text, field.Encoding);
                    }
            }
        }
예제 #4
0
 public override void CopyFrom(HTTPFormBase fields)
 {
     base.Fields    = fields.Fields;
     base.IsChanged = true;
     if (this.Form == null)
     {
         this.Form = new WWWForm();
         if (base.Fields != null)
         {
             for (int i = 0; i < base.Fields.Count; i++)
             {
                 HTTPFieldData hTTPFieldData = base.Fields[i];
                 if (string.IsNullOrEmpty(hTTPFieldData.Text) && hTTPFieldData.Binary != null)
                 {
                     this.Form.AddBinaryData(hTTPFieldData.Name, hTTPFieldData.Binary, hTTPFieldData.FileName, hTTPFieldData.MimeType);
                 }
                 else
                 {
                     this.Form.AddField(hTTPFieldData.Name, hTTPFieldData.Text, hTTPFieldData.Encoding);
                 }
             }
         }
     }
 }
예제 #5
0
        /// <summary>
        /// Will create the form implementation based on the value of the FormUsage property.
        /// </summary>
        private HTTPFormBase SelectFormImplementation()
        {
            // Our form already created with a previous
            if (FormImpl != null)
                return FormImpl;

            // No field added to this request yet
            if (FieldCollector == null)
                return null;

            switch (FormUsage)
            {
                case HTTPFormUsage.Automatic:
                    // A really simple decision making: if there are at least one field with binary data, or a 'long' string value then we will choose a Multipart form.
                    //  Otherwise Url Encoded form will be used.
                    if (FieldCollector.HasBinary || FieldCollector.HasLongValue)
                        goto case HTTPFormUsage.Multipart;
                    else
                        goto case HTTPFormUsage.UrlEncoded;

                case HTTPFormUsage.UrlEncoded:  FormImpl = new HTTPUrlEncodedForm(); break;
                case HTTPFormUsage.Multipart:   FormImpl = new HTTPMultiPartForm(); break;
            #if !UNITY_WP8
                case HTTPFormUsage.Unity:       FormImpl = new UnityForm(); break;
            #endif
            }

            // Copy the fields, and other properties to the new implementation
            FormImpl.CopyFrom(FieldCollector);

            return FormImpl;
        }
예제 #6
0
 /// <summary>
 /// Manually set a HTTP Form.
 /// </summary>
 public void SetForm(HTTPFormBase form)
 {
     FormImpl = form;
 }
예제 #7
0
 /// <summary>
 /// Set or overwrite the internal form. Remarks: on WP8 it doesn't supported!
 /// </summary>
 public void SetFields(UnityEngine.WWWForm wwwForm)
 {
     #if !UNITY_WP8
     FormUsage = HTTPFormUsage.Unity;
     FormImpl = new UnityForm(wwwForm);
     #endif
 }
예제 #8
0
        /// <summary>
        /// Add a field with a given string value.
        /// </summary>
        public void AddField(string fieldName, string value, System.Text.Encoding e)
        {
            if (FieldCollector == null)
                FieldCollector = new HTTPFormBase();

            FieldCollector.AddField(fieldName, value, e);
        }
예제 #9
0
        /// <summary>
        /// Add a field with binary content to the form.
        /// </summary>
        public void AddBinaryData(string fieldName, byte[] content, string fileName, string mimeType)
        {
            if (FieldCollector == null)
                FieldCollector = new HTTPFormBase();

            FieldCollector.AddBinaryData(fieldName, content, fileName, mimeType);
        }
        /// <summary>
        /// It should 'clone' all the data from the given HTTPFormBase object.
        /// Called after the form-implementation created.
        /// </summary>
        public virtual void CopyFrom(HTTPFormBase fields)
        {
            this.Fields = new List<HTTPFieldData>(fields.Fields);
            this.IsChanged = true;

            this.HasBinary = fields.HasBinary;
            this.HasLongValue = fields.HasLongValue;
        }