Ejemplo n.º 1
0
        /// <summary>
        /// Full constructor.
        /// </summary>
        /// <param name="content">An existing <see cref="Windows.Web.Http.IHttpContent"/> implementation to be compressed.</param>
        /// <param name="encodingType">The type of compression to use. Supported values are 'gzip' and 'deflate'.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="content"/> or <paramref name="encodingType"/> are null.</exception>
        /// <exception cref="System.InvalidOperationException">Thrown if <paramref name="encodingType"/> is not 'gzip' or 'deflate'.</exception>
        public CompressedWebContent(IHttpContent content, string encodingType)
        {
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }

            if (encodingType == null)
            {
                throw new ArgumentNullException("encodingType");
            }

            this.encodingType = encodingType;

            originalContent = content;
            if (String.Compare(this.encodingType, "gzip", true) != 0 && String.Compare(this.encodingType, "deflate", true) != 0)
            {
                throw new InvalidOperationException(string.Format("Encoding '{0}' is not supported. Only supports gzip or deflate encoding.", this.encodingType));
            }

            headers = new HttpContentHeaderCollection();
            originalContent.CopyHeadersTo(this);

            headers.ContentEncoding.Add(new HttpContentCodingHeaderValue(encodingType));
            headers.ContentLength = null;
        }
Ejemplo n.º 2
0
 public HttpJsonContent(JObject json)
 {
     this.json                   = json;
     headers                     = new HttpContentHeaderCollection();
     headers.ContentType         = new HttpMediaTypeHeaderValue("application/json");
     headers.ContentType.CharSet = "UTF-8";
 }
Ejemplo n.º 3
0
        public ConvertedHttpContent(System.Net.Http.HttpContent httpContent)
        {
            content = httpContent;
            Headers = new HttpContentHeaderCollection();

            foreach (KeyValuePair <string, IEnumerable <string> > header in httpContent.Headers)
            {
                Headers.Add(header.Key, header.Value.First());
            }
        }
        public static ICollection<ContentType> GetContentType(this IContentTypeDetector contentTypeDetector, Uri url, ContentKind requiredKind, HttpContentHeaderCollection headers, string fileName)
        {
            var mimeType = default(string);

            var contentTypeHeader = headers.ContentType;
            if (null != contentTypeHeader)
                mimeType = contentTypeHeader.MediaType;

            return contentTypeDetector.GetContentType(url, requiredKind, mimeType, fileName);
        }
 		public HttpJsonContent(IJsonValue jsonValue) {
 			if (jsonValue == null) {
 				throw new ArgumentException("jsonValue cannot be null.");
 			}
 
 			this.jsonValue = jsonValue;
 			headers = new HttpContentHeaderCollection();
 			headers.ContentType = new HttpMediaTypeHeaderValue("application/json");
 			headers.ContentType.CharSet = "UTF-8";
 		}
Ejemplo n.º 6
0
 public HttpJsonContent(T json)
 {
     this.json = json;
     Headers   = new HttpContentHeaderCollection
     {
         ContentType = new HttpMediaTypeHeaderValue("application/json")
         {
             CharSet = "UTF-8"
         }
     };
 }
Ejemplo n.º 7
0
 public HttpJsonContent(IJsonValue jsonValue)
 {
     if (jsonValue == null)
     {
         throw new ArgumentException("jsonValue cannot be null.");
     }
     this.jsonValue = jsonValue;
     headers = new HttpContentHeaderCollection();
     headers.ContentType = new HttpMediaTypeHeaderValue("application/json");
     headers.ContentType.CharSet = "UTF-8";
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Given headers, extract the date we will use to mark when this file was last modified on the server.
 /// </summary>
 /// <param name="dt"></param>
 /// <returns></returns>
 private string ExtractLastModifiedHeader(HttpContentHeaderCollection dt)
 {
     return(dt.LastModified.HasValue ? dt.LastModified.Value.ToString() : "");
 }
Ejemplo n.º 9
0
        protected async override void OnActivated(IActivatedEventArgs args)
        {
            base.OnActivated(args);

            if (args.Kind == ActivationKind.VoiceCommand)
            {
                VoiceCommandActivatedEventArgs command = args as VoiceCommandActivatedEventArgs;
                SpeechRecognitionResult        result  = command.Result;

                string cmdName      = result.RulePath[0];
                string arg          = "";
                string access_token = "";
                string device       = "";
                string function     = "";
                switch (cmdName)
                {
                case "LightsOn":
                    arg      = "on";
                    device   = "";
                    function = "all_lights";
                    break;

                case "LightsOff":
                    //turn off the lights
                    arg      = "off";
                    device   = "";
                    function = "all_lights";
                    break;

                case "LockDoor":
                    arg      = "lock";
                    device   = "";
                    function = "door";
                    break;

                case "UnlockDoor":
                    arg      = "unlock";
                    device   = "";
                    function = "door";
                    break;

                default:
                    Debug.Write("Command not found");
                    break;
                }

                //turn on the lights
                IEnumerable <KeyValuePair <string, string> > data = new List <KeyValuePair <string, string> >()
                {
                    new KeyValuePair <string, string>("access_token", access_token),
                    new KeyValuePair <string, string>("args", arg)
                };
                System.Uri   uri     = new System.Uri("https://api.particle.io/v1/devices/" + device + "/" + function);
                IHttpContent content = new HttpFormUrlEncodedContent(data);
                using (HttpClient client = new HttpClient())
                {
                    using (HttpResponseMessage res = await client.PostAsync(uri, content))
                    {
                        using (IHttpContent hcontent = res.Content)
                        {
                            string mcontent = await hcontent.ReadAsStringAsync();

                            HttpContentHeaderCollection headers = hcontent.Headers;
                        }
                    }
                }
            }
        }
Ejemplo n.º 10
0
 void InitData(string jsonValue)
 {
     this._jsonValue = jsonValue;
     _headers = new HttpContentHeaderCollection();
     _headers.ContentType = new HttpMediaTypeHeaderValue("application/json");
     _headers.ContentType.CharSet = "UTF-8";
 }