Example #1
0
        public DpoClass(ITableSchema metaTable, ClassName cname, DpoOption option)
        {
            this.metaTable = metaTable;

            this.nameSpace = cname.Namespace;
            this.className = cname.Class;

            this.option = option;

            this.code = new CSharpBuilder {
                Namespace = cname.Namespace,
            };

            code.AddUsing("System");
            code.AddUsing("System.Collections.Generic");
            code.AddUsing("System.Text");
            code.AddUsing("System.Data");
            code.AddUsing("System.Drawing");
            code.AddUsing("Sys.Data");
            code.AddUsing("Sys.Data.Manager");

            clss = new Class(cname.Class, new CodeBuilder.TypeInfo {
                Type = typeof(DPObject)
            })
            {
                Modifier = Modifier.Public | Modifier.Partial,
                Sorted   = option.CodeSorted
            };

            this.code.AddClass(clss);

            nonvalized     = NonvalizedList(nameSpace, className);
            nullableFields = NullableList(nameSpace, className);
        }
Example #2
0
        public DpoClass(ITable metaTable, ClassName cname, DpoOption option)
        {
            this.metaTable = metaTable;

            this.nameSpace = cname.Namespace;
            this.className = cname.Class;

            this.option = option;

            this.code = new CSharpBuilder { nameSpace = cname.Namespace, };

            code.AddUsing("System");
            code.AddUsing("System.Collections.Generic");
            code.AddUsing("System.Text");
            code.AddUsing("System.Data");
            code.AddUsing("System.Drawing");
            code.AddUsing("Sys.Data");
            code.AddUsing("Sys.Data.Manager");

            clss = new Class(cname.Class, new CodeBuilder.TypeInfo { type = typeof(DPObject) })
            {
                modifier = Modifier.Public | Modifier.Partial,
                Sorted = option.CodeSorted
            };

            this.code.AddClass(clss);

            nonvalized = NonvalizedList(nameSpace, className);
            nullableFields = NullableList(nameSpace, className);
        }
Example #3
0
        public void ExportClass(Command cmd)
        {
            DpoOption option = new DpoOption();

            option.NameSpace = cfg.GetValue<string>("dpo.ns", "Sys.DataModel.Dpo");
            option.OutputPath = cfg.GetValue<string>("dpo.path", $"{Configuration.MyDocuments}\\DataModel\\Dpo");
            option.Level = cfg.GetValue<Level>("dpo.level", Level.Application);
            option.HasProvider = cfg.GetValue<bool>("dpo.hasProvider", false);
            option.HasTableAttribute = cfg.GetValue<bool>("dpo.hasTableAttr", true);
            option.HasColumnAttribute = cfg.GetValue<bool>("dpo.hasColumnAttr", true);
            option.IsPack = cfg.GetValue<bool>("dpo.isPack", true);
            option.CodeSorted = cmd.Has("sort");

            option.ClassNameSuffix = cfg.GetValue<string>("dpo.suffix", Setting.DPO_CLASS_SUFFIX_CLASS_NAME);
            option.ClassNameRule =
                name => name.Substring(0, 1).ToUpper() + name.Substring(1).ToLower() + option.ClassNameSuffix;

            if (tname != null)
            {
                var clss = new DpoGenerator(tname) { Option = option };
                clss.CreateClass();
                stdio.WriteLine("generated class {0} at {1}", tname.ShortName, option.OutputPath);
            }
            else if (dname != null)
            {
                stdio.WriteLine("start to generate database {0} class to directory: {1}", dname, option.OutputPath);
                CancelableWork.CanCancel(cts =>
                {
                    var md = new MatchedDatabase(dname, cmd.wildcard, cfg.exportExcludedTables);
                    TableName[] tnames = md.MatchedTableNames;
                    foreach (var tn in tnames)
                    {
                        if (cts.IsCancellationRequested)
                            return;

                        try
                        {
                            var clss = new DpoGenerator(tn) { Option = option };
                            clss.CreateClass();
                            stdio.WriteLine("generated class for {0} at {1}", tn.ShortName, option.OutputPath);
                        }
                        catch (Exception ex)
                        {
                            stdio.ErrorFormat("failed to generate class {0}, {1}", tn.ShortName, ex.Message);
                        }
                    }

                    stdio.WriteLine("completed");
                    return;
                });
            }
            else
            {
                stdio.ErrorFormat("warning: database is not selected");
            }
        }