Beispiel #1
0
 public static void writeInstance(XmlTextWriter xmlWriter, Instance instance)
 {
     xmlWriter.WriteStartElement("Instance");
     xmlWriter.WriteAttributeString("type_ref", instance.Type.Id.ToString());
     xmlWriter.WriteAttributeString("identifier", instance.Identifier);
     xmlWriter.WriteAttributeString("isArray", instance.IsArray.ToString());
     if (instance is ValueInstance)
     {
         ValueInstance valueInstance = (ValueInstance)instance;
         xmlWriter.WriteAttributeString("value", valueInstance.Value);
     }
     else if (instance is ArrayInstance)
     {
         ArrayInstance arrayInstance = (ArrayInstance)instance;
         foreach (Instance inst in arrayInstance.ArrayItems)
         {
             writeInstance(xmlWriter, inst);
         }
     }
     else if (instance is ReferenceInstance)
     {
         ReferenceInstance referenceInstance = (ReferenceInstance)instance;
         foreach (Instance inst in referenceInstance.Properties)
         {
             writeInstance(xmlWriter, inst);
         }
     }
     xmlWriter.WriteEndElement();
 }
Beispiel #2
0
        // 进程模板选中项变化的处理
        private void process_ComboBox_Changed(object sender, SelectionChangedEventArgs e)
        {
            // 安全锁锁定时不做任何修改
            if (TopoNodeEWVM.SafetyLock)
            {
                return;
            }
            // 清空属性列表
            TopoNodeEWVM.TopoNode.Properties.Clear();
            // 获取选中的Process
            ComboBox process_ComboBox = ControlExtensions.FindControl <ComboBox>(this, "process_ComboBox");

            if (process_ComboBox.SelectedItem == null)
            {
                return;
            }
            Process process = (Process)process_ComboBox.SelectedItem;

            // 构造这个属性列表
            foreach (Attribute attribute in process.Attributes)
            {
                if (attribute.Type is UserType) // 复合类型
                {
                    ReferenceInstance referenceInstance = ReferenceInstance.build((UserType)attribute.Type, attribute.Identifier);
                    TopoNodeEWVM.TopoNode.Properties.Add(referenceInstance);
                }
                else // 基本类型
                {
                    ValueInstance valueInstance = new ValueInstance(attribute.Type, attribute.Identifier);
                    TopoNodeEWVM.TopoNode.Properties.Add(valueInstance);
                }
            }
            ResourceManager.mainWindowVM.Tips = "进程模板被修改为[" + process.Name + "],例化对象已重新生成";
        }
Beispiel #3
0
        public static Instance readInstance(XmlNode node, Dictionary <int, Type> typeDict)
        {
            XmlElement element = (XmlElement)node;
            int        typeRef = int.Parse(element.GetAttribute("type_ref"));

            Debug.Assert(typeDict.ContainsKey(typeRef));
            string identifier = element.GetAttribute("identifier");
            bool   isArray    = bool.Parse(element.GetAttribute("isArray"));
            // 使用临时Attribute来构造Instance
            Attribute attribute = new Attribute(
                typeDict[typeRef],
                identifier,
                isArray,
                true
                );

            if (isArray) // 数组类型,继续解析数组项
            {
                ArrayInstance arrayInstance = new ArrayInstance(attribute);
                foreach (XmlNode childNode in node.ChildNodes)
                {
                    Instance itemInstance = readInstance(childNode, typeDict);
                    arrayInstance.ArrayItems.Add(itemInstance);
                }
                return(arrayInstance);
            }
            else if (typeDict[typeRef] is UserType) // 引用类型,继续解析成员
            {
                ReferenceInstance referenceInstance = new ReferenceInstance(attribute);
                foreach (XmlNode childNode in node.ChildNodes)
                {
                    Instance propInstance = readInstance(childNode, typeDict);
                    referenceInstance.Properties.Add(propInstance);
                }
                return(referenceInstance);
            }
            else // 值类型,要把值读出来
            {
                ValueInstance valueInstance = new ValueInstance(attribute);
                valueInstance.Value = element.GetAttribute("value");
                return(valueInstance);
            }
        }