public CodeDomClassStubGenerator(ClassInfo ci, SoodaProject options)
        {
            this.classInfo = ci;
            this.options = options;
            string keyGen = "none";

            if (!ci.ReadOnly && ci.GetPrimaryKeyFields().Length == 1)
            {
                switch (ci.GetFirstPrimaryKeyField().DataType)
                {
                    case FieldDataType.Integer:
                        keyGen = "integer";
                        break;

                    case FieldDataType.Guid:
                        keyGen = "guid";
                        break;

                    case FieldDataType.Long:
                        keyGen = "long";
                        break;
                }
            }

            if (ci.KeyGenName != null)
                keyGen = ci.KeyGenName;

            this.KeyGen = keyGen;
        }
        public CodeDomClassStubGenerator(ClassInfo ci, SoodaProject options)
        {
            this.classInfo = ci;
            this.options   = options;
            string keyGen = "none";

            if (!ci.ReadOnly && ci.GetPrimaryKeyFields().Length == 1)
            {
                switch (ci.GetFirstPrimaryKeyField().DataType)
                {
                case FieldDataType.Integer:
                    keyGen = "integer";
                    break;

                case FieldDataType.Guid:
                    keyGen = "guid";
                    break;

                case FieldDataType.Long:
                    keyGen = "long";
                    break;
                }
            }

            if (ci.KeyGenName != null)
            {
                keyGen = ci.KeyGenName;
            }

            this.KeyGen = keyGen;
        }
Beispiel #3
0
        public static SoodaProject LoadFrom(XmlTextReader reader)
        {
#if SOODA_NO_VALIDATING_READER
            XmlSerializer ser     = new XmlSerializer(typeof(SoodaProject));
            SoodaProject  project = (SoodaProject)ser.Deserialize(reader);
#else
            XmlReaderSettings readerSettings = new XmlReaderSettings();
            readerSettings.ValidationType = ValidationType.Schema;
            readerSettings.Schemas.Add(NamespaceURI, GetSoodaProjectXsdStreamXmlReader());
            XmlReader validatingReader = XmlReader.Create(reader, readerSettings);

            XmlSerializer ser     = new XmlSerializer(typeof(SoodaProject));
            SoodaProject  project = (SoodaProject)ser.Deserialize(validatingReader);
#endif
            return(project);
        }
Beispiel #4
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;
            }
        }
 public CodeGenerator(SoodaProject Project, ICodeGeneratorOutput Output)
 {
     this.Project = Project;
     this.Output = Output;
 }