Esempio n. 1
0
 public Document(Documents.File file)
 {
     File = file;
     UpdateRelateName();
     BeanDefine = new BeanDefine(this, file.Name);
     Beans      = new ReadOnlyCollection <Bean>(_Beans);
 }
Esempio n. 2
0
        public VarDefine(BeanDefine bean, XmlElement self)
        {
            this.Self   = self;
            this.Parent = bean;

            _Name    = self.GetAttribute("name");
            _Type    = ToEType(self.GetAttribute("type"));
            _Value   = self.GetAttribute("value");
            _Foreign = self.GetAttribute("foreign");

            string v = self.GetAttribute("nw");

            this._GridColumnNameWidth = v.Length > 0 ? int.Parse(v) : 0;
            v = self.GetAttribute("vw");
            this._GridColumnValueWidth = v.Length > 0 ? int.Parse(v) : 0;
            _Properties    = self.GetAttribute("properties");
            PropertiesList = FormMain.Instance.PropertyManager.Parse(_Properties);
            _Default       = self.GetAttribute("default");

            _Comment = self.GetAttribute("comment");
            if (_Comment.Length == 0)
            {
                XmlNode c = self.NextSibling;
                if (c != null && XmlNodeType.Text == c.NodeType)
                {
                    _Comment = c.InnerText.Trim();
                    Regex regex = new Regex("[\r\n]");
                    _Comment = regex.Replace(_Comment, "");
                }
            }
        }
Esempio n. 3
0
        public void SaveAs(string fileName, bool create, Property.DataOutputFlags flags)
        {
            XmlDocument xml = create ? null : Xml;

            if (null == xml)
            {
                xml = new XmlDocument();
                xml.AppendChild(xml.CreateElement("ZezeConfig"));
                if (false == create)
                {
                    Xml = xml;
                }
            }

            if (flags == Property.DataOutputFlags.All)
            {
                BeanDefine.SaveAs(xml, xml.DocumentElement, create);
            }

            for (int i = 0; i < _Beans.Count; ++i)
            {
                Bean b = _Beans[i];
                b.RowIndex = i;
                b.SaveAs(xml, xml.DocumentElement, create, flags);
            }

            using (TextWriter sw = new StreamWriter(fileName, false, Encoding.UTF8))
            {
                xml.Save(sw);
            }
        }
Esempio n. 4
0
        public EnumDefine(BeanDefine bean, XmlElement self)
        {
            this.Parent = bean;
            this.Self   = self;
            this._Name  = self.GetAttribute("name");
            ValueMap    = new ReadOnlyDictionary <string, ValueDefine>(_ValueMap);

            XmlNodeList childNodes = self.ChildNodes;

            foreach (XmlNode node in childNodes)
            {
                if (XmlNodeType.Element != node.NodeType)
                {
                    continue;
                }
                XmlElement e = (XmlElement)node;

                switch (e.Name)
                {
                case "value":
                    AddValue(new ValueDefine(this, e));
                    break;

                default:
                    throw new Exception("node=" + e.Name);
                }
            }
        }
Esempio n. 5
0
        public BeanDefine(Document doc, XmlElement self, BeanDefine parent = null)
        {
            this.Document = doc;
            this.Parent   = parent;
            this.Self     = self;

            EnumDefines    = new ReadOnlyDictionary <string, EnumDefine>(_EnumDefines);
            BeanDefines    = new ReadOnlyDictionary <string, BeanDefine>(_BeanDefines);
            Variables      = new ReadOnlyCollection <VarDefine>(_Variables);
            ReferenceFroms = new ReadOnlyDictionary <string, ReferenceFrom>(_ReferenceFroms);

            _Name = self.GetAttribute("name");
            if (Name.Length == 0)
            {
                _Name = doc.Name;
            }
            string tmp = self.GetAttribute("Locked");

            _Locked = tmp.Length > 0 ? bool.Parse(tmp) : false;

            XmlNodeList childNodes = self.ChildNodes;

            foreach (XmlNode node in childNodes)
            {
                if (XmlNodeType.Element != node.NodeType)
                {
                    continue;
                }

                XmlElement e = (XmlElement)node;

                switch (e.Name)
                {
                case "BeanDefine":
                    var bdnew = new BeanDefine(Document, e, this);
                    _BeanDefines.Add(bdnew.Name, bdnew);
                    break;

                case "variable":
                    _Variables.Add(new VarDefine(this, e));
                    break;

                case "enum":
                    var enew = new EnumDefine(this, e);
                    _EnumDefines.Add(enew.Name, enew);
                    break;

                case "ReferenceFrom":
                    var rf = new ReferenceFrom(e);
                    _ReferenceFroms.Add($"{rf.FullName}:{rf.VarName}", rf);
                    break;

                default:
                    throw new Exception("node=" + e.Name);
                }
            }
        }
Esempio n. 6
0
 public BeanDefine(Document doc, string name = null, BeanDefine parent = null)
 {
     this.Document  = doc;
     this.Parent    = parent;
     this._Name     = null != name ? name : doc.Name;
     EnumDefines    = new ReadOnlyDictionary <string, EnumDefine>(_EnumDefines);
     BeanDefines    = new ReadOnlyDictionary <string, BeanDefine>(_BeanDefines);
     Variables      = new ReadOnlyCollection <VarDefine>(_Variables);
     ReferenceFroms = new ReadOnlyDictionary <string, ReferenceFrom>(_ReferenceFroms);
 }
Esempio n. 7
0
        public BeanDefine Search(string [] path, int offset)
        {
            BeanDefine r = this;

            for (int i = offset; i < path.Length && null != r; ++i)
            {
                r = r.GetSubBeanDefine(path[i]);
            }
            return(r);
        }
Esempio n. 8
0
File: Bean.cs Progetto: e2wugui/zeze
        public void SaveAs(XmlDocument xml, XmlElement parent, bool create, Property.DataOutputFlags flags)
        {
            XmlElement self = create ? null : Self;

            if (null == self)
            {
                self = xml.CreateElement("bean");
                parent.AppendChild(self);
                if (false == create)
                {
                    Self = self;
                }
            }

            if (flags == Property.DataOutputFlags.All)
            {
                self.SetAttribute("DefineFullName", DefineFullName);
            }

            if (RowIndex >= 0)
            {
                self.SetAttribute("row", RowIndex.ToString());
            }

            // 使用 DefineFullName 找到 BeanDefine。慢的话,可以加cache优化速度。
            BeanDefine beanDefine = Document.BeanDefine;

            if (false == string.IsNullOrEmpty(DefineFullName))
            {
                beanDefine = FormMain.Instance.Documents.SearchReference(DefineFullName);
            }

            foreach (var varDefine in beanDefine.Variables)
            {
                if (0 == (varDefine.DataOutputFlags & flags))
                {
                    continue;
                }

                if (VariableMap.TryGetValue(varDefine.Name, out var varData))
                {
                    varDefine.DetectType(varData.Value);
                    varData.SaveAs(xml, self, create, flags);
                }
                else
                {
                    varDefine.DetectType("");
                }
            }
        }
Esempio n. 9
0
        private void InsertBeanDefine(int insertIndex, string fullName, BeanDefine bean)
        {
            // row for bean start
            define.Rows.Insert(insertIndex, 1);
            DataGridViewCellCollection cellsBeanStart = define.Rows[insertIndex].Cells;

            for (int i = 0; i < cellsBeanStart.Count; ++i)
            {
                cellsBeanStart[i].ReadOnly = true;
            }
            DataGridViewCell cellLocked = cellsBeanStart["BeanLocked"];

            cellLocked.Value = bean.Locked ? "Yes" : "No";
            cellLocked.Tag   = bean; // BeanDefine
            cellsBeanStart["VarName"].Value    = fullName;
            cellsBeanStart["VarName"].ReadOnly = false;

            // row for vars
            foreach (var v in bean.Variables)
            {
                ++insertIndex;
                InsertVariable(insertIndex, v);
            }

            // row for bean end
            ++insertIndex;
            define.Rows.Insert(insertIndex, 1);
            DataGridViewCellCollection cellsBeanEnd = define.Rows[insertIndex].Cells;

            for (int i = 0; i < cellsBeanEnd.Count; ++i)
            {
                cellsBeanEnd[i].ReadOnly = true;
            }
            DataGridViewCell cellBeanEnd = cellsBeanEnd["VarName"];

            cellBeanEnd.Value       = ",";
            cellBeanEnd.Tag         = new VarDefine(bean, "");
            cellBeanEnd.ToolTipText = "双击增加变量(数据列)";
        }
Esempio n. 10
0
        public void BuildGridData()
        {
            FormMain.Instance.FormError.RemoveErrorByGrid(GridData);
            GridData = new GridData(this);

            BeanDefine.BuildGridColumns(GridData, 0, new ColumnTag(ColumnTag.ETag.Normal), -1);

            var param = new Bean.UpdateParam()
            {
                UpdateType = Bean.EUpdate.Grid
            };

            foreach (var bean in _Beans)
            {
                int insertIndex = GridData.RowCount;
                GridData.InsertRow(insertIndex);

                int colIndex = 0;
                if (bean.Update(GridData, GridData.GetRow(insertIndex), ref colIndex, 0, param))
                {
                    break;
                }
            }

            for (int i = 0; i < GridData.ColumnCount; ++i)
            {
                ColumnTag tag = GridData.GetColumn(i).ColumnTag;
                switch (tag.Tag)
                {
                case ColumnTag.ETag.AddVariable:
                case ColumnTag.ETag.ListStart:
                case ColumnTag.ETag.ListEnd:
                    continue;
                }
                tag.BuildUniqueIndex(GridData, i);
            }
        }
Esempio n. 11
0
        /// <summary>
        /// AddVariable
        /// </summary>
        /// <param name="name"></param>
        /// <param name="type"></param>
        /// <param name="reference"></param>
        /// <returns>error string.</returns>
        public (VarDefine, bool, string) AddVariable(string name,
                                                     VarDefine.EType type = VarDefine.EType.Undecided, string reference = null)
        {
            if (GetVariable(name) != null)
            {
                return(null, false, "duplicate variable name");
            }

            VarDefine var = new VarDefine(this, name)
            {
                Type  = type,
                Value = reference,
                GridColumnValueWidth = 50,
            };

            bool create = false;

            switch (type)
            {
            case VarDefine.EType.List:
                if (string.IsNullOrEmpty(reference))
                {
                    var.Value = var.FullName();
                    if (_BeanDefines.TryGetValue(var.Name, out var exist))
                    {
                        if (false == exist.NamespaceOnly)
                        {
                            return(null, false, $"尝试为变量'{var.Name}'创建一个 BeanDefine 失败:已经存在。");
                        }
                    }
                    else
                    {
                        exist = new BeanDefine(Document, var.Name, this);
                        _BeanDefines.Add(var.Name, exist);
                    }
                    var.Reference = exist;
                    exist.AddReferenceFrom(var, ReferenceFrom.Reasons.List);
                    create = true;
                }
                else
                {
                    var r = FormMain.Instance.Documents.SearchReference(var.Value);
                    if (null == r)
                    {
                        return(null, false, "list reference bean not found.");
                    }
                    var.Reference = r;
                    r.AddReferenceFrom(var, ReferenceFrom.Reasons.List);
                }
                break;

            case VarDefine.EType.Enum:
                _EnumDefines.Add(var.Name, new EnumDefine(this, var.Name));
                break;
            }

            _Variables.Add(var);
            var.CreateXmlElementIfNeed(); // 调整变量顺序的时候需要这个创建好。
            Document.IsChanged = true;
            return(var, create, "");
        }
Esempio n. 12
0
 public VarDefine(BeanDefine bean, string name)
 {
     this.Parent = bean;
     this._Name  = name;
 }
Esempio n. 13
0
 public EnumDefine(BeanDefine bean, string name)
 {
     this.Parent = bean;
     this._Name  = name;
     ValueMap    = new ReadOnlyDictionary <string, ValueDefine>(_ValueMap);
 }