Exemplo n.º 1
0
        internal string Render(string internalName, GxDictionary propbag)
        {
            if (!File.Exists(GetTemplateAction(m_Type)))
            {
                return(String.Empty);
            }
#if NETCORE
            var    stubble = new StubbleBuilder().Build();
            string output  = string.Empty;
            if (GetTemplateDateTime() > LastRenderTime || m_Template == null)
            {
                m_Template     = File.ReadAllText(GetTemplateFile(m_Type));
                LastRenderTime = DateTime.UtcNow;
            }
            return(stubble.Render(m_Template, propbag));
#else
            Encoders.HtmlEncode = (input) => input;

            if (GetTemplateDateTime() > LastRenderTime || m_Template == null)
            {
                m_Template = new Template();
#pragma warning disable SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}'
                m_Template.Load(new StringReader(File.ReadAllText(GetTemplateAction(m_Type))));
#pragma warning restore SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}'
                LastRenderTime = DateTime.UtcNow;
                // Do not use template.Compile, it doesnt work with nested SDTs
            }
            StringBuilder sb = new StringBuilder();
            m_Template.Render(propbag, new StringWriter(sb), null);
            return(sb.ToString());
#endif
        }
Exemplo n.º 2
0
 public string RenderControl(string controlType, string internalName, GxDictionary propbag)
 {
     if (!m_Generators.TryGetValue(controlType, out UserControlGenerator userControlGenerator))
     {
         userControlGenerator      = new UserControlGenerator(controlType);
         m_Generators[controlType] = userControlGenerator;
     }
     return(userControlGenerator.Render(internalName, propbag));
 }
Exemplo n.º 3
0
        public void GenerateSimpleUC()
        {
            GXUserControl ucMycontrol1 = new GXUserControl();

            UserControlFactoryImpl factory = new UserControlFactoryImpl();
            GxDictionary           propbag = new GxDictionary();

            string GetTemplateFile(string type)
            {
                return("TestModule.MyControl.view");
            }

            var context = new GxContext();

            StringBuilder sb = new StringBuilder();

            context.OutputWriter = new HtmlTextWriter(new StringWriter(sb));
            UserControlGenerator.GetTemplateAction = GetTemplateFile;

            // Initialize Data in SDT Collection
            var    AV6ItemCollection = new GXBaseCollection <SdtItem>(context, "Item", "testuc");
            string HELLO             = "Hello Test UC";
            string ONE     = "One";
            string TWO     = "Two";
            var    AV7Item = new SdtItem(context)
            {
                gxTpr_Name = ONE
            };

            AV6ItemCollection.Add(AV7Item, 0);
            AV7Item = new SdtItem(context)
            {
                gxTpr_Name = TWO
            };
            AV6ItemCollection.Add(AV7Item, 0);
            ucMycontrol1.SetProperty("Items", AV6ItemCollection);

            ucMycontrol1.SetProperty("Message", HELLO);
            ucMycontrol1.SetProperty("Boolean", true);
            ucMycontrol1.Render(context, "testmodule.mycontrol", "internalName", "MYCONTROL1Container");

            string output = sb.ToString();

            AssertContains(ONE, output);
            AssertContains(TWO, output);
            AssertContains(HELLO, output);
            AssertContains("Boolean:true", output);
        }
 public GxDictionary Difference(GxDictionary dic)
 {
     return(null);
 }