Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("umbraco Presenents - LINQ to umbraco Generator version " + Assembly.GetEntryAssembly().GetName().Version);
            Console.WriteLine("Copyright (C) umbraco 2009." + Environment.NewLine);

            ArgsParser parsedArgs;

            try
            {
                parsedArgs = new ArgsParser(args);
            }
            catch (ArgumentNullException ex)
            {
                Console.WriteLine(Strings.ArgumentMissing, ex.ParamName);
                Console.WriteLine();
                ShowHelp();
                return;
            }
            catch (FileNotFoundException ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine();
                ShowHelp();
                return;
            }
            catch (DirectoryNotFoundException ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine();
                ShowHelp();
                return;
            }

            switch (parsedArgs.Mode)
            {
            case RunMode.Xml:
                DTMLGenerator gen = new DTMLGenerator(parsedArgs.OutputFilePath, parsedArgs.ConnectionString, parsedArgs.DataContextName, parsedArgs.DisablePluralization);
                gen.GenerateDTMLFile();
                break;

            case RunMode.Class:
                CodeBuilder.ClassGenerator builder = CodeBuilder.ClassGenerator.CreateBuilder(parsedArgs.DtmlPath, parsedArgs.Namespace, parsedArgs.Language);
                builder.GenerateCode();
                builder.Save();
                break;

            case RunMode.Help:
                ShowHelp();
                break;

            default:
                break;
            }
        }
#pragma warning restore 0414

        /// <summary>
        /// Function that builds the contents of the generated file based on the contents of the input file
        /// </summary>
        /// <param name="inputFileContent">Content of the input file</param>
        /// <returns>Generated file as a byte array</returns>
        protected override byte[] GenerateCode(string inputFileContent)
        {
            var args = new ClassGeneratorArgs()
            {
                Namespace = this.FileNameSpace,
                Dtml = XDocument.Parse(inputFileContent),
                Provider = this.GetCodeProvider()
            };

            var builder = new ClassGenerator(args);

            //this.GetVSProject().References.Add("umbraco.Linq.Core");
            //this.GetVSProject().References.Add("System.Core");
            //this.GetVSProject().References.Add("umbraco");

            builder.GenerateCode();
            return builder.SaveForVs();
        }
#pragma warning restore 0414

        /// <summary>
        /// Function that builds the contents of the generated file based on the contents of the input file
        /// </summary>
        /// <param name="inputFileContent">Content of the input file</param>
        /// <returns>Generated file as a byte array</returns>
        protected override byte[] GenerateCode(string inputFileContent)
        {
            var args = new ClassGeneratorArgs()
            {
                Namespace = this.FileNameSpace,
                Dtml      = XDocument.Parse(inputFileContent),
                Provider  = this.GetCodeProvider()
            };

            var builder = new ClassGenerator(args);

            //this.GetVSProject().References.Add("umbraco.Linq.Core");
            //this.GetVSProject().References.Add("System.Core");
            //this.GetVSProject().References.Add("umbraco");

            builder.GenerateCode();
            return(builder.SaveForVs());
        }