示例#1
0
        private void LoadTemplateFileInfos2(string root, DirectoryInfo dirInfo, int level, List <TemplateFileInfo> result)
        {
            TemplateFileInfo skinConfigFile = null;

            foreach (FileInfo file in dirInfo.GetFiles("*"))
            {
                if (
                    StringUtil.EqualsIgnoreCase(file.Extension, ".aspx") ||
                    StringUtil.EqualsIgnoreCase(file.Extension, ".ascx") ||
                    StringUtil.EqualsIgnoreCase(file.Extension, ".js") ||
                    StringUtil.EqualsIgnoreCase(file.Extension, ".css") ||
                    StringUtil.EqualsIgnoreCase(file.Extension, ".html")
                    )
                {
                    result.Add(new TemplateFileInfo(file.Name, file.FullName.Substring(root.Length), level));
                }
                else if (StringUtil.EqualsIgnoreCase(file.Name, "_skin.config"))
                {
                    skinConfigFile = new TemplateFileInfo(file.Name, file.FullName.Substring(root.Length), level);
                }
            }

            if (skinConfigFile != null)
            {
                result.Add(skinConfigFile);
            }
        }
示例#2
0
 public void Reset(TemplateFileInfo templateInfo, String templatesDirectory, OdcmObject currentType, OdcmModel currentModel)
 {
     this.TemplateFile       = templateInfo.FullPath;
     this.TemplatesDirectory = templatesDirectory;
     this.CurrentType        = currentType;
     this.CurrentModel       = currentModel;
 }
示例#3
0
        /// <summary>
        ///    根据模板导出列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="fileName"></param>
        /// <param name="dataItems"></param>
        /// <param name="htmlTemplate"></param>
        /// <returns></returns>
        public async Task <TemplateFileInfo> ExportListByTemplate <T>(string fileName, IList <T> dataItems, string htmlTemplate = null) where T : class
        {
            if (string.IsNullOrWhiteSpace(fileName))
            {
                throw new ArgumentException("文件名必须填写!", nameof(fileName));
            }
            var exporter   = new HtmlExporter();
            var htmlString = await exporter.ExportListByTemplate(dataItems, htmlTemplate);

            using (var generatedDocument = new MemoryStream())
            {
                using (var package =
                           WordprocessingDocument.Create(generatedDocument, WordprocessingDocumentType.Document))
                {
                    var mainPart = package.MainDocumentPart;
                    if (mainPart == null)
                    {
                        mainPart = package.AddMainDocumentPart();
                        new Document(new Body()).Save(mainPart);
                    }

                    var converter = new HtmlConverter(mainPart);
                    converter.ParseHtml(htmlString);

                    mainPart.Document.Save();
                }

                File.WriteAllBytes(fileName, generatedDocument.ToArray());
                var fileInfo = new TemplateFileInfo(fileName,
                                                    "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
                return(fileInfo);
            }
        }
示例#4
0
 public virtual string WritePath(TemplateFileInfo template, String entityTypeName)
 {
     return(Path.Combine(
                template.TemplateLanguage,
                template.TemplateType.ToString(),
                this.TransformFileName(template, entityTypeName)
                ));
 }
示例#5
0
        public async Task <TemplateFileInfo> ExportByTemplate <T>(string fileName, T data,
                                                                  string htmlTemplate) where T : class
        {
            var file   = new TemplateFileInfo(fileName, "text/html");
            var result = await ExportByTemplate(data, htmlTemplate);

            File.WriteAllText(fileName, result, Encoding.UTF8);
            return(file);
        }
        internal override void ProcessData(AmcpParsedData data)
        {
            base.ProcessData(data);

            for (var i = 1; i < data.Data.Count; i++)
            {
                _templateList.Add(TemplateFileInfo.Parse(data.Data[i]));
            }
        }
示例#7
0
        public override String WritePath(TemplateFileInfo template, String entityTypeName)
        {
            var    theNamespace  = CreateNamespace(template.TemplateType.ToString().ToLower());
            var    namespacePath = CreatePathFromNamespace(theNamespace);
            var    fileName      = TransformFileName(template, entityTypeName);
            String filePath      = Path.Combine(namespacePath, fileName);

            return(filePath);
        }
示例#8
0
        /// <summary>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="fileName"></param>
        /// <param name="dataItems"></param>
        /// <param name="htmlTemplate"></param>
        /// <returns></returns>
        public async Task<TemplateFileInfo> ExportListByTemplate<T>(string fileName, IList<T> dataItems,
            string htmlTemplate = null) where T : class
        {
            var file = new TemplateFileInfo(fileName, "text/html");

            var result = await ExportListByTemplate(dataItems, htmlTemplate);
            File.WriteAllText(fileName, result, Encoding.UTF8);
            return file;
        }
示例#9
0
        /// <summary>
        ///     创建Excel
        /// </summary>
        /// <param name="fileName">文件名</param>
        /// <param name="creator"></param>
        /// <returns></returns>
        public static TemplateFileInfo CreateExcelPackage(string fileName, Action <ExcelPackage> creator)
        {
            var file = new TemplateFileInfo(fileName, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");

            using (var excelPackage = new ExcelPackage())
            {
                creator(excelPackage);
                Save(excelPackage, file);
            }
            return(file);
        }
示例#10
0
        protected virtual string TransformFileName(TemplateFileInfo template, String entityTypeName)
        {
            String result;

            if (template.TemplateType == TemplateType.Fetchers)
            {
                result = template.TemplateName.Replace("Entity", entityTypeName);
            }
            else
            {
                result = String.Format("{0}.{1}", entityTypeName, template.FileExtension);
            }

            return(result);
        }
        public override string WritePath(TemplateFileInfo template, String entityTypeName)
        {
            String prefix       = ConfigurationService.Settings.NamespacePrefix;
            String coreFileName = this.TransformFileName(template, entityTypeName);
            String extension    = template.FileExtension;

            String containerName = entityTypeName == this.Model.EntityContainer.Name ? String.Empty : this.Model.EntityContainer.Name;

            return(Path.Combine(
                       template.TemplateType.ToString(),
                       String.Format("{0}{1}{2}",
                                     prefix,
                                     containerName,
                                     coreFileName
                                     )
                       ));
        }
示例#12
0
        /// <summary>
        ///     Handles request only for manifest.xsf files. A manifest.xsf response requires the URL requested to be written to
        ///     the csd file itself so the remaing files it documents can be downloaded in other requests the Microsoft InfoPath
        ///     Filler application performs.
        /// </summary>
        /// <param name="context"></param>
        public override void ProcessRequest(HttpContext context)
        {
            TemplateFileInfo _TemplateFileInfo = TemplateController.ParseTemplateFileInfo(context);

            if (!_TemplateFileInfo.FileName.Equals(HrefVirtualFilename(_TemplateFileInfo.DocTypeName, _TemplateFileInfo.solutionVersion), StringComparison.InvariantCultureIgnoreCase))
            {
                base.ProcessRequest(context);
            }
            else
            {
                context.Response.DisableKernelCache();
                context.Response.Clear();
                context.Response.ClearContent();
                context.Response.ClearHeaders();

                Regex regPublishUrl = new Regex("(?<=publishUrl=\")(.*?)(?=\")", RegexOptions.Multiline);

                // The publish URL within this file needs to be updated to the current requested URL for the InfoPath application form to like it
                //string ManifestPath = context.Request.MapPath(new Uri(RequestPaths.AbsoluteUri).LocalPath);
                string UrlReferrer_AbsoluteUri = context.Request.UrlReferrer == null ? "" : context.Request.UrlReferrer.AbsoluteUri;

                string   filename;
                string[] lines = TemplateController.Instance.OpenText(context, out filename)
                                 .Split('\n', '\r');

                // render the publishUrl as the calling request or that of a registered listener
                string publishUrl = UrlReferrer_AbsoluteUri.Contains("/" + ReverseProxy.DirectoryName)
                                        ? UrlReferrer_AbsoluteUri
                                        : RequestPaths.AbsoluteUri;

                context.Response.ClearContent();

                for (int i = 0; i < lines.Length; i++)
                {
                    context.Response.Write(
                        regPublishUrl.IsMatch(lines[i]) ?
                        regPublishUrl.Replace(lines[i], publishUrl) :
                        lines[i]);
                }

                context.Response.ContentType = "text/xml";
            }
        }
示例#13
0
        private void LoadTemplateFileInfos1(string root, DirectoryInfo dirInfo, int level, List <TemplateFileInfo> result)
        {
            foreach (DirectoryInfo directory in dirInfo.GetDirectories())
            {
                if (directory.Name == ".svn" || directory.Name == "__模板编辑历史记录__")
                {
                    continue;
                }

                TemplateFileInfo dir = new TemplateFileInfo(directory.Name, directory.FullName.Substring(root.Length), level);
                dir.IsDir = true;

                result.Add(dir);

                LoadTemplateFileInfos1(root, directory, level + 1, result);

                //LoadTemplateFileInfos2(root, directory, level + 1, isMaxPages, result);
            }

            LoadTemplateFileInfos2(root, dirInfo, level, result);
        }
示例#14
0
        /// <summary>
        ///    根据模板导出列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="fileName"></param>
        /// <param name="dataItems"></param>
        /// <param name="htmlTemplate"></param>
        /// <returns></returns>
        public async Task <TemplateFileInfo> ExportListByTemplate <T>(string fileName, ICollection <T> dataItems, string htmlTemplate = null) where T : class
        {
            if (string.IsNullOrWhiteSpace(fileName))
            {
                throw new ArgumentException("文件名必须填写!", nameof(fileName));
            }

            var exporter   = new HtmlExporter();
            var htmlString = await exporter.ExportListByTemplate(dataItems, htmlTemplate);

            var converter = new BasicConverter(new PdfTools());
            var doc       = new HtmlToPdfDocument
            {
                GlobalSettings =
                {
                    ColorMode   = ColorMode.Color,
                    Orientation = Orientation.Landscape,
                    PaperSize   = PaperKind.A4,
                    Out         = fileName,
                },
                Objects =
                {
                    new ObjectSettings
                    {
                        PagesCount     = true,
                        HtmlContent    = htmlString,
                        WebSettings    = { DefaultEncoding = "utf-8" },
                        HeaderSettings ={ FontSize                             =9, Right = "[page]/[toPage]", Line = true, Spacing = 2.812 },
                        Encoding       = System.Text.Encoding.UTF8
                    }
                }
            };

            converter.Convert(doc);
            var fileInfo = new TemplateFileInfo(fileName, "application/pdf");

            return(fileInfo);
        }
示例#15
0
        /// <summary>
        ///     根据模板导出
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="fileName"></param>
        /// <param name="data"></param>
        /// <param name="htmlTemplate"></param>
        /// <returns></returns>
        public async Task <TemplateFileInfo> ExportByTemplate <T>(string fileName, T data, string htmlTemplate) where T : class
        {
            if (string.IsNullOrWhiteSpace(fileName))
            {
                throw new ArgumentException("文件名必须填写!", nameof(fileName));
            }

            var exporterAttribute = GetExporterAttribute <T>();
            var exporter          = new HtmlExporter();
            var htmlString        = await exporter.ExportByTemplate(data, htmlTemplate);

            if (exporterAttribute.IsWriteHtml)
            {
                File.WriteAllText(fileName + ".html", htmlString);
            }

            var doc = GetHtmlToPdfDocumentByExporterAttribute(fileName, exporterAttribute, htmlString);

            PdfConverter.Convert(doc);
            var fileInfo = new TemplateFileInfo(fileName, "application/pdf");

            return(fileInfo);
        }
示例#16
0
 private static void Save(Workbook excelPackage, TemplateFileInfo file)
 {
     excelPackage.Save(file.FileName);
 }
示例#17
0
        public virtual void ProcessRequest(HttpContext context)
        {
            // ensure the latest content has been processed & imported
            ImporterController.TryDocRevImporting();

            TemplateFileInfo _TemplateFileInfo = TemplateController.ParseTemplateFileInfo(context);

            if (!string.IsNullOrWhiteSpace(_TemplateFileInfo.DocTypeName)
                &&
                !string.IsNullOrWhiteSpace(_TemplateFileInfo.solutionVersion)
                &&
                !string.IsNullOrWhiteSpace(_TemplateFileInfo.FileName))
            {
                // serve a supporting template file up (the the target Interpreter may need to alter it in some way, qazi-dynamic)
                InstanceLocatorByName <DocBaseInterpreter>(_TemplateFileInfo.DocTypeName, _TemplateFileInfo.solutionVersion)
                .ProcessRequest(context);
            }
            else
            {
                // serve a filled & stored document rendered previously
                context.Response.DisableKernelCache();
                context.Response.Clear();
                context.Response.ClearContent();
                context.Response.ClearHeaders();

                object docData;

                if (context.Request.Params.AllKeys.Any(m => m == Parm.DocId.ToString()))
                {
                    docData = DocExchange.LuceneController.GetDocData(
                        context.Request.Params[Parm.DocTypeName],
                        context.Request.Params[Parm.DocId],
                        HttpUtility.UrlDecode(context.Request.Params[Parm.RelayUrl]),
                        long.Parse(context.Request.Params[Parm.LogSequenceNumber] ?? "0"));
                }
                else
                {
                    docData = ((BaseDoc)(context.Request.Params.AllKeys.Any(m => m == Parm.DocCache)
                                              ? HttpRuntime.Cache[context.Request.Params[Parm.DocCache]]
                                              : Compressor.DecompressFromBase64String(HttpUtility.UrlDecode(context.Request.Params[Parm.DocBin]))
                                         .FromBytes <BaseDoc>()));
                }

                DocBaseInterpreter        _DocBaseInterpreter = null;
                DocProcessingInstructions _DocProcessingInstructions;

                //TODO:need to tidy up this code block as its really hard to follow.. In the end, that docData may be a POCO, raw bytes or text... Need to rewrites it's PI here before it's shoved over the repsonse.stream
                if (docData is BaseDoc)
                {
                    // get the interpreter & convert docData from poco to its raw form
                    _DocBaseInterpreter = InstanceLocatorByName <DocBaseInterpreter>(((BaseDoc)docData).DocTypeName, ((BaseDoc)docData).solutionVersion);
                    if (_DocBaseInterpreter is DocByteInterpreter)
                    {
                        docData = ((DocByteInterpreter)_DocBaseInterpreter).WriteByte((BaseDoc)docData);
                    }
                    else
                    {
                        docData = ((DocTextInterpreter)_DocBaseInterpreter).WriteText((BaseDoc)docData);
                    }
                }

                if (docData is byte[])
                {
                    _DocBaseInterpreter        = _DocBaseInterpreter ?? LocateInstance((byte[])docData);
                    _DocProcessingInstructions = Instance.ReadDocPI((byte[])docData);
                    docData = Instance.ModPI((byte[])docData, href: DocBaseInterpreter.BuildHref(context, _DocProcessingInstructions.DocTypeName, _DocProcessingInstructions.solutionVersion));
                    context.Response.BinaryWrite((byte[])docData);
                }
                else
                {
                    _DocBaseInterpreter        = _DocBaseInterpreter ?? LocateInstance((string)docData);
                    _DocProcessingInstructions = Instance.ReadDocPI((string)docData);
                    docData = Instance.ModPI((string)docData, href: DocBaseInterpreter.BuildHref(context, _DocProcessingInstructions.DocTypeName, _DocProcessingInstructions.solutionVersion));
                    context.Response.Write((string)docData);
                }

                context.Response.ContentType = _DocBaseInterpreter.ContentInfo.ContentType;
                context.Response.AddHeader(
                    "content-disposition",
                    string.Format(
                        "attachment; filename=\"{0}\";",
                        DocBaseInterpreter.GetFilename(_DocProcessingInstructions, context.Request.Params["ContentFileExtension"])));
            }
        }
示例#18
0
        private static readonly string SharedResourceFileName  = "Shared"; //Shared.resxのこと

        public static string Resource(this TemplateFileInfo info, string name, params object[] args)
        {
            return(Resource(info.VirtualPath, name, args));
        }
示例#19
0
 private static void Save(ExcelPackage excelPackage, TemplateFileInfo file)
 {
     excelPackage.SaveAs(new FileInfo(file.FileName));
 }
示例#20
0
        // see https://msdn.microsoft.com/en-us/library/bb126579(v=vs.110).aspx

        public CustomT4Host(TemplateFileInfo templateInfo, String templatesDirectory, OdcmObject currentType, OdcmModel currentModel)
        {
            this.Reset(templateInfo, templatesDirectory, currentType, currentModel);
        }