示例#1
0
        public void ExportClass()
        {
            DpoOption option = new DpoOption
            {
                NameSpace          = cfg.GetValue <string>(ConfigKey._GENERATOR_DPO_NS, "Sys.DataModel.Dpo"),
                OutputPath         = cmd.OutputPath(ConfigKey._GENERATOR_DPO_PATH, $"{ConfigurationEnvironment.MyDocuments}\\DataModel\\Dpo"),
                Level              = cfg.GetValue <Level>(ConfigKey._GENERATOR_DPO_LEVEL, Level.Application),
                HasProvider        = cfg.GetValue <bool>(ConfigKey._GENERATOR_DPO_HASPROVIDER, false),
                HasTableAttribute  = cfg.GetValue <bool>(ConfigKey._GENERATOR_DPO_HASTABLEATTR, true),
                HasColumnAttribute = cfg.GetValue <bool>(ConfigKey._GENERATOR_DPO_HASCOLUMNATTR, true),
                IsPack             = cfg.GetValue <bool>(ConfigKey._GENERATOR_DPO_ISPACK, true),
                CodeSorted         = cmd.Has("sort"),

                ClassNameSuffix = cfg.GetValue <string>(ConfigKey._GENERATOR_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();
                cout.WriteLine("generated class {0} at {1}", tname.ShortName, option.OutputPath);
            }
            else if (dname != null)
            {
                cout.WriteLine("start to generate database {0} class to directory: {1}", dname, option.OutputPath);
                CancelableWork.CanCancel(cts =>
                {
                    var md             = new MatchedDatabase(dname, cmd);
                    TableName[] tnames = md.TableNames();
                    foreach (var tn in tnames)
                    {
                        if (cts.IsCancellationRequested)
                        {
                            return;
                        }


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

                    cout.WriteLine("completed");
                    return;
                });
            }
            else
            {
                cerr.WriteLine("warning: database is not selected");
            }
        }
示例#2
0
 public string OutputPath(string configKey, string defaultPath)
 {
     return(OutputPath() ?? cfg.GetValue <string>(configKey, defaultPath));
 }