Ejemplo n.º 1
0
 /// <summary>
 /// 添加到opf
 /// </summary>
 /// <param name="chName"></param>
 /// <param name="img"></param>
 /// <param name="newBook"></param>
 public static void AddImgFileList(string chName, BookImage img,Book newBook)
 {
     var fileInfo = new BookFileInfo
     {
         chName = chName,
         fileAllName = "Images/" + img.storeName + img.ext,
         fileName = img.storeName + img.ext,
         clearName = img.storeName + img.ext,
         inContents = false,
         media_type = "image/" + img.ext.Replace(".", "").Replace("jpg", "jpeg")
     };
     newBook.filelist.Add(fileInfo);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 复制模板的CSS,返回成功或失败
        /// </summary>
        /// <param name="toPath"></param>
        /// <param name="newBook"></param>
        /// <returns></returns>
        public static bool CopyCSS(string toPath, Book newBook)
        {
            string cssModelPathFolder = Application.StartupPath + BasePath + SofeSetting.Get("生成模板") + "/Styles";
            if (!Directory.Exists(cssModelPathFolder))
            {
                return false;
            }
            if (!Directory.Exists(toPath))
            {
                Directory.CreateDirectory(toPath);
            }
            List<BookImage> nlbi = new List<BookImage>();
            DirectoryInfo theFolder = new DirectoryInfo(cssModelPathFolder);
            FileInfo[] fi = theFolder.GetFiles("*.*");
            int cssFileCount = 0;
            foreach (FileInfo tmpfi in fi)
            {
                string extension = tmpfi.Extension.ToLower();
                if (extension == ".css")
                {
                    cssFileCount++;
                    string imgpath = tmpfi.FullName;
                    string filename = imgpath.Substring(imgpath.LastIndexOf(@"\") + 1);
                    string ext = filename.Substring(filename.LastIndexOf('.'));
                    filename = filename.Substring(0, filename.LastIndexOf('.'));

                    BookFileInfo fileInfo = new BookFileInfo();
                    fileInfo.chName = "层叠样式表";
                    fileInfo.fileAllName = "Styles/" + filename + ext;
                    fileInfo.fileName = filename + ext; //带后缀的
                    fileInfo.clearName = filename; //不带后缀的
                    fileInfo.inContents = false;
                    fileInfo.media_type = "text/css";
                    newBook.filelist.Add(fileInfo);
                }
            }

            if (cssFileCount==0)
            {
                return false;
            }
            DefaultModel.CopyFolder(cssModelPathFolder, toPath);
            return true;
        }
Ejemplo n.º 3
0
        async Task SaveBookFile(BookFileInfo file)
        {
            try
            {
                var newFile = new BookFileInfo
                {
                    Id       = Guid.NewGuid().ToString(),
                    Content  = file.Content,
                    BookId   = file.BookId,
                    FileType = file.FileType,
                    FilePath = file.FilePath,
                    FileName = file.FileName
                };

                await _originalDataSource.SaveFile(newFile);

                _messages.Write("Uploaded: {0}", file.FileName);
            }
            catch (Exception ex)
            {
                _messages.WriteError(ex, "uploading {0}", file.FilePath);
            }
        }
Ejemplo n.º 4
0
        async Task <BookFileInfo> ReadBookFile(BookInfo book, string filepath)
        {
            string type = GetFileType(filepath);

            if (type == null)
            {
                return(null);
            }

            byte[] content = await _reader.ReadAllFileAsync(filepath);

            var bookfile = new BookFileInfo
            {
                Id       = filepath,
                FileName = Path.GetFileName(filepath),
                FileType = type,
                FilePath = filepath,
                BookId   = book.Id,
                Content  = content
            };

            return(bookfile);
        }
Ejemplo n.º 5
0
        public async Task SaveFile(BookFileInfo file)
        {
            IBookSqlDal repo = GetBookSqlDal();

            await repo.FileIns(file);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 将文件添加入文件列表中
 /// </summary>
 /// <param name="chName"></param>
 /// <param name="fileAllName">相对于OEBPS文件夹的文件地址 如 Text/ass.XHTML</param>
 /// <param name="fileName">文件名 如 ass.Xhtml</param>
 /// <param name="clearName">不带后缀的文件名</param>
 /// <param name="inContents">是否在目录里</param>
 private static void _addFileList(string chName, string fileAllName, string fileName, string clearName, bool inContents)
 {
     BookFileInfo fileInfo = new BookFileInfo();
     fileInfo.chName = chName;
     fileInfo.fileAllName = fileAllName;
     fileInfo.fileName = fileName;
     fileInfo.clearName = clearName;
     fileInfo.inContents = inContents;
     fileInfo.media_type = "application/xhtml+xml";
     newBook.filelist.Add(fileInfo);
 }
Ejemplo n.º 7
0
 public async Task SaveFile(BookFileInfo file)
 {
     await GetBookSqlDal().FileIns(file);
 }
Ejemplo n.º 8
0
 public static void CopyMisc(string toPath, Book newBook)
 {
     //复制内容
     string imageModelPath = Application.StartupPath + BasePath + SofeSetting.Get("生成模板") + "/Misc";
     if (!Directory.Exists(imageModelPath))
     {
         return;
     }
     if (!Directory.Exists(toPath))
     {
         Directory.CreateDirectory(toPath);
     }
     List<BookImage> lbis = ImgManger._searchImg(imageModelPath,"|.js|.txt|");
     foreach (var file in lbis)
     {
         var fileInfo = new BookFileInfo
         {
             chName = "文本",
             fileAllName = "Misc/" + file.storeName + file.ext,
             fileName = file.storeName + file.ext,
             clearName = file.storeName + file.ext,
             inContents = false,
             media_type = "text/plain"
         };
         newBook.filelist.Add(fileInfo);
     }
     DefaultModel.CopyFolder(imageModelPath, toPath);
 }
Ejemplo n.º 9
0
 bool TryGetDateFromFilePath(BookFileInfo file, out DateTime date)
 {
     return(TryGetDateFromFilePath(file.Id, out date));
 }