public void ProcessRequest(HttpContext context)
        {
            string req_path = context.Request.AppRelativeCurrentExecutionFilePath;
            TemplateManager <TemplateBase> tm = new TemplateManager <TemplateBase>();
            TemplateBase tb = tm.LoadTemplate(req_path.Replace(".tt", ".ascx"));

            TemplatePropertyManager.SetProperties(tb, context);

            int mode = -1;

            if (int.TryParse(context.Request.QueryString["__mode"], out mode) && mode == 2) //二进制导出
            {
                if (tb.ValidQueryCondition())
                {
                    tb.ExportToExcel();
                }
            }
            else
            {
                string html = tm.RenderTemplate(tb);
                html = REGEX_BETWEEN_TAGS.Replace(html, "><");
                html = REGEX_LINE_BREAKS.Replace(html, string.Empty);
                context.Response.Clear();
                context.Response.Write(html);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="XsltExtensions"/> class.
 /// </summary>
 /// <param name="engine"><see cref="T:Tridion.ContentManager.Templating.Engine" /></param>
 /// <param name="package"><see cref="T:Tridion.ContentManager.Templating.Package" /></param>
 /// <param name="templateBase"><see cref="T:TcmTemplating.TemplateBase" /></param>
 public XsltExtensions(Engine engine, Package package, TemplateBase templateBase)
 {
     mTemplatingLogger = TemplatingLogger.GetLogger(this.GetType());
     mEngine = engine;
     mPackage = package;
     mTemplateBase = templateBase;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="XsltExtensions"/> class.
 /// </summary>
 /// <param name="engine"><see cref="T:Tridion.ContentManager.Templating.Engine" /></param>
 /// <param name="package"><see cref="T:Tridion.ContentManager.Templating.Package" /></param>
 /// <param name="templateBase"><see cref="T:TcmTemplating.TemplateBase" /></param>
 public XsltExtensions(Engine engine, Package package, TemplateBase templateBase)
 {
     mTemplatingLogger = TemplatingLogger.GetLogger(this.GetType());
     mEngine           = engine;
     mPackage          = package;
     mTemplateBase     = templateBase;
 }
        private JObject GetTemplateData(CodeGenerationContext codeGenerationContext, TemplateBase template)
        {
            var dataProviders = _dataProviderLocator.FindDataProvider(template);
            IEnumerable <string> missingDataProviders = null;

            if (dataProviders == null)
            {
                missingDataProviders = template.DataContracts;
            }
            else
            {
                missingDataProviders = template.DataContracts.Where(t => !dataProviders.ContainsKey(t));
            }

            if (missingDataProviders.Any())
            {
                throw new InvalidOperationException(
                          string.Format("Could not locate data providers for the following data contracts: {0}",
                                        string.Join(',', missingDataProviders)));
            }

            var result = JObject.Parse("{}");

            foreach (var dp in dataProviders)
            {
                var dataObj = dp.Value.GetData(dp.Key, codeGenerationContext);
                if (dataObj == null)
                {
                    _logger.Log(string.Format("Received null data for data contract: {0}", dp.Key), LogMessageLevel.Trace);
                }
            }

            return(result);
        }
        private void RenderTemplate()
        {
            //Template.Debug = true;
            //var data = new Dictionary<string, object>();
            //data.Add("ProgramName", "TestAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
            //Template.Debug = true;
            //OutputText = Template.ProcessTemplate(TemplateText, data);

            Template tt = new Template();

            tt.AddTemplateItem("testTemplate", string.Format(@"<# var P=Data[""P""] as Dictionary<string, object>; #>{0}", TemplateText));
            tt.Process();
            tt.AssemblyName = "Test";

            tt.Compile();
            TemplateBase temp = tt.CreateInstance("testTemplate");
            var          P    = new Dictionary <string, object>();

            foreach (var item in ParameterList.Where(x => !x.IsTemplate).ToList())
            {
                if (item.DataType == "Array")
                {
                    List <string> values = item.ValueList.Where(x => !x.IsTemplate).Select(x => x.PropertyValue).ToList();
                    P.Add(item.PropertyName, values);
                }
                else
                {
                    P.Add(item.PropertyName, item.PropertyValue);
                }
            }

            temp.Data["P"] = P;

            OutputText = temp.Render();
        }
Beispiel #6
0
    public void GetTemplate()
    {
        switch (template)
        {
        case TemplateType.UIView:
        {
            break;
        }

        case TemplateType.UIController:
        {
            if (templateCode == null || templateCode.GetType() != typeof(UIControllerTemplate))
            {
                templateCode = new UIControllerTemplate();
            }
            break;
        }

        case TemplateType.UIModel:
        {
            break;
        }

        case TemplateType.EffectTest:
        {
            if (templateCode == null || templateCode.GetType() != typeof(EffectTestDriverTemplates))
            {
                templateCode = new EffectTestDriverTemplates();
            }
            break;
        }
        }
    }
Beispiel #7
0
        /// <summary>
        /// 发送微信模板消息
        /// </summary>
        /// <param name="model">传入对应的消息模型</param>
        /// <returns></returns>
        public OpenApiResult SendMsg(TemplateBase model)
        {
            if (string.IsNullOrEmpty(model.token))
            {
                throw new Exception("接收消息token不能为空");
            }
            if (string.IsNullOrEmpty(model.touser))
            {
                throw new Exception("接收消息的用户Openid不能为空");
            }
            if (string.IsNullOrEmpty(model.template_id))
            {
                throw new Exception("模板消息ID不能为空");
            }
            if (model.data == null)
            {
                throw new Exception("模板消息不能为空");
            }
            var url = string.Format("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={0}", model.token);

            try
            {
                var modelstr = JsonConvert.SerializeObject(model);
                var res      = Senparc.Weixin.CommonAPIs.CommonJsonSend.Send <OpenApiResult>(model.token, url, model);
                return(res);
            }
            catch (Exception e)
            {
                return(new OpenApiResult()
                {
                    Error_code = -1, Error_msg = e.Message
                });
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TransformXml"/> class.
        /// </summary>
        /// <param name="engine"><see cref="T:Tridion.ContentManager.Templating.Engine" /></param>
        /// <param name="package"><see cref="T:Tridion.ContentManager.Templating.Package" /></param>
        /// <param name="templateBase"><see cref="T:TcmTemplating.TemplateBase" /></param>
        private TransformXml(Engine engine, Package package, TemplateBase templateBase)
        {
            mEngine = engine;
            mXslCompiledTransform = new XslCompiledTransform();

            mXsltArgumentList = new XsltArgumentList();
            mXsltArgumentList.AddExtensionObject("urn:XSLTExtensions", XsltExtensions(engine, package, templateBase));
        }
        internal ExecuteContextAdapter(TemplateBase template, ExecuteContext context)
        {
            Contract.Requires(template != null);

            _template = template;
            _context  = context;
            SetContext(_context);
        }
        public void DoStuff()
        {
            _template = new TemplateImpl0();
            _template.Execute();

            _template = new TemplateImpl1();
            _template.Execute();
        }
        ///<summary>
        /// Creates a new instance of the OutlineTextProcessor class.
        ///</summary>
        public OutlineTextProcessor(ModelItem modelItemParam, TemplateBase templateParam, string fontPathParam)
        {
            modelItem = modelItemParam;
            template = templateParam;

            PrivateFontCollection fontcollection = new PrivateFontCollection();
            fontcollection.AddFontFile(fontPathParam + template.Font.FileName);
            fontFamily = fontcollection.Families[0];
        }
        internal static void OutputTemplateBase(string symbol, TemplateBase baseType)
        {
            Log.Warn("	***Base Token Template***");
            Log.Info("		-Symbol: "+ symbol);
            Log.Warn("		-Formula:");
            Log.Info("			"+ baseType.Base.Tooling);
            Log.Error("		***Properties***");

            Log.Warn("	***Base Token Reference End***");
        }
        ///<summary>
        /// Creates a new instance of the OutlineTextProcessor class.
        ///</summary>
        public OutlineTextProcessor(ModelItem modelItemParam, TemplateBase templateParam, string fontPathParam)
        {
            modelItem = modelItemParam;
            template  = templateParam;

            PrivateFontCollection fontcollection = new PrivateFontCollection();

            fontcollection.AddFontFile(fontPathParam + template.Font.FileName);
            fontFamily = fontcollection.Families[0];
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="TransformXml"/> class.
 /// </summary>
 /// <param name="engine"><see cref="T:Tridion.ContentManager.Templating.Engine" /></param>
 /// <param name="package"><see cref="T:Tridion.ContentManager.Templating.Package" /></param>
 /// <param name="templateBase"><see cref="T:TcmTemplating.TemplateBase" /></param>
 /// <param name="styleSheet">styleSheet resource full namespace</param>
 public TransformXml(Engine engine, Package package, TemplateBase templateBase, String styleSheet)
     : this(engine, package, templateBase)
 {
     using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(styleSheet))
     {
         using (XmlReader reader = XmlReader.Create(stream))
         {
             mXslCompiledTransform.Load(reader, XsltSettings, new XmlTcmUriResolver(engine));
         }
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="FormatTextResolver" /> class.
        /// </summary>
        /// <param name="templateBase"><see cref="T:TcmTemplating.TemplateBase" /></param>
        /// <param name="formatTextResolvers">List (in priority) of format text resolvers to use</param>
        public FormatTextResolver(TemplateBase templateBase, IEnumerable<IFormatTextResolver> formatTextResolvers)
        {
            mTemplateBase = templateBase;

            if (formatTextResolvers == null || formatTextResolvers.Count() == 0)
                formatTextResolvers = new IFormatTextResolver[] { new DefaultFormatTextResolver() };
            else
                formatTextResolvers = formatTextResolvers.Concat(new IFormatTextResolver[] { new DefaultFormatTextResolver() });

            mResolvers = formatTextResolvers;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="TransformXml"/> class.
 /// </summary>
 /// <param name="engine"><see cref="T:Tridion.ContentManager.Templating.Engine" /></param>
 /// <param name="package"><see cref="T:Tridion.ContentManager.Templating.Package" /></param>
 /// <param name="templateBase"><see cref="T:TcmTemplating.TemplateBase" /></param>
 /// <param name="styleSheet">styleSheet resource full namespace</param>
 public TransformXml(Engine engine, Package package, TemplateBase templateBase, String styleSheet)
     : this(engine, package, templateBase)
 {
     using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(styleSheet))
     {
         using (XmlReader reader = XmlReader.Create(stream))
         {
             mXslCompiledTransform.Load(reader, XsltSettings, new XmlTcmUriResolver(engine));
         }
     }
 }
Beispiel #17
0
        public static List <CommandBase> Parse(TemplateBase template)
        {
            Template = template;
            List <CommandBase> returnValue = new List <CommandBase>();

            do
            {
                //NeedsAdvance = false; //RSH - 11/29/16 - to handle block advancing last/final line of it - do we need to reset needs advance to prevent >1 line processed
                AdvanceTemplateLine();
            }while (CurrentTemplateLineIndex > -1);
            return(returnValue);
        }
 private async Task RunTemplate <T>(TemplateBase <T> template, T model) where T : FilePreviewModel
 {
     model.Header     = this.header;
     template.Context = new TemplateExecutionContext(
         this.owinContext,
         new ViewDataDictionary
     {
         ["Title"]   = this.header.Breadcrumbs[this.header.Breadcrumbs.Length - 1],
         ["NoIndex"] = true
     });
     template.Model = model;
     File.WriteAllText(this.htmlFile.FullName, await template.RunAsync().ConfigureAwait(false), ResponseHelper.DefaultEncoding);
 }
Beispiel #19
0
        private string RenderMasterView(IDictionary context, string templatePath, TemplateBase instance)
        {
            var masterPath = Helpers.ResolveTemplatePath(instance.Layout, new[] { Path.GetDirectoryName(templatePath) });

            var masterInstance = generator.generate(context, masterPath);

            //RenderBody is a func that we can overwrite
            masterInstance.RenderBody = () => instance.Result;

            masterInstance.Execute();

            return(masterInstance.Result);
        }
Beispiel #20
0
 /// <summary>
 /// Get a view result object
 /// </summary>
 /// <typeparam name="T">Model type</typeparam>
 /// <param name="view">Instance of the compiled view class</param>
 /// <param name="model">Model object</param>
 /// <returns></returns>
 protected ViewResult <T> View <T>(TemplateBase <T> view, T model)
 {
     if (!string.IsNullOrEmpty(AsyncToken) &&
         Page.Request.HttpMethod == "GET" &&
         Page.Request.QueryString["AsyncWebPart"] == AsyncToken)
     {
         // rendering on async callback
         return(new PartialViewResult <T>(this, view, model));
     }
     else
     {
         return(new ViewResult <T>(this, view, model));
     }
 }
        public static Dictionary <string, Dictionary <string, string> > ParseTemplateJsonFile(string filePath)
        {
            if (!File.Exists(filePath))
            {
                return(null);
            }

            StreamReader r    = new StreamReader(filePath);
            var          json = r.ReadToEnd();

            var options = new JsonSerializerOptions
            {
                IgnoreNullValues = true // If JSON values contains empty string then ignore
            };

            var dict = JsonSerializer.Deserialize <Dictionary <string, Dictionary <string, string> > >(json, options);

            var tree = new TemplateBase();

            foreach (KeyValuePair <string, Dictionary <string, string> > entry in dict)
            {
                // Base leafs
                Console.WriteLine($"> {entry.Key.ToString()} : {entry.Value.ToString()}");

                var baseNode = new TemplateBaseLeaf()
                {
                    Description = "",
                    Id          = "",
                    Name        = entry.Key,
                };

                foreach (KeyValuePair <string, string> inside in entry.Value)
                {
                    //var node = inside.Value.Split(",");
                    //baseNode.Nodes.Add(new TemplateNode()
                    //{
                    //    Description = "",
                    //    Id = "",
                    //    Name = inside.Key,
                    //    Value = node[0],
                    //    Writable = (node[1] == "true")
                    //});
                    Console.WriteLine($"--> {inside.Key.ToString()} : {inside.Value.ToString()}");
                }

                tree.BaseLeafs.Add(baseNode);
            }

            return(dict);
        }
Beispiel #22
0
 private void Run(List <TableDefinition> tables, TemplateBase template)
 {
     if (template is StaticTemplate)
     {
         Run(tables, (StaticTemplate)template);
     }
     else
     {
         if (template is DynamicTemplate)
         {
             Run(tables, (DynamicTemplate)template);
         }
     }
 }
        public string RemoveQuery(string projectionName, UserInfo userInfo, string parentProjectionName, int?parentEntityId, string gridMode)
        {
            TemplateBase template = null;

            if (!String.IsNullOrEmpty(parentProjectionName) && parentEntityId.HasValue && parentEntityId.Value > 0)
            {
                template = new Templates.DeleteRelationEntity(userInfo, projectionName, parentProjectionName, parentEntityId, gridMode);
            }
            else
            {
                template = new Templates.Delete(userInfo, projectionName);
            }
            string retVal = template.TransformText();

            return(retVal);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FormatTextResolver" /> class.
        /// </summary>
        /// <param name="templateBase"><see cref="T:TcmTemplating.TemplateBase" /></param>
        /// <param name="formatTextResolvers">List (in priority) of format text resolvers to use</param>
        public FormatTextResolver(TemplateBase templateBase, IEnumerable <IFormatTextResolver> formatTextResolvers)
        {
            mTemplateBase = templateBase;

            if (formatTextResolvers == null || formatTextResolvers.Count() == 0)
            {
                formatTextResolvers = new IFormatTextResolver[] { new DefaultFormatTextResolver() }
            }
            ;
            else
            {
                formatTextResolvers = formatTextResolvers.Concat(new IFormatTextResolver[] { new DefaultFormatTextResolver() });
            }

            mResolvers = formatTextResolvers;
        }
Beispiel #25
0
 internal static void Init(TemplateBase view)
 {
     try
     {
         view.Title           = "ES | GESTIONE CANTIERI";
         view.Version         = "rev. 1.3a";
         view.LogoSoftware    = "Images.es.cantieri.png";
         view.LogoESD         = "Images.logoESD.png";
         view.BackgroundImage = "Images.background.png";
         view.UrlHomePortal   = "http://www.3gcostruzioni.it";
         view.SoftwareHouse   = "ESD - Engineering System Development";
     }
     catch (Exception ex)
     {
         UtilityError.Write(ex);
     }
 }
Beispiel #26
0
 internal static void Init(TemplateBase view)
 {
     try
     {
         view.Title = "ES | GESTIONE CANTIERI";
         view.Version = "rev. 1.3a";
         view.LogoSoftware = "Images.es.cantieri.png";
         view.LogoESD = "Images.logoESD.png";
         view.BackgroundImage = "Images.background.png";
         view.UrlHomePortal = "http://www.3gcostruzioni.it";
         view.SoftwareHouse = "ESD - Engineering System Development";
     }
     catch (Exception ex)
     {
         UtilityError.Write(ex);
     }
 }
Beispiel #27
0
        public static ProjectLicenseGroup GetLicenseGroup(IProjectTemplate projectTemplate)
        {
            TemplateBase templateBase = projectTemplate as TemplateBase;

            if (templateBase != null)
            {
                VSTemplateTemplateData templateData = templateBase.Template.TemplateData;
                if (templateData.ExpressionBlendPrototypingEnabled)
                {
                    return(ProjectLicenseGroup.SketchFlow);
                }
                if (templateData.TemplateID != null && templateData.TemplateID.StartsWith("Microsoft.Blend.WindowsPhone.", StringComparison.Ordinal))
                {
                    return(ProjectLicenseGroup.SilverlightMobile);
                }
            }
            return(ProjectLicenseGroup.WpfSilverlight);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TransformXml"/> class.
        /// </summary>
        /// <param name="engine"><see cref="T:Tridion.ContentManager.Templating.Engine" /></param>
        /// <param name="package"><see cref="T:Tridion.ContentManager.Templating.Package" /></param>
        /// <param name="templateBase"><see cref="T:TcmTemplating.TemplateBase" /></param>
        /// <param name="templateBuildingBlock">Tridion template building block to use as source</param>
        public TransformXml(Engine engine, Package package, TemplateBase templateBase, TcmUri templateBuildingBlockUri)
            : this(engine, package, templateBase)
        {
            if (templateBuildingBlockUri.ItemType != ItemType.TemplateBuildingBlock)
                throw new ArgumentException("templateBuildingBlock is not ItemType.TemplateBuildingBlock");

            TemplateBuildingBlock templateBuildingBlock = engine.GetObject(templateBuildingBlockUri) as TemplateBuildingBlock;

            String content = templateBuildingBlock.Content.Replace("tcm:include", "xsl:include");

            using (StringReader sr = new StringReader(content))
            {
                using (XmlReader reader = XmlReader.Create(sr))
                {
                    mXslCompiledTransform.Load(reader, XsltSettings, new XmlTcmUriResolver(engine));
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TransformXml"/> class.
        /// </summary>
        /// <param name="engine"><see cref="T:Tridion.ContentManager.Templating.Engine" /></param>
        /// <param name="package"><see cref="T:Tridion.ContentManager.Templating.Package" /></param>
        /// <param name="templateBase"><see cref="T:TcmTemplating.TemplateBase" /></param>
        /// <param name="templateBuildingBlock">Tridion template building block to use as source</param>
        public TransformXml(Engine engine, Package package, TemplateBase templateBase, Uri templateBuildingBlockUri) : this(engine, package, templateBase)
        {
            TemplateBuildingBlock templateBuildingBlock = engine.GetObject(templateBuildingBlockUri.ToString()) as TemplateBuildingBlock;

            if (templateBuildingBlock == null)
            {
                throw new ArgumentException("templateBuildingBlock is not ItemType.TemplateBuildingBlock");
            }

            String content = templateBuildingBlock.Content.Replace("tcm:include", "xsl:include");

            using (StringReader sr = new StringReader(content))
            {
                using (XmlReader reader = XmlReader.Create(sr))
                {
                    mXslCompiledTransform.Load(reader, XsltSettings, new XmlTcmUriResolver(engine));
                }
            }
        }
Beispiel #30
0
        private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.ViewModel.TemplateSelectIndex >= 0)
            {
                TemplateBase template = this.ViewModel.Templates[this.ViewModel.TemplateSelectIndex];
                if (template == null || template.Vars == null || template.Vars.Count <= 0)
                {
                    return;
                }
                ClearElement();

                VarInfoAttribute varInfo = null;
                string           val     = string.Empty;
                //添加新模板变量
                for (int i = 0; i < template.Vars.Count; i++)
                {
                    //读取以往的状态
                    varInfo = template.Vars[i];
                    val     = ApplicationGlobal.Instance.States.GetValue($"{template.Name}.{varInfo.VarName}");
                    if (!string.IsNullOrEmpty(val))
                    {
                        varInfo.VarDefault = val;
                    }

                    RowDefinition def = new RowDefinition();
                    def.Height = new GridLength(30, GridUnitType.Auto);
                    this.varPanel.RowDefinitions.Add(def);

                    TextBlock title = new TextBlock();
                    title.Text = template.Vars[i].VarTitle;
                    Grid.SetColumn(title, 0);
                    Grid.SetRow(title, i);
                    title.VerticalAlignment = VerticalAlignment.Center;
                    this.varPanel.Children.Add(title);

                    UserControl element = CreateElement(varInfo);
                    Grid.SetColumn(element, 2);
                    Grid.SetRow(element, i);
                    this.varPanel.Children.Add(element);
                }
            }
        }
        /// <summary>
        /// Resolves an application specific Tridion image for a given <see cref="T:Tridion.ContentManager.ContentManagement.Component" />
        /// </summary>
        /// <param name="templateBase"><see cref="T:TcmTemplate.TemplateBase" /></param>
        /// <param name="xhtml"><see cref="T:System.Linq.Xml.XElement" /> with XHTML to transform</param>
        /// <param name="component"><see cref="T:Tridion.ContentManager.ContentManagement.Component" /></param>
        public virtual void Resolve(TemplateBase templateBase, XElement xhtml, Component component)
        {
            xhtml.SetAttributeValue("title", LinkTitle(component));

            // Publish multi-media components
            if (component.ComponentType == ComponentType.Multimedia)
            {
                String binaryUrl = templateBase.PublishBinary(component);

                if (String.Equals(xhtml.Name.LocalName, "img", StringComparison.OrdinalIgnoreCase))
                    xhtml.SetAttributeValue("src", PrefixLink(binaryUrl));
                else
                    xhtml.SetAttributeValue("href", PrefixLink(binaryUrl));

                return;
            }

            // Normal component link, render as <a href="tcm:5-22">
            xhtml.SetAttributeValue("href", component.Id);
        }
Beispiel #32
0
        public static Bitmap GetResultImage(Model model)
        {
            string fontPath = GetFontPath();

            IRepository <TextTemplate>    _textTemplateRepository    = new Repository <TextTemplate>(new DbContextFactory());
            IRepository <ClipartTemplate> _clipartTemplateRepository = new Repository <ClipartTemplate>(new DbContextFactory());

            if (model == null)
            {
                return(null); //ToDo
            }
            ImageConverter ic        = new ImageConverter();
            Image          img       = (Image)ic.ConvertFrom(model.Image);
            Bitmap         bmpResult = new Bitmap(img);

            Graphics graphics = Graphics.FromImage(bmpResult);

            foreach (var modelItem in model.Items)
            {
                TemplateBase template = null;

                if (modelItem.ItemType == 0)
                {
                    template = _textTemplateRepository.GetAllWithInclude("Font").Where(p => p.Id == modelItem.TemplateId).FirstOrDefault();
                }
                else
                {
                    template = _clipartTemplateRepository.GetAllWithInclude("Font").Where(p => p.Id == modelItem.TemplateId).FirstOrDefault();
                }

                OutlineTextProcessor outlineTextProcessor = new OutlineTextProcessor(modelItem, template, fontPath);
                Bitmap image = outlineTextProcessor.GetImage();

                graphics.DrawImage((Image)image, new Point(modelItem.PositionLeft, modelItem.PositionTop));
            }

            graphics.Flush();
            graphics.Dispose();

            return(bmpResult);
        }
Beispiel #33
0
        //ToDo -
        private void ModelToSampleForm_Load(object sender, EventArgs e)
        {
            string fontPath = @"E:\xWork\Apps\Work\AddTextToImage\AddTextToImage.WebUI\fonts\";

            model = _modelRepository.Get(ModelId);

            if (model != null)
            {
                ImageConverter ic        = new ImageConverter();
                Image          img       = (Image)ic.ConvertFrom(model.Image);
                Bitmap         bmpResult = new Bitmap(img);

                Graphics graphics = Graphics.FromImage(bmpResult);

                foreach (var modelItem in model.Items)
                {
                    TemplateBase template = null;

                    if (modelItem.ItemType == 0)
                    {
                        template = _textTemplateRepository.GetAllWithInclude("Font").Where(p => p.Id == modelItem.TemplateId).FirstOrDefault();
                    }
                    else
                    {
                        template = _clipartTemplateRepository.GetAllWithInclude("Font").Where(p => p.Id == modelItem.TemplateId).FirstOrDefault();
                    }

                    OutlineTextProcessor outlineTextProcessor = new OutlineTextProcessor(modelItem, template, fontPath);
                    Bitmap image = outlineTextProcessor.GetImage();

                    graphics.DrawImage((Image)image, new Point(modelItem.PositionLeft, modelItem.PositionTop));
                }

                resultImage = bmpResult;

                graphics.Flush();
                graphics.Dispose();
            }
        }
Beispiel #34
0
        public HttpResponseMessage ModelItem(int id, [FromUri] ModelItem modelItem)
        {
            TemplateBase template = null;

            if (!ModelState.IsValid)
            {
                return(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }

            if (modelItem.ItemType == 0)
            {
                template = _textTemplateRepository.GetAllWithInclude("Font").Where(p => p.Id == modelItem.TemplateId).FirstOrDefault();
            }
            else
            {
                template = _clipartTemplateRepository.GetAllWithInclude("Font").Where(p => p.Id == modelItem.TemplateId).FirstOrDefault();
            }

            if (template == null)
            {
                return(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }

            string fontPath = HostingEnvironment.MapPath("~/fonts/");

            OutlineTextProcessor outlineTextProcessor = new OutlineTextProcessor(modelItem, template, fontPath);
            Bitmap image = outlineTextProcessor.GetImage();

            using (MemoryStream memoryStream = new MemoryStream())
            {
                image.Save(memoryStream, ImageFormat.Png);

                HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);

                response.Content = new ByteArrayContent(memoryStream.ToArray());
                response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
                return(response);
            }
        }
Beispiel #35
0
        /// <summary>
        /// Resolves an application specific Tridion image for a given <see cref="T:Tridion.ContentManager.ContentManagement.Component" />
        /// </summary>
        /// <param name="templateBase"><see cref="T:TcmTemplate.TemplateBase" /></param>
        /// <param name="xhtml"><see cref="T:System.Linq.Xml.XElement" /> with XHTML to transform</param>
        /// <param name="component"><see cref="T:Tridion.ContentManager.ContentManagement.Component" /></param>
        public virtual void Resolve(TemplateBase templateBase, XElement xhtml, Component component)
        {
            xhtml.SetAttributeValue("title", LinkTitle(component));

            // Publish multi-media components
            if (component.ComponentType == ComponentType.Multimedia)
            {
                String binaryUrl = templateBase.PublishBinary(component);

                if (String.Equals(xhtml.Name.LocalName, "img", StringComparison.OrdinalIgnoreCase))
                {
                    xhtml.SetAttributeValue("src", PrefixLink(binaryUrl));
                }
                else
                {
                    xhtml.SetAttributeValue("href", PrefixLink(binaryUrl));
                }

                return;
            }

            // Normal component link, render as <a href="tcm:5-22">
            xhtml.SetAttributeValue("href", component.Id);
        }
Beispiel #36
0
 public RazorHtmlHelper(TemplateBase template)
 {
     this._template = template;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="TransformXml"/> class.
        /// </summary>
        /// <param name="engine"><see cref="T:Tridion.ContentManager.Templating.Engine" /></param>
        /// <param name="package"><see cref="T:Tridion.ContentManager.Templating.Package" /></param>
        /// <param name="templateBase"><see cref="T:TcmTemplating.TemplateBase" /></param>
        private TransformXml(Engine engine, Package package, TemplateBase templateBase)
        {
            mEngine = engine;
            mXslCompiledTransform = new XslCompiledTransform();

            mXsltArgumentList = new XsltArgumentList();
            mXsltArgumentList.AddExtensionObject("urn:XSLTExtensions", XsltExtensions(engine, package, templateBase));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="FormatTextResolver" /> class.
 /// </summary>
 /// <param name="templateBase"><see cref="T:TcmTemplating.TemplateBase" /></param>
 public FormatTextResolver(TemplateBase templateBase)
     : this(templateBase, null)
 {
 }
 /// <summary>
 /// Constructs the <see cref="T:TcmTemplating.Helper.XsltExtensions" /> for this transformation
 /// </summary>
 /// <param name="engine"><see cref="T:Tridion.ContentManager.Templating.Engine" /></param>
 /// <param name="package"><see cref="T:Tridion.ContentManager.Templating.Package" /></param>
 /// <param name="templateBase"><see cref="T:TcmTemplating.TemplateBase" /></param>
 /// <returns>Initialized <see cref="T:TcmTemplating.Helpers.XsltExtensions" /></returns>
 protected virtual object XsltExtensions(Engine engine, Package package, TemplateBase templateBase)
 {
     return new XsltExtensions(engine, package, templateBase);
 }
 public CompilationResults(GeneratorResults generatorResults, TemplateBase compiled)
     : base(true, generatorResults.Document, generatorResults.ParserErrors, generatorResults.GeneratedCode, generatorResults.DesignTimeLineMappings)
 {
     this.Compiled = compiled;
 }