コード例 #1
0
        protected NameValueHeaderValue(NameValueHeaderValue source)
        {
            Contract.Requires(source != null);

            _name = source._name;
            _value = source._value;
        }
コード例 #2
0
        public async void RenameAsset(IAsset asset, string newName)
        {
            // Create the request
            var client = new HttpClient();
            var resource = string.Format("https://wamsbluclus001rest-hs.cloudapp.net/API/Assets('{0}')", asset.Id);
            var request = new HttpRequestMessage(new HttpMethod("MERGE"), resource);

            // Set the request content
            var content = string.Format("{{ 'Name' : '{0}' }}", newName);
            var stringContent = new StringContent(content, Encoding.UTF8, "application/json");
            var oDataParameter = new NameValueHeaderValue("odata", "verbose");
            stringContent.Headers.ContentType.Parameters.Add(oDataParameter);
            request.Content = stringContent;
            
            // Set the request headers
            var jsonAccessToken = await this.GetAccessToken();
            string accessToken = JsonConvert.DeserializeObject<dynamic>(jsonAccessToken).access_token.Value;
            request.Headers.Add("Authorization", "Bearer " + accessToken);
            request.Headers.Add("DataServiceVersion", "3.0");
            request.Headers.Add("MaxDataServiceVersion", "3.0");
            request.Headers.Add("x-ms-version", "1.0");
            request.Headers.Host = "wamsbluclus001rest-hs.cloudapp.net";
            var mediaType = new MediaTypeWithQualityHeaderValue("application/json");
            mediaType.Parameters.Add(oDataParameter);
            client.DefaultRequestHeaders.Accept.Add(mediaType);

            // Make the request
            var response = await client.SendAsync(request);
            response.EnsureSuccessStatusCode();
        }
コード例 #3
0
        protected NameValueHeaderValue(NameValueHeaderValue source)
        {
            Contract.Requires(source != null);

            this.name = source.name;
            this.value = source.value;
        }
コード例 #4
0
        protected NameValueHeaderValue(NameValueHeaderValue source)
        {
            Debug.Assert(source != null);

            _name = source._name;
            _value = source._value;
        }
コード例 #5
0
        private static MediaTypeWithQualityHeaderValue CreateMultipartMediaTypeHeader(string contentType)
        {
            var multipartHeader = new MediaTypeWithQualityHeaderValue(MultipartRelatedContentType);
            var contentHeader   = new NameValueHeaderValue("type", "\"" + contentType + "\"");

            multipartHeader.Parameters.Add(contentHeader);
            return(multipartHeader);
        }
コード例 #6
0
		public void Ctor_ValidArguments ()
		{
			NameValueHeaderValue nvh;
			
			nvh = new NameValueHeaderValue ("arg", "~");
			Assert.AreEqual ("~", nvh.Value, "#1");
			
			nvh = new NameValueHeaderValue ("arg", "\"\x7f\x80\"");
			Assert.AreEqual ("\"\x7f\x80\"", nvh.Value, "#2");
		}
コード例 #7
0
 private void CheckValidParsedValue(string input, int startIndex, NameValueHeaderValue expectedResult,
     int expectedIndex)
 {
     HttpHeaderParser parser = GenericHeaderParser.MultipleValueNameValueParser;
     object result = null;
     Assert.True(parser.TryParseValue(input, null, ref startIndex, out result),
         string.Format("TryParse returned false: {0}", input));
     Assert.Equal(expectedIndex, startIndex);
     Assert.Equal(result, expectedResult);
 }
コード例 #8
0
		public void Equals ()
		{
			var value = new NameValueHeaderValue ("ab");
			Assert.AreEqual (value, new NameValueHeaderValue ("ab"), "#1");
			Assert.AreEqual (value, new NameValueHeaderValue ("AB"), "#2");
			Assert.AreNotEqual (value, new NameValueHeaderValue ("AA"), "#3");
			Assert.AreEqual (value, new NameValueHeaderValue ("AB", ""), "#3-1");

			value = new NameValueHeaderValue ("ab", "DD");
			Assert.AreEqual (value, new NameValueHeaderValue ("Ab", "DD"), "#4");
			Assert.AreNotEqual (value, new NameValueHeaderValue ("AB"), "#5");
			Assert.AreEqual (value, new NameValueHeaderValue ("Ab", "dd"), "#6");
		}
コード例 #9
0
        public void ToString_UseNoValueAndTokenAndQuotedStringValues_SerializedCorrectly()
        {
            NameValueHeaderValue nameValue = new NameValueHeaderValue("text", "token");
            Assert.Equal("text=token", nameValue.ToString());

            nameValue.Value = "\"quoted string\"";
            Assert.Equal("text=\"quoted string\"", nameValue.ToString());

            nameValue.Value = null;
            Assert.Equal("text", nameValue.ToString());

            nameValue.Value = string.Empty;
            Assert.Equal("text", nameValue.ToString());
        }
コード例 #10
0
        public void Equals_ValuesUseDifferentValues_ValuesAreEqualOrDifferentAccordingToRfc()
        {
            NameValueWithParametersHeaderValue nameValue1 = new NameValueWithParametersHeaderValue("text", "value");
            NameValueWithParametersHeaderValue nameValue2 = new NameValueWithParametersHeaderValue("text", "value");
            NameValueHeaderValue nameValue3 = new NameValueHeaderValue("text", "value");

            // NameValueWithParametersHeaderValue just calls methods of the base class. Just verify Parameters is used.
            Assert.True(nameValue1.Equals(nameValue2), "No parameters.");
            Assert.False(nameValue1.Equals(null), "Compare to null.");
            Assert.False(nameValue1.Equals(nameValue3), "Compare to base class instance.");

            nameValue1.Parameters.Add(new NameValueHeaderValue("param1", "value1"));
            Assert.False(nameValue1.Equals(nameValue2), "none vs. 1 parameter.");

            nameValue2.Parameters.Add(new NameValueHeaderValue("param1", "value1"));
            Assert.True(nameValue1.Equals(nameValue2), "1 parameter vs. 1 parameter.");
        }
コード例 #11
0
        public void Quality_AddQualityParameterThenUseProperty_ParametersEntryIsOverwritten()
        {
            MediaTypeWithQualityHeaderValue mediaType = new MediaTypeWithQualityHeaderValue("text/plain");

            NameValueHeaderValue quality = new NameValueHeaderValue("q", "0.132");
            mediaType.Parameters.Add(quality);
            Assert.Equal(1, mediaType.Parameters.Count);
            Assert.Equal("q", mediaType.Parameters.First().Name);
            Assert.Equal(0.132, mediaType.Quality);

            mediaType.Quality = 0.9;
            Assert.Equal(0.9, mediaType.Quality);
            Assert.Equal(1, mediaType.Parameters.Count);
            Assert.Equal("q", mediaType.Parameters.First().Name);

            mediaType.Parameters.Remove(quality);
            Assert.Null(mediaType.Quality);
        }
コード例 #12
0
        public async Task GivenARequestWithMutipleTransferSyntaxHeaders_WhenRetrievingInstance_TheServerShouldReturnBadRequest(string transferSyntaxHeader)
        {
            (InstanceIdentifier identifier, DicomFile file) = await CreateAndStoreDicomFile();

            var requestUri = new Uri(string.Format(DicomWebConstants.BaseInstanceUriFormat, identifier.StudyInstanceUid, identifier.SeriesInstanceUid, identifier.SopInstanceUid), UriKind.Relative);

            using (var request = new HttpRequestMessage(HttpMethod.Get, requestUri))
            {
                // Set accept header to multipart/related; type="application/dicom"
                MediaTypeWithQualityHeaderValue multipartHeader = new MediaTypeWithQualityHeaderValue(KnownContentTypes.MultipartRelated);
                NameValueHeaderValue            contentHeader   = new NameValueHeaderValue("type", "\"" + KnownContentTypes.ApplicationDicom + "\"");
                multipartHeader.Parameters.Add(contentHeader);

                request.Headers.TryAddWithoutValidation("Accept", $"{multipartHeader.ToString()};{transferSyntaxHeader}");

                using (HttpResponseMessage response = await _client.HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, _defaultCancellationToken))
                {
                    Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
                }
            }
        }
コード例 #13
0
        public async Task GivenInstanceWithFrames_WhenRetrieveRequestForFrameInInstance_ValidateReturnedHeaders(params int[] frames)
        {
            (InstanceIdentifier identifier, DicomFile file) = await CreateAndStoreDicomFile(2);

            var requestUri = new Uri(string.Format(DicomWebConstants.BaseRetrieveFramesUriFormat, identifier.StudyInstanceUid, identifier.SeriesInstanceUid, identifier.SopInstanceUid, string.Join("%2C", frames)), UriKind.Relative);

            using (var request = new HttpRequestMessage(HttpMethod.Get, requestUri))
            {
                // Set accept header to multipart/related; type="application/octet-stream"
                MediaTypeWithQualityHeaderValue multipartHeader = new MediaTypeWithQualityHeaderValue(KnownContentTypes.MultipartRelated);
                NameValueHeaderValue            contentHeader   = new NameValueHeaderValue("type", "\"" + KnownContentTypes.ApplicationOctetStream + "\"");
                multipartHeader.Parameters.Add(contentHeader);

                string transferSyntaxHeader = ";transfer-syntax=\"*\"";
                request.Headers.TryAddWithoutValidation("Accept", $"{multipartHeader.ToString()}{transferSyntaxHeader}");

                request.Headers.Add("transfer-syntax", "*");

                using (HttpResponseMessage response = await _client.HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, _defaultCancellationToken))
                {
                    Assert.True(response.IsSuccessStatusCode);

                    await using (Stream stream = await response.Content.ReadAsStreamAsync())
                    {
                        // Open stream in response message's content and read using multipart reader.
                        MultipartSection part;
                        var media           = MediaTypeHeaderValue.Parse(response.Content.Headers.ContentType.ToString());
                        var multipartReader = new MultipartReader(HeaderUtilities.RemoveQuotes(media.Boundary).Value, stream, 100);

                        while ((part = await multipartReader.ReadNextSectionAsync(_defaultCancellationToken)) != null)
                        {
                            // Validate header on individual parts is application/octet-stream.
                            Assert.Equal(KnownContentTypes.ApplicationOctetStream, part.ContentType);
                        }
                    }
                }
            }
        }
コード例 #14
0
        public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext)
        {
            var boundry = Guid.NewGuid().ToString();
            var multipartFormDataContent = new MultipartContent("mixed", boundry);

            //content. .StatusCode = (int)System.Net.HttpStatusCode.OK;
            var contentType = new MediaTypeHeaderValue("multipart/mixed"); // String.Format("multipart/mixed; boundary={0}", boundry));
            var boundaryParameter = new NameValueHeaderValue("boundary", boundry);
            contentType.Parameters.Add(boundaryParameter);
            contentType.Parameters.Add(new System.Net.Http.Headers.NameValueHeaderValue("revision", "0.1"));
            content.Headers.ContentType = contentType;
            //content.Headers.Add("Accept", "multipart/mixed");
            //content.Headers.Add("MIME-Version", "1.0");

            var entities = (IEnumerable<object>)value;
            foreach (var entity in entities)
            {
                var entityContent = new ObjectContent<object>(entity, new JsonMediaTypeFormatter());
                entityContent.Headers.LastModified = DateTime.UtcNow; // Add("Last-Modified", entity.LastModified.ToUniversalTime().ToString("R"));
                entityContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/x-" + entity.GetType().Name);
                multipartFormDataContent.Add(entityContent);
            }
            return multipartFormDataContent.CopyToAsync(writeStream);
        }
コード例 #15
0
 public void Clone_Call_CloneFieldsMatchSourceFields()
 {
     NameValueHeaderValue source = new NameValueHeaderValue("name", "value");
     NameValueHeaderValue clone = (NameValueHeaderValue)((ICloneable)source).Clone();
     Assert.Equal(source.Name, clone.Name);
     Assert.Equal(source.Value, clone.Value);
 }
コード例 #16
0
 public void Equals_NameUseDifferentCasing_ConsideredEqual()
 {
     NameValueHeaderValue nameValue1 = new NameValueHeaderValue("text");
     NameValueHeaderValue nameValue2 = new NameValueHeaderValue("TEXT");
     Assert.True(nameValue1.Equals(nameValue2), "text vs. TEXT.");
 }
コード例 #17
0
 public void Ctor_NameNull_Throw()
 {
     Assert.Throws<ArgumentException>(() => { NameValueHeaderValue nameValue = new NameValueHeaderValue(null); });
 }
コード例 #18
0
        public void Equals_ValuesUseDifferentValues_ValuesAreEqualOrDifferentAccordingToRfc()
        {
            NameValueHeaderValue nameValue1 = new NameValueHeaderValue("text");
            NameValueHeaderValue nameValue2 = new NameValueHeaderValue("text");

            nameValue1.Value = null;
            nameValue2.Value = null;
            Assert.True(nameValue1.Equals(nameValue2), "<null> vs. <null>.");

            nameValue1.Value = "token";
            nameValue2.Value = null;
            Assert.False(nameValue1.Equals(nameValue2), "token vs. <null>.");

            nameValue1.Value = null;
            nameValue2.Value = "token";
            Assert.False(nameValue1.Equals(nameValue2), "<null> vs. token.");

            nameValue1.Value = string.Empty;
            nameValue2.Value = "token";
            Assert.False(nameValue1.Equals(nameValue2), "string.Empty vs. token.");

            nameValue1.Value = null;
            nameValue2.Value = string.Empty;
            Assert.True(nameValue1.Equals(nameValue2), "<null> vs. string.Empty.");

            nameValue1.Value = "token";
            nameValue2.Value = "TOKEN";
            Assert.True(nameValue1.Equals(nameValue2), "token vs. TOKEN.");

            nameValue1.Value = "token";
            nameValue2.Value = "token";
            Assert.True(nameValue1.Equals(nameValue2), "token vs. token.");

            nameValue1.Value = "\"quoted string\"";
            nameValue2.Value = "\"QUOTED STRING\"";
            Assert.False(nameValue1.Equals(nameValue2), "\"quoted string\" vs. \"QUOTED STRING\".");

            nameValue1.Value = "\"quoted string\"";
            nameValue2.Value = "\"quoted string\"";
            Assert.True(nameValue1.Equals(nameValue2), "\"quoted string\" vs. \"quoted string\".");

            Assert.False(nameValue1.Equals(null), "\"quoted string\" vs. <null>.");
        }
コード例 #19
0
 public void GetHashCode_NameUseDifferentCasing_HashDiffersAccordingToRfc()
 {
     NameValueHeaderValue nameValue1 = new NameValueHeaderValue("text");
     NameValueHeaderValue nameValue2 = new NameValueHeaderValue("TEXT");
     Assert.Equal(nameValue1.GetHashCode(), nameValue2.GetHashCode());
 }
コード例 #20
0
 private void CheckValidTryParse(string input, NameValueHeaderValue expectedResult)
 {
     NameValueHeaderValue result = null;
     Assert.True(NameValueHeaderValue.TryParse(input, out result));
     Assert.Equal(expectedResult, result);
 }
コード例 #21
0
 public void Ctor_NameValidFormat_SuccessfullyCreated()
 {
     NameValueHeaderValue nameValue = new NameValueHeaderValue("text", null);
     Assert.Equal("text", nameValue.Name);
 }
コード例 #22
0
 public override int GetHashCode()
 {
     // The value string is case-insensitive.
     return(StringComparer.OrdinalIgnoreCase.GetHashCode(_value) ^ NameValueHeaderValue.GetHashCode(_parameters));
 }
コード例 #23
0
 internal static int GetNameValueLength(string input, int startIndex, out NameValueHeaderValue parsedValue)
 {
     return GetNameValueLength(input, startIndex, s_defaultNameValueCreator, out parsedValue);
 }
コード例 #24
0
		public void Properties_Invalid ()
		{
			var value = new NameValueHeaderValue ("s");
			try {
				value.Value = "   ";
				Assert.Fail ("#1");
			} catch (FormatException) {
			}
		}
コード例 #25
0
		public void Properties ()
		{
			var value = new NameValueHeaderValue ("s", "p");
			Assert.AreEqual ("s", value.Name, "#1");
			Assert.AreEqual ("p", value.Value, "#2");

			value = new NameValueHeaderValue ("s");
			Assert.AreEqual ("s", value.Name, "#3");
			Assert.IsNull (value.Value, "#4");

			value.Value = "bb";
			Assert.AreEqual ("bb", value.Value, "#5");

			value.Value = null;
		}
コード例 #26
0
 public void Ctor_NameEmpty_Throw()
 {
     // null and empty should be treated the same. So we also throw for empty strings.
     Assert.Throws<ArgumentException>(() => { NameValueHeaderValue nameValue = new NameValueHeaderValue(string.Empty); });
 }
コード例 #27
0
        public static bool TryParse(string input, out NameValueHeaderValue parsedValue)
        {
            int index = 0;
            object output;
            parsedValue = null;

            if (GenericHeaderParser.SingleValueNameValueParser.TryParseValue(input, null, ref index, out output))
            {
                parsedValue = (NameValueHeaderValue)output;
                return true;
            }
            return false;
        }
コード例 #28
0
 private void CheckValidParse(string input, NameValueHeaderValue expectedResult)
 {
     NameValueHeaderValue result = NameValueHeaderValue.Parse(input);
     Assert.Equal(expectedResult, result);
 }
コード例 #29
0
		private NameValueWithParametersHeaderValue (NameValueHeaderValue source)
			: base (source)
		{
		}
コード例 #30
0
 private static void CheckValue(string value)
 {
     NameValueHeaderValue nameValue = new NameValueHeaderValue("text", value);
     Assert.Equal(value, nameValue.Value);
 }
コード例 #31
0
        internal static int GetNameValueLength(string input, int startIndex,
            Func<NameValueHeaderValue> nameValueCreator, out NameValueHeaderValue parsedValue)
        {
            Contract.Requires(input != null);
            Contract.Requires(startIndex >= 0);
            Contract.Requires(nameValueCreator != null);

            parsedValue = null;

            if (string.IsNullOrEmpty(input) || (startIndex >= input.Length))
            {
                return 0;
            }

            // Parse the name, i.e. <name> in name/value string "<name>=<value>". Caller must remove 
            // leading whitespaces.
            int nameLength = HttpRuleParser.GetTokenLength(input, startIndex);

            if (nameLength == 0)
            {
                return 0;
            }

            string name = input.Substring(startIndex, nameLength);
            int current = startIndex + nameLength;
            current = current + HttpRuleParser.GetWhitespaceLength(input, current);

            // Parse the separator between name and value
            if ((current == input.Length) || (input[current] != '='))
            {
                // We only have a name and that's OK. Return.
                parsedValue = nameValueCreator();
                parsedValue._name = name;
                current = current + HttpRuleParser.GetWhitespaceLength(input, current); // skip whitespaces
                return current - startIndex;
            }

            current++; // skip delimiter.
            current = current + HttpRuleParser.GetWhitespaceLength(input, current);

            // Parse the value, i.e. <value> in name/value string "<name>=<value>"
            int valueLength = GetValueLength(input, current);

            if (valueLength == 0)
            {
                return 0; // We have an invalid value. 
            }

            // Use parameterless ctor to avoid double-parsing of name and value, i.e. skip public ctor validation.
            parsedValue = nameValueCreator();
            parsedValue._name = name;
            parsedValue._value = input.Substring(current, valueLength);
            current = current + valueLength;
            current = current + HttpRuleParser.GetWhitespaceLength(input, current); // skip whitespaces
            return current - startIndex;
        }
コード例 #32
0
 public void Value_CallSetterWithInvalidValues_Throw()
 {
     // Just verify that the setter calls the same validation the ctor invokes.
     Assert.Throws<FormatException>(() => { var x = new NameValueHeaderValue("name"); x.Value = " x "; });
     Assert.Throws<FormatException>(() => { var x = new NameValueHeaderValue("name"); x.Value = "x y"; });
 }
コード例 #33
0
        public void Quality_AddQualityParameterUpperCase_CaseInsensitiveComparison()
        {
            MediaTypeWithQualityHeaderValue mediaType = new MediaTypeWithQualityHeaderValue("text/plain");

            NameValueHeaderValue quality = new NameValueHeaderValue("Q", "0.132");
            mediaType.Parameters.Add(quality);
            Assert.Equal(1, mediaType.Parameters.Count);
            Assert.Equal("Q", mediaType.Parameters.First().Name);
            Assert.Equal(0.132, mediaType.Quality);
        }
コード例 #34
0
        public void GetHashCode_ValuesUseDifferentValues_HashDiffersAccordingToRfc()
        {
            NameValueHeaderValue nameValue1 = new NameValueHeaderValue("text");
            NameValueHeaderValue nameValue2 = new NameValueHeaderValue("text");

            nameValue1.Value = null;
            nameValue2.Value = null;
            Assert.Equal(nameValue1.GetHashCode(), nameValue2.GetHashCode());

            nameValue1.Value = "token";
            nameValue2.Value = null;
            Assert.NotEqual(nameValue1.GetHashCode(), nameValue2.GetHashCode());

            nameValue1.Value = "token";
            nameValue2.Value = string.Empty;
            Assert.NotEqual(nameValue1.GetHashCode(), nameValue2.GetHashCode());

            nameValue1.Value = null;
            nameValue2.Value = string.Empty;
            Assert.Equal(nameValue1.GetHashCode(), nameValue2.GetHashCode());

            nameValue1.Value = "token";
            nameValue2.Value = "TOKEN";
            Assert.Equal(nameValue1.GetHashCode(), nameValue2.GetHashCode());

            nameValue1.Value = "token";
            nameValue2.Value = "token";
            Assert.Equal(nameValue1.GetHashCode(), nameValue2.GetHashCode());

            nameValue1.Value = "\"quoted string\"";
            nameValue2.Value = "\"QUOTED STRING\"";
            Assert.NotEqual(nameValue1.GetHashCode(), nameValue2.GetHashCode());

            nameValue1.Value = "\"quoted string\"";
            nameValue2.Value = "\"quoted string\"";
            Assert.Equal(nameValue1.GetHashCode(), nameValue2.GetHashCode());
        }
コード例 #35
0
 public override string ToString()
 {
     return(_mediaType + NameValueHeaderValue.ToString(_parameters, ';', true));
 }