• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# XmlElementHelper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中XmlElementHelper的典型用法代码示例。如果您正苦于以下问题:C# XmlElementHelper类的具体用法?C# XmlElementHelper怎么用?C# XmlElementHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



XmlElementHelper类属于命名空间,在下文中一共展示了XmlElementHelper类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: DummyNode

        public DummyNode(int inputCount, int outputCount, string legacyName, XmlElement originalElement, string legacyAssembly, Nature nodeNature)
        {
            InputCount = inputCount;
            OutputCount = outputCount;
            LegacyNodeName = legacyName;
            NickName = legacyName;
            OriginalNodeContent = originalElement;
            LegacyAssembly = legacyAssembly;
            NodeNature = nodeNature;

            Description = GetDescription();
            ShouldDisplayPreviewCore = false;

            UpdatePorts();

            // Take the position from the old node (because a dummy node
            // should always be created at the location of the old node).
            var helper = new XmlElementHelper(originalElement);
            X = helper.ReadDouble("x", 0.0);
            Y = helper.ReadDouble("y", 0.0);

            //Take the GUID from the old node (dummy nodes should have their
            //GUID's. This will allow the Groups to work as expected. MAGN-7568)
            GUID = helper.ReadGuid("guid", this.GUID);
        }
开发者ID:ankushraizada,项目名称:Dynamo,代码行数:25,代码来源:DummyNode.cs


示例2: DeserializeCore

 protected override void DeserializeCore(XmlElement element, SaveContext context)
 {
     XmlElementHelper helper = new XmlElementHelper(element);
     this.GUID = helper.ReadGuid("guid", this.GUID);
     this.Text = helper.ReadString("text", "New Note");
     this.X = helper.ReadDouble("x", 0.0);
     this.Y = helper.ReadDouble("y", 0.0);
 }
开发者ID:algobasket,项目名称:Dynamo,代码行数:8,代码来源:NoteModel.cs


示例3: SerializeCore

 protected override void SerializeCore(XmlElement element, SaveContext context)
 {
     var helper = new XmlElementHelper(element);
     helper.SetAttribute("guid", GUID);
     helper.SetAttribute("text", Text);
     helper.SetAttribute("x", X);
     helper.SetAttribute("y", Y);
 }
开发者ID:ankushraizada,项目名称:Dynamo,代码行数:8,代码来源:NoteModel.cs


示例4: DeserializeCore

 protected override void DeserializeCore(XmlElement nodeElement, SaveContext context)
 {
     var helper = new XmlElementHelper(nodeElement);
     GUID = helper.ReadGuid("guid", GUID);
     Text = helper.ReadString("text", "New Note");
     X = helper.ReadDouble("x", 0.0);
     Y = helper.ReadDouble("y", 0.0);
 }
开发者ID:norbertzsiros,项目名称:Dynamo,代码行数:8,代码来源:NoteModel.cs


示例5: SerializeCore

        protected override void SerializeCore(XmlElement nodeElement, SaveContext context)
        {
            base.SerializeCore(nodeElement, context);
            XmlElement outEl = nodeElement.OwnerDocument.CreateElement(typeof(string).FullName);

            var helper = new XmlElementHelper(outEl);
            helper.SetAttribute("value", SerializeValue());
            nodeElement.AppendChild(outEl);
        }
开发者ID:norbertzsiros,项目名称:Dynamo,代码行数:9,代码来源:BaseTypes.cs


示例6: DeserializeCore

        protected override void DeserializeCore(XmlElement nodeElement, SaveContext context)
        {
            var helper = new XmlElementHelper(nodeElement);
            GUID = helper.ReadGuid("guid", GUID);
            Text = helper.ReadString("text", "New Note");
            X = helper.ReadDouble("x", 0.0);
            Y = helper.ReadDouble("y", 0.0);

            // Notify listeners that the position of the note has changed, 
            // then parent group will also redraw itself.
            ReportPosition();
        }
开发者ID:ankushraizada,项目名称:Dynamo,代码行数:12,代码来源:NoteModel.cs


示例7: TestDoubleAttributes

        public void TestDoubleAttributes()
        {
            XmlElement element = xmlDocument.CreateElement("element");

            // Test attribute writing.
            XmlElementHelper writer = new XmlElementHelper(element);
            writer.SetAttribute("ValidName", -12.34);

            // Test reading of existing attribute.
            XmlElementHelper reader = new XmlElementHelper(element);
            Assert.AreEqual(-12.34, reader.ReadDouble("ValidName"));

            // Test reading of non-existence attribute with default value.
            Assert.AreEqual(56.78, reader.ReadDouble("InvalidName", 56.78));

            // Test reading of non-existence attribute without default value.
            Assert.Throws<InvalidOperationException>(() =>
            {
                reader.ReadDouble("InvalidName");
            });
        }
开发者ID:ankushraizada,项目名称:Dynamo,代码行数:21,代码来源:XmlHelperTests.cs


示例8: TestBooleanAttributes

        public void TestBooleanAttributes()
        {
            XmlElement element = xmlDocument.CreateElement("element");

            // Test attribute writing.
            XmlElementHelper writer = new XmlElementHelper(element);
            writer.SetAttribute("ValidName", true);

            // Test reading of existing attribute.
            XmlElementHelper reader = new XmlElementHelper(element);
            Assert.AreEqual(true, reader.ReadBoolean("ValidName"));

            // Test reading of non-existence attribute with default value.
            Assert.AreEqual(true, reader.ReadBoolean("InvalidName", true));
            Assert.AreEqual(false, reader.ReadBoolean("InvalidName", false));

            // Test reading of non-existence attribute without default value.
            Assert.Throws<InvalidOperationException>(() =>
            {
                reader.ReadBoolean("InvalidName");
            });
        }
开发者ID:ankushraizada,项目名称:Dynamo,代码行数:22,代码来源:XmlHelperTests.cs


示例9: LoadConnectorFromXml

        /// <summary>
        ///     Creates and initializes a ConnectorModel from its Xml representation.
        /// </summary>
        /// <param name="connEl">XmlElement for a ConnectorModel.</param>
        /// <param name="nodes">Dictionary to be used for looking up a NodeModel by it's Guid.</param>
        /// <returns>Returns the new instance of ConnectorModel loaded from XmlElement.</returns>
        public static ConnectorModel LoadConnectorFromXml(XmlElement connEl, IDictionary<Guid, NodeModel> nodes)
        {
            var helper = new XmlElementHelper(connEl);

            var guid = helper.ReadGuid("guid", Guid.NewGuid());
            var guidStart = helper.ReadGuid("start");
            var guidEnd = helper.ReadGuid("end");
            int startIndex = helper.ReadInteger("start_index");
            int endIndex = helper.ReadInteger("end_index");

            //find the elements to connect
            NodeModel start;
            if (nodes.TryGetValue(guidStart, out start))
            {
                NodeModel end;
                if (nodes.TryGetValue(guidEnd, out end))
                {
                    return ConnectorModel.Make(start, end, startIndex, endIndex, guid);
                }
            }

            return null;
        }
开发者ID:norbertzsiros,项目名称:Dynamo,代码行数:29,代码来源:NodeGraph.cs


示例10: SaveNode

 protected override void SaveNode(XmlDocument xmlDoc, XmlElement nodeElement, SaveContext context)
 {
     base.SaveNode(xmlDoc, nodeElement, context);
     var helper = new XmlElementHelper(nodeElement);
     helper.SetAttribute("CodeText", code);
     helper.SetAttribute("ShouldFocus", shouldFocus);
 }
开发者ID:TheChosen0ne,项目名称:Dynamo,代码行数:7,代码来源:CodeBlockNode.cs


示例11: DeserializeCore

 protected override void DeserializeCore(XmlElement element, SaveContext context)
 {
     base.DeserializeCore(element, context);
     if (context == SaveContext.Undo)
     {
         var helper = new XmlElementHelper(element);
         shouldFocus = helper.ReadBoolean("ShouldFocus");
         code = helper.ReadString("CodeText");
         ProcessCodeDirect();
     }
 }
开发者ID:TheChosen0ne,项目名称:Dynamo,代码行数:11,代码来源:CodeBlockNode.cs


示例12: SerializeCore

      void SerializeCore(XmlElement element, SaveContext context)
 {            
     XmlElementHelper helper = new XmlElementHelper(element);
     helper.SetAttribute("guid", this.GUID);
     helper.SetAttribute("annotationText", this.AnnotationText);
     helper.SetAttribute("left", this.X);
     helper.SetAttribute("top", this.Y);
     helper.SetAttribute("width", this.Width);
     helper.SetAttribute("height", this.Height);
     helper.SetAttribute("fontSize", this.FontSize);
     helper.SetAttribute("InitialTop", this.InitialTop);
     helper.SetAttribute("InitialHeight", this.InitialHeight);
     helper.SetAttribute("TextblockHeight", this.TextBlockHeight);
     helper.SetAttribute("backgrouund", (this.Background == null ? "" : this.Background.ToString()));        
     //Serialize Selected models
     XmlDocument xmlDoc = element.OwnerDocument;            
     foreach (var guids in this.SelectedModels.Select(x => x.GUID))
     {
         if (xmlDoc != null)
         {
             var modelElement = xmlDoc.CreateElement("Models");
             element.AppendChild(modelElement);
             XmlElementHelper mhelper = new XmlElementHelper(modelElement);
             modelElement.SetAttribute("ModelGuid", guids.ToString());
         }
     }
 }
开发者ID:norbertzsiros,项目名称:Dynamo,代码行数:27,代码来源:AnnotationModel.cs


示例13: DeserializeCore

        protected override void DeserializeCore(XmlElement element, SaveContext context)
        {
            base.DeserializeCore(element, context);

            var helper = new XmlElementHelper(element);
            var script = helper.ReadString("Script", string.Empty);
            this._script = script;
        }
开发者ID:kscalvin,项目名称:Dynamo,代码行数:8,代码来源:dynPython.cs


示例14: SerializeCore

        protected override void SerializeCore(XmlElement element, SaveContext context)
        {
            base.SerializeCore(element, context); //Base implementation must be called
            
            if (context != SaveContext.Undo) return;

            var helper = new XmlElementHelper(element);
            helper.SetAttribute("functionId", Definition.FunctionId.ToString());
            helper.SetAttribute("functionName", NickName);
            helper.SetAttribute("functionDesc", Description);

            XmlDocument xmlDoc = element.OwnerDocument;
            foreach (string input in InPortData.Select(x => x.NickName))
            {
                XmlElement inputEl = xmlDoc.CreateElement("functionInput");
                inputEl.SetAttribute("inputValue", input);
                element.AppendChild(inputEl);
            }

            foreach (string input in OutPortData.Select(x => x.NickName))
            {
                XmlElement outputEl = xmlDoc.CreateElement("functionOutput");
                outputEl.SetAttribute("outputValue", input);
                element.AppendChild(outputEl);
            }
        }
开发者ID:khoaho,项目名称:Dynamo,代码行数:26,代码来源:Function.cs


示例15: CreateModel

        public void CreateModel(XmlElement modelData)
        {
            var helper = new XmlElementHelper(modelData);
            string typeName = helper.ReadString("type", String.Empty);
            if (string.IsNullOrEmpty(typeName))
            {
                // If there wasn't a "type" attribute, then we fall-back onto 
                // the name of the XmlElement itself, which is usually the type 
                // name.
                typeName = modelData.Name;
                if (string.IsNullOrEmpty(typeName))
                {
                    string guid = helper.ReadString("guid");
                    throw new InvalidOperationException(
                        string.Format("No type information: {0}", guid));
                }
            }

            /*
            if (typeName.Equals("Dynamo.Graph.Nodes.ZeroTouch.DSFunction") ||
                typeName.Equals("Dynamo.Graph.Nodes.ZeroTouch.DSVarArgFunction"))
            {
                // For DSFunction and DSVarArgFunction node types, the type name
                // is actually embedded within "name" attribute (for an example,
                // "[email protected],double").
                // 
                typeName = modelData.Attributes["name"].Value;
            }
            */

            if (typeName.Contains("ConnectorModel"))
            {
                var connector = NodeGraph.LoadConnectorFromXml(modelData,
                    Nodes.ToDictionary(node => node.GUID));

                // It is possible that in some cases connector can't be created,
                // for example, connector connects to a custom node instance
                // whose input ports have been changed, so connector can't find
                // its end port owner.
                if (connector == null)
                {
                    var guidAttribute = modelData.Attributes["guid"];
                    if (guidAttribute == null)
                    {
                        throw new InvalidOperationException("'guid' field missing from recorded model");
                    }
                    undoRecorder.RecordModelAsOffTrack(Guid.Parse(guidAttribute.Value)); 
                }
                else 
                {
                    OnConnectorAdded(connector); // Update view-model and view.
                }
            }
            else if (typeName.Contains("NoteModel"))
            {
                var noteModel = NodeGraph.LoadNoteFromXml(modelData);
                AddNote(noteModel);

                //check whether this note belongs to a group
                foreach (var annotation in Annotations)
                {
                    //this note "was" in a group
                    if (annotation.DeletedModelBases.Any(m => m.GUID == noteModel.GUID))
                    {
                        annotation.AddToSelectedModels(noteModel);
                    }
                }
            }
            else if (typeName.Contains("AnnotationModel"))
            {
                var selectedNodes = this.Nodes == null ? null : this.Nodes.Where(s => s.IsSelected);
                var selectedNotes = this.Notes == null ? null : this.Notes.Where(s => s.IsSelected);

                var annotationModel = new AnnotationModel(selectedNodes, selectedNotes);
                annotationModel.ModelBaseRequested += annotationModel_GetModelBase;
                annotationModel.Disposed += (_) => annotationModel.ModelBaseRequested -= annotationModel_GetModelBase;
                annotationModel.Deserialize(modelData, SaveContext.Undo);
                AddNewAnnotation(annotationModel);
            }

            else if (typeName.Contains("PresetModel"))
            {
                var preset = new PresetModel(this.Nodes);
                preset.Deserialize(modelData, SaveContext.Undo);
                presets.Add(preset);
                //we raise this property change here so that this event bubbles up through
                //the model and to the DynamoViewModel so that presets show in the UI menu if our undo/redo
                //created the first preset
                RaisePropertyChanged("EnablePresetOptions");
               
            }
            else // Other node types.
            {
                NodeModel nodeModel = NodeFactory.CreateNodeFromXml(modelData, SaveContext.Undo, ElementResolver);
                
                AddAndRegisterNode(nodeModel);
                
                //check whether this node belongs to a group
                foreach (var annotation in Annotations)
                {
//.........这里部分代码省略.........
开发者ID:mikeyforrest,项目名称:Dynamo,代码行数:101,代码来源:WorkspaceModel.cs


示例16: SerializeCore

 protected override void SerializeCore(XmlElement element)
 {
     XmlElementHelper helper = new XmlElementHelper(element);
     helper.SetAttribute("NodeId", NodeId);
 }
开发者ID:heegwon,项目名称:Dynamo,代码行数:5,代码来源:RecordableCommands.cs


示例17: DeserializeCore

            internal static CreateCustomNodeCommand DeserializeCore(XmlElement element)
            {
                XmlElementHelper helper = new XmlElementHelper(element);

                return new CreateCustomNodeCommand(
                    helper.ReadGuid("NodeId"),
                    helper.ReadString("Name"),
                    helper.ReadString("Category"),
                    helper.ReadString("Description"),
                    helper.ReadBoolean("MakeCurrent"));
            }
开发者ID:heegwon,项目名称:Dynamo,代码行数:11,代码来源:RecordableCommands.cs


示例18: GetModelForElement

        public ModelBase GetModelForElement(XmlElement modelData)
        {
            // TODO(Ben): This may or may not be true, but I guess we should be 
            // using "System.Type" (given the "type" information in "modelData"),
            // and determine the matching category (e.g. is this a Node, or a 
            // Connector?) instead of checking in each and every collections we
            // have in the workspace.
            // 
            // System.Type type = System.Type.GetType(helper.ReadString("type"));
            // if (typeof(Dynamo.Models.NodeModel).IsAssignableFrom(type))
            //     return Nodes.First((x) => (x.GUID == modelGuid));

            var helper = new XmlElementHelper(modelData);
            Guid modelGuid = helper.ReadGuid("guid");

            ModelBase foundModel = GetModelInternal(modelGuid);
            if (null != foundModel)
                return foundModel;

            throw new ArgumentException(
                string.Format("Unhandled model type: {0}", helper.ReadString("type", modelData.Name)));
        }
开发者ID:mikeyforrest,项目名称:Dynamo,代码行数:22,代码来源:WorkspaceModel.cs


示例19: DeserializeCore

        protected override void DeserializeCore(XmlElement element, SaveContext context)
        {
            base.DeserializeCore(element, context); //Base implementation must be called

            if (context != SaveContext.Undo) return;

            var helper = new XmlElementHelper(element);
            NickName = helper.ReadString("functionName");

            Controller.DeserializeCore(element, context);

            XmlNodeList inNodes = element.SelectNodes("functionInput");
            XmlNodeList outNodes = element.SelectNodes("functionOutput");

            var inData =
                inNodes.Cast<XmlNode>()
                    .Select(
                        (inputNode, i) =>
                            new
                            {
                                data = new PortData(inputNode.Attributes[0].Value, "Input #" + (i + 1)),
                                idx = i
                            });

            foreach (var dataAndIdx in inData)
            {
                if (InPortData.Count > dataAndIdx.idx)
                    InPortData[dataAndIdx.idx] = dataAndIdx.data;
                else
                    InPortData.Add(dataAndIdx.data);
            }

            var outData =
                outNodes.Cast<XmlNode>()
                    .Select(
                        (outputNode, i) =>
                            new
                            {
                                data = new PortData(outputNode.Attributes[0].Value, "Output #" + (i + 1)),
                                idx = i
                            });

            foreach (var dataAndIdx in outData)
            {
                if (OutPortData.Count > dataAndIdx.idx)
                    OutPortData[dataAndIdx.idx] = dataAndIdx.data;
                else
                    OutPortData.Add(dataAndIdx.data);
            }

            //Added it the same way as LoadNode. But unsure of when 'Output' ChildNodes will
            //be added to element. As of now I dont think it is added during serialize

            #region Legacy output support

            foreach (var portData in 
                from XmlNode subNode in element.ChildNodes
                where subNode.Name.Equals("Output")
                select new PortData(subNode.Attributes[0].Value, "function output"))
            {
                if (OutPortData.Any())
                    OutPortData[0] = portData;
                else
                    OutPortData.Add(portData);
            }

            #endregion

            RegisterAllPorts();

            Description = helper.ReadString("functionDesc");
        }
开发者ID:khoaho,项目名称:Dynamo,代码行数:72,代码来源:Function.cs


示例20: SerializeCore

        protected override void SerializeCore(XmlElement element, SaveContext context)
        {
            base.SerializeCore(element, context);

            var helper = new XmlElementHelper(element);
            helper.SetAttribute("Script", this.Script);
        }
开发者ID:kscalvin,项目名称:Dynamo,代码行数:7,代码来源:dynPython.cs



注:本文中的XmlElementHelper类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# XmlHelper类代码示例发布时间:2022-05-24
下一篇:
C# XmlElement类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap