public override void Assign(object value, IGraphProcessingEnvironment procEnv) { IGraphElement elem = (IGraphElement)DestVar.GetVariableValue(procEnv); AttributeType attrType; value = ContainerHelper.IfAttributeOfElementIsContainerThenCloneContainer( elem, AttributeName, value, out attrType); AttributeChangeType changeType = AttributeChangeType.Assign; if (elem is INode) { procEnv.Graph.ChangingNodeAttribute((INode)elem, attrType, changeType, value, null); } else { procEnv.Graph.ChangingEdgeAttribute((IEdge)elem, attrType, changeType, value, null); } elem.SetAttribute(AttributeName, value); if (elem is INode) { procEnv.Graph.ChangedNodeAttribute((INode)elem, attrType); } else { procEnv.Graph.ChangedEdgeAttribute((IEdge)elem, attrType); } }
///////////////////////////////////////////////////////////////////////////////// public static void AssignAttribute(object target, object value, string attributeName, IGraph graph) { if (target is IGraphElement) { IGraphElement elem = (IGraphElement)target; AttributeType attrType; value = ContainerHelper.IfAttributeOfElementIsContainerThenCloneContainer( elem, attributeName, value, out attrType); BaseGraph.ChangingAttributeAssign(graph, elem, attrType, value); elem.SetAttribute(attributeName, value); BaseGraph.ChangedAttribute(graph, elem, attrType); } else if (target is IObject) { IObject elem = (IObject)target; AttributeType attrType = elem.Type.GetAttributeType(attributeName); BaseGraph.ChangingAttributeAssign(graph, elem, attrType, value); elem.SetAttribute(attributeName, value); } else //if(target is ITransientObject) { ITransientObject elem = (ITransientObject)target; elem.SetAttribute(attributeName, value); } }
public override void Assign(object value, IGraphProcessingEnvironment procEnv) { IGraphElement elem = (IGraphElement)DestVar.GetVariableValue(procEnv); AttributeType attrType; value = ContainerHelper.IfAttributeOfElementIsContainerThenCloneContainer( elem, AttributeName, value, out attrType); BaseGraph.ChangingAttributeAssign(procEnv.Graph, elem, attrType, value); elem.SetAttribute(AttributeName, value); BaseGraph.ChangedAttribute(procEnv.Graph, elem, attrType); }
public void DoUndo(IGraphProcessingEnvironment procEnv) { String attrName = _attrType.Name; LGSPGraphProcessingEnvironment procEnv_ = (LGSPGraphProcessingEnvironment)procEnv; if (_undoOperation == UndoOperation.PutElement) { if (_attrType.Kind == AttributeKind.SetAttr) { ChangingElementAttribute(procEnv_); IDictionary dict = (IDictionary)_elem.GetAttribute(_attrType.Name); dict.Add(_value, null); } else if (_attrType.Kind == AttributeKind.MapAttr) { ChangingElementAttribute(procEnv_); IDictionary dict = (IDictionary)_elem.GetAttribute(_attrType.Name); dict.Add(_keyOfValue, _value); } else if (_attrType.Kind == AttributeKind.ArrayAttr) { ChangingElementAttribute(procEnv_); IList array = (IList)_elem.GetAttribute(_attrType.Name); if (_keyOfValue == null) { array.Add(_value); } else { array.Insert((int)_keyOfValue, _value); } } else //if(_attrType.Kind == AttributeKind.DequeAttr) { ChangingElementAttribute(procEnv_); IDeque deque = (IDeque)_elem.GetAttribute(_attrType.Name); if (_keyOfValue == null) { deque.EnqueueFront(_value); } else { deque.EnqueueAt((int)_keyOfValue, _value); } } } else if (_undoOperation == UndoOperation.RemoveElement) { if (_attrType.Kind == AttributeKind.SetAttr) { ChangingElementAttribute(procEnv_); IDictionary dict = (IDictionary)_elem.GetAttribute(_attrType.Name); dict.Remove(_value); } else if (_attrType.Kind == AttributeKind.MapAttr) { ChangingElementAttribute(procEnv_); IDictionary dict = (IDictionary)_elem.GetAttribute(_attrType.Name); dict.Remove(_keyOfValue); } else if (_attrType.Kind == AttributeKind.ArrayAttr) { ChangingElementAttribute(procEnv_); IList array = (IList)_elem.GetAttribute(_attrType.Name); if (_keyOfValue == null) { array.RemoveAt(array.Count - 1); } else { array.RemoveAt((int)_keyOfValue); } } else //if(_attrType.Kind == AttributeKind.DequeAttr) { ChangingElementAttribute(procEnv_); IDeque deque = (IDeque)_elem.GetAttribute(_attrType.Name); if (_keyOfValue == null) { deque.DequeueBack(); } else { deque.DequeueAt((int)_keyOfValue); } } } else if (_undoOperation == UndoOperation.AssignElement) { if (_attrType.Kind == AttributeKind.ArrayAttr) { ChangingElementAttribute(procEnv_); IList array = (IList)_elem.GetAttribute(_attrType.Name); array[(int)_keyOfValue] = _value; } else if (_attrType.Kind == AttributeKind.DequeAttr) { ChangingElementAttribute(procEnv_); IDeque deque = (IDeque)_elem.GetAttribute(_attrType.Name); deque[(int)_keyOfValue] = _value; } else //if(_attrType.Kind == AttributeKind.MapAttr) { ChangingElementAttribute(procEnv_); IDictionary dict = (IDictionary)_elem.GetAttribute(_attrType.Name); dict[_keyOfValue] = _value; } } else if (_undoOperation == UndoOperation.Assign) { ChangingElementAttribute(procEnv_); _elem.SetAttribute(attrName, _value); } // otherwise UndoOperation.None }
private static void ReadAttributes(IGraphElement elem, XmlElement xmlelem) { GrGenType type = elem.Type; foreach (XmlElement attrelem in xmlelem.GetElementsByTagName("attr")) { String attrname = attrelem.GetAttribute("name"); String attrval = attrelem.InnerText; AttributeType attrType = type.GetAttributeType(attrname); object value = null; switch (attrType.Kind) { case AttributeKind.BooleanAttr: if (attrval.Equals("true", StringComparison.OrdinalIgnoreCase)) { value = true; } else if (attrval.Equals("false", StringComparison.OrdinalIgnoreCase)) { value = false; } else { throw new Exception("Attribute \"" + attrname + "\" must be either \"true\" or \"false\"!"); } break; case AttributeKind.EnumAttr: { int val; if (Int32.TryParse(attrval, out val)) { value = val; } else { foreach (EnumMember member in attrType.EnumType.Members) { if (attrval == member.Name) { value = member.Value; break; } } if (value == null) { String errorText = "Attribute \"" + attrname + "\" must be one of the following values:"; foreach (EnumMember member in attrType.EnumType.Members) { errorText += " - " + member.Name + " = " + member.Value; } throw new Exception(errorText); } } break; } case AttributeKind.ByteAttr: { sbyte val; if (!SByte.TryParse(attrval, out val)) { throw new Exception("Attribute \"" + attrname + "\" must be a byte (signed)!"); } value = val; break; } case AttributeKind.ShortAttr: { short val; if (!Int16.TryParse(attrval, out val)) { throw new Exception("Attribute \"" + attrname + "\" must be a short!"); } value = val; break; } case AttributeKind.IntegerAttr: { int val; if (!Int32.TryParse(attrval, out val)) { throw new Exception("Attribute \"" + attrname + "\" must be an integer!"); } value = val; break; } case AttributeKind.LongAttr: { long val; if (!Int64.TryParse(attrval, out val)) { throw new Exception("Attribute \"" + attrname + "\" must be a long!"); } value = val; break; } case AttributeKind.StringAttr: value = attrval; break; case AttributeKind.FloatAttr: { float val; if (!Single.TryParse(attrval, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out val)) { throw new Exception("Attribute \"" + attrname + "\" must be a floating point number!"); } value = val; break; } case AttributeKind.DoubleAttr: { double val; if (!Double.TryParse(attrval, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out val)) { throw new Exception("Attribute \"" + attrname + "\" must be a floating point number!"); } value = val; break; } case AttributeKind.ObjectAttr: { throw new Exception("Attribute \"" + attrname + "\" is an object type attribute!\n" + "It is not possible to assign a value to an object type attribute!"); } case AttributeKind.SetAttr: case AttributeKind.MapAttr: case AttributeKind.ArrayAttr: case AttributeKind.DequeAttr: default: throw new Exception("Unsupported attribute value type: \"" + attrType.Kind + "\""); // TODO: support set=SetAttr and seq=ArrayAttr, here and in export } elem.SetAttribute(attrname, value); } }
private void ParseAttributeValue(IGraphElement elem, AttributeType attrType) { object attributeValue = JustParseAttributeValue(elem, attrType); /*AttributeChangeType changeType = AttributeChangeType.Assign; if(elem is INode) graph.ChangingNodeAttribute((INode)elem, attrType, changeType, value, null); else graph.ChangingEdgeAttribute((IEdge)elem, attrType, changeType, value, null); */ elem.SetAttribute(attrType.Name, attributeValue); /*if(elem is INode) graph.ChangedNodeAttribute((INode)elem, attrType); else graph.ChangedEdgeAttribute((IEdge)elem, attrType); */ }