/// <summary> /// Event handler for IGraph.OnChangingNodeAttribute and IGraph.OnChangingEdgeAttribute. /// </summary> /// <param name="element">The node or edge whose attribute is changed.</param> /// <param name="attrType">The type of the attribute to be changed.</param> /// <param name="changeType">The type of the change which will be made.</param> /// <param name="newValue">The new value of the attribute, if changeType==Assign. /// Or the value to be inserted/removed if changeType==PutElement/RemoveElement on set. /// Or the new map pair value to be inserted if changeType==PutElement on map. /// Or the new value to be inserted/added if changeType==PutElement on array. /// Or the new value to be assigned to the given position if changeType==AssignElement on array.</param> /// <param name="keyValue">The map pair key to be inserted/removed if changeType==PutElement/RemoveElement on map. /// The array index to be removed/written to if changeType==RemoveElement/AssignElement on array.</param> void ChangingAttribute(IGraphElement element, AttributeType attrType, AttributeChangeType changeType, Object newValue, Object keyValue) { foreach (RecordingState recordingState in recordings.Values) { MainGraphExportContext mainExportContext = recordingState.mainExportContext; AddSubgraphsAsNeeded(mainExportContext, element, attrType, newValue, recordingState.writer); AddSubgraphsAsNeeded(mainExportContext, element, attrType, keyValue, recordingState.writer); switch (changeType) { case AttributeChangeType.Assign: recordingState.writer.Write("@(\"" + graph.GetElementName(element) + "\")." + attrType.Name + " = "); GRSExport.EmitAttribute(mainExportContext, attrType, newValue, graph, recordingState.writer); recordingState.writer.WriteLine(); break; case AttributeChangeType.PutElement: recordingState.writer.Write("@(\"" + graph.GetElementName(element) + "\")." + attrType.Name); switch (attrType.Kind) { case AttributeKind.SetAttr: recordingState.writer.Write(".add("); recordingState.writer.Write(GRSExport.ToString(mainExportContext, newValue, attrType.ValueType, graph)); recordingState.writer.WriteLine(")"); break; case AttributeKind.MapAttr: recordingState.writer.Write(".add("); recordingState.writer.Write(GRSExport.ToString(mainExportContext, keyValue, attrType.KeyType, graph)); recordingState.writer.Write(", "); recordingState.writer.Write(GRSExport.ToString(mainExportContext, newValue, attrType.ValueType, graph)); recordingState.writer.WriteLine(")"); break; case AttributeKind.ArrayAttr: if (keyValue == null) { recordingState.writer.Write(".add("); recordingState.writer.Write(GRSExport.ToString(mainExportContext, newValue, attrType.ValueType, graph)); recordingState.writer.WriteLine(")"); } else { recordingState.writer.Write(".add("); recordingState.writer.Write(GRSExport.ToString(mainExportContext, newValue, attrType.ValueType, graph)); recordingState.writer.Write(", "); recordingState.writer.Write(GRSExport.ToString(mainExportContext, keyValue, new AttributeType(null, null, AttributeKind.IntegerAttr, null, null, null, null, null, null, typeof(int)), graph)); recordingState.writer.WriteLine(")"); } break; case AttributeKind.DequeAttr: if (keyValue == null) { recordingState.writer.Write(".add("); recordingState.writer.Write(GRSExport.ToString(mainExportContext, newValue, attrType.ValueType, graph)); recordingState.writer.WriteLine(")"); } else { recordingState.writer.Write(".add("); recordingState.writer.Write(GRSExport.ToString(mainExportContext, newValue, attrType.ValueType, graph)); recordingState.writer.Write(", "); recordingState.writer.Write(GRSExport.ToString(mainExportContext, keyValue, new AttributeType(null, null, AttributeKind.IntegerAttr, null, null, null, null, null, null, typeof(int)), graph)); recordingState.writer.WriteLine(")"); } break; default: throw new Exception("Wrong attribute type for attribute change type"); } break; case AttributeChangeType.RemoveElement: recordingState.writer.Write("@(\"" + graph.GetElementName(element) + "\")." + attrType.Name); switch (attrType.Kind) { case AttributeKind.SetAttr: recordingState.writer.Write(".rem("); recordingState.writer.Write(GRSExport.ToString(mainExportContext, newValue, attrType.ValueType, graph)); recordingState.writer.WriteLine(")"); break; case AttributeKind.MapAttr: recordingState.writer.Write(".rem("); recordingState.writer.Write(GRSExport.ToString(mainExportContext, keyValue, attrType.KeyType, graph)); recordingState.writer.WriteLine(")"); break; case AttributeKind.ArrayAttr: recordingState.writer.Write(".rem("); if (keyValue != null) { recordingState.writer.Write(GRSExport.ToString(mainExportContext, keyValue, new AttributeType(null, null, AttributeKind.IntegerAttr, null, null, null, null, null, null, typeof(int)), graph)); } recordingState.writer.WriteLine(")"); break; case AttributeKind.DequeAttr: recordingState.writer.Write(".rem("); if (keyValue != null) { recordingState.writer.Write(GRSExport.ToString(mainExportContext, keyValue, new AttributeType(null, null, AttributeKind.IntegerAttr, null, null, null, null, null, null, typeof(int)), graph)); } recordingState.writer.WriteLine(")"); break; default: throw new Exception("Wrong attribute type for attribute change type"); } break; case AttributeChangeType.AssignElement: recordingState.writer.Write("@(\"" + graph.GetElementName(element) + "\")." + attrType.Name); switch (attrType.Kind) { case AttributeKind.ArrayAttr: recordingState.writer.Write("["); recordingState.writer.Write(GRSExport.ToString(mainExportContext, keyValue, new AttributeType(null, null, AttributeKind.IntegerAttr, null, null, null, null, null, null, typeof(int)), graph)); recordingState.writer.Write("] = "); recordingState.writer.WriteLine(GRSExport.ToString(mainExportContext, newValue, attrType.ValueType, graph)); break; case AttributeKind.DequeAttr: recordingState.writer.Write("["); recordingState.writer.Write(GRSExport.ToString(mainExportContext, keyValue, new AttributeType(null, null, AttributeKind.IntegerAttr, null, null, null, null, null, null, typeof(int)), graph)); recordingState.writer.Write("] = "); recordingState.writer.WriteLine(GRSExport.ToString(mainExportContext, newValue, attrType.ValueType, graph)); break; case AttributeKind.MapAttr: recordingState.writer.Write("["); recordingState.writer.Write(GRSExport.ToString(mainExportContext, keyValue, attrType.KeyType, graph)); recordingState.writer.Write("] = "); recordingState.writer.WriteLine(GRSExport.ToString(mainExportContext, newValue, attrType.ValueType, graph)); break; default: throw new Exception("Wrong attribute type for attribute change type"); } break; default: throw new Exception("Unknown attribute change type"); } } }