/// <summary>
 /// Creates an <see cref="ObjectResult"/> object with a Protobuf-Net content header.
 /// </summary>
 /// <param name="value">Protobuf-Net serializable object value.</param>
 public ProtobufNetObjectResult(object value)
     : base(value)
 {
     //Writes the content types to be only the protobuf-net content type
     this.ContentTypes.Clear();
     ContentTypes.Add(new MediaTypeHeaderValue("application/Protobuf-Net"));
 }
Example #2
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ProblemResult" /> class.  I will set the following:
 ///     <para>
 ///         <see cref="RequestErrorObject.Instance" /> value to the ActionContext.HttpContext.Request.Path
 ///     </para>
 ///     <para>
 ///         <see cref="ObjectResult.StatusCode" /> value to the <see cref="RequestErrorObject.Status" />
 ///     </para>
 ///     <para>
 ///         I will clear all content types and add "application/problem+json"
 ///     </para>
 /// </summary>
 /// <param name="error">The error.</param>
 public ProblemResult(RequestErrorObject error)
     : base(error)
 {
     _error     = error;
     StatusCode = _error.Status;
     ContentTypes.Clear();
     ContentTypes.Add(Constants.ResponseTypes.ErrorResponseContentType);
 }
Example #3
0
        // ---

        private APIResponse(HttpStatusCode statusCode, Response response) : base(response)
        {
            _httpStatusCode = statusCode;
            _response       = response;

            StatusCode   = (int)statusCode;
            DeclaredType = typeof(Response);
            ContentTypes.Clear();
            ContentTypes.Add("application/json");
        }
Example #4
0
        public ScriptObjectResult(object value, IDictionary <string, object> headers) : base(value)
        {
            Headers = headers;
            string contentType = null;

            if (value != null &&
                (headers?.TryGetValue("content-type", out contentType, ignoreCase: true) ?? false) &&
                MediaTypeHeaderValue.TryParse(contentType, out MediaTypeHeaderValue mediaType))
            {
                ContentTypes.Add(mediaType);
            }
        }
Example #5
0
        private void SaveRelationships(OpcRelationships relationships)
        {
            if (!ContentTypes.Any(ct => string.Equals(ct.Extension, "rels", StringComparison.OrdinalIgnoreCase)))
            {
                ContentTypes.Add(new OpcContentType("rels", OpcKnownMimeTypes.OpenXmlRelationship, OpcContentTypeMode.Default));
            }
            var path  = relationships.DocumentUri.ToPackagePath();
            var entry = Archive.GetEntry(path) ?? Archive.CreateEntry(path);

            using (var stream = entry.Open())
            {
                stream.SetLength(0L);
                var newXml = relationships.ToXml();
                newXml.Save(stream, SaveOptions.None);
            }
        }
Example #6
0
        /// <summary>
        /// Mime types that this class can handle per default
        /// </summary>
        /// <remarks>
        /// Contains the following mime types:
        /// <list type="table">
        /// <item><term><![CDATA[txt]]></term><value><![CDATA[text/plain]]></value></item>
        /// <item><term><![CDATA[html]]></term><value><![CDATA[text/html]]></value></item>
        /// <item><term><![CDATA[htm]]></term><value><![CDATA[text/html]]></value></item>
        /// <item><term><![CDATA[jpg]]></term><value><![CDATA[image/jpg]]></value></item>
        /// <item><term><![CDATA[jpeg]]></term><value><![CDATA[image/jpg]]></value></item>
        /// <item><term><![CDATA[bmp]]></term><value><![CDATA[image/bmp]]></value></item>
        /// <item><term><![CDATA[gif]]></term><value><![CDATA[image/gif]]></value></item>
        /// <item><term><![CDATA[png]]></term><value><![CDATA[image/png]]></value></item>
        /// <item><term><![CDATA[ico]]></term><value><![CDATA[image/vnd.microsoft.icon]]></value></item>
        /// <item><term><![CDATA[css]]></term><value><![CDATA[text/css]]></value></item>
        /// <item><term><![CDATA[gzip]]></term><value><![CDATA[application/x-gzip]]></value></item>
        /// <item><term><![CDATA[zip]]></term><value><![CDATA[multipart/x-zip]]></value></item>
        /// <item><term><![CDATA[tar]]></term><value><![CDATA[application/x-tar]]></value></item>
        /// <item><term><![CDATA[pdf]]></term><value><![CDATA[application/pdf]]></value></item>
        /// <item><term><![CDATA[rtf]]></term><value><![CDATA[application/rtf]]></value></item>
        /// <item><term><![CDATA[xls]]></term><value><![CDATA[application/vnd.ms-excel]]></value></item>
        /// <item><term><![CDATA[ppt]]></term><value><![CDATA[application/vnd.ms-powerpoint]]></value></item>
        /// <item><term><![CDATA[doc]]></term><value><![CDATA[application/application/msword]]></value></item>
        /// <item><term><![CDATA[js]]></term><value><![CDATA[application/javascript]]></value></item>
        /// <item><term><![CDATA[au]]></term><value><![CDATA[audio/basic]]></value></item>
        /// <item><term><![CDATA[snd]]></term><value><![CDATA[audio/basic]]></value></item>
        /// <item><term><![CDATA[es]]></term><value><![CDATA[audio/echospeech]]></value></item>
        /// <item><term><![CDATA[mp3]]></term><value><![CDATA[audio/mpeg]]></value></item>
        /// <item><term><![CDATA[mp2]]></term><value><![CDATA[audio/mpeg]]></value></item>
        /// <item><term><![CDATA[mid]]></term><value><![CDATA[audio/midi]]></value></item>
        /// <item><term><![CDATA[wav]]></term><value><![CDATA[audio/x-wav]]></value></item>
        /// <item><term><![CDATA[swf]]></term><value><![CDATA[application/x-shockwave-flash]]></value></item>
        /// <item><term><![CDATA[avi]]></term><value><![CDATA[video/avi]]></value></item>
        /// <item><term><![CDATA[rm]]></term><value><![CDATA[audio/x-pn-realaudio]]></value></item>
        /// <item><term><![CDATA[ram]]></term><value><![CDATA[audio/x-pn-realaudio]]></value></item>
        /// <item><term><![CDATA[aif]]></term><value><![CDATA[audio/x-aiff]]></value></item>
        /// </list>
        /// </remarks>
        public void AddDefaultMimeTypes()
        {
            ContentTypes.Add("default", new ContentTypeHeader("application/octet-stream"));
            ContentTypes.Add("txt", new ContentTypeHeader("text/plain;charset=UTF-8"));
            ContentTypes.Add("xml", new ContentTypeHeader("text/xml;charset=UTF-8"));
            ContentTypes.Add("html", new ContentTypeHeader("text/html;charset=UTF-8"));
            ContentTypes.Add("htm", new ContentTypeHeader("text/html;charset=UTF-8"));
            ContentTypes.Add("jpg", new ContentTypeHeader("image/jpg"));
            ContentTypes.Add("jpeg", new ContentTypeHeader("image/jpg"));
            ContentTypes.Add("bmp", new ContentTypeHeader("image/bmp"));
            ContentTypes.Add("gif", new ContentTypeHeader("image/gif"));
            ContentTypes.Add("png", new ContentTypeHeader("image/png"));

            ContentTypes.Add("ico", new ContentTypeHeader("image/vnd.microsoft.icon"));
            ContentTypes.Add("css", new ContentTypeHeader("text/css"));
            ContentTypes.Add("exe", new ContentTypeHeader("application/octet-stream"));
            ContentTypes.Add("gzip", new ContentTypeHeader("application/x-gzip"));
            ContentTypes.Add("zip", new ContentTypeHeader("multipart/x-zip"));
            ContentTypes.Add("tar", new ContentTypeHeader("application/x-tar"));
            ContentTypes.Add("pdf", new ContentTypeHeader("application/pdf"));
            ContentTypes.Add("rtf", new ContentTypeHeader("application/rtf"));
            ContentTypes.Add("xls", new ContentTypeHeader("application/vnd.ms-excel"));
            ContentTypes.Add("ppt", new ContentTypeHeader("application/vnd.ms-powerpoint"));
            ContentTypes.Add("doc", new ContentTypeHeader("application/application/msword"));
            ContentTypes.Add("js", new ContentTypeHeader("application/javascript"));
            ContentTypes.Add("au", new ContentTypeHeader("audio/basic"));
            ContentTypes.Add("snd", new ContentTypeHeader("audio/basic"));
            ContentTypes.Add("es", new ContentTypeHeader("audio/echospeech"));
            ContentTypes.Add("mp3", new ContentTypeHeader("audio/mpeg"));
            ContentTypes.Add("mp2", new ContentTypeHeader("audio/mpeg"));
            ContentTypes.Add("mid", new ContentTypeHeader("audio/midi"));
            ContentTypes.Add("wav", new ContentTypeHeader("audio/x-wav"));
            ContentTypes.Add("swf", new ContentTypeHeader("application/x-shockwave-flash"));
            ContentTypes.Add("avi", new ContentTypeHeader("video/avi"));
            ContentTypes.Add("rm", new ContentTypeHeader("audio/x-pn-realaudio"));
            ContentTypes.Add("ram", new ContentTypeHeader("audio/x-pn-realaudio"));
            ContentTypes.Add("aif", new ContentTypeHeader("audio/x-aiff"));
        }
 public ContentTypeAttribute(string mediaType)
 {
     ContentTypes.Add(MediaTypeHeaderValue.Parse(mediaType));
 }
 /// <summary>
 /// Add all the details for a content type to this
 /// </summary>
 /// <param name="t">The content type</param>
 public void AddContentType(Type t)
 {
     ContentTypes.Add(t.FullName);
     AddTypeInner(t);
 }