123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace BestHTTP.Forms
- {
-
-
-
- public class HTTPFormBase
- {
- const int LongLength = 256;
- #region Properties
-
-
-
- public List<HTTPFieldData> Fields { get; set; }
-
-
-
- public bool IsEmpty { get { return Fields == null || Fields.Count == 0; } }
-
-
-
- public bool IsChanged { get; protected set; }
-
-
-
- public bool HasBinary { get; protected set; }
-
-
-
- public bool HasLongValue { get; protected set; }
- #endregion
- #region Field Management
- public void AddBinaryData(string fieldName, byte[] content)
- {
- AddBinaryData(fieldName, content, null, null);
- }
- public void AddBinaryData(string fieldName, byte[] content, string fileName)
- {
- AddBinaryData(fieldName, content, fileName, null);
- }
- public void AddBinaryData(string fieldName, byte[] content, string fileName, string mimeType)
- {
- if (Fields == null)
- Fields = new List<HTTPFieldData>();
- HTTPFieldData field = new HTTPFieldData();
- field.Name = fieldName;
- if (fileName == null)
- field.FileName = fieldName + ".dat";
- else
- field.FileName = fileName;
- if (mimeType == null)
- field.MimeType = "application/octet-stream";
- else
- field.MimeType = mimeType;
- field.Binary = content;
- Fields.Add(field);
- HasBinary = IsChanged = true;
- }
- public void AddField(string fieldName, string value)
- {
- AddField(fieldName, value, System.Text.Encoding.UTF8);
- }
- public void AddField(string fieldName, string value, System.Text.Encoding e)
- {
- if (Fields == null)
- Fields = new List<HTTPFieldData>();
- HTTPFieldData field = new HTTPFieldData();
- field.Name = fieldName;
- field.FileName = null;
- if (e != null)
- field.MimeType = "text/plain; charset=" + e.WebName;
- field.Text = value;
- field.Encoding = e;
- Fields.Add(field);
- IsChanged = true;
- HasLongValue |= value.Length > LongLength;
- }
- #endregion
- #region Virtual Functions
-
-
-
-
- public virtual void CopyFrom(HTTPFormBase fields)
- {
- this.Fields = new List<HTTPFieldData>(fields.Fields);
- this.IsChanged = true;
- this.HasBinary = fields.HasBinary;
- this.HasLongValue = fields.HasLongValue;
- }
-
-
-
- public virtual void PrepareRequest(HTTPRequest request)
- {
- throw new NotImplementedException();
- }
-
-
-
- public virtual byte[] GetData()
- {
- throw new NotImplementedException();
- }
- #endregion
- }
- }
|