Beispiel #1
0
        //生成项目字典
        public void PublishDictionary()
        {
            NameValueCollection Params = HttpContext.Request.Form; //参数
            string projectCode         = Params["projectCode"];    //项目编码
            string fileName            = Params["projectName"];    //项目名称
            string path      = Server.MapPath(string.Format("~/Content/Pack/{0}", User.Identity.Name));
            string directory = Server.MapPath(string.Format("~/Content/Html/{0}/{1}", User.Identity.Name, fileName));

            try
            {
                path = GenerateHtml(projectCode, fileName, path, directory);
                do
                {
                    DZips.ZipFileDirectory(directory, path);
                } while (DZips.ValidZipFile(path));
                Response.Write("{HasError:false,msg:'项目字典生成成功!'}");
            }catch (Exception ex) {
                NHibernateHelper.WriteErrorLog("生成项目字典", ex);
                Response.Write("{HasError:true,msg:'项目字典生成失败!'}");
            }
            Response.End();
        }
Beispiel #2
0
        /// <summary>
        /// 生成HTML文件,返回压缩包路径
        /// </summary>
        /// <param name="projectCode">项目编码</param>
        /// <param name="fileName">项目名称</param>
        /// <param name="path">压缩包目录</param>
        /// <param name="directory">模板目录</param>
        /// <returns></returns>
        private string GenerateHtml(string projectCode, string fileName, string path, string directory)
        {
            string indexPath = Server.MapPath("~/Content/Templates/default/index.html"); //首页模板路径
            string itemsPath = Server.MapPath("~/Content/Templates/default/items.html"); //子页模板路径

            //判断文件夹是否存在
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
                Directory.CreateDirectory(directory + "/Items");
                //复制文件
                string copyPath = Server.MapPath("~/Content/Templates/default/Style");
                DZips.CopyDirs(copyPath, directory + "/Style");
                System.IO.File.Copy(Server.MapPath("~/Content/Templates/default/favicon.ico"), directory + "/favicon.ico");
                //根据项目编码,生成HTML文件
                BuildIndex(projectCode, fileName, directory, indexPath, itemsPath);
            }
            else
            {
                //移除原有的HTML文件
                System.IO.File.Delete(directory + "/index.html");
                FileInfo[] files = new DirectoryInfo(directory + "\\Items").GetFiles();
                for (int i = 0; i < files.Length; i++)
                {
                    if (files[i].Name.Substring(files[i].Name.LastIndexOf(".") + 1) == "html")
                    {
                        System.IO.File.Delete(files[i].FullName);
                    }
                }
                //根据项目编码,生成HTML文件
                BuildIndex(projectCode, fileName, directory, indexPath, itemsPath);
            }
            path += string.Format("/{0}.zip", fileName);
            return(path);
        }
Beispiel #3
0
        //打包项目字典
        public void UnpackDictionary()
        {
            NameValueCollection Params = HttpContext.Request.Form; //参数
            string   projectCode       = Params["projectCode"];    //项目编码
            string   fileName          = Params["projectName"];    //项目名称
            string   path      = Server.MapPath(string.Format("~/Content/Pack/{0}/{1}.zip", User.Identity.Name, fileName));
            string   directory = Server.MapPath(string.Format("~/Content/Html/{0}/{1}", User.Identity.Name, fileName));
            FileInfo fi        = new FileInfo(path);

            if (fi.Exists)//输出压缩包
            {
                WriteZip(fi);
            }
            else//压缩项目字典
            {
                do
                {
                    DZips.ZipFileDirectory(directory, path);
                } while (DZips.ValidZipFile(path));
                fi = new FileInfo(path);
                WriteZip(fi);
            }
        }