コード例 #1
0
        protected static void ProcessMetadata(AppOptionInfo opts, EntityMap ent, Property prop)
        {
            var key = string.Concat(ent.Name, ".", prop.Name);

            if (opts.MetadataDictionary.TryGetValue(key, out var metadata))
            {
                foreach (var tuple in metadata)
                {
                    prop.MetaDataAttributes.Add(tuple.Item1.Replace("data_", string.Empty), tuple.Item2);
                }
            }

            if (prop.PropertyName.Equals("CreatedOn") || prop.PropertyName.Equals("CreatedBy"))
            {
                prop.MetaDataAttributes.Add("editable", "false");
            }

            key = string.Concat("*.", prop.Name);
            if (opts.MetadataDictionary.TryGetValue(key, out metadata))
            {
                foreach (var tuple in metadata)
                {
                    var metaDataAttributeName = tuple.Item1.Replace("data_", string.Empty);
                    if (prop.MetaDataAttributes.ContainsKey(metaDataAttributeName))
                    {
                        continue;
                    }
                    prop.MetaDataAttributes.Add(metaDataAttributeName, tuple.Item2);
                }
            }
        }
コード例 #2
0
        private static void ProcessComplexTypeMap(AppOptionInfo opts)
        {
            if (string.IsNullOrWhiteSpace(opts.ComplexTypeMap))
            {
                return;
            }

            if (!File.Exists(opts.ComplexTypeMap))
            {
                return;
            }
            try
            {
                using (var reader = new StreamReader(opts.ComplexTypeMap))
                {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        var names = line.Split(new string[] { ",", ";", "|" }, StringSplitOptions.RemoveEmptyEntries);
                        if (names.Length > 1)
                        {
                            if (!opts.ComplexTypesTypeMap.ContainsKey(names[0]))
                            {
                                opts.ComplexTypesTypeMap.Add(names[0], names[1]);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("Could not process complex type map file.", ex);
            }
        }
コード例 #3
0
 protected static void ProcessMetadata(AppOptionInfo opts, EntityMap ent)
 {
     if (opts.MetadataDictionary.TryGetValue(ent.Name, out var metadata))
     {
         foreach (var tuple in metadata)
         {
             ent.MetaDataAttributes.Add(tuple.Item1.Replace("data_", string.Empty), tuple.Item2);
         }
     }
 }
コード例 #4
0
        protected static string GetCodeMapFile(AppOptionInfo opts, bool throwIfNotExist = true)
        {
            string codeMapFile = opts.MapFile;

            if (!Path.IsPathRooted(codeMapFile))
            {
                codeMapFile = Path.GetFullPath(codeMapFile);
            }

            Console.WriteLine("Reading Code Map file...");
            if (!File.Exists(codeMapFile) && throwIfNotExist)
            {
                throw new GoliathDataException($"Map file {codeMapFile} not found.");
            }

            return(codeMapFile);
        }
コード例 #5
0
        protected static void ProcessActivatedProperties(AppOptionInfo opts, EntityMap ent, Property prop)
        {
            var ignoreOnUpdate = string.Concat(ent.Name, ".", prop.Name, ".IgnoreOnUpdate");
            var lazyload       = string.Concat(ent.Name, ".", prop.Name, ".LazyLoad");
            var isNullable     = string.Concat(ent.Name, ".", prop.Name, ".IsNullable");
            var isUnique       = string.Concat(ent.Name, ".", prop.Name, ".IsUnique");

            if (opts.ActivatedActivatedProperties.ContainsKey(ignoreOnUpdate))
            {
                bool val;
                bool.TryParse(opts.ActivatedActivatedProperties[ignoreOnUpdate], out val);
                prop.IgnoreOnUpdate = val;
            }

            if (opts.ActivatedActivatedProperties.ContainsKey(lazyload))
            {
                bool val;
                bool.TryParse(opts.ActivatedActivatedProperties[lazyload], out val);
                prop.LazyLoad = val;
            }

            if (opts.ActivatedActivatedProperties.ContainsKey(isNullable))
            {
                bool val;
                bool.TryParse(opts.ActivatedActivatedProperties[isNullable], out val);
                prop.IsNullable = val;
            }

            if (opts.ActivatedActivatedProperties.ContainsKey(isUnique))
            {
                bool val;
                bool.TryParse(opts.ActivatedActivatedProperties[isUnique], out val);
                prop.IsUnique = val;
            }

            if (prop.PropertyName.Equals("CreatedOn") || prop.PropertyName.Equals("CreatedBy"))
            {
                prop.IgnoreOnUpdate = true;
            }
        }
コード例 #6
0
        protected static SupportedRdbms GetSupportedRdbms(AppOptionInfo opts)
        {
            SupportedRdbms rdbms;

            if (!string.IsNullOrWhiteSpace(opts.ProviderName))
            {
                switch (opts.ProviderName.ToUpper())
                {
                case "MSSQL2008":
                    rdbms = SupportedRdbms.Mssql2008;
                    break;

                case "MSSQL2008R2":
                    rdbms = SupportedRdbms.Mssql2008R2;
                    break;

                case "POSTGRESQL8":
                    rdbms = SupportedRdbms.Postgresql8;
                    break;

                case "POSTGRESQL9":
                    rdbms = SupportedRdbms.Postgresql9;
                    break;

                case "SQLITE3":
                    rdbms = SupportedRdbms.Sqlite3;
                    break;

                default:
                    rdbms = SupportedRdbms.Mssql2008;
                    break;
                }
            }

            else
            {
                rdbms = SupportedRdbms.Mssql2008R2;
            }
            return(rdbms);
        }
コード例 #7
0
        protected static void ProcessActivatedProperties(AppOptionInfo opts, EntityMap ent)
        {
            var isTrackable = string.Concat(ent.Name, ".IsTrackable");
            var extends     = string.Concat(ent.Name, ".Extends");
            var tableAlias  = string.Concat(ent.Name, ".TableAlias");

            if (opts.ActivatedActivatedProperties.ContainsKey(isTrackable))
            {
                bool val;
                bool.TryParse(opts.ActivatedActivatedProperties[isTrackable], out val);
                ent.IsTrackable = val;
            }

            if (opts.ActivatedActivatedProperties.ContainsKey(extends))
            {
                ent.Extends = opts.ActivatedActivatedProperties[extends];
            }

            if (opts.ActivatedActivatedProperties.ContainsKey(tableAlias))
            {
                ent.TableAlias = opts.ActivatedActivatedProperties[tableAlias];
            }
        }
コード例 #8
0
 public abstract void Execute(AppOptionInfo opts, CodeGenRunner codeGenRunner);
コード例 #9
0
        private static void ProcessExtensionMap(AppOptionInfo opts)
        {
            if (string.IsNullOrWhiteSpace(opts.ExtensionMap))
            {
                return;
            }

            if (!File.Exists(opts.ExtensionMap))
            {
                return;
            }
            try
            {
                using (var reader = new StreamReader(opts.ExtensionMap))
                {
                    string txt   = reader.ReadToEnd();
                    var    lines = txt.Split(new string[] { "\n", "\r", ";" }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var line in lines)
                    {
                        var stms = line.Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries);
                        if (stms.Length > 1)
                        {
                            var name  = stms[0].Trim();
                            var value = stms[1].Trim().Replace("\"", string.Empty).Replace("'", string.Empty);

                            var entParts = name.Trim().Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries);
                            if (name.Contains("data_"))
                            {
                                if (entParts.Length > 2)
                                {
                                    var key = string.Concat(entParts[0].Trim(), ".", entParts[1].Trim());
                                    if (!opts.MetadataDictionary.ContainsKey(key))
                                    {
                                        var lst = new List <Tuple <string, string> > {
                                            Tuple.Create(entParts[2].Trim(), value)
                                        };
                                        opts.MetadataDictionary.Add(key, lst);
                                    }
                                    else
                                    {
                                        opts.MetadataDictionary[key].Add(Tuple.Create(entParts[2].Trim(), value));
                                    }
                                }
                                else
                                {
                                    var key = entParts[0].Trim();
                                    if (!opts.MetadataDictionary.ContainsKey(key))
                                    {
                                        var lst = new List <Tuple <string, string> > {
                                            Tuple.Create(entParts[1].Trim(), value)
                                        };
                                        opts.MetadataDictionary.Add(key, lst);
                                    }
                                    else
                                    {
                                        opts.MetadataDictionary[key].Add(Tuple.Create(entParts[1].Trim(), value));
                                    }
                                }
                            }
                            else
                            {
                                if (!opts.ActivatedActivatedProperties.ContainsKey(name))
                                {
                                    opts.ActivatedActivatedProperties.Add(name, value);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("Could not process complex type map file.", ex);
            }
        }
コード例 #10
0
        public static AppOptionInfo ParseOptions(string[] args)
        {
            var opts = new AppOptionInfo();

            if (args.Length > 0)
            {
                opts.ActionName = args[0];
            }

            var p = new OptionSet()
                    .Add("action=", c =>
            {
                opts.ActionName = c;
            })
                    .Add("includeGeneratedColumns=", c =>
            {
                bool includeGeneratedColumns;
                if (bool.TryParse(c, out includeGeneratedColumns))
                {
                    opts.ExportDatabaseGeneratedColumns = includeGeneratedColumns;
                }
            })
                    .Add("includeIdentityColumn=", c =>
            {
                bool includeIdentityColumn;
                if (bool.TryParse(c, out includeIdentityColumn))
                {
                    opts.ExportIdentityColumn = includeIdentityColumn;
                }
            })

                    .Add("createMap", w => opts.ActionName        = w)
                    .Add("combineMaps", w => opts.ActionName      = w)
                    .Add("export", w => opts.ActionName           = w)
                    .Add("generate", w => opts.ActionName         = w)
                    .Add("generateAll", w => opts.ActionName      = w)
                    .Add("generateEnum", w => opts.ActionName     = w)
                    .Add("generateEntities", w => opts.ActionName = w)
                    .Add("merge", w => opts.Merge                                 = true)
                    .Add("namespace=|n=", w => opts.Namespace                     = w)
                    .Add("baseModel=", w => opts.BaseModelXml                     = w)
                    .Add("pluginFolder=", w => opts.PluginFolder                  = w)
                    .Add("exclude=", w => opts.Excluded                           = w)
                    .Add("include=", w => opts.Include                            = w)
                    .Add("mapLinkTable", w => opts.SupportManyToMany              = false)
                    .Add("generateLinkTable", w => opts.GenerateLinkTable         = true)
                    .Add("tableInheritance", w => opts.SupportTableInheritance    = true)
                    .Add("entity=", w => opts.EntityModel                         = w)
                    .Add("renameConfig=", w => opts.RenameConfig                  = w)
                    .Add("complexTypeMap=", w => opts.ComplexTypeMap              = w)
                    .Add("extension=", w => opts.ExtensionMap                     = w)
                    .Add("defaultKeygen=", w => opts.DefaultKeygen                = w)
                    .Add("statementMap=", w => opts.MappedStatementFile           = w)
                    .Add("datamap=|map=|m=", w => opts.MapFile                    = w)
                    .Add("connectionstring=|c=", w => opts.ConnectionString       = w)
                    .Add("provider=", w => opts.ProviderName                      = w)
                    .Add("assembly=|a=", w => opts.AssemblyName                   = w)
                    .Add("workingFolder=|w=", w => opts.WorkingFolder             = w)
                    .Add("out=|o=", w => opts.OutputFile                          = w)
                    .Add("in=|i=", w => opts.TemplateName                         = w)
                    .Add("queryProvider=", w => opts.QueryProviderName            = w)
                    .Add("importDialect=", w => opts.ImportSqlDialect             = w)
                    .Add("exportDialect=", w => opts.ExportSqlDialect             = w)
                    .Add("compress", w => opts.Compress                           = true)
                    .Add("fileLimit=", w => opts.FileSizeLimitInKb                = w)
                    .Add("additiontalNamespaces=", w => opts.AdditionalNameSpaces = w)
                    .Add("templateFolder=|t=", w => opts.TemplateFolder           = w)
                    .Add("props=|properties=", w =>
            {
                if (string.IsNullOrWhiteSpace(w))
                {
                    return;
                }
                var propertyPairs = w.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var propertyPair in propertyPairs)
                {
                    var propArray = propertyPair.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
                    if (propArray.Length < 2)
                    {
                        continue;
                    }

                    if (opts.ExtendedProperties.ContainsKey(propArray[0]))
                    {
                        throw new InvalidOperationException($"Property {propArray[0]} already added.");
                    }

                    opts.ExtendedProperties.Add(propArray[0].Trim(), propArray[1].Trim());
                }
            });

            p.Parse(args);

            if (string.IsNullOrWhiteSpace(opts.ConnectionString))
            {
                //string providerName;
                //opts.ConnectionString = ExtractConnectionString("default", out providerName);
                //opts.ProviderName = providerName;
            }

            if (string.IsNullOrWhiteSpace(opts.Namespace))
            {
                opts.Namespace = "MyApp.Name.Core";
            }

            if (string.IsNullOrWhiteSpace(opts.AssemblyName))
            {
                opts.AssemblyName = opts.Namespace;
            }

            if (string.IsNullOrWhiteSpace(opts.ProviderName))
            {
                opts.ProviderName = "MSSQL2008";
            }

            if (string.IsNullOrWhiteSpace(opts.MapFile))
            {
                opts.MapFile = "data.map.xml";
            }

            if (string.IsNullOrWhiteSpace(opts.WorkingFolder))
            {
                opts.WorkingFolder = AppDomain.CurrentDomain.BaseDirectory;
            }
            else
            {
                var isRooted = Path.IsPathRooted(opts.WorkingFolder);
                if (!isRooted)
                {
                    opts.WorkingFolder = Path.GetFullPath(opts.WorkingFolder);
                }
            }

            if (string.IsNullOrWhiteSpace(opts.TemplateFolder))
            {
                opts.TemplateFolder = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Templates");
            }

            if (string.IsNullOrWhiteSpace(opts.ActionName))
            {
                opts.ActionName = "createMap";
            }

            if (string.IsNullOrWhiteSpace(opts.Excluded))
            {
                opts.ExcludedArray = new string[] { }
            }
            ;
            else
            {
                opts.ExcludedArray = opts.Excluded.Split(new string[] { ",", ";", "|" }, StringSplitOptions.RemoveEmptyEntries);
            }

            ProcessRenames(opts);
            ProcessComplexTypeMap(opts);
            ProcessExtensionMap(opts);

            return(opts);
        }