コード例 #1
0
        /// <summary>
        /// Gets the droid MVVM cross view layout.
        /// </summary>
        /// <param name="textTemplateInfo">The text template information.</param>
        /// <param name="tokens">The tokens.</param>
        /// <param name="viewName">Name of the view.</param>
        internal void GetDroidMvvmCrossViewLayout(
            TextTemplateInfo textTemplateInfo,
            Dictionary <string, string> tokens,
            string viewName)
        {
            string viewTemplateName = textTemplateInfo.ShortTemplateName.Replace(".t4", ".axml.t4");

            TextTemplateInfo childTextTemplateInfo = new TextTemplateInfo
            {
                ProjectSuffix     = this.SettingsService.DroidProjectSuffix,
                ProjectFolder     = "Resources\\Layout",
                Tokens            = tokens,
                ShortTemplateName = viewTemplateName,
                TemplateName      = this.SettingsService.ItemTemplatesDirectory + "\\Droid\\" + viewTemplateName
            };

            TextTransformationRequest textTransformationRequest = new TextTransformationRequest
            {
                SourceFile        = childTextTemplateInfo.TemplateName,
                Parameters        = tokens,
                RemoveFileHeaders = this.SettingsService.RemoveDefaultFileHeaders,
                RemoveXmlComments = this.SettingsService.RemoveDefaultComments,
                RemoveThisPointer = this.SettingsService.RemoveThisPointer
            };

            TextTransformation textTransformation = this.GetTextTransformationService().Transform(textTransformationRequest);

            childTextTemplateInfo.TextOutput = textTransformation.Output;
            childTextTemplateInfo.FileName   = viewName + "." + textTransformation.FileExtension;

            textTemplateInfo.ChildItems.Add(childTextTemplateInfo);
        }
コード例 #2
0
 internal TransformContext(TextTransformation transformation, ITextTemplatingEngineHost host)
 {
     this.Transformation      = transformation;
     this.Host                = host;
     this.Dte                 = (DTE)((IServiceProvider)host).GetService(typeof(DTE));
     this.TemplageProjectItem = this.Dte.Solution.FindProjectItem(host.TemplateFile);
 }
コード例 #3
0
        /// <summary>
        /// Transforms the specified source file.
        /// </summary>
        /// <param name="textTransformationRequest">The text transformation request.</param>
        /// <returns>The Text Transformation.</returns>
        public TextTransformation Transform(TextTransformationRequest textTransformationRequest)
        {
            TraceService.WriteLine("TextTransformationService::Transform sourceFile=" + textTransformationRequest.SourceFile);

            string sourceText = this.GetText(textTransformationRequest.SourceFile);

            TraceService.WriteDebugLine("sourceText=" + sourceText);

            SimpleTextTemplatingEngine engine = new SimpleTextTemplatingEngine();

            TraceService.WriteLine("Before processing template via SimpleTextTemplatingEngine");

            TextTransformation textTransformation = engine.ProcessTemplate(
                sourceText,
                textTransformationRequest.Parameters,
                textTransformationRequest.RemoveFileHeaders,
                textTransformationRequest.RemoveXmlComments,
                textTransformationRequest.RemoveThisPointer);

            TraceService.WriteLine("After processing template via SimpleTextTemplatingEngine = SUCCESS!");

            TraceService.WriteDebugLine("output=" + textTransformation.Output);

            return(textTransformation);
        }
 public static void WriteNewLine(this TextTransformation textTransformation, int count = 1)
 {
     for (var i = 0; i < count; i++)
     {
         textTransformation.WriteLine(string.Empty);
     }
 }
コード例 #5
0
 public static void RunCodeGenerator(this TextTransformation transformation, ITextTemplatingEngineHost host, Generator generator)
 {
     using (TransformContextScope contextScope = new TransformContextScope(transformation, host))
     {
         generator.Run();
     }
 }
コード例 #6
0
        public void Render(ApiGraph api, TextTransformation output)
        {
            api.AssertNotNull("api");
            output.AssertNotNull("output");

            new AngularTestCodeRenderingSession(api, output).Run();
        }
 public static void Block(this TextTransformation textTransformation, Action action)
 {
     WriteNewLine(textTransformation);
     textTransformation.WriteLine("{");
     Tab(textTransformation, action);
     WriteNewLine(textTransformation);
     textTransformation.Write("}");
 }
コード例 #8
0
        /// <summary>Unindents subsequent generated code.</summary>
        /// <param name="source">The source.</param>
        /// <param name="count">The number of times to unindent.</param>
        public static TextTransformation Unindent(this TextTransformation source, int count = 1)
        {
            for (int index = 0; index < count; ++index)
            {
                source.PopIndent();
            }

            return(source);
        }
コード例 #9
0
 public TextTemplatingEngineHost(
     IDictionary <string, string> knownMacros,
     string templateFile,
     TextTransformation transformation
     )
 {
     Helper         = new MacroResolveHelper(knownMacros);
     Transformation = transformation;
     TemplateFile   = templateFile;
 }
コード例 #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VSTemplate"/> class.
        /// </summary>
        /// <param name="parent">The parent text transformation.</param>
        protected VSTemplate(TextTransformation parent)
        {
            if (parent == null)
            {
                throw new ArgumentNullException(nameof(parent));
            }

            _host = new Lazy <ITextTemplatingEngineHost>(() => HostFactory(parent));
            _dte  = new Lazy <DTE>(DTEFactory);
        }
コード例 #11
0
        public static void OnTransformationEnded(TextTransformation transformation)
        {
            try
            {
                if (transformation == null)
                {
                    throw new ArgumentNullException("transformation");
                }

                if (TransformationContext.transformation != null && !TransformationContext.Errors.HasErrors)
                {
                    //Update the files in the default AppDomain to avoid remoting errors on Database projects
                    //BindingFlags invokeInternalStaticMethod = BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.NonPublic;
                    //AppDomain defaultDomain = (AppDomain)typeof(AppDomain).InvokeMember("GetDefaultDomain", invokeInternalStaticMethod, null, null, null, CultureInfo.InvariantCulture);

                    //var bd1 = defaultDomain.BaseDirectory;

                    //var setup = new AppDomainSetup();
                    //setup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
                    //AppDomain serverAppDomain = AppDomain.CreateDomain("ServerAppDomain", null, setup);

                    //var udf = TransformationContext.outputManager;
                    //defaultDomain.DoCallBack(udf.UpdateFiles);

                    OutputProcessor.Host = Host;
                    outputManager.UpdateFiles();
                }

                TransformationContext.transformation = null;
                TransformationContext.outputManager  = null;
                TransformationContext.project        = null;
                TransformationContext.projectItem    = null;
                TransformationContext.dte            = null;

                if (TransformationContext.TransformationEnded != null)
                {
                    TransformationContext.TransformationEnded(null, EventArgs.Empty);
                }
            }
            catch (TransformationException e)
            {
                // Display expected errors in the Error List window without the call stack
                CompilerErrorCollection errors = new CompilerErrorCollection();
                CompilerError           error  = new CompilerError();
                error.ErrorText = e.Message;
                error.FileName  = Host.TemplateFile;
                errors.Add(error);
                TransformationContext.Host.LogErrors(errors);
            }
            finally
            {
                DestroyTraceListener();
            }
        }
コード例 #12
0
        /// <summary>
        /// This method is a part of T4 Toolbox infrastructure. Don't call it in your code.
        /// </summary>
        /// <param name="transformation">
        /// Instance of the <see cref="TextTransformation"/> class generated by T4 engine.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Method throws <see cref="ArgumentNullException"/> when the specified
        /// <paramref name="transformation"/> is null.
        /// </exception>
        /// <remarks>
        /// During template transformation, this method is called by code in T4Toolbox.tt.
        /// </remarks>
        public static void OnTransformationStarted(TextTransformation transformation)
        {
            if (transformation == null)
            {
                throw new ArgumentNullException("transformation");
            }

            TransformationContext.transformation = transformation;
            TransformationContext.outputManager  = new OutputManager();

            CreateTraceListener();
        }
コード例 #13
0
        /// <summary>
        /// Gets the MVVM cross view.
        /// </summary>
        /// <param name="itemTemplateInfo">The item template information.</param>
        /// <param name="tokens">The tokens.</param>
        /// <param name="viewTemplateName">Name of the view template.</param>
        /// <param name="viewName">Name of the view.</param>
        /// <returns></returns>
        public TextTemplateInfo GetMvvmCrossView(
            ItemTemplateInfo itemTemplateInfo,
            Dictionary <string, string> tokens,
            string viewTemplateName,
            string viewName)
        {
            TraceService.WriteLine("MvvmCrossViewFactory::GetMvvmCrossView viewTemplateName=" + viewTemplateName);

            if (itemTemplateInfo.ProjectSuffix == this.SettingsService.iOSProjectSuffix)
            {
                return(this.GetiOSMvvmCrossView(
                           itemTemplateInfo,
                           tokens,
                           viewTemplateName,
                           viewName));
            }

            TextTemplateInfo textTemplateInfo = new TextTemplateInfo
            {
                ProjectSuffix     = itemTemplateInfo.ProjectSuffix,
                ProjectFolder     = "Views",
                Tokens            = tokens,
                ShortTemplateName = viewTemplateName,
                TemplateName      = this.SettingsService.ItemTemplatesDirectory + "\\" + itemTemplateInfo.ProjectType + "\\" + viewTemplateName
            };

            TextTransformationRequest textTransformationRequest = new TextTransformationRequest
            {
                SourceFile        = textTemplateInfo.TemplateName,
                Parameters        = textTemplateInfo.Tokens,
                RemoveFileHeaders = this.SettingsService.RemoveDefaultFileHeaders,
                RemoveXmlComments = this.SettingsService.RemoveDefaultComments,
                RemoveThisPointer = this.SettingsService.RemoveThisPointer
            };

            TextTransformation textTransformation = this.GetTextTransformationService().Transform(textTransformationRequest);

            textTemplateInfo.TextOutput = textTransformation.Output;
            textTemplateInfo.FileName   = viewName + "." + textTransformation.FileExtension;

            if (itemTemplateInfo.ProjectSuffix == this.SettingsService.DroidProjectSuffix)
            {
                textTemplateInfo.FileOperations.Add(
                    this.GetCompileFileOperation(textTemplateInfo.ProjectSuffix, textTemplateInfo.FileName));
            }
            else
            {
                textTemplateInfo.FileOperations.Add(
                    this.GetPageFileOperation(textTemplateInfo.ProjectSuffix, textTemplateInfo.FileName));
            }

            return(textTemplateInfo);
        }
コード例 #14
0
        /// <summary>
        /// Gets the text output.
        /// </summary>
        /// <param name="sourceText">The source text.</param>
        /// <param name="parameters">The parameters.</param>
        /// <param name="removeFileHeaders">if set to <c>true</c> [remove file headers].</param>
        /// <param name="removeXmlComments">if set to <c>true</c> [remove XML comments].</param>
        /// <param name="removeThisPointer">if set to <c>true</c> [remove this pointer].</param>
        /// <returns></returns>
        public string GetTextOutput(
            string sourceText,
            IDictionary <string, string> parameters,
            bool removeFileHeaders,
            bool removeXmlComments,
            bool removeThisPointer)
        {
            SimpleTextTemplatingEngine engine = new SimpleTextTemplatingEngine();

            TextTransformation textTransformation = engine.ProcessTemplate(sourceText, parameters, removeFileHeaders, removeXmlComments, removeThisPointer);

            return(textTransformation.Output);
        }
コード例 #15
0
        public DomainGeneratorSession(TextTransformation caller, ITextTemplatingEngineHost host)
            : this()
        {
            #region Check arguments
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }
            #endregion

            this.TemplateFile = host.TemplateFile;
            IServiceProvider hostServiceProvider = (IServiceProvider)host;
            this.Dte = (EnvDTE.DTE)hostServiceProvider.GetService(typeof(EnvDTE.DTE));
        }
コード例 #16
0
        public void ComputeHashHex_WithNullInput_ReturnsValidHashes()
        {
            var actualMd5HashHex    = TextTransformation.ComputeHashHex <MD5CryptoServiceProvider>(null, Encoding.UTF8);
            var actualSha1HashHex   = TextTransformation.ComputeHashHex <SHA1Managed>(null, Encoding.UTF8);
            var actualSha256HashHex = TextTransformation.ComputeHashHex <SHA256Managed>(null, Encoding.UTF8);
            var actualSha384HashHex = TextTransformation.ComputeHashHex <SHA384Managed>(null, Encoding.UTF8);
            var actualSha512HashHex = TextTransformation.ComputeHashHex <SHA512Managed>(null, Encoding.UTF8);

            Assert.Equal("d41d8cd98f00b204e9800998ecf8427e", actualMd5HashHex);
            Assert.Equal("da39a3ee5e6b4b0d3255bfef95601890afd80709", actualSha1HashHex);
            Assert.Equal("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", actualSha256HashHex);
            Assert.Equal("38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b", actualSha384HashHex);
            Assert.Equal("cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e", actualSha512HashHex);
        }
コード例 #17
0
        private static ITextTemplatingEngineHost HostFactory(TextTransformation transformation)
        {
            Type         transformationType = transformation.GetType();
            PropertyInfo hostProperty       = transformationType.GetProperty("Host");

            if (hostProperty == null)
            {
                throw new NotSupportedException(
                          "Unable to access the templating engine host. "
                          + "Please make sure your template includes hostspecific=\"true\" "
                          + "attribute in the <#@ template #> directive.");
            }

            return((ITextTemplatingEngineHost)hostProperty.GetValue(transformation, null));
        }
        public static void PrintOnNewRowForEach <TValue>(this TextTransformation textTransformation, IEnumerable <TValue> iterator, ActionDelegateWithIndexAndLength <TValue> action)
        {
            var list  = iterator.ToList();
            var count = list.Count;

            foreach (var pair in list.WithIndex())
            {
                if (pair.Key > 0)
                {
                    WriteNewLine(textTransformation);
                }

                action(pair.Value, pair.Key, count);
            }
        }
コード例 #19
0
        /// <summary>Makes a unique identifier.</summary>
        /// <param name="source">The source.</param>
        /// <param name="prefix">The optional prefix.</param>
        /// <param name="suffix">The optional suffix.</param>
        /// <returns>The unique identifier.</returns>
        public static string MakeUniqueIdentifier(this TextTransformation source, string prefix = null, string suffix = null)
        {
            if (source.Session == null)
            {
                source.Session = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);
            }

            object value;
            var    current = source.Session.TryGetValue("UniqueIdentifierCounter", out value) ? (int)value : 1;

            var str = String.Format("_{0}temp{1}{2}", prefix ?? "", suffix ?? "", current++);

            source.Session["UniqueIdentifierCounter"] = current;

            return(str);
        }
コード例 #20
0
        internal TransformationContext(TextTransformation transformation, StringBuilder generationEnvironment)
        {
            if (transformation == null)
            {
                throw new ArgumentNullException("transformation");
            }

            if (generationEnvironment == null)
            {
                throw new ArgumentNullException("generationEnvironment");
            }

            PropertyInfo hostProperty = transformation.GetType().GetProperty("Host");

            if (hostProperty == null)
            {
                throw new ArgumentException("TextTransformation does not have Host property");
            }

            this.Host = (ITextTemplatingEngineHost)hostProperty.GetValue(transformation);
            if (this.Host == null)
            {
                throw new ArgumentException("TextTransformation.Host is null.");
            }

            this.Transformation = transformation;

            // Create a special output file for the transformation output.
            this.outputFiles.Add(new OutputFile(generationEnvironment));

            this.provider = (ITransformationContextProvider)this.GetService(typeof(ITransformationContextProvider));
            if (this.provider == null)
            {
                throw new InvalidOperationException("ITransformationContextProvider service is not available.");
            }

            this.InitializeParameters();
        }
コード例 #21
0
        /// <summary>
        ///     Gets the code behind text template information.
        /// </summary>
        /// <param name="projectSuffix">The project suffix.</param>
        /// <param name="viewName">Name of the view.</param>
        /// <param name="viewTemplateName">Name of the view template.</param>
        /// <param name="tokens">The tokens.</param>
        /// <returns>A TextTemplateInfo.</returns>
        protected TextTemplateInfo GetCodeBehindTextTemplateInfo(
            string projectSuffix,
            string viewName,
            string viewTemplateName,
            Dictionary <string, string> tokens)
        {
            var templateDirectory = this.SettingsService.ItemTemplatesDirectory;

            if (projectSuffix == this.SettingsService.XamarinFormsProjectSuffix)
            {
                templateDirectory += "\\XamarinForms";
            }

            TextTemplateInfo textTemplateInfo = new TextTemplateInfo
            {
                ProjectSuffix     = projectSuffix,
                ProjectFolder     = "Views",
                Tokens            = tokens,
                ShortTemplateName = viewTemplateName,
                TemplateName      = templateDirectory + "\\" + "BlankViewCodeBehind.t4"
            };

            TextTransformationRequest textTransformationRequest = new TextTransformationRequest
            {
                SourceFile        = textTemplateInfo.TemplateName,
                Parameters        = textTemplateInfo.Tokens,
                RemoveFileHeaders = this.SettingsService.RemoveDefaultFileHeaders,
                RemoveXmlComments = this.SettingsService.RemoveDefaultComments,
                RemoveThisPointer = this.SettingsService.RemoveThisPointer
            };

            TextTransformation textTransformation = this.GetTextTransformationService().Transform(textTransformationRequest);

            textTemplateInfo.TextOutput = textTransformation.Output;
            textTemplateInfo.FileName   = viewName + "." + textTransformation.FileExtension;

            return(textTemplateInfo);
        }
コード例 #22
0
        void Load(CompilerResults results, string fullName)
        {
            var  assembly      = results.CompiledAssembly;
            Type transformType = assembly.GetType(fullName);

            tt = (TextTransformation)Activator.CreateInstance(transformType);

            //set the host property if it exists
            var hostProp = transformType.GetProperty("Host", typeof(ITextTemplatingEngineHost));

            if (hostProp != null && hostProp.CanWrite)
            {
                hostProp.SetValue(tt, host, null);
            }

            var sessionHost = host as ITextTemplatingSessionHost;

            if (sessionHost != null)
            {
                //FIXME: should we create a session if it's null?
                tt.Session = sessionHost.Session;
            }
        }
コード例 #23
0
 public TransformContextScope(TextTransformation transformation, ITextTemplatingEngineHost host)
 {
     TransformContext.Current = new TransformContext(transformation, host);
 }
コード例 #24
0
        /// <summary>
        /// Getis the os MVVM cross view.
        /// </summary>
        /// <param name="itemTemplateInfo">The item template information.</param>
        /// <param name="tokens">The tokens.</param>
        /// <param name="viewTemplateName">Name of the view template.</param>
        /// <param name="viewName">Name of the view.</param>
        /// <returns>A TextTemplateInfo.</returns>
        internal TextTemplateInfo GetiOSMvvmCrossView(
            ItemTemplateInfo itemTemplateInfo,
            Dictionary <string, string> tokens,
            string viewTemplateName,
            string viewName)
        {
            TraceService.WriteLine("MvvmCrossViewFactory::GetiOSMvvmCrossView viewTemplateName=" + viewTemplateName);

            string folder = viewTemplateName.Replace("View.t4", string.Empty);

            TraceService.WriteLine("folder=" + folder);

            string subFolder = this.SettingsService.SelectedMvvmCrossiOSViewType;

            TraceService.WriteLine("subFolder=" + subFolder);

            folder = folder.Replace(subFolder, string.Empty);

            TraceService.WriteLine("folder=" + folder);

            string templateFolder  = this.SettingsService.ItemTemplatesDirectory + "\\iOS\\" + folder + "\\" + subFolder + "\\";
            string shortFolderName = folder + "\\" + subFolder + "\\";

            TraceService.WriteLine("templateFolder=" + templateFolder);

            TextTemplateInfo textTemplateInfo = new TextTemplateInfo
            {
                ProjectSuffix     = this.SettingsService.iOSProjectSuffix,
                ProjectFolder     = "Views",
                Tokens            = tokens,
                ShortTemplateName = shortFolderName + "View.t4",
                TemplateName      = templateFolder + "View.t4"
            };

            TextTransformationRequest textTransformationRequest = new TextTransformationRequest
            {
                SourceFile        = textTemplateInfo.TemplateName,
                Parameters        = tokens,
                RemoveFileHeaders = this.SettingsService.RemoveDefaultFileHeaders,
                RemoveXmlComments = this.SettingsService.RemoveDefaultComments,
                RemoveThisPointer = this.SettingsService.RemoveThisPointer
            };

            TextTransformation textTransformation = this.GetTextTransformationService().Transform(textTransformationRequest);

            textTemplateInfo.TextOutput = textTransformation.Output;
            textTemplateInfo.FileName   = viewName + "." + textTransformation.FileExtension;

            textTemplateInfo.FileOperations.Add(this.GetCompileFileOperation(
                                                    textTemplateInfo.ProjectSuffix,
                                                    textTemplateInfo.FileName));

            //// now handle xib and story board options!

            TraceService.WriteLine("SelectedMvvmCrossiOSViewType=" + this.SettingsService.SelectedMvvmCrossiOSViewType);

            if (this.SettingsService.SelectedMvvmCrossiOSViewType == MvvmCrossViewType.StoryBoard.GetDescription() ||
                this.SettingsService.SelectedMvvmCrossiOSViewType == MvvmCrossViewType.Xib.GetDescription())
            {
                viewTemplateName = this.SettingsService.SelectedMvvmCrossiOSViewType == MvvmCrossViewType.Xib.GetDescription() ? "ViewXib.t4" : "ViewStoryBoard.t4";

                TraceService.WriteLine("Adding ChildTextTemplate ViewTemplateName=" + viewTemplateName);

                TextTemplateInfo childTextTemplateInfo = new TextTemplateInfo
                {
                    ProjectSuffix     = itemTemplateInfo.ProjectSuffix,
                    ProjectFolder     = "Views",
                    Tokens            = tokens,
                    ShortTemplateName = shortFolderName + viewTemplateName,
                    TemplateName      = templateFolder + viewTemplateName
                };

                TextTransformationRequest childTextTransformationRequest = new TextTransformationRequest
                {
                    SourceFile        = childTextTemplateInfo.TemplateName,
                    Parameters        = tokens,
                    RemoveFileHeaders = this.SettingsService.RemoveDefaultFileHeaders,
                    RemoveXmlComments = this.SettingsService.RemoveDefaultComments,
                    RemoveThisPointer = this.SettingsService.RemoveThisPointer
                };

                textTransformation = this.GetTextTransformationService().Transform(childTextTransformationRequest);

                childTextTemplateInfo.TextOutput = textTransformation.Output;
                childTextTemplateInfo.FileName   = viewName + "." + textTransformation.FileExtension;

                textTemplateInfo.ChildItems.Add(childTextTemplateInfo);

                //// add in designer file

                viewTemplateName = "ViewDesigner.t4";

                TraceService.WriteLine("Adding ChildTextTemplate ViewTemplateName=" + viewTemplateName);

                childTextTemplateInfo = new TextTemplateInfo
                {
                    ProjectSuffix     = itemTemplateInfo.ProjectSuffix,
                    ProjectFolder     = "Views",
                    Tokens            = tokens,
                    ShortTemplateName = shortFolderName + viewTemplateName,
                    TemplateName      = templateFolder + viewTemplateName
                };

                childTextTransformationRequest = new TextTransformationRequest
                {
                    SourceFile        = childTextTemplateInfo.TemplateName,
                    Parameters        = tokens,
                    RemoveFileHeaders = this.SettingsService.RemoveDefaultFileHeaders,
                    RemoveXmlComments = this.SettingsService.RemoveDefaultComments,
                    RemoveThisPointer = this.SettingsService.RemoveThisPointer
                };

                textTransformation = this.GetTextTransformationService().Transform(childTextTransformationRequest);

                childTextTemplateInfo.TextOutput = textTransformation.Output;
                childTextTemplateInfo.FileName   = viewName + ".designer." + textTransformation.FileExtension;

                textTemplateInfo.ChildItems.Add(childTextTemplateInfo);
            }

            return(textTemplateInfo);
        }
コード例 #25
0
 public static MySqlORMGenerator GenerateModelsFromMySql(this TextTransformation transformation, ITextTemplatingEngineHost host, string nameSpaces, string SchemaConnectionString)
 {
     return(new MySqlORMGenerator(host, nameSpaces, SchemaConnectionString));
 }
コード例 #26
0
        /// <summary>
        /// Processes the template.
        /// </summary>
        /// <param name="sourceText">The source text.</param>
        /// <param name="parameters">The parameters.</param>
        /// <param name="removeFileHeaders">if set to <c>true</c> [remove file headers].</param>
        /// <param name="removeXmlComments">if set to <c>true</c> [remove XML comments].</param>
        /// <param name="removeThisPointer">if set to <c>true</c> [remove this pointer].</param>
        /// <returns></returns>
        public TextTransformation ProcessTemplate(
            string sourceText,
            IDictionary<string, string> parameters,
            bool removeFileHeaders,
            bool removeXmlComments,
            bool removeThisPointer)
        {
            TraceService.WriteLine("SimpleTextTemplatingEngine::ProcessTemplate");

            TextTransformation textTransformation = new TextTransformation();

            //// first remove the this pointer if required

            if (removeThisPointer)
            {
                sourceText = sourceText.Replace("this.", string.Empty);
            }

            //// now remove all the parameter definitions!

            string[] lines = sourceText.Split('\n');

            //// by default make it a standard csharp source file!

            textTransformation.FileExtension = "cs";

            string extensionLine = lines.FirstOrDefault(x => x.StartsWith("<#@ Output Extension="));

            if (string.IsNullOrEmpty(extensionLine) == false)
            {
                ///// <#@ Output Extension="cs" #>

                string[] parts = extensionLine.Split('"');

                if (parts.Length > 1)
                {
                    textTransformation.FileExtension = parts[1];
                }
            }

            IEnumerable<string> newLines = lines.Where(x => x.StartsWith("<#@ ") == false);

            if (removeFileHeaders)
            {
                newLines = newLines.Where(x => x.TrimStart().StartsWith("//") == false);
            }

            if (removeXmlComments)
            {
                newLines = newLines.Where(x => x.TrimStart().StartsWith("///") == false);
            }

            string output = string.Empty;

            foreach (string newLine in newLines)
            {
                output += newLine + "\n";
            }

            if (parameters != null)
            {
                foreach (KeyValuePair<string, string> parameter in parameters)
                {
                    string t4Parameter = $"<#= {parameter.Key} #>";

                    output = output.Replace(t4Parameter, parameter.Value);
                }
            }

            //// sort out single LF and replace with CR LF!
            textTransformation.Output = Regex.Replace(output, @"\r\n|\r|\n", "\r\n");

            return textTransformation;
        }
コード例 #27
0
        /// <summary>
        /// Creates new or appends to existing output file.
        /// </summary>
        /// <param name="output">
        /// An <see cref="OutputInfo"/> object that describes content generated by a template.
        /// </param>
        /// <param name="content">
        /// A <see cref="String"/> that contains content generated by a template.
        /// </param>
        /// <param name="host">
        /// An <see cref="ITextTemplatingEngineHost"/> object hosting the <paramref name="transformation"/>.
        /// </param>
        /// <param name="transformation">
        /// <see cref="TextTransformation"/> object generated by T4 based on top-level .tt file.
        /// </param>
        /// <remarks>
        /// Multiple outputs can be combined in a single output file during code
        /// generation. This allows user to customize a composite code generator
        /// to generate output with required granularity without having to modify
        /// the generator itself.
        /// </remarks>
        public void Append(OutputInfo output, string content, ITextTemplatingEngineHost host, TextTransformation transformation)
        {
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }

            if (host == null)
            {
                throw new ArgumentNullException("host");
            }

            string previousDirectory = Environment.CurrentDirectory;

            Environment.CurrentDirectory = Path.GetDirectoryName(host.TemplateFile);

            try
            {
                Validate(output);

                if (string.IsNullOrEmpty(output.File))
                {
                    this.AppendToStandardOutput(output, content, host, transformation);
                }
                else
                {
                    this.AppendToOutputFile(output, content, host);
                }
            }
            finally
            {
                Environment.CurrentDirectory = previousDirectory;
            }
        }
コード例 #28
0
        /// <summary>
        /// Processes the template.
        /// </summary>
        /// <param name="sourceText">The source text.</param>
        /// <param name="parameters">The parameters.</param>
        /// <param name="removeFileHeaders">if set to <c>true</c> [remove file headers].</param>
        /// <param name="removeXmlComments">if set to <c>true</c> [remove XML comments].</param>
        /// <param name="removeThisPointer">if set to <c>true</c> [remove this pointer].</param>
        /// <returns></returns>
        public TextTransformation ProcessTemplate(
            string sourceText,
            IDictionary <string, string> parameters,
            bool removeFileHeaders,
            bool removeXmlComments,
            bool removeThisPointer)
        {
            TraceService.WriteLine("SimpleTextTemplatingEngine::ProcessTemplate");

            TextTransformation textTransformation = new TextTransformation();

            //// first remove the this pointer if required

            if (removeThisPointer)
            {
                sourceText = sourceText.Replace("this.", string.Empty);
            }

            //// now remove all the parameter definitions!

            string[] lines = sourceText.Split('\n');

            //// by default make it a standard csharp source file!

            textTransformation.FileExtension = "cs";

            string extensionLine = lines.FirstOrDefault(x => x.StartsWith("<#@ Output Extension="));

            if (string.IsNullOrEmpty(extensionLine) == false)
            {
                ///// <#@ Output Extension="cs" #>

                string[] parts = extensionLine.Split('"');

                if (parts.Length > 1)
                {
                    textTransformation.FileExtension = parts[1];
                }
            }

            IEnumerable <string> newLines = lines.Where(x => x.StartsWith("<#@ ") == false);

            if (removeFileHeaders)
            {
                newLines = newLines.Where(x => x.TrimStart().StartsWith("//") == false);
            }

            if (removeXmlComments)
            {
                newLines = newLines.Where(x => x.TrimStart().StartsWith("///") == false);
            }

            string output = string.Empty;

            foreach (string newLine in newLines)
            {
                output += newLine + "\n";
            }

            if (parameters != null)
            {
                foreach (KeyValuePair <string, string> parameter in parameters)
                {
                    string t4Parameter = $"<#= {parameter.Key} #>";

                    output = output.Replace(t4Parameter, parameter.Value);
                }
            }

            //// sort out single LF and replace with CR LF!
            textTransformation.Output = Regex.Replace(output, @"\r\n|\r|\n", "\r\n");

            return(textTransformation);
        }
コード例 #29
0
        public static MySqlORMGenerator GenerateModelsFromRemoteMySql(this TextTransformation transformation, ITextTemplatingEngineHost host, string nameSpaces, string ConfigServer, string db, string AppName, string Password, string servername = null, string Version = "1.0")
        {
            var ConfigUrl = $"{ConfigServer}/api/{Version}/appconfig/DbScheme?appname={AppName}&configpwd={Password}&db={db}&servername={servername}";

            return(new MySqlORMGenerator(host, nameSpaces, new Uri(ConfigUrl)));
        }
コード例 #30
0
 public static ComponentBuilder <TConfig, TTag> SetTransformation <TConfig, TTag>(this ComponentBuilder <TConfig, TTag> builder, TextTransformation transformation)
     where TConfig : BootstrapConfig
     where TTag : Tag
 {
     builder.Component.ToggleCss(transformation);
     return(builder);
 }
コード例 #31
0
ファイル: OrmExtensions.cs プロジェクト: au-x/Cissy.Core
 public static ORMGenerator GenerateOrm(this TextTransformation transformation, ITextTemplatingEngineHost host, string SectionName, string ConnectionName, string SchemaConnectionString)
 {
     return(new ORMGenerator(host, SectionName, ConnectionName, SchemaConnectionString));
 }