Пример #1
0
 /// <summary>
 /// Generates source code for the virtual path of the build provider, and adds the source code to a specified assembly builder.
 /// </summary>
 /// <param name="assemblyBuilder">The assembly builder that references the source code generated by the build provider.</param>
 public override void GenerateCode(AssemblyBuilder assemblyBuilder)
 {
     using (DalGenerator gen = new DalGenerator(this.VirtualPath, true)) {
         assemblyBuilder.AddCodeCompileUnit(this, gen.Generate());
         //CodeHelper.BuildCodeTreeFromMapFile(this.VirtualPath, true));
     }
 }
Пример #2
0
        /// <summary>
        /// When overridden in a derived class, executes the task.
        /// </summary>
        /// <returns>
        /// true if the task successfully executed; otherwise, false.
        /// </returns>
        public override bool Execute()
        {
            if (_outDir == null)
            {
                _outDir = Path.GetDirectoryName(_fileName);
            }
            if (!_outDir.EndsWith("\\"))
            {
                _outDir += "\\";
            }
            Log.LogMessage("Generating DAL for " + Language + " file:" + FileName);
            string inputFileContent;

            ///
            /// Read the file contents
            ///
            if (File.Exists(this.FileName))
            {
                using (StreamReader reader = new StreamReader(FileName)) {
                    inputFileContent = reader.ReadToEnd();
                }
                ///
                /// Build a CodeDOM tree of the file to return
                ///
                CodeCompileUnit unit;// = CodeHelper.BuildCodeTreeFromMapFile(inputFileContent);
                using (DalGenerator dalGen = new DalGenerator(inputFileContent)) {
                    unit = dalGen.Generate();
                }
                // Code provider
                CodeDomProvider      provider = CodeDomProvider.CreateProvider(_language);
                CodeGeneratorOptions options  = new CodeGeneratorOptions();
                options.BlankLinesBetweenMembers = true;
                options.BracingStyle             = "Block";
                options.ElseOnClosing            = true;
                options.IndentString             = "    ";
                options.VerbatimOrder            = false;
                //return true;
                string          path;
                CodeCompileUnit code;
                CodeNamespace   ns;
                foreach (CodeTypeDeclaration type in unit.Namespaces[0].Types)
                {
                    path = string.Format("{0}{1}.{2}", _outDir, type.Name, provider.FileExtension);
                    code = new CodeCompileUnit();
                    ns   = new CodeNamespace(unit.Namespaces[0].Name);
                    foreach (CodeNamespaceImport import in unit.Namespaces[0].Imports)
                    {
                        ns.Imports.Add(import);
                    }
                    code.Namespaces.Add(ns);
                    ns.Types.Add(type);
                    using (StreamWriter writer = new StreamWriter(path)) {
                        provider.GenerateCodeFromCompileUnit(code, writer, options);
                    }
                }
            }
            // Success
            return(true);
        }