Example #1
0
        /// <summary>
        /// Generates the contents of the given file extension.
        /// If null is returned, it means to preserve the existing file instead
        /// of generating a new one.
        /// </summary>
        /// <param name="fileExtension">One of the file extensions from the <see cref="GetEnumerator()"/> method.</param>
        /// <returns>The generated content for the given file extension, or null.</returns>
        private byte[] GenerateAllContent(string fileExtension)
        {
            System.Diagnostics.Debugger.Log(0, "", String.Format("Called 'GenerateAllContent'; fileExtension={0} ", fileExtension));

            // For debugging purposes, it is better to be able to edit the .tt files without having to
            // recompile the solution to test changes. During release, use the embedded .tt files
            // instead.
            if (IsTextTemplateGenerator(fileExtension))
            {
                return(GenerateFromTextTemplate(fileExtension));
            }
            else if (fileExtension == "diagram")
            {
                return(null);
            }
            else
            {
                if (fileExtension == CodeFileExtension)
                {
                    // Shouldnt get here?
                    Diagnostics.DebugWrite("FG.GenerateAllContent >> fileExtension == CodeFileExtension ('{0}'). Returning null... ", fileExtension);
                    return(null);
                }
                else if (fileExtension == string.Format("{0}-gen", CodeFileExtension))
                {
                    System.Diagnostics.Debugger.Log(0, "", String.Format("Generating class file! fileExtension is of ?-gen. Running CodeFileGenerator.GenerateCode with InputFilePath={0}", InputFilePath));
                    return(CodeFileGenerator.GenerateCode(InputFilePath));
                }
                else
                {
                    throw new ApplicationException("Unhandled file content");
                }
            }
        }
Example #2
0
        /// <summary>
        /// Generates the contents of the given file extension.
        /// If null is returned, it means to preserve the existing file instead
        /// of generating a new one.
        /// </summary>
        /// <param name="fileExtension">One of the file extensions from the <see cref="GetEnumerator()"/> method.</param>
        /// <returns>The generated content for the given file extension, or null.</returns>
        private byte[] GenerateAllContent(string fileExtension)
        {
            System.Diagnostics.Debugger.Log(0, "", String.Format("Called 'GenerateAllContent'; fileExtension={0} ", fileExtension));

            string inputFileContent;

            // For debugging purposes, it is better to be able to edit the .tt files without having to
            // recompile the solution to test changes. During release, use the embedded .tt files
            // instead.
            switch (fileExtension)
            {
            case "config":
                Diagnostics.DebugWrite("GenerateAllContent >> ConfigurationSectionDesignerSample template file={0}", Path.Combine(TextTemplateFolder, "ConfigurationSectionDesignerSample.tt"));

                inputFileContent = File.ReadAllText(Path.Combine(TextTemplateFolder, "ConfigurationSectionDesignerSample.tt"));
                break;

            case "xsd":
                inputFileContent = File.ReadAllText(Path.Combine(TextTemplateFolder, "ConfigurationSectionDesignerSchema.tt"));
                break;

            // Preserve the diagram and cs files, don't write anything to them
            case "diagram":
                return(null);

            // Generate the code behind file!
            default:
                if (fileExtension == CodeFileExtension)
                {
                    return(null);
                }
                else if (fileExtension == string.Format("{0}-gen", CodeFileExtension))
                {
                    System.Diagnostics.Debugger.Log(0, "", String.Format("fileExtension is of ?-gen. Running CodeFileGenerator.GenerateCode with InputFilePath={0}", InputFilePath));

                    return(CodeFileGenerator.GenerateCode(InputFilePath));
                }
                else
                {
                    throw new ApplicationException("Unhandled file content");
                }
            }

            // Replace our input file name placeholder with the real input file name
            // so the text transformer knows which .csd file to work on.
            System.Diagnostics.Debugger.Log(0, "", String.Format("Replacing $inputFileName$ with real value before running TemplateGenerator.GenerateCode(InputFilePath={0},inputFileContent={1}); ", InputFilePath, "TOO LONG!"));

            inputFileContent = inputFileContent.Replace("$inputFileName$", InputFilePath);
            return(TemplateGenerator.GenerateCode(InputFilePath, inputFileContent));
        }
        /// <summary>
        /// Generates the contents of the given file extension.
        /// If null is returned, it means to preserve the existing file instead
        /// of generating a new one.
        /// </summary>
        /// <param name="fileExtension">One of the file extensions from the <see cref="GetEnumerator()"/> method.</param>
        /// <returns>The generated content for the given file extension, or null.</returns>
        private byte[] GenerateAllContent(string fileExtension)
        {
            string inputFileContent;

            // For debugging purposes, it is better to be able to edit the .tt files without having to
            // recompile the solution to test changes. During release, use the embedded .tt files
            // instead.
            switch (fileExtension)
            {
            case "config":
                inputFileContent = File.ReadAllText(Path.Combine(TextTemplateFolder, "ConfigurationSectionDesignerSample.tt"));
                break;

            case "xsd":
                inputFileContent = File.ReadAllText(Path.Combine(TextTemplateFolder, "ConfigurationSectionDesignerSchema.tt"));
                break;

            // Preserve the diagram and cs files, don't write anything to them
            case "diagram":
                return(null);

            default:
                if (fileExtension == CodeFileExtension)
                {
                    return(null);
                }
                else if (fileExtension == string.Format("{0}-gen", CodeFileExtension))
                {
                    return(CodeFileGenerator.GenerateCode(InputFilePath));
                }
                else
                {
                    throw new ApplicationException("Unhandled file content");
                }
            }

            // Replace our input file name placeholder with the real input file name
            // so the text transformer knows which .csd file to work on.
            inputFileContent = inputFileContent.Replace("$inputFileName$", InputFilePath);
            return(TemplateGenerator.GenerateCode(InputFilePath, inputFileContent));
        }