コード例 #1
0
        protected override void ExecuteTask()
        {
            Log(Level.Verbose, "Loading Sooda project from '{0}'", _projectFile.FullName);
            SoodaProject  project   = SoodaProject.LoadFrom(_projectFile.FullName);
            CodeGenerator generator = new CodeGenerator(project, this);

            if (Rebuild)
            {
                generator.RebuildIfChanged = false;
            }

            string oldDirectory = Environment.CurrentDirectory;

            try
            {
                // temporarily change to the directory which contains the project file
                Environment.CurrentDirectory = _projectFile.DirectoryName;
                generator.Run();
            }
            finally
            {
                Environment.CurrentDirectory = oldDirectory;
            }
        }
コード例 #2
0
        public static int Main(string[] args)
        {
            try
            {
                Sooda.CodeGen.SoodaProject  project   = new SoodaProject();
                Sooda.CodeGen.CodeGenerator generator = new CodeGenerator(project, new ConsoleCodeGeneratorOutput());

                string writeProjectTo = null;

                for (int i = 0; i < args.Length; ++i)
                {
                    switch (args[i])
                    {
                    case "/?":
                    case "-?":
                    case "--help":
                    case "-h":
                        return(Usage());

                    // generator options (this run only)

                    case "--rebuild-if-changed":
                        generator.RebuildIfChanged = true;
                        break;

                    case "--force-rebuild":
                        generator.RebuildIfChanged = false;
                        break;

                    case "-l":
                    case "--lang":
                        project.Language = args[++i];
                        break;

                    case "-p":
                    case "--project":
                        string projectType = args[++i];
                        ExternalProjectInfo projectInfo = new ExternalProjectInfo(projectType);
                        project.ExternalProjects.Add(projectInfo);
                        break;

                    case "--separate-stubs":
                        project.SeparateStubs = true;
                        break;

                    case "--merged-stubs":
                        project.SeparateStubs = false;
                        break;

                    case "--schema-embed-xml":
                        project.EmbedSchema = EmbedSchema.Xml;
                        break;

                    case "--schema-embed-bin":
                        project.EmbedSchema = EmbedSchema.Binary;
                        break;

                    case "--nullable-as":
                        project.NullableRepresentation = (PrimitiveRepresentation)Enum.Parse(typeof(PrimitiveRepresentation), args[++i], true);
                        break;

                    case "--not-null-as":
                        project.NotNullRepresentation = (PrimitiveRepresentation)Enum.Parse(typeof(PrimitiveRepresentation), args[++i], true);
                        break;

                    case "-s":
                    case "--schema":
                        project.SchemaFile = args[++i];
                        break;

                    case "-a":
                    case "--assembly-name":
                        project.AssemblyName = args[++i];
                        break;

                    case "-bc":
                    case "--base-class":
                        project.BaseClassName = args[++i];
                        break;

                    case "--null-propagation":
                        project.NullPropagation = true;
                        break;

                    case "--no-null-propagation":
                        project.NullPropagation = false;
                        break;

                    case "--no-typed-queries":
                        project.WithTypedQueryWrappers = false;
                        break;

                    case "--no-soql":
                        project.WithSoql = false;
                        break;

                    case "--rewrite-skeletons":
                        generator.RewriteSkeletons = true;
                        break;

                    case "--rewrite-projects":
                    case "--rewrite-project":
                        generator.RewriteProjects = true;
                        break;

                    case "-n":
                    case "-ns":
                    case "--namespace":
                        project.OutputNamespace = args[++i];
                        break;

                    case "-o":
                    case "-out":
                    case "--output":
                        project.OutputPath = args[++i];
                        break;

                    case "--write-project":
                        writeProjectTo = args[++i];
                        break;

                    default:
                        if (args[i].EndsWith(".soodaproject"))
                        {
                            string fullPath = Path.GetFullPath(args[i]);
                            Console.WriteLine("Loading project from file '{0}'...", fullPath);
                            Environment.CurrentDirectory = Path.GetDirectoryName(fullPath);
                            generator.Project            = SoodaProject.LoadFrom(fullPath);
                            //XmlSerializer ser = new XmlSerializer(typeof(SoodaProject));
                            //ser.Serialize(Console.Out, project);
                            //Console.WriteLine("OUT: {0}", project.OutputPath);
                        }
                        else
                        {
                            Console.WriteLine("Unknown option '{0}'", args[i]);
                            return(Usage());
                        }
                        break;
                    }
                }
                ;

                if (writeProjectTo != null)
                {
                    project.WriteTo(writeProjectTo);
                }

                generator.Run();

                return(0);
            }
            catch (SoodaCodeGenException ex)
            {
                Console.WriteLine("ERROR: " + ex.Message);
                if (ex.InnerException != null)
                {
                    Console.WriteLine(ex.InnerException);
                }
                return(1);
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: " + ex);
                return(1);
            }
        }