Esempio n. 1
0
        internal static void Transform()
        {
            //Start transformation without argument
            string template1 = "This is a template displaying the current date & time: <#= System.DateTime.Now #>";
            string output = Template.Transform(template1);

            string template2 = @"<#@ property name=""Name"" type=""System.String""" +
                   @"    processor=""PropertyProcessor"" #>" +
                   @"This is a template displaying one argument: <#= Name #>";
            //Start transformation with a single argument
            string output2 = Template.Transform(template2, "Name", "Homer Simpson");

            //Start transformation with multiple arguments
            var arguments = new TemplateArgumentCollection
            {
               //Argument             Name     &  Value
               new TemplateArgument("FirstName", "Homer"),
               new TemplateArgument("LastName", "Simpson"),
               new TemplateArgument("Color", Color.Yellow)
            };
            string template3 = @"<#@ property name=""FirstName"" type=""System.String""" +
                   @"    processor=""PropertyProcessor"" #>" +
                   @"<#@ property name=""LastName"" type=""System.String""" +
                   @"    processor=""PropertyProcessor"" #>" +
                   @"<#@ property name=""Color"" type=""System.Drawing.Color""" +
                   @"    processor=""PropertyProcessor"" #>" +
                   @"This is a template displaying multiple arguments: "+
                   @"<#= FirstName #> <#= LastName #> is <#= Color.Name #>";
            string output3 = Template.Transform(template3, arguments);
        }
        public static string Transform(IGenerateArgument preferences)
        {
            ViewModelGenerateArgument viewModelGenerateArgument = (ViewModelGenerateArgument)preferences;

            //Get template from the embedded resources
            string template = TemplateResources.Get("NMG.Core.Templates.ViewModelClassTemplate.tt", typeof(ViewModelClassTemplate));
            var arguments = new TemplateArgumentCollection
                {
                    //Argument             Name     &  Value
                    new TemplateArgument("ClassName", viewModelGenerateArgument.ClassName),
                    new TemplateArgument("NamespaceName",viewModelGenerateArgument.NamespaceName),
                    new TemplateArgument("FieldNames",viewModelGenerateArgument.FieldNames),
                    new TemplateArgument("MethodNames",viewModelGenerateArgument.MethodNames),
                    new TemplateArgument("DetailList",viewModelGenerateArgument.DetailList),
                    new TemplateArgument("ListNames",viewModelGenerateArgument.ListName)
                };
            //Allows us to show the generated class
            var transformer = new TextTransformer();
            transformer.ClassDefinitionGenerated += HostClassDefinitionGenerated;

            //start the tranformation in th current appdomain
            var output = transformer.Transform(template, arguments);
            transformer.ClassDefinitionGenerated -= HostClassDefinitionGenerated;

            return output;
        }
Esempio n. 3
0
        internal static void Transform()
        {
//Start transformation without argument
            string template1 = "This is a template displaying the current date & time: <#= System.DateTime.Now #>";
            string output    = Template.Transform(template1);

            string template2 = @"<#@ property name=""Name"" type=""System.String""" +
                               @"    processor=""PropertyProcessor"" #>" +
                               @"This is a template displaying one argument: <#= Name #>";
//Start transformation with a single argument
            string output2 = Template.Transform(template2, "Name", "Homer Simpson");

//Start transformation with multiple arguments
            var arguments = new TemplateArgumentCollection
            {
                //Argument             Name     &  Value
                new TemplateArgument("FirstName", "Homer"),
                new TemplateArgument("LastName", "Simpson"),
                new TemplateArgument("Color", Color.Yellow)
            };
            string template3 = @"<#@ property name=""FirstName"" type=""System.String""" +
                               @"    processor=""PropertyProcessor"" #>" +
                               @"<#@ property name=""LastName"" type=""System.String""" +
                               @"    processor=""PropertyProcessor"" #>" +
                               @"<#@ property name=""Color"" type=""System.Drawing.Color""" +
                               @"    processor=""PropertyProcessor"" #>" +
                               @"This is a template displaying multiple arguments: " +
                               @"<#= FirstName #> <#= LastName #> is <#= Color.Name #>";
            string output3 = Template.Transform(template3, arguments);
        }
        public override string Act(ITextTransformer transformer, string template)
        {
            var arguments = new TemplateArgumentCollection
            {
                new TemplateArgument("Argument1", "This is argument1 Value!"),
                new TemplateArgument {
                    Name = "Argument2", Value = "This is argument2 Value!"
                },
                new TemplateArgument("Argument3", "This is argument3 Value!")
            };

            return(transformer.Transform(template, arguments));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Controller"/> class.
        /// </summary>
        public Controller()
        {
            TemplateDomainAction = TemplateDomainActionCreate;
            Template             = DefaultTemplate;
            Arguments            = new TemplateArgumentCollection
            {
                new TemplateArgument("Argument", "Test")
            };

            transformer = new TextTransformer();
            transformer.ClassDefinitionGenerated += Host_ClassDefinitionGenerated;

            RefreshDomainProperties();
        }
        /// <summary />
        public void TestInitialize()
        {
            var transformer  = new Mock <ITextTransformer>();
            var fileLoader   = new Mock <IFileLoader>();
            var pathResolver = new Mock <IPathResolver>();

            _host = new Host(transformer.Object, pathResolver.Object, fileLoader.Object);
            _host.LogErrors(new CompilerErrorCollection()); ///Ensure there are errors

            var arguments = new TemplateArgumentCollection
            {
                new TemplateArgument(ArgumentName1, _argumentValue1),
                new TemplateArgument(ArgumentName2, _argumentValue2),
                new TemplateArgument(ArgumentName3, _argumentValue3)
            };

            _host.Initialize(arguments);
        }
        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);
        }
Esempio n. 8
0
        public void TestInitialize()
        {
            var transformer  = new Mock <ITextTransformer>();
            var fileLoader   = new Mock <IFileLoader>();
            var pathResolver = new Mock <IPathResolver>();

            _host = new Host(transformer.Object, pathResolver.Object, fileLoader.Object);

            var arguments = new TemplateArgumentCollection
            {
                new TemplateArgument(ArgumentName1, _argumentValue1),
                new TemplateArgument(ArgumentName2, _argumentValue2),
                new TemplateArgument(ArgumentName3, _argumentValue3)
            };

            CallContext.SetData(ArgumentName1, _argumentValue1);
            CallContext.SetData(ArgumentName2, _argumentValue2);
            CallContext.SetData(ArgumentName3, _argumentValue3);

            _host.Finish(arguments);
        }
        public static string Transform(IGenerateArgument preferences)
        {
            DaoGenerateArgument daoGenerateArgument = (DaoGenerateArgument)preferences;

            //Get template from the embedded resources
            string template = TemplateResources.Get("NMG.Core.Templates.HibernateDaoClassTemplate.tt", typeof(HibernateDaoInterfaceTemplate));
            var arguments = new TemplateArgumentCollection
                {
                    //Argument             Name     &  Value
                    new TemplateArgument("ClassName", daoGenerateArgument.ClassName),
                    new TemplateArgument("NamespaceName",daoGenerateArgument.NamespaceName),
                    new TemplateArgument("ModelNamespaceName",daoGenerateArgument.ModelNamespaceName)
                };
            //Allows us to show the generated class
            var transformer = new TextTransformer();
            transformer.ClassDefinitionGenerated += HostClassDefinitionGenerated;

            //start the tranformation in th current appdomain
            var output = transformer.Transform(template, arguments);
            transformer.ClassDefinitionGenerated -= HostClassDefinitionGenerated;

            return output;
        }
Esempio n. 10
0
        public static string Transform(IGenerateArgument preferences)
        {
            DataLayerXmlGenerateArgument businessGenerateArgument = (DataLayerXmlGenerateArgument)preferences;

            //Get template from the embedded resources
            string template = TemplateResources.Get("NMG.Core.Templates.DataLayerXmlTemplate.tt", typeof(DataLayerXmlTemplate));
            var arguments = new TemplateArgumentCollection
                {
                    //Argument             Name     &  Value
                    new TemplateArgument("AssemblyName", businessGenerateArgument.AssemblyName),
                    new TemplateArgument("DaoAssemblyName",businessGenerateArgument.DaoAssemblyName),
                    new TemplateArgument("DaoNamesList",businessGenerateArgument.DaoNamesList),
                };
            //Allows us to show the generated class
            var transformer = new TextTransformer();
            transformer.ClassDefinitionGenerated += HostClassDefinitionGenerated;

            //start the tranformation in th current appdomain
            var output = transformer.Transform(template, arguments);
            transformer.ClassDefinitionGenerated -= HostClassDefinitionGenerated;

            return output;
        }
Esempio n. 11
0
        /// <summary>
        /// Start the transformation.
        /// </summary>
        /// <param name="template">The template.</param>
        /// <param name="arguments">The arguments.</param>
        /// <returns></returns>
        /// <exception cref="TextTransformationException">when an error has occured during transformation.</exception>
        protected override string StartTransformation(
            string template,
            TemplateArgumentCollection arguments)
        {
            CheckAutoRecycle();

            if (arguments != null)
            {
                foreach (TemplateArgument pair in arguments)
                {
                    AddAssemblyReference(pair.Value);
                }
            }
            return base.StartTransformation(template, arguments);
        }
Esempio n. 12
0
 /// <summary>
 /// Initializes the host with the specified argument dictionary. 
 /// This will populate the CallContext with the desired arguments.
 /// </summary>
 /// <param name="arguments">The arguments.</param>
 public void Initialize(TemplateArgumentCollection arguments)
 {
     _compilationErrors = null;
     if (arguments != null)
     {
         foreach (var argument in arguments)
         {
             CallContext.LogicalSetData(argument.Name, argument.Value);
         }
     }
 }
Esempio n. 13
0
        /// <summary>
        /// Remove arguments from CallContet and checks whether errors have 
        /// occured during transformation a throw exception
        /// when necesssary.
        /// </summary>
        /// <exception cref="TextTransformationException">when an error has occured during transformation.</exception>
        public void Finish(TemplateArgumentCollection arguments)
        {
            if (arguments != null)
            {
                foreach (var argument in arguments)
                {
                    CallContext.FreeNamedDataSlot(argument.Name);
                }
            }

            if (_compilationErrors != null && _compilationErrors.HasErrors)
            {
                ThrowTransformationException();
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Start the transformation.
        /// </summary>
        /// <param name="templateSource">The template source.</param>
        /// <param name="arguments">The arguments.</param>
        /// <returns></returns>
        /// <exception cref="TextTransformationException">when an error has occured during transformation.</exception>
        protected virtual string StartTransformation(string templateSource, TemplateArgumentCollection arguments)
        {
            _host.Initialize(arguments);

            string result = _engine.ProcessTemplate(templateSource, _host);

            _host.Finish(arguments);
            return result;
        }
Esempio n. 15
0
        /// <summary>
        /// Transforms the specified template using a dictionary of named arguments.
        /// </summary>
        /// <param name="templateSource">The template.</param>
        /// <param name="arguments">A dictionary containing named arguments used to transform the text.</param>
        /// <exception cref="TextTransformationException">Text transformation has failed.</exception>
        /// <exception cref="ArgumentNullException">template is null or empty.</exception>
        /// <returns>The output of the text transformation.</returns>
        public string Transform(string templateSource, TemplateArgumentCollection arguments)
        {
            if (arguments == null)
            {
                throw new ArgumentNullException("arguments");
            }

            lock (_transformationLock)
            {
                return StartTransformation(templateSource, arguments);
            }
        }