コード例 #1
0
ファイル: Epub.cs プロジェクト: SheepRock/EpubWriter
        /// <summary>
        /// Adds a xhtml, css or javascript file to the book. Returns the correponding file id.
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="content"></param>
        /// <param name="mediaType"></param>
        /// <returns></returns>
        public string AddTextFile(string fileName, string content, TextMediaType mediaType)
        {
            //Gets the media-type
            string mType = "";

            switch (mediaType)
            {
            case TextMediaType.Css:
                mType = "text/css";
                break;

            case TextMediaType.Javascript:
                mType = "application/javascript";
                break;

            case TextMediaType.Xhtml:
                mType = "application/xhtml+xml";
                break;
            }
            //Adds the file to the zip package
            AddFile(Combine(ContentFolder, fileName), content);

            //Gets a new ID for the file
            string id = GetNewItemId();

            //Asdds the file to the manifest
            opf.Root.Element(opfNamespace + "manifest").Add(
                new XElement(opfNamespace + "item",
                             new XAttribute("id", id),
                             new XAttribute("href", fileName),
                             new XAttribute("media-type", mType)
                             )
                );
            return(id);
        }
コード例 #2
0
 public RawStringResult(ApiController controller, string content, TextMediaType mediaType)
     : base(
         content,
         controller.Configuration.Services.GetContentNegotiator(),
         controller.Request,
         new[] { new RawStringFormatter(GetMediaTypeString(mediaType)) }
         )
 {
 }
コード例 #3
0
        private static string GetMediaTypeString(TextMediaType mediaType)
        {
            switch (mediaType)
            {
            case TextMediaType.PlainText:
                return(MediaType.PlainText);

            case TextMediaType.Json:
                return(MediaType.Json);

            case TextMediaType.Xml:
                return(MediaType.Xml);

            default:
                return(null);
            }
        }