Exemple #1
0
        static void LoadDefine()
        {
            long   start         = DateTime.Now.Ticks;
            string namespacePath = "无法解析Xml.NamespaceXml";

            try
            {
                var moduleXml = Util.Deserialize(Setting.Module, typeof(ModuleXml)) as ModuleXml;
                if (moduleXml.Name.IsEmpty())
                {
                    throw new Exception("数据结构导出时必须指定命名空间根节点<Module Name =\"**\">");
                }
                GroupWrap.LoadGroup(moduleXml.Groups);
                Setting.ModuleName = moduleXml.Name;
                string        moduleDir = Path.GetDirectoryName(Setting.Module);
                List <string> imports   = moduleXml.Imports;
                for (int i = 0; i < imports.Count; i++)
                {
                    ///命名空间目录与模块目录并列
                    namespacePath = Path.Combine(moduleDir, imports[i]);
                    var nsx = Util.Deserialize(namespacePath, typeof(NamespaceXml)) as NamespaceXml;

                    string space = nsx.Name;
                    var    cls   = nsx.Classes;
                    for (int k = 0; k < cls.Count; k++)
                    {
                        ClassXml xml  = cls[k];
                        var      info = new ClassWrap(xml, space);
                        if (info.IsConfig())
                        {
                            new ConfigWrap(xml, space, Path.GetDirectoryName(namespacePath));
                        }
                    }
                    var ens = nsx.Enums;
                    for (int k = 0; k < ens.Count; k++)
                    {
                        new EnumWrap(ens[k], space);
                    }
                }
            }
            catch (Exception e)
            {
                Util.LogErrorFormat("路径:{0} 错误:{1}\n{2}", namespacePath, e.Message, e.StackTrace);
                return;
            }
            long  end    = DateTime.Now.Ticks;
            float second = (end - start) * 1f / TimeSpan.TicksPerSecond;

            Util.LogFormat("#{0,-40} 耗时 {1:F3}s", "加载数据结构定义", second);
        }
Exemple #2
0
        public ConfigWrap(ClassXml des, string namespace0, string moduleDir)
        {
            _des       = des;
            _namespace = namespace0;
            _fullName  = string.Format("{0}.{1}", namespace0, des.Name);
            _groups    = new HashSet <string>(Util.Split(des.Group));
            if (_groups.Count == 0)
            {
                _groups.Add(Setting.DefualtGroup);
            }

            if (des.Index.IsEmpty())
            {
                Error("索引(Index)未填写");
            }
            ClassWrap cls = ClassWrap.Get(_fullName);

            _index = cls.Fields.Find(f => f.Name == des.Index);
            if (_index == null)
            {
                Error("配置主键字段不存在:" + des.Index);
                return;
            }
            _index.CreateKeyChecker();

            string path = Path.Combine(moduleDir, _des.DataPath);

            if (File.Exists(path))
            {
                _inputFiles = new string[] { path }
            }
            ;
            else if (Directory.Exists(path))
            {
                _inputFiles = Directory.GetFiles(path);
            }
            else
            {
                Error("数据路径不存在:" + path);
            }
            _outputFile = _fullName.Replace('.', '\\').ToLower();

            Add(this);
        }
Exemple #3
0
        public ClassWrap(ClassXml des, string namespace0)
        {
            _des      = des;
            _fields   = new List <FieldWrap>();
            _children = new HashSet <string>();
            if (Name.IsEmpty())
            {
                Error("未指定Class名称");
            }
            if (!Util.MatchIdentifier(Name))
            {
                Error("命名不合法:" + Name);
            }

            _namespace = namespace0;
            _fullName  = string.Format("{0}.{1}", namespace0, des.Name);
            _inherit   = des.Inherit;
            _inherit   = CorrectType(this, _inherit);
            _groups    = new HashSet <string>(Util.Split(des.Group == null ? "" : des.Group.ToLower()));
            if (_groups.Count == 0)
            {
                _groups.Add(Setting.DefualtGroup);
            }

            Add(this);
            _fields = new List <FieldWrap>();
            for (int i = 0; i < des.Fields.Count; i++)
            {
                var fieldDes = des.Fields[i];
                var info     = new FieldWrap(this, fieldDes.Name, fieldDes.Type, fieldDes.Group, fieldDes.Desc, fieldDes.Attribute, _groups);
                info.CreateChecker(fieldDes);
                Fields.Add(info);
            }
            _consts = new List <ConstWrap>();
            for (int i = 0; i < des.Consts.Count; i++)
            {
                var constDes = des.Consts[i];
                var info     = new ConstWrap(this, constDes.Name, constDes.Type, constDes.Value, constDes.Group, constDes.Desc, _groups);
                Consts.Add(info);
            }
        }