Example #1
0
        static void Main()
        {
            Console.WriteLine("Transform a very simple template\n\r");
            SimpleTemplate.Transform();

            Console.WriteLine("Transform examples from documentation\n\r");
            DocumentationExamples.Transform();

            Console.WriteLine("\n\r\n\rTransform the ClassDefinition template in current app-domain\n\r");
            ClassTemplate.Transform(new TextTransformer());

            Console.WriteLine("\n\r\n\rTransform the ClassDefinition template in new app-domain\n\r");
            using (var domain = new DomainTextTransformer())
            {
                ClassTemplate.Transform(domain);
            }

            Console.WriteLine("\n\r\n\rMeasure the transformation of the ClassDefinition template\n\r");
            ClassTemplate.Measure();

            Console.WriteLine("Transform a template that includes a template from EntryAssembly path\n\r");
            IncludeTemplate.Transform();

            Console.ReadKey();
        }
Example #2
0
        static void Main()
        {
            Console.WriteLine("Transform a very simple template\n\r");
            SimpleTemplate.Transform();

            Console.WriteLine("Transform examples from documentation\n\r");
            DocumentationExamples.Transform();

            Console.WriteLine("\n\r\n\rTransform the ClassDefinition template in current app-domain\n\r");
            ClassTemplate.Transform(new TextTransformer());

            Console.WriteLine("\n\r\n\rTransform the ClassDefinition template in new app-domain\n\r");
            using (var domain = new DomainTextTransformer())
            {
                ClassTemplate.Transform(domain);
            }

            Console.WriteLine("\n\r\n\rMeasure the transformation of the ClassDefinition template\n\r");
            ClassTemplate.Measure();

            Console.WriteLine("Transform a template that includes a template from EntryAssembly path\n\r");
            IncludeTemplate.Transform();

            Console.ReadKey();
        }
Example #3
0
        protected void Application_Start(object sender, EventArgs e)
        {
            var textTransformer = new DomainTextTransformer {
                AutoRecycle = true, RecycleThreshold = 30
            };

            Application["Transformer"] = textTransformer;
        }
        public void Initialize()
        {
            var host   = new Mock <ITextTransformerHost>();
            var engine = new Mock <ITextTemplatingEngine>();

            _appDomainManager.Setup(a => a.Create(It.IsAny <string>())).Returns(_appDomain).Verifiable();

            _transformer = new DomainTextTransformer(_appDomainManager.Object, host.Object, engine.Object);
        }
        internal static void Measure()
        {
            //Prepare the argument that will be passes to the template
            var class1 = new ClassDefinition
            {
                Name      = "TestClass",
                Namespace = "TC.CustomTemplating.Example.Generated"
            };

            class1.Properties.Add(new Property("Name", typeof(string)));
            class1.Properties.Add(new Property("Lenght", typeof(int)));
            class1.Properties.Add(new Property("L", typeof(int)));

            double    min   = double.MaxValue;
            double    max   = 0;
            double    first = double.MinValue;
            const int numberOfTransformations = 100;

            //Get template from the embedded resources
            string template = TemplateResources.Get("TC.CustomTemplating.Example.Class.tt", typeof(ClassTemplate));

            //Create a new domain wherein the transformation will
            //take place
            using (var transformer = new DomainTextTransformer())
            {
                //We try to transform it n times
                Stopwatch watch = new Stopwatch();
                for (int i = 0; i < numberOfTransformations; i++)
                {
                    //start the tranformation
                    watch.Reset();
                    watch.Start();
                    transformer.Transform(template, "Class", class1);
                    watch.Stop();

                    //Measure
                    var milliseconds = watch.ElapsedMilliseconds;
                    if (first == double.MinValue)
                    {
                        first = milliseconds;
                    }
                    else
                    {
                        max = Math.Max(max, milliseconds);
                    }
                    min = Math.Min(min, milliseconds);
                }
            }

            Console.WriteLine("--BEGIN MEASUREMENT RESULTS--");
            Console.WriteLine("Number Of Transformations: {0}", numberOfTransformations);
            Console.WriteLine("First Time: {0}ms", first);
            Console.WriteLine("Min Time: {0}ms", min);
            Console.WriteLine("Max Time: {0}ms  (without first time)", max);
            Console.WriteLine("--END MEASUREMENT RESULTS--");
        }
Example #6
0
        internal static void Measure()
        {
            //Prepare the argument that will be passes to the template
            var class1 = new ClassDefinition
                             {
                                 Name = "TestClass",
                                 Namespace = "TC.CustomTemplating.Example.Generated"
                             };
            class1.Properties.Add(new Property("Name", typeof(string)));
            class1.Properties.Add(new Property("Lenght", typeof(int)));
            class1.Properties.Add(new Property("L", typeof(int)));

            double min = double.MaxValue;
            double max = 0;
            double first = double.MinValue;
            const int numberOfTransformations = 100;

            //Get template from the embedded resources
            string template = TemplateResources.Get("TC.CustomTemplating.Example.Class.tt", typeof(ClassTemplate));

            //Create a new domain wherein the transformation will
            //take place
            using (var transformer = new DomainTextTransformer())
            {
                //We try to transform it n times
                Stopwatch watch = new Stopwatch();
                for (int i = 0; i < numberOfTransformations; i++)
                {
                    //start the tranformation
                    watch.Reset();
                    watch.Start();
                    transformer.Transform(template, "Class", class1);
                    watch.Stop();

                    //Measure
                    var milliseconds = watch.ElapsedMilliseconds;
                    if (first == double.MinValue)
                    {
                        first = milliseconds;
                    }
                    else
                    {
                        max = Math.Max(max, milliseconds);
                    }
                    min = Math.Min(min, milliseconds);
                }
            }

            Console.WriteLine("--BEGIN MEASUREMENT RESULTS--");
            Console.WriteLine("Number Of Transformations: {0}", numberOfTransformations);
            Console.WriteLine("First Time: {0}ms", first);
            Console.WriteLine("Min Time: {0}ms", min);
            Console.WriteLine("Max Time: {0}ms  (without first time)", max);
            Console.WriteLine("--END MEASUREMENT RESULTS--");
        }
        public void with_arguments_it_should_call_appDomainManager()
        {
            //Arrange
            _appDomain = AppDomain.CreateDomain(new Guid().ToString());
            _appDomainManager.Setup(a => a.Create(It.IsAny <string>())).Returns(_appDomain);
            _engine.Setup(e => e.ProcessTemplate(Template, _host.Object)).Returns(Result);

            //Act
            _transformer = new DomainTextTransformer(_appDomainManager.Object, _host.Object, _engine.Object);
            _result      = _transformer.Transform(Template);
        }
        public void TestInitialize()
        {
            //Arrange
            _appDomain = AppDomain.CreateDomain(new Guid().ToString());
            _appDomainManager.Setup(a => a.Create(It.IsAny <string>())).Returns(_appDomain);
            _engine.Setup(e => e.ProcessTemplate(Template, _host.Object)).Returns(Result);

            _transformer       = new DomainTextTransformer(_appDomainManager.Object, _host.Object, _engine.Object);
            _initialAssemblies = _transformer.AssemblyReferences.Count;

            //Act
            _result = _transformer.Transform(Template, ArgumentName, null);
        }
        public void with_arguments_it_should_call_appDomainManager()
        {
            //Arrange
            _appDomain = AppDomain.CreateDomain(new Guid().ToString());
            _appDomainManager.Setup(a => a.Create(It.IsAny <string>())).Returns(_appDomain);
            _engine.Setup(e => e.ProcessTemplate(Template, _host.Object)).Returns(Result);

            _transformer       = new DomainTextTransformer(_appDomainManager.Object, _host.Object, _engine.Object);
            _initialAssemblies = _transformer.AssemblyReferences.Count;

            _arguments = new TemplateArgumentCollection
            {
                new TemplateArgument(ArgumentName1, _argumentValue1),
                new TemplateArgument(ArgumentName2, _argumentValue2),
            };
            //Act
            _result = _transformer.Transform(Template, _arguments);
        }
        public void with_arguments_it_should_call_appDomainManager()
        {
            var appDomainManager = new Mock <IAppDomainManager>();
            var host             = new Mock <ITextTransformerHost>();
            var engine           = new Mock <ITextTemplatingEngine>();

            var appDomain = AppDomain.CreateDomain(new Guid().ToString());

            try
            {
                appDomainManager.Setup(a => a.Create(It.IsAny <string>())).Returns(appDomain);

                var transformer = new DomainTextTransformer(appDomainManager.Object, host.Object, engine.Object);
                transformer.Recycle();

                appDomainManager.Verify(a => a.Create(It.IsAny <string>()), Times.Exactly(2));
            }
            finally
            {
                AppDomain.Unload(appDomain);
            }
        }
        /// <summary>
        /// Toggles the template domain.
        /// </summary>
        internal void ToggleTemplateDomain()
        {
            transformer.ClassDefinitionGenerated -= Host_ClassDefinitionGenerated;

            if (domain == null)
            {
                domain                  = new DomainTextTransformer();
                domain.AutoRecycle      = true;
                domain.RecycleThreshold = 5;
                TemplateDomainAction    = TemplateDomainActionUnload;
                transformer             = domain;
            }
            else
            {
                domain.Dispose();
                domain = null;
                TemplateDomainAction = TemplateDomainActionCreate;
                transformer          = new TextTransformer();
            }

            transformer.ClassDefinitionGenerated += Host_ClassDefinitionGenerated;

            RefreshDomainProperties();
        }
Example #12
0
 public void Initialize()
 {
     _transformer = new DomainTextTransformer();
 }