示例#1
0
        public void MultipartRequestHelperTest_Multipartboundarylengthlimit()
        {
            var mediaType = new Microsoft.Net.Http.Headers.MediaTypeHeaderValue("plain/text");

            mediaType.Boundary = new StringSegment("test");
            MultipartRequestHelper.GetBoundary(mediaType, 3);
        }
 public XmlFhirSerializerOutputFormatter()
 {
     foreach (var mediaType in Hl7.Fhir.Rest.ContentType.XML_CONTENT_HEADERS)
     {
         SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse(mediaType));
     }
     SupportedEncodings.Add(Encoding.UTF8);
 }
示例#3
0
        public void MultipartRequestHelperTest_boundarySucces()
        {
            var mediaType =
                new Microsoft.Net.Http.Headers.MediaTypeHeaderValue("plain/text")
            {
                Boundary = new StringSegment("test")
            };
            var boundary = MultipartRequestHelper.GetBoundary(mediaType, 10);

            Assert.AreEqual("test", boundary);
        }
示例#4
0
        public async Task <IActionResult> GetById(Guid profileId, Guid employeeId)
        {
            var profileResult = await _profileReadCommand.ExecuteAsync(profileId);

            var employeeResult = await _employeeReadCommand.ExecuteAsync(employeeId);

            var userInfo = new UserInfoResult
            {
                Profile        = profileResult,
                ShortName      = employeeResult.Organization?.ShortName,
                AcademicDegree = employeeResult.AcademicDegree,
                AcademicRank   = employeeResult.AcademicRank,
                Education      = employeeResult.Education,
                Fio            = employeeResult.Passport?.ToFio(),
                Email          = employeeResult.Contact?.Email,
                ///TODO: реализовать получение и заполнение факсов + база
                Fax = null,
                MobilePhoneNumber = employeeResult.Contact?.MobilePhoneNumber,
                WorkPlace         = employeeResult.WorkPlace,
                Position          = employeeResult.Position
            };

            var jsonOptions = new JsonSerializerOptions()
            {
                WriteIndented        = true,
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase
            };

            var objectJson = System.Text.Json.JsonSerializer.SerializeToUtf8Bytes(userInfo, jsonOptions);

            /*var objectJson = JsonConvert.SerializeObject(userInfo, new JsonSerializerSettings
             * {
             *  ContractResolver = new DefaultContractResolver
             *  {
             *      NamingStrategy = new CamelCaseNamingStrategy()
             *  },
             *  Formatting = Formatting.Indented
             * });*/

            /*var result = new HttpResponseMessage(HttpStatusCode.OK)
             * {
             *  Content = new StringContent(objectJson)
             * };
             *
             * result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");*/

            var mediaType = new Microsoft.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
            var result    = new FileContentResult(objectJson, mediaType);

            return(result);
        }
示例#5
0
        public static string GetBoundary(Microsoft.Net.Http.Headers.MediaTypeHeaderValue contentType, int lengthLimit)
        {
            var boundary = HeaderUtilities.RemoveQuotes(contentType.Parameters.FirstOrDefault(x => x.Name == BoundaryString)?.Value ?? default(StringSegment));

            if (StringSegment.IsNullOrEmpty(boundary))
            {
                throw new InvalidDataException("Missing content-type boundary.");
            }

            if (boundary.Length > lengthLimit)
            {
                throw new InvalidDataException($"Multipart boundary length limit {lengthLimit} exceeded.");
            }

            return(boundary.ToString());
        }
示例#6
0
        public ZipResult(Microsoft.Net.Http.Headers.MediaTypeHeaderValue contentType, string zipFileName,
                         IEnumerable <string> filenames,
                         //Dictionary<string, string> files,
                         Dictionary <string, string> newFilesFromString,
                         Func <Stream, ActionContext, Task> callback)
            : base((contentType ?? new Microsoft.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream")).ToString())
        {
            if (callback == null)
            {
                callback = async(outputStream, _) =>
                {
                    using (var zipArchive = new ZipArchive(new WriteOnlyStreamWrapper(outputStream), ZipArchiveMode.Create))
                    {
                        Dictionary <string, string> files = new Dictionary <string, string>();
                        foreach (var item in filenames)
                        {
                            files[Path.GetFileName(item)] = item;
                        }
                        foreach (var item in newFilesFromString)
                        {
                            //COCONET TODO:完善字符串的插入
                        }

                        foreach (var kvp in files)
                        {
                            var zipEntry = zipArchive.CreateEntry(kvp.Key);
                            using (var zipStream = zipEntry.Open())
                            {
                                //COCONET 需要测试。原始方法在.net core 2.1中找不到:Microsoft.AspNetCore.Sockets.Client.GetStreamAsync()
                                using (var stream = await Client.GetStreamAsync(kvp.Value))
                                {
                                    await stream.CopyToAsync(zipStream);
                                }
                            }
                        }
                    }
                };
            }
            //throw new ArgumentNullException(nameof(callback));

            _callback = callback;
        }
示例#7
0
 public bool CanHandle(MediaTypeHeaderValue accept)
 {
     return(accept.MediaType.ToString().IndexOf("foo/bar", StringComparison.OrdinalIgnoreCase) >= 0);
 }
 public bool CanHandle(MediaTypeHeaderValue accept) => accept
 .MediaType.ToString()
 .IndexOf("application/vnd.badger+json",
          StringComparison.OrdinalIgnoreCase) >= 0;
 public bool CanHandle(MediaTypeHeaderValue accept) =>
 accept.MediaType.ToString().IndexOf("text/html", StringComparison.OrdinalIgnoreCase) >= 0;
示例#10
0
 public bool CanHandle(Microsoft.Net.Http.Headers.MediaTypeHeaderValue accept)
 {
     return(accept.MediaType.ToString().IndexOf("json", StringComparison.OrdinalIgnoreCase) >= 0);
 }
 public bool CanHandle(Microsoft.Net.Http.Headers.MediaTypeHeaderValue accept)
 {
     return(accept.MediaType.Equals("text/html"));
 }
 public bool SupportContentType(Microsoft.Net.Http.Headers.MediaTypeHeaderValue contentType)
 {
     return(contentType.MediaType == "application/json" || contentType.MediaType == "*/*");
 }
 public bool IsSubsetOf(Microsoft.Net.Http.Headers.MediaTypeHeaderValue otherMediaType)
 {
     throw null;
 }
 public bool SupportContentType(Microsoft.Net.Http.Headers.MediaTypeHeaderValue contentType)
 {
     return(contentType.MediaType == "text/html" || contentType.MediaType == "application/xhtml+xml" ||
            contentType.MediaType == "application/xml" ||
            contentType.MediaType == "text/xml");
 }
 public static bool IsTextType(this Microsoft.Net.Http.Headers.MediaTypeHeaderValue mediaType)
 => mediaType.IsNotDefaultOrNull()?
 new MediaTypeHeaderValue(mediaType.MediaType.Value).IsTextType()
         :
 false;
示例#16
0
 public static bool TryParse(Microsoft.Extensions.Primitives.StringSegment input, out Microsoft.Net.Http.Headers.MediaTypeHeaderValue parsedValue)
 {
     throw null;
 }
 public static bool TryParse(string input, out Microsoft.Net.Http.Headers.MediaTypeHeaderValue parsedValue)
 {
     parsedValue = default(Microsoft.Net.Http.Headers.MediaTypeHeaderValue); throw null;
 }
示例#18
0
        public void MultipartRequestHelperTest_Missingcontenttypeboundary()
        {
            var mediaType = new Microsoft.Net.Http.Headers.MediaTypeHeaderValue("plain/text");

            MultipartRequestHelper.GetBoundary(mediaType, 50);
        }