本文整理汇总了C#中XmlElementHelper.ReadString方法的典型用法代码示例。如果您正苦于以下问题:C# XmlElementHelper.ReadString方法的具体用法?C# XmlElementHelper.ReadString怎么用?C# XmlElementHelper.ReadString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlElementHelper
的用法示例。
在下文中一共展示了XmlElementHelper.ReadString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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);
}
示例3: 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();
}
示例4: DeserializeCore
protected override void DeserializeCore(XmlElement element, SaveContext context)
{
XmlElementHelper helper = new XmlElementHelper(element);
this.GUID = helper.ReadGuid("guid", Guid.NewGuid());
// Resolve node nick name.
string nickName = helper.ReadString("nickname", string.Empty);
if (!string.IsNullOrEmpty(nickName))
this.nickName = nickName;
else
{
System.Type type = this.GetType();
var attribs = type.GetCustomAttributes(typeof(NodeNameAttribute), true);
NodeNameAttribute attrib = attribs[0] as NodeNameAttribute;
if (null != attrib)
this.nickName = attrib.Name;
}
this.X = helper.ReadDouble("x", 0.0);
this.Y = helper.ReadDouble("y", 0.0);
this.isVisible = helper.ReadBoolean("isVisible", true);
this.isUpstreamVisible = helper.ReadBoolean("isUpstreamVisible", true);
this.argumentLacing = helper.ReadEnum("lacing", LacingStrategy.Disabled);
if (context == SaveContext.Undo)
{
// Fix: MAGN-159 (nodes are not editable after undo/redo).
interactionEnabled = helper.ReadBoolean("interactionEnabled", true);
this.state = helper.ReadEnum("nodeState", ElementState.ACTIVE);
// We only notify property changes in an undo/redo operation. Normal
// operations like file loading or copy-paste have the models created
// in different ways and their views will always be up-to-date with
// respect to their models.
RaisePropertyChanged("InteractionEnabled");
RaisePropertyChanged("State");
RaisePropertyChanged("NickName");
RaisePropertyChanged("ArgumentLacing");
RaisePropertyChanged("IsVisible");
RaisePropertyChanged("IsUpstreamVisible");
// Notify listeners that the position of the node has changed,
// then all connected connectors will also redraw themselves.
this.ReportPosition();
}
}
示例5: DeserializeCore
internal static OpenFileCommand DeserializeCore(XmlElement element)
{
XmlElementHelper helper = new XmlElementHelper(element);
string xmlFilePath = helper.ReadString("XmlFilePath");
if (File.Exists(xmlFilePath) == false)
{
// Try to find the file right next to the command XML file.
string xmlFileName = Path.GetFileName(xmlFilePath);
Uri uri = new Uri(element.OwnerDocument.BaseURI);
string directory = Path.GetDirectoryName(uri.AbsolutePath);
xmlFilePath = Path.Combine(directory, xmlFileName);
// If it still cannot be resolved, fall back to system search.
if (File.Exists(xmlFilePath) == false)
xmlFilePath = Path.GetFullPath(xmlFileName);
if (File.Exists(xmlFilePath) == false) // When all else fail.
{
var message = "Target file cannot be found!";
throw new FileNotFoundException(message, xmlFileName);
}
}
return new OpenFileCommand(xmlFilePath);
}
示例6: 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();
}
}
示例7: DeserializeCore
internal static AddPresetCommand DeserializeCore(XmlElement element)
{
var helper = new XmlElementHelper(element);
var modelGuids = DeserializeGuid(element, helper);
if (modelGuids.Count()<1)
{
throw new ArgumentNullException("No IDs were deserialized during load of preset creation command");
}
return new AddPresetCommand(helper.ReadString("name"), helper.ReadString("description"),modelGuids);
}
示例8: 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)));
}
示例9: 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;
}
示例10: DeserializeCore
protected override void DeserializeCore(XmlElement nodeElement, SaveContext context)
{
var helper = new XmlElementHelper(nodeElement);
if (context != SaveContext.Copy)
GUID = helper.ReadGuid("guid", GUID);
// Resolve node nick name.
string name = helper.ReadString("nickname", string.Empty);
if (!string.IsNullOrEmpty(name))
nickName = name;
else
{
Type type = GetType();
object[] attribs = type.GetCustomAttributes(typeof(NodeNameAttribute), true);
var attrib = attribs[0] as NodeNameAttribute;
if (null != attrib)
nickName = attrib.Name;
}
X = helper.ReadDouble("x", 0.0);
Y = helper.ReadDouble("y", 0.0);
isVisible = helper.ReadBoolean("isVisible", true);
isUpstreamVisible = helper.ReadBoolean("isUpstreamVisible", true);
argumentLacing = helper.ReadEnum("lacing", LacingStrategy.Disabled);
var portInfoProcessed = new HashSet<int>();
//read port information
foreach (XmlNode subNode in nodeElement.ChildNodes)
{
if (subNode.Name == "PortInfo")
{
int index = int.Parse(subNode.Attributes["index"].Value);
if (index < InPorts.Count)
{
portInfoProcessed.Add(index);
bool def = bool.Parse(subNode.Attributes["default"].Value);
inPorts[index].UsingDefaultValue = def;
}
}
}
//set defaults
foreach (
var port in
inPorts.Select((x, i) => new { x, i }).Where(x => !portInfoProcessed.Contains(x.i)))
port.x.UsingDefaultValue = false;
if (context == SaveContext.Undo)
{
// Fix: MAGN-159 (nodes are not editable after undo/redo).
//interactionEnabled = helper.ReadBoolean("interactionEnabled", true);
state = helper.ReadEnum("nodeState", ElementState.Active);
// We only notify property changes in an undo/redo operation. Normal
// operations like file loading or copy-paste have the models created
// in different ways and their views will always be up-to-date with
// respect to their models.
RaisePropertyChanged("InteractionEnabled");
RaisePropertyChanged("State");
RaisePropertyChanged("NickName");
RaisePropertyChanged("ArgumentLacing");
RaisePropertyChanged("IsVisible");
RaisePropertyChanged("IsUpstreamVisible");
// Notify listeners that the position of the node has changed,
// then all connected connectors will also redraw themselves.
ReportPosition();
}
}
示例11: DeserializeCore
protected override void DeserializeCore(XmlElement element, SaveContext context)
{
base.DeserializeCore(element, context); //Base implementation must be called
if (context == SaveContext.Undo)
{
XmlElementHelper helper = new XmlElementHelper(element);
FormulaString = helper.ReadString("formulaString");
}
}
示例12: CreateModel
public void CreateModel(XmlElement modelData)
{
XmlElementHelper 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 USE_DSENGINE
if (typeName.Equals("Dynamo.Nodes.DSFunction") ||
typeName.Equals("Dynamo.Nodes.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;
}
#endif
if (typeName.StartsWith("Dynamo.Models.ConnectorModel"))
{
ConnectorModel connector = ConnectorModel.Make();
connector.Deserialize(modelData, SaveContext.Undo);
Connectors.Add(connector);
}
else if (typeName.StartsWith("Dynamo.Models.NoteModel"))
{
NoteModel noteModel = new NoteModel(0.0, 0.0);
noteModel.Deserialize(modelData, SaveContext.Undo);
Notes.Add(noteModel);
}
else // Other node types.
{
NodeModel nodeModel = DynamoModel.CreateNodeInstance(typeName);
nodeModel.WorkSpace = this;
nodeModel.Deserialize(modelData, SaveContext.Undo);
Nodes.Add(nodeModel);
}
}
示例13: DeserializeCore
protected override void DeserializeCore(XmlElement element, SaveContext context)
{
base.DeserializeCore(element, context); //Base implementation must be called
if (context == SaveContext.Undo)
{
var helper = new XmlElementHelper(element);
NickName = helper.ReadString("functionName");
Guid funcId;
if (!Guid.TryParse(helper.ReadString("functionId"), out funcId))
funcId = GuidUtility.Create(GuidUtility.UrlNamespace, NickName);
if (!VerifyFuncId(ref funcId))
{
LoadProxyCustomNode(funcId);
return;
}
Definition = Workspace.DynamoModel.CustomNodeManager.GetFunctionDefinition(funcId);
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");
}
}
示例14: 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)
{
//.........这里部分代码省略.........
示例15: DeserializeCore
protected override void DeserializeCore(XmlElement element, SaveContext context)
{
base.DeserializeCore(element, context); //Base implementation must be called.
var helper = new XmlElementHelper(element);
var metricConversion = helper.ReadString("conversionMetric");
var selectedMetricConversionFrom = helper.ReadString("conversionFrom");
var selectedMetricConversionTo = helper.ReadString("conversionTo");
SelectedMetricConversion = Enum.Parse(typeof(ConversionMetricUnit), metricConversion) is ConversionMetricUnit ?
(ConversionMetricUnit)Enum.Parse(typeof(ConversionMetricUnit), metricConversion) : ConversionMetricUnit.Length;
SelectedFromConversion = Enum.Parse(typeof(ConversionUnit), selectedMetricConversionFrom) is ConversionUnit ?
(ConversionUnit)Enum.Parse(typeof(ConversionUnit), selectedMetricConversionFrom) : ConversionUnit.Meters;
SelectedToConversion = Enum.Parse(typeof(ConversionUnit), selectedMetricConversionTo) is ConversionUnit ?
(ConversionUnit)Enum.Parse(typeof(ConversionUnit), selectedMetricConversionTo) : ConversionUnit.Meters;
}