本文整理汇总了C#中XmlElementHelper类的典型用法代码示例。如果您正苦于以下问题:C# XmlElementHelper类的具体用法?C# XmlElementHelper怎么用?C# XmlElementHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlElementHelper类属于命名空间,在下文中一共展示了XmlElementHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
示例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");
});
}
示例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");
});
}
示例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;
}
示例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);
}
示例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();
}
}
示例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());
}
}
}
示例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;
}
示例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);
}
}
示例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)
{
//.........这里部分代码省略.........