public override void Assign(object value, IGraphProcessingEnvironment procEnv)
        {
            IGraphElement elem = (IGraphElement)DestVar.GetVariableValue(procEnv);
            object container = elem.GetAttribute(AttributeName);
            object key = KeyExpression.Evaluate(procEnv);
            AttributeType attrType = elem.Type.GetAttributeType(AttributeName);

            BaseGraph.ChangingAttributeAssignElement(procEnv.Graph, elem, attrType, value, key);

            if(container is IList)
            {
                IList array = (IList)container;
                array[(int)key] = value;
            }
            else if(container is IDeque)
            {
                IDeque deque = (IDeque)container;
                deque[(int)key] = value;
            }
            else
            {
                IDictionary map = (IDictionary)container;
                map[key] = value;
            }

            BaseGraph.ChangedAttribute(procEnv.Graph, elem, attrType);
        }
示例#2
0
 public static object GetGraphElementAttributeOrElementOfMatch(object source, string attributeOrElementName)
 {
     if (source is IMatch)
     {
         IMatch match = (IMatch)source;
         object value = match.getNode(attributeOrElementName);
         if (value != null)
         {
             return(value);
         }
         value = match.getEdge(attributeOrElementName);
         if (value != null)
         {
             return(value);
         }
         value = match.getVariable(attributeOrElementName);
         return(value);
     }
     else
     {
         IGraphElement elem  = (IGraphElement)source;
         object        value = elem.GetAttribute(attributeOrElementName);
         value = ContainerHelper.IfAttributeOfElementIsContainerThenCloneContainer(
             elem, attributeOrElementName, value);
         return(value);
     }
 }
示例#3
0
 protected void WriteAttributes(IGraphElement elem)
 {
     foreach(AttributeType attrType in elem.Type.AttributeTypes)
     {
         object value = elem.GetAttribute(attrType.Name);
         String valuestr = (value == null) ? "" : value.ToString();
         switch(attrType.Kind)
         {
         case AttributeKind.BooleanAttr:
         case AttributeKind.DoubleAttr:
         case AttributeKind.FloatAttr:
         case AttributeKind.ByteAttr:
         case AttributeKind.ShortAttr:
         case AttributeKind.IntegerAttr:
         case AttributeKind.LongAttr:
         case AttributeKind.StringAttr:
             xmlwriter.WriteAttributeString(RemoveGrGenPrefix(attrType.Name), valuestr);
             break;
         case AttributeKind.EnumAttr:
             xmlwriter.WriteAttributeString(RemoveGrGenPrefix(attrType.Name), RemoveGrGenPrefix(valuestr));
             break;
         default:
             throw new Exception("Unsupported attribute value type: \"" + attrType.Kind + "\"");
         }
     }
 }
示例#4
0
        private String GetElemLabelWithChangedAttr(IGraphElement elem, AttributeType changedAttrType, object newValue)
        {
            List <InfoTag> infoTagTypes = dumpInfo.GetTypeInfoTags(elem.Type);
            String         infoTagStr   = "";

            if (infoTagTypes != null)
            {
                foreach (InfoTag infoTag in infoTagTypes)
                {
                    object attr;
                    if (infoTag.AttributeType == changedAttrType)
                    {
                        attr = newValue;
                    }
                    else
                    {
                        attr = elem.GetAttribute(infoTag.AttributeType.Name);
                    }
                    if (attr == null)
                    {
                        continue;
                    }
                    infoTagStr += "\\n" + infoTag.AttributeType.Name + " = " + attr.ToString();
                }
            }

            return(dumpInfo.GetElementName(elem) + ":" + elem.Type.Name + infoTagStr);
        }
示例#5
0
        /// <summary>
        /// Dumps all attributes in the form "kind owner::name = value" into a String List
        /// </summary>
        /// <param name="elem">IGraphElement which attributes are to be dumped</param>
        /// <returns>A String List containing the dumped attributes </returns>
        private List <String> DumpAttributes(IGraphElement elem)
        {
            List <String> attribs = new List <String>();

            foreach (AttributeType attrType in elem.Type.AttributeTypes)
            {
                object attr = elem.GetAttribute(attrType.Name);
                String attrString;
                if (attr != null)
                {
                    if (attr is double)
                    {
                        attrString = ((double)attr).ToString(System.Globalization.CultureInfo.InvariantCulture);
                    }
                    else if (attr is float)
                    {
                        attrString = ((float)attr).ToString(System.Globalization.CultureInfo.InvariantCulture) + "f";
                    }
                    else
                    {
                        attrString = attr.ToString();
                    }
                }
                else
                {
                    attrString = "<Not initialized>";
                }
                attribs.Add(String.Format("{0} {1}::{2} = {3}", GetKindName(attrType),
                                          attrType.OwnerType.Name, attrType.Name, attrString));
            }
            return(attribs);
        }
示例#6
0
 private static void ExtractAttribute(IList array, string attribute, IList extractedArray)
 {
     foreach (object element in array)
     {
         IGraphElement graphElement = (IGraphElement)element;
         extractedArray.Add(graphElement.GetAttribute(attribute));
     }
 }
示例#7
0
        protected List <Attr> GetAttributes(IGraphElement elem)
        {
            List <Attr> attrs = new List <Attr>();

            foreach (AttributeType attrType in elem.Type.AttributeTypes)
            {
                object value = elem.GetAttribute(attrType.Name);

                String valType;
                String valuestr = (value == null) ? "" : value.ToString();
                switch (attrType.Kind)
                {
                case AttributeKind.BooleanAttr:
                    valType  = "bool";
                    valuestr = ((bool)value) ? "true" : "false";
                    break;

                case AttributeKind.DoubleAttr:
                case AttributeKind.FloatAttr:
                    valType = "double";
                    if (value is float)
                    {
                        valuestr = ((float)value).ToString(System.Globalization.CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        valuestr = ((double)value).ToString(System.Globalization.CultureInfo.InvariantCulture);
                    }
                    break;

                case AttributeKind.ByteAttr:
                case AttributeKind.ShortAttr:
                case AttributeKind.IntegerAttr:
                case AttributeKind.LongAttr:
                    valType = "int"; break;

                // TODO: This does not allow differentiating between empty and null strings
                case AttributeKind.StringAttr:
                    valType = "string";
                    break;

                case AttributeKind.EnumAttr:
                    valType = "enum";
                    break;

                default:
                    throw new Exception("Unsupported attribute value type: \"" + attrType.Kind + "\"");
                }
                attrs.Add(new Attr(attrType.Name, valType, valuestr));
            }
            return(attrs);
        }
示例#8
0
        /// <summary>
        /// Dumps all attributes in the form "kind owner::name = value" into a String List
        /// </summary>
        /// <param name="elem">IGraphElement which attributes are to be dumped</param>
        /// <returns>A String List containing the dumped attributes </returns>
        private static List <String> DumpAttributes(IGraphElement elem)
        {
            List <String> attribs = new List <String>();

            foreach (AttributeType attrType in elem.Type.AttributeTypes)
            {
                object attr       = elem.GetAttribute(attrType.Name);
                String attrString = (attr != null) ? attr.ToString() : "<Not initialized>";
                attribs.Add(String.Format("{0}::{1} : {2} = {3}",
                                          attrType.OwnerType.Name, attrType.Name, attrType.GetKindName(), attrString));
            }
            return(attribs);
        }
示例#9
0
 private void EncodeAttr(AttributeType attrType, IGraphElement elem, out String attrTypeString, out String attrValueString)
 {
     if (attrType.Kind == AttributeKind.SetAttr || attrType.Kind == AttributeKind.MapAttr)
     {
         EmitHelper.ToString((IDictionary)elem.GetAttribute(attrType.Name), out attrTypeString, out attrValueString, attrType, graph);
         attrValueString = Encode(attrValueString);
     }
     else if (attrType.Kind == AttributeKind.ArrayAttr)
     {
         EmitHelper.ToString((IList)elem.GetAttribute(attrType.Name), out attrTypeString, out attrValueString, attrType, graph);
         attrValueString = Encode(attrValueString);
     }
     else if (attrType.Kind == AttributeKind.DequeAttr)
     {
         EmitHelper.ToString((IDeque)elem.GetAttribute(attrType.Name), out attrTypeString, out attrValueString, attrType, graph);
         attrValueString = Encode(attrValueString);
     }
     else
     {
         EmitHelper.ToString(elem.GetAttribute(attrType.Name), out attrTypeString, out attrValueString, attrType, graph);
         attrValueString = Encode(attrValueString);
     }
 }
示例#10
0
 /// <summary>
 /// If the attribute of the given name of the given element is a container attribute
 /// then return a clone of the given container value, otherwise just return the original value;
 /// additionally returns the AttributeType of the attribute of the element.
 /// </summary>
 public static object IfAttributeOfElementIsContainerThenCloneContainer(
     IGraphElement element, String AttributeName, object value, out AttributeType attrType)
 {
     attrType = element.Type.GetAttributeType(AttributeName);
     if (attrType.Kind == AttributeKind.SetAttr || attrType.Kind == AttributeKind.MapAttr)
     {
         Type keyType, valueType;
         ContainerHelper.GetDictionaryTypes(element.GetAttribute(AttributeName), out keyType, out valueType);
         return(ContainerHelper.NewDictionary(keyType, valueType, value)); // by-value-semantics -> clone dictionary
     }
     else if (attrType.Kind == AttributeKind.ArrayAttr)
     {
         Type valueType;
         ContainerHelper.GetListType(element.GetAttribute(AttributeName), out valueType);
         return(ContainerHelper.NewList(valueType, value)); // by-value-semantics -> clone array
     }
     else if (attrType.Kind == AttributeKind.DequeAttr)
     {
         Type valueType;
         ContainerHelper.GetDequeType(element.GetAttribute(AttributeName), out valueType);
         return(ContainerHelper.NewDeque(valueType, value)); // by-value-semantics -> clone deque
     }
     return(value);
 }
示例#11
0
        private static String GetElemLabel(IGraphElement elem, DumpInfo dumpInfo)
        {
            List <InfoTag> infoTagTypes = dumpInfo.GetTypeInfoTags(elem.Type);
            String         label        = dumpInfo.GetElemTypeLabel(elem.Type);
            bool           first        = true;

            if (label == null)
            {
                label = dumpInfo.GetElementName(elem) + ":" + elem.Type.Name;
                first = false;
            }

            if (infoTagTypes != null)
            {
                foreach (InfoTag infoTag in infoTagTypes)
                {
                    object attr = elem.GetAttribute(infoTag.AttributeType.Name);
                    if (attr == null)
                    {
                        continue;
                    }

                    if (!first)
                    {
                        label += "\n";
                    }
                    else
                    {
                        first = false;
                    }

                    if (infoTag.ShortInfoTag)
                    {
                        label += attr.ToString();
                    }
                    else
                    {
                        label += infoTag.AttributeType.Name + " = " + attr.ToString();
                    }
                }
            }

            return(label);
        }
示例#12
0
        private String GetElemLabel(IGraphElement elem)
        {
            List <InfoTag> infoTagTypes = dumpInfo.GetTypeInfoTags(elem.Type);
            String         infoTagStr   = "";

            if (infoTagTypes != null)
            {
                foreach (InfoTag infoTag in infoTagTypes)
                {
                    object attr = elem.GetAttribute(infoTag.AttributeType.Name);
                    if (attr == null)
                    {
                        continue;
                    }
                    infoTagStr += "\\n" + infoTag.AttributeType.Name + " = " + attr.ToString();
                }
            }

            return(dumpInfo.GetElementName(elem) + ":" + elem.Type.Name + infoTagStr);
        }
示例#13
0
 private void EncodeAttr(AttributeType attrType, IGraphElement elem, out String attrTypeString, out String attrValueString)
 {
     if (attrType.Kind == AttributeKind.SetAttr || attrType.Kind == AttributeKind.MapAttr)
     {
         EmitHelper.ToString((IDictionary)elem.GetAttribute(attrType.Name), out attrTypeString, out attrValueString, attrType, graph);
         attrValueString = Encode(attrValueString);
     }
     else if(attrType.Kind == AttributeKind.ArrayAttr)
     {
         EmitHelper.ToString((IList)elem.GetAttribute(attrType.Name), out attrTypeString, out attrValueString, attrType, graph);
         attrValueString = Encode(attrValueString);
     }
     else if(attrType.Kind == AttributeKind.DequeAttr)
     {
         EmitHelper.ToString((IDeque)elem.GetAttribute(attrType.Name), out attrTypeString, out attrValueString, attrType, graph);
         attrValueString = Encode(attrValueString);
     }
     else
     {
         EmitHelper.ToString(elem.GetAttribute(attrType.Name), out attrTypeString, out attrValueString, attrType, graph);
         attrValueString = Encode(attrValueString);
     }
 }
示例#14
0
        private void ContainerAddIndexed(IGraphElement elem, String attrName, object keyObj, object valueObj)
        {
            object attr = elem.GetAttribute(attrName);

            if(attr is IDictionary)
            {
                IDictionary dict = attr as IDictionary;
                dict[keyObj] = valueObj;
            }
            else if(attr is IList)
            {
                IList array = attr as IList;
                array.Insert((int)valueObj, keyObj);
            }
            else if(attr is IDeque)
            {
                IDeque deque = attr as IDeque;
                deque.EnqueueAt((int)valueObj, keyObj);
            }
            else
                throw new Exception(graph.GetElementName(elem) + "." + attrName + " is neither a map nor an array nor a deque.");
        }
示例#15
0
		//Stolen from GXLExport.cs
		private string CanonizeElement (IGraphElement elem)
		{
				List<String> attributes = new List<String> ();
			foreach (AttributeType attrType in elem.Type.AttributeTypes) {
				object value = elem.GetAttribute (attrType.Name);
				
				String valType;
				String valuestr = (value == null) ? "" : value.ToString ();
				switch (attrType.Kind) {
				case AttributeKind.BooleanAttr:
					valType = "bool";
					valuestr = ((bool)value) ? "true" : "false";
					break;
					
				case AttributeKind.DoubleAttr:
				case AttributeKind.FloatAttr:
					valType = "double";
                    valuestr = ((double)value).ToString(System.Globalization.CultureInfo.InvariantCulture);
                    break;
					
				case AttributeKind.ByteAttr:
				case AttributeKind.ShortAttr:
				case AttributeKind.IntegerAttr:
				case AttributeKind.LongAttr:
					valType = "int";
					break;
					
				// TODO: This does not allow differentiating between empty and null strings
				case AttributeKind.StringAttr:
					valType = "string";
					valuestr= "\"" + valuestr + "\"";
					break;
					
				case AttributeKind.EnumAttr:
					valType = "enum";
					break;
					
				default:
					throw new Exception ("Unsupported attribute value type: \"" + attrType.Kind + "\"");
				}

				attributes.Add (attrType.Name + ":" + valType + ":" + valuestr);
			}

			attributes.Sort ((x,y) => x.CompareTo (y));
	
			string elemTypeName = null;
			string elemClassName = elem.GetType ().Name;

			if (elem is INode) {
				elemTypeName = "Node";
			} else if (elem is IEdge) {
				elemTypeName = "Edge";
			} else {
				elemTypeName = "Unsupported Graph Element Type";
			}

			StringBuilder sb = new StringBuilder (elemClassName + ":" + elemTypeName);

			if (attributes.Count > 0) {
				sb.Append (",");
				for (int i=0; i< (attributes.Count-1); i++) {
					sb.Append (attributes [i] + ",");
				}
			}

			if(attributes.Count > 0)
				sb.Append(attributes[attributes.Count-1]);

			return sb.ToString();
		}
示例#16
0
        //Stolen from GXLExport.cs
        private string CanonizeElement(IGraphElement elem)
        {
            List <String> attributes = new List <String>();

            foreach (AttributeType attrType in elem.Type.AttributeTypes)
            {
                object value = elem.GetAttribute(attrType.Name);

                String valType;
                String valuestr = (value == null) ? "" : value.ToString();
                switch (attrType.Kind)
                {
                case AttributeKind.BooleanAttr:
                    valType  = "bool";
                    valuestr = ((bool)value) ? "true" : "false";
                    break;

                case AttributeKind.DoubleAttr:
                case AttributeKind.FloatAttr:
                    valType  = "double";
                    valuestr = ((double)value).ToString(System.Globalization.CultureInfo.InvariantCulture);
                    break;

                case AttributeKind.ByteAttr:
                case AttributeKind.ShortAttr:
                case AttributeKind.IntegerAttr:
                case AttributeKind.LongAttr:
                    valType = "int";
                    break;

                // TODO: This does not allow differentiating between empty and null strings
                case AttributeKind.StringAttr:
                    valType  = "string";
                    valuestr = "\"" + valuestr + "\"";
                    break;

                case AttributeKind.EnumAttr:
                    valType = "enum";
                    break;

                default:
                    throw new Exception("Unsupported attribute value type: \"" + attrType.Kind + "\"");
                }

                attributes.Add(attrType.Name + ":" + valType + ":" + valuestr);
            }

            attributes.Sort((x, y) => x.CompareTo(y));

            string elemTypeName  = null;
            string elemClassName = elem.GetType().Name;

            if (elem is INode)
            {
                elemTypeName = "Node";
            }
            else if (elem is IEdge)
            {
                elemTypeName = "Edge";
            }
            else
            {
                elemTypeName = "Unsupported Graph Element Type";
            }

            StringBuilder sb = new StringBuilder(elemClassName + ":" + elemTypeName);

            if (attributes.Count > 0)
            {
                sb.Append(",");
                for (int i = 0; i < (attributes.Count - 1); ++i)
                {
                    sb.Append(attributes [i] + ",");
                }
            }

            if (attributes.Count > 0)
            {
                sb.Append(attributes[attributes.Count - 1]);
            }

            return(sb.ToString());
        }
示例#17
0
 public object ExecuteNoImplicitContainerCopy(IGraphProcessingEnvironment procEnv, out IGraphElement elem, out AttributeType attrType)
 {
     elem = SourceValue(procEnv);
     object value = elem.GetAttribute(AttributeName);
     attrType = elem.Type.GetAttributeType(AttributeName);
     return value;
 }
示例#18
0
        private static bool AddSubgraphAsNeeded(MainGraphExportContext mainGraphContext,
            IGraphElement elem, AttributeType attrType)
        {
            if(attrType.Kind == AttributeKind.GraphAttr)
                return AddSubgraphAsNeeded(mainGraphContext, (INamedGraph)elem.GetAttribute(attrType.Name));

            bool graphAdded = false;

            if(attrType.Kind == AttributeKind.SetAttr
                || attrType.Kind == AttributeKind.MapAttr
                || attrType.Kind == AttributeKind.ArrayAttr
                || attrType.Kind == AttributeKind.DequeAttr)
            {
                if(attrType.ValueType.Kind == AttributeKind.GraphAttr)
                {
                    if(attrType.Kind == AttributeKind.SetAttr)
                    {
                        IDictionary set = (IDictionary)elem.GetAttribute(attrType.Name);
                        foreach(DictionaryEntry entry in set)
                        {
                            graphAdded |= AddSubgraphAsNeeded(mainGraphContext, (INamedGraph)entry.Key);
                        }
                    }
                    else if(attrType.Kind == AttributeKind.MapAttr)
                    {
                        IDictionary map = (IDictionary)elem.GetAttribute(attrType.Name);
                        foreach(DictionaryEntry entry in map)
                        {
                            graphAdded |= AddSubgraphAsNeeded(mainGraphContext, (INamedGraph)entry.Value);
                        }
                    }
                    else if(attrType.Kind == AttributeKind.ArrayAttr)
                    {
                        IList array = (IList)elem.GetAttribute(attrType.Name);
                        foreach(object entry in array)
                        {
                            graphAdded |= AddSubgraphAsNeeded(mainGraphContext, (INamedGraph)entry);
                        }
                    }
                    else if(attrType.Kind == AttributeKind.DequeAttr)
                    {
                        IDeque deque = (IDeque)elem.GetAttribute(attrType.Name);
                        foreach(object entry in deque)
                        {
                            graphAdded |= AddSubgraphAsNeeded(mainGraphContext, (INamedGraph)entry);
                        }
                    }
                }
            }

            if(attrType.Kind == AttributeKind.MapAttr)
            {
                if(attrType.KeyType.Kind == AttributeKind.GraphAttr)
                {
                    IDictionary map = (IDictionary)elem.GetAttribute(attrType.Name);
                    foreach(DictionaryEntry entry in map)
                    {
                        graphAdded |= AddSubgraphAsNeeded(mainGraphContext, (INamedGraph)entry.Key);
                    }
                }
            }

            return graphAdded;
        }
        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
        }
示例#20
0
        private void ParseAttributeValueIndexed(IGraphElement elem, AttributeType attrType, string attrName, object index)
        {
            object value = ParseAttributeSimpleValue(attrType);
            object attr = elem.GetAttribute(attrName);

            if(attr is IList)
            {
                IList array = (IList)attr;
                array[(int)index] = value;
            }
            else if(attr is IDeque)
            {
                IDeque deque = (IDeque)attr;
                deque[(int)index] = value;
            }
            else
            {
                IDictionary setmap = (IDictionary)attr;
                setmap[index] = value;
            }
        }
示例#21
0
        private void ContainerRem(IGraphElement elem, String attrName, object keyObj)
        {
            object attr = elem.GetAttribute(attrName);

            if(attr is IDictionary)
            {
                IDictionary dict = attr as IDictionary;
                dict.Remove(keyObj);
            }
            else if(attr is IList)
            {
                IList array = attr as IList;
                if(keyObj != null)
                    array.RemoveAt((int)keyObj);
                else
                    array.RemoveAt(array.Count - 1);
            }
            else if(attr is IDeque)
            {
                IDeque deque = attr as IDeque;
                if(keyObj != null)
                    deque.DequeueAt((int)keyObj);
                else
                    deque.Dequeue();
            }
            else
                throw new Exception(graph.GetElementName(elem) + "." + attrName + " is not a container.");
        }
        public IGraph _graph; // for ToString only

        public LGSPUndoAttributeChanged(IGraphElement elem, AttributeType attrType,
                AttributeChangeType changeType, Object newValue, Object keyValue, 
                LGSPGraphProcessingEnvironment procEnv)
        {
            _elem = elem;
            _attrType = attrType;
            if(procEnv.graph is LGSPNamedGraph) _name = ((LGSPNamedGraph)procEnv.graph).GetElementName(_elem);
            else _name = "?";
            _graph = procEnv.graph;

            if (_attrType.Kind == AttributeKind.SetAttr)
            {
                if (changeType == AttributeChangeType.PutElement)
                {
                    IDictionary dict = (IDictionary)_elem.GetAttribute(_attrType.Name);
                    if (dict.Contains(newValue))
                    {
                        _undoOperation = UndoOperation.None;
                    }
                    else
                    {
                        _undoOperation = UndoOperation.RemoveElement;
                        _value = newValue;
                    }
                }
                else if (changeType == AttributeChangeType.RemoveElement)
                {
                    IDictionary dict = (IDictionary)_elem.GetAttribute(_attrType.Name);
                    if (dict.Contains(newValue))
                    {
                        _undoOperation = UndoOperation.PutElement;
                        _value = newValue;
                    }
                    else
                    {
                        _undoOperation = UndoOperation.None;
                    }
                }
                else // Assign
                {
                    Type keyType, valueType;
                    IDictionary dict = ContainerHelper.GetDictionaryTypes(
                        _elem.GetAttribute(_attrType.Name), out keyType, out valueType);
                    IDictionary clonedDict = ContainerHelper.NewDictionary(keyType, valueType, dict);
                    _undoOperation = UndoOperation.Assign;
                    _value = clonedDict;
                }
            }
            else if (_attrType.Kind == AttributeKind.ArrayAttr)
            {
                if (changeType == AttributeChangeType.PutElement)
                {
                    IList array = (IList)_elem.GetAttribute(_attrType.Name);
                    _undoOperation = UndoOperation.RemoveElement;
                    _keyOfValue = keyValue;
                }
                else if (changeType == AttributeChangeType.RemoveElement)
                {
                    IList array = (IList)_elem.GetAttribute(_attrType.Name);
                    _undoOperation = UndoOperation.PutElement;
                    if(keyValue == null)
                    {
                        _value = array[array.Count-1];
                    }
                    else
                    {
                        _value = array[(int)keyValue];
                        _keyOfValue = keyValue;
                    }
                }
                else if(changeType == AttributeChangeType.AssignElement)
                {
                    IList array = (IList)_elem.GetAttribute(_attrType.Name);
                    _undoOperation = UndoOperation.AssignElement;
                    _value = array[(int)keyValue];
                    _keyOfValue = keyValue;
                }
                else // Assign
                {
                    Type valueType;
                    IList array = ContainerHelper.GetListType(
                        _elem.GetAttribute(_attrType.Name), out valueType);
                    IList clonedArray = ContainerHelper.NewList(valueType, array);
                    _undoOperation = UndoOperation.Assign;
                    _value = clonedArray;
                }
            }
            else if(_attrType.Kind == AttributeKind.DequeAttr)
            {
                if(changeType == AttributeChangeType.PutElement)
                {
                    IDeque deque = (IDeque)_elem.GetAttribute(_attrType.Name);
                    _undoOperation = UndoOperation.RemoveElement;
                    _keyOfValue = keyValue;
                }
                else if(changeType == AttributeChangeType.RemoveElement)
                {
                    IDeque deque = (IDeque)_elem.GetAttribute(_attrType.Name);
                    _undoOperation = UndoOperation.PutElement;
                    if(keyValue == null)
                    {
                        _value = deque.Front;
                    }
                    else
                    {
                        _value = deque[(int)keyValue];
                        _keyOfValue = keyValue;
                    }
                }
                else if(changeType == AttributeChangeType.AssignElement)
                {
                    IDeque deque = (IDeque)_elem.GetAttribute(_attrType.Name);
                    _undoOperation = UndoOperation.AssignElement;
                    _value = deque[(int)keyValue];
                    _keyOfValue = keyValue;
                }
                else // Assign
                {
                    Type valueType;
                    IDeque deque = ContainerHelper.GetDequeType(
                        _elem.GetAttribute(_attrType.Name), out valueType);
                    IDeque clonedDeque = ContainerHelper.NewDeque(valueType, deque);
                    _undoOperation = UndoOperation.Assign;
                    _value = clonedDeque;
                }
            }
            else if(_attrType.Kind == AttributeKind.MapAttr)
            {
                if (changeType == AttributeChangeType.PutElement)
                {
                    IDictionary dict = (IDictionary)_elem.GetAttribute(_attrType.Name);
                    if (dict.Contains(keyValue))
                    {
                        if (dict[keyValue] == newValue)
                        {
                            _undoOperation = UndoOperation.None;
                        }
                        else
                        {
                            _undoOperation = UndoOperation.PutElement;
                            _value = dict[keyValue];
                            _keyOfValue = keyValue;
                        }
                    }
                    else
                    {
                        _undoOperation = UndoOperation.RemoveElement;
                        _value = newValue;
                        _keyOfValue = keyValue;
                    }
                }
                else if (changeType == AttributeChangeType.RemoveElement)
                {
                    IDictionary dict = (IDictionary)_elem.GetAttribute(_attrType.Name);
                    if (dict.Contains(keyValue))
                    {
                        _undoOperation = UndoOperation.PutElement;
                        _value = dict[keyValue];
                        _keyOfValue = keyValue;
                    }
                    else
                    {
                        _undoOperation = UndoOperation.None;
                    }
                }
                else if(changeType == AttributeChangeType.AssignElement)
                {
                    IDictionary dict = (IDictionary)_elem.GetAttribute(_attrType.Name);
                    if(dict[keyValue] == newValue)
                    {
                        _undoOperation = UndoOperation.None;
                    }
                    else
                    {
                        _undoOperation = UndoOperation.AssignElement;
                        _value = dict[keyValue];
                        _keyOfValue = keyValue;
                    }
                }
                else // Assign
                {
                    Type keyType, valueType;
                    IDictionary dict = ContainerHelper.GetDictionaryTypes(
                        _elem.GetAttribute(_attrType.Name), out keyType, out valueType);
                    IDictionary clonedDict = ContainerHelper.NewDictionary(keyType, valueType, dict);
                    _undoOperation = UndoOperation.Assign;
                    _value = clonedDict;
                }
            }
            else // Primitve Type Assign
            {
                _undoOperation = UndoOperation.Assign;
                _value = _elem.GetAttribute(_attrType.Name);
            }
        }
示例#23
0
        private static bool AddSubgraphAsNeeded(MainGraphExportContext mainGraphContext,
                                                IGraphElement elem, AttributeType attrType)
        {
            if (attrType.Kind == AttributeKind.GraphAttr)
            {
                return(AddSubgraphAsNeeded(mainGraphContext, (INamedGraph)elem.GetAttribute(attrType.Name)));
            }

            bool graphAdded = false;

            if (attrType.Kind == AttributeKind.SetAttr ||
                attrType.Kind == AttributeKind.MapAttr ||
                attrType.Kind == AttributeKind.ArrayAttr ||
                attrType.Kind == AttributeKind.DequeAttr)
            {
                if (attrType.ValueType.Kind == AttributeKind.GraphAttr)
                {
                    if (attrType.Kind == AttributeKind.SetAttr)
                    {
                        IDictionary set = (IDictionary)elem.GetAttribute(attrType.Name);
                        foreach (DictionaryEntry entry in set)
                        {
                            graphAdded |= AddSubgraphAsNeeded(mainGraphContext, (INamedGraph)entry.Key);
                        }
                    }
                    else if (attrType.Kind == AttributeKind.MapAttr)
                    {
                        IDictionary map = (IDictionary)elem.GetAttribute(attrType.Name);
                        foreach (DictionaryEntry entry in map)
                        {
                            graphAdded |= AddSubgraphAsNeeded(mainGraphContext, (INamedGraph)entry.Value);
                        }
                    }
                    else if (attrType.Kind == AttributeKind.ArrayAttr)
                    {
                        IList array = (IList)elem.GetAttribute(attrType.Name);
                        foreach (object entry in array)
                        {
                            graphAdded |= AddSubgraphAsNeeded(mainGraphContext, (INamedGraph)entry);
                        }
                    }
                    else if (attrType.Kind == AttributeKind.DequeAttr)
                    {
                        IDeque deque = (IDeque)elem.GetAttribute(attrType.Name);
                        foreach (object entry in deque)
                        {
                            graphAdded |= AddSubgraphAsNeeded(mainGraphContext, (INamedGraph)entry);
                        }
                    }
                }
            }

            if (attrType.Kind == AttributeKind.MapAttr)
            {
                if (attrType.KeyType.Kind == AttributeKind.GraphAttr)
                {
                    IDictionary map = (IDictionary)elem.GetAttribute(attrType.Name);
                    foreach (DictionaryEntry entry in map)
                    {
                        graphAdded |= AddSubgraphAsNeeded(mainGraphContext, (INamedGraph)entry.Key);
                    }
                }
            }

            return(graphAdded);
        }
示例#24
0
        private static String GetElemLabel(IGraphElement elem, DumpInfo dumpInfo)
        {
            List<InfoTag> infoTagTypes = dumpInfo.GetTypeInfoTags(elem.Type);
            String label = dumpInfo.GetElemTypeLabel(elem.Type);
            bool first = true;

            if(label == null)
            {
                label = dumpInfo.GetElementName(elem) + ":" + elem.Type.Name;
                first = false;
            }

            if(infoTagTypes != null)
            {
                foreach(InfoTag infoTag in infoTagTypes)
                {
                    object attr = elem.GetAttribute(infoTag.AttributeType.Name);
                    if(attr == null) continue;

                    if(!first) label += "\n";
                    else first = false;

                    if(infoTag.ShortInfoTag)
                        label += attr.ToString();
                    else
                        label += infoTag.AttributeType.Name + " = " + attr.ToString();
                }
            }

            return label;
        }
示例#25
0
        protected List<Attr> GetAttributes(IGraphElement elem)
        {
            List<Attr> attrs = new List<Attr>();
            foreach(AttributeType attrType in elem.Type.AttributeTypes) {
                object value = elem.GetAttribute(attrType.Name);

                String valType;
                String valuestr = (value == null) ? "" : value.ToString();
                switch(attrType.Kind)
                {
                    case AttributeKind.BooleanAttr:
                        valType = "bool";
                        valuestr = ((bool)value) ? "true" : "false";
                        break;

                    case AttributeKind.DoubleAttr:
                    case AttributeKind.FloatAttr:
                        valType = "double";
                        if(value is float)
                            valuestr = ((float)value).ToString(System.Globalization.CultureInfo.InvariantCulture);
                        else
                            valuestr = ((double)value).ToString(System.Globalization.CultureInfo.InvariantCulture);
                        break;

                    case AttributeKind.ByteAttr:
                    case AttributeKind.ShortAttr:
                    case AttributeKind.IntegerAttr:
                    case AttributeKind.LongAttr:
                        valType = "int"; break;

                    // TODO: This does not allow differentiating between empty and null strings
                    case AttributeKind.StringAttr: valType = "string"; break;

                    case AttributeKind.EnumAttr: valType = "enum"; break;

                    default:
                        throw new Exception("Unsupported attribute value type: \"" + attrType.Kind + "\"");
                }
                attrs.Add(new Attr(attrType.Name, valType, valuestr));
            }
            return attrs;
        }
        public bool FetchObjectToBeShownAsGraph(Sequence seq, out object toBeShownAsGraph, out AttributeType attrType)
        {
            do
            {
                Console.WriteLine("Enter name of variable or attribute access to show as graph (just enter for abort): ");
                Console.WriteLine("Examples: \"v\", \"v.a\", \"@(\"$0\").a\" ");
                String str = Console.ReadLine();
                if (str.Length == 0)
                {
                    toBeShownAsGraph = null;
                    attrType         = null;
                    return(true);
                }

                if (str.StartsWith("@"))
                {
                    // graph element by name
                    string        attributeName;
                    IGraphElement elem = ParseAccessByName(str, out attributeName);
                    if (elem == null)
                    {
                        Console.WriteLine("Can't parse graph access / unknown graph element: " + str);
                        continue;
                    }
                    if (attributeName == null)
                    {
                        Console.WriteLine("The result of a graph access is a node or edge, you must access an attribute: " + str);
                        continue;
                    }
                    attrType = elem.Type.GetAttributeType(attributeName);
                    if (attrType == null)
                    {
                        Console.WriteLine("Unknown attribute: " + attributeName);
                        continue;
                    }
                    object attribute = elem.GetAttribute(attributeName);
                    if (attribute == null)
                    {
                        Console.WriteLine("Null-valued attribute: " + attributeName);
                        continue;
                    }

                    toBeShownAsGraph = attribute;
                    return(false);
                }
                else
                {
                    // variable
                    string attributeName;
                    object value = ParseVariable(str, seq, out attributeName);
                    if (value == null)
                    {
                        Console.WriteLine("Can't parse variable / unknown variable / null-valued variable: " + str);
                        continue;
                    }

                    if (attributeName != null)
                    {
                        if (!(value is IGraphElement))
                        {
                            Console.WriteLine("Can't access attribute, the variable value is not a graph element: " + str);
                            continue;
                        }
                        IGraphElement elem = (IGraphElement)value;
                        attrType = elem.Type.GetAttributeType(attributeName);
                        if (attrType == null)
                        {
                            Console.WriteLine("Unknown attribute: " + attributeName);
                            continue;
                        }
                        object attribute = elem.GetAttribute(attributeName);
                        if (attribute == null)
                        {
                            Console.WriteLine("Null-valued attribute: " + attributeName);
                            continue;
                        }

                        toBeShownAsGraph = attribute;
                        return(false);
                    }
                    else
                    {
                        attrType         = null;
                        toBeShownAsGraph = value;
                        return(false);
                    }
                }
            }while(true);
        }
示例#27
0
        private void ContainerAdd(IGraphElement elem, String attrName, object keyObj)
        {
            object attr = elem.GetAttribute(attrName);

            if(attr is IDictionary)
            {
                IDictionary dict = attr as IDictionary;
                dict[keyObj] = null;
            }
            else if(attr is IList)
            {
                IList array = attr as IList;
                array.Add(keyObj);
            }
            else if(attr is IDeque)
            {
                IDeque deque = attr as IDeque;
                deque.Enqueue(keyObj);
            }
            else
                throw new Exception(graph.GetElementName(elem) + "." + attrName + " is neither a set nor an array nor a deque.");
        }
        public readonly IGraph _graph; // for ToString only

        public LGSPUndoAttributeChanged(IGraphElement elem, AttributeType attrType,
                                        AttributeChangeType changeType, Object newValue, Object keyValue,
                                        LGSPGraphProcessingEnvironment procEnv)
        {
            _elem     = elem;
            _attrType = attrType;
            if (procEnv.graph is LGSPNamedGraph)
            {
                _name = ((LGSPNamedGraph)procEnv.graph).GetElementName(_elem);
            }
            else
            {
                _name = "?";
            }
            _graph = procEnv.graph;

            if (_attrType.Kind == AttributeKind.SetAttr)
            {
                if (changeType == AttributeChangeType.PutElement)
                {
                    IDictionary dict = (IDictionary)_elem.GetAttribute(_attrType.Name);
                    if (dict.Contains(newValue))
                    {
                        _undoOperation = UndoOperation.None;
                    }
                    else
                    {
                        _undoOperation = UndoOperation.RemoveElement;
                        _value         = newValue;
                    }
                }
                else if (changeType == AttributeChangeType.RemoveElement)
                {
                    IDictionary dict = (IDictionary)_elem.GetAttribute(_attrType.Name);
                    if (dict.Contains(newValue))
                    {
                        _undoOperation = UndoOperation.PutElement;
                        _value         = newValue;
                    }
                    else
                    {
                        _undoOperation = UndoOperation.None;
                    }
                }
                else // Assign
                {
                    Type        keyType;
                    Type        valueType;
                    IDictionary dict = ContainerHelper.GetDictionaryTypes(
                        _elem.GetAttribute(_attrType.Name), out keyType, out valueType);
                    IDictionary clonedDict = ContainerHelper.NewDictionary(keyType, valueType, dict);
                    _undoOperation = UndoOperation.Assign;
                    _value         = clonedDict;
                }
            }
            else if (_attrType.Kind == AttributeKind.ArrayAttr)
            {
                if (changeType == AttributeChangeType.PutElement)
                {
                    IList array = (IList)_elem.GetAttribute(_attrType.Name);
                    _undoOperation = UndoOperation.RemoveElement;
                    _keyOfValue    = keyValue;
                }
                else if (changeType == AttributeChangeType.RemoveElement)
                {
                    IList array = (IList)_elem.GetAttribute(_attrType.Name);
                    _undoOperation = UndoOperation.PutElement;
                    if (keyValue == null)
                    {
                        _value = array[array.Count - 1];
                    }
                    else
                    {
                        _value      = array[(int)keyValue];
                        _keyOfValue = keyValue;
                    }
                }
                else if (changeType == AttributeChangeType.AssignElement)
                {
                    IList array = (IList)_elem.GetAttribute(_attrType.Name);
                    _undoOperation = UndoOperation.AssignElement;
                    _value         = array[(int)keyValue];
                    _keyOfValue    = keyValue;
                }
                else // Assign
                {
                    Type  valueType;
                    IList array = ContainerHelper.GetListType(
                        _elem.GetAttribute(_attrType.Name), out valueType);
                    IList clonedArray = ContainerHelper.NewList(valueType, array);
                    _undoOperation = UndoOperation.Assign;
                    _value         = clonedArray;
                }
            }
            else if (_attrType.Kind == AttributeKind.DequeAttr)
            {
                if (changeType == AttributeChangeType.PutElement)
                {
                    IDeque deque = (IDeque)_elem.GetAttribute(_attrType.Name);
                    _undoOperation = UndoOperation.RemoveElement;
                    _keyOfValue    = keyValue;
                }
                else if (changeType == AttributeChangeType.RemoveElement)
                {
                    IDeque deque = (IDeque)_elem.GetAttribute(_attrType.Name);
                    _undoOperation = UndoOperation.PutElement;
                    if (keyValue == null)
                    {
                        _value = deque.Front;
                    }
                    else
                    {
                        _value      = deque[(int)keyValue];
                        _keyOfValue = keyValue;
                    }
                }
                else if (changeType == AttributeChangeType.AssignElement)
                {
                    IDeque deque = (IDeque)_elem.GetAttribute(_attrType.Name);
                    _undoOperation = UndoOperation.AssignElement;
                    _value         = deque[(int)keyValue];
                    _keyOfValue    = keyValue;
                }
                else // Assign
                {
                    Type   valueType;
                    IDeque deque = ContainerHelper.GetDequeType(
                        _elem.GetAttribute(_attrType.Name), out valueType);
                    IDeque clonedDeque = ContainerHelper.NewDeque(valueType, deque);
                    _undoOperation = UndoOperation.Assign;
                    _value         = clonedDeque;
                }
            }
            else if (_attrType.Kind == AttributeKind.MapAttr)
            {
                if (changeType == AttributeChangeType.PutElement)
                {
                    IDictionary dict = (IDictionary)_elem.GetAttribute(_attrType.Name);
                    if (dict.Contains(keyValue))
                    {
                        if (dict[keyValue] == newValue)
                        {
                            _undoOperation = UndoOperation.None;
                        }
                        else
                        {
                            _undoOperation = UndoOperation.PutElement;
                            _value         = dict[keyValue];
                            _keyOfValue    = keyValue;
                        }
                    }
                    else
                    {
                        _undoOperation = UndoOperation.RemoveElement;
                        _value         = newValue;
                        _keyOfValue    = keyValue;
                    }
                }
                else if (changeType == AttributeChangeType.RemoveElement)
                {
                    IDictionary dict = (IDictionary)_elem.GetAttribute(_attrType.Name);
                    if (dict.Contains(keyValue))
                    {
                        _undoOperation = UndoOperation.PutElement;
                        _value         = dict[keyValue];
                        _keyOfValue    = keyValue;
                    }
                    else
                    {
                        _undoOperation = UndoOperation.None;
                    }
                }
                else if (changeType == AttributeChangeType.AssignElement)
                {
                    IDictionary dict = (IDictionary)_elem.GetAttribute(_attrType.Name);
                    if (dict[keyValue] == newValue)
                    {
                        _undoOperation = UndoOperation.None;
                    }
                    else
                    {
                        _undoOperation = UndoOperation.AssignElement;
                        _value         = dict[keyValue];
                        _keyOfValue    = keyValue;
                    }
                }
                else // Assign
                {
                    Type        keyType, valueType;
                    IDictionary dict = ContainerHelper.GetDictionaryTypes(
                        _elem.GetAttribute(_attrType.Name), out keyType, out valueType);
                    IDictionary clonedDict = ContainerHelper.NewDictionary(keyType, valueType, dict);
                    _undoOperation = UndoOperation.Assign;
                    _value         = clonedDict;
                }
            }
            else // Primitve Type Assign
            {
                _undoOperation = UndoOperation.Assign;
                _value         = _elem.GetAttribute(_attrType.Name);
            }
        }
示例#29
0
        public static void AssignAttributeIndexed(object target, object key, object value, string attributeName, IGraph graph)
        {
            if (target is IGraphElement)
            {
                IGraphElement elem      = (IGraphElement)target;
                object        container = elem.GetAttribute(attributeName);
                AttributeType attrType  = elem.Type.GetAttributeType(attributeName);

                BaseGraph.ChangingAttributeAssignElement(graph, elem, attrType, value, key);

                if (container is IList)
                {
                    IList array = (IList)container;
                    array[(int)key] = value;
                }
                else if (container is IDeque)
                {
                    IDeque deque = (IDeque)container;
                    deque[(int)key] = value;
                }
                else
                {
                    IDictionary map = (IDictionary)container;
                    map[key] = value;
                }

                BaseGraph.ChangedAttribute(graph, elem, attrType);
            }
            else if (target is IObject)
            {
                IObject       elem      = (IObject)target;
                object        container = elem.GetAttribute(attributeName);
                AttributeType attrType  = elem.Type.GetAttributeType(attributeName);

                if (container is IList)
                {
                    IList array = (IList)container;
                    array[(int)key] = value;
                }
                else if (container is IDeque)
                {
                    IDeque deque = (IDeque)container;
                    deque[(int)key] = value;
                }
                else
                {
                    IDictionary map = (IDictionary)container;
                    map[key] = value;
                }
            }
            else
            {
                ITransientObject elem      = (ITransientObject)target;
                object           container = elem.GetAttribute(attributeName);
                AttributeType    attrType  = elem.Type.GetAttributeType(attributeName);

                if (container is IList)
                {
                    IList array = (IList)container;
                    array[(int)key] = value;
                }
                else if (container is IDeque)
                {
                    IDeque deque = (IDeque)container;
                    deque[(int)key] = value;
                }
                else
                {
                    IDictionary map = (IDictionary)container;
                    map[key] = value;
                }
            }
        }
示例#30
0
        public static IList Extract(object container, string memberOrAttribute, IGraphProcessingEnvironment procEnv)
        {
            IList  array          = (IList)container;
            string arrayType      = TypesHelper.DotNetTypeToXgrsType(array.GetType());
            string arrayValueType = TypesHelper.ExtractSrc(arrayType);

            if (arrayValueType.StartsWith("match<"))
            {
                if (arrayValueType == "match<>")
                {
                    if (array.Count > 0)
                    {
                        IMatch match        = (IMatch)array[0];
                        object matchElement = match.GetMember(memberOrAttribute);
                        Type   matchElementType;
                        if (matchElement is IGraphElement)
                        {
                            matchElementType = TypesHelper.GetType(((IGraphElement)matchElement).Type, procEnv.Graph.Model);
                        }
                        else
                        {
                            matchElementType = matchElement.GetType();
                        }
                        Type  listType       = typeof(List <>).MakeGenericType(matchElementType);
                        IList extractedArray = (IList)Activator.CreateInstance(listType);
                        ExtractMatchMember(array, memberOrAttribute, extractedArray);
                        return(extractedArray);
                    }
                    else
                    {
                        return(new List <object>());
                    }
                }
                else
                {
                    if (arrayValueType.StartsWith("match<class "))
                    {
                        MatchClassFilterer matchClass  = procEnv.Actions.GetMatchClass(TypesHelper.GetMatchClassName(arrayValueType));
                        IPatternElement    element     = matchClass.info.GetPatternElement(memberOrAttribute);
                        GrGenType          elementType = element.Type;
                        Type  listType       = typeof(List <>).MakeGenericType(TypesHelper.GetType(elementType, procEnv.Graph.Model));
                        IList extractedArray = (IList)Activator.CreateInstance(listType);
                        ExtractMatchMember(array, memberOrAttribute, extractedArray);
                        return(extractedArray);
                    }
                    else
                    {
                        IAction         action         = procEnv.Actions.GetAction(TypesHelper.GetRuleName(arrayValueType));
                        IPatternElement element        = action.RulePattern.PatternGraph.GetPatternElement(memberOrAttribute);
                        GrGenType       elementType    = element.Type;
                        Type            listType       = typeof(List <>).MakeGenericType(TypesHelper.GetType(elementType, procEnv.Graph.Model));
                        IList           extractedArray = (IList)Activator.CreateInstance(listType);
                        ExtractMatchMember(array, memberOrAttribute, extractedArray);
                        return(extractedArray);
                    }
                }
            }
            else
            {
                GrGenType graphElementType = TypesHelper.GetNodeOrEdgeType(arrayValueType, procEnv.Graph.Model);
                if (graphElementType != null)
                {
                    AttributeType attributeType  = graphElementType.GetAttributeType(memberOrAttribute);
                    Type          listType       = typeof(List <>).MakeGenericType(attributeType.Type);
                    IList         extractedArray = (IList)Activator.CreateInstance(listType);
                    ExtractAttribute(array, memberOrAttribute, extractedArray);
                    return(extractedArray);
                }
                else
                {
                    if (array.Count > 0)
                    {
                        IGraphElement graphElement = (IGraphElement)array[0];
                        object        element      = graphElement.GetAttribute(memberOrAttribute);
                        Type          elementType;
                        if (element is IGraphElement)
                        {
                            elementType = TypesHelper.GetType(((IGraphElement)element).Type, procEnv.Graph.Model);
                        }
                        else
                        {
                            elementType = element.GetType();
                        }
                        Type  listType       = typeof(List <>).MakeGenericType(elementType);
                        IList extractedArray = (IList)Activator.CreateInstance(listType);
                        ExtractAttribute(array, memberOrAttribute, extractedArray);
                        return(extractedArray);
                    }
                    else
                    {
                        return(new List <object>());
                    }
                }
            }
        }
示例#31
0
        public void RetypingElement(IGraphElement oldElem, IGraphElement newElem)
        {
            bool      isNode  = oldElem is INode;
            GrGenType oldType = oldElem.Type;
            GrGenType newType = newElem.Type;

            if (isNode)
            {
                if (dumpInfo.IsExcludedNodeType((NodeType)oldType))
                {
                    return;
                }
            }
            else
            {
                if (dumpInfo.IsExcludedEdgeType((EdgeType)oldType))
                {
                    return;
                }
            }

            String elemKind       = isNode ? "Node" : "Edge";
            String elemNamePrefix = isNode ? "n" : "e";
            String name           = elemNamePrefix + graph.GetElementName(oldElem);

            ycompStream.Write("set" + elemKind + "Label \"" + name + "\" \"" + GetElemLabel(newElem) + "\"\n");

            // remove the old attributes
            foreach (AttributeType attrType in oldType.AttributeTypes)
            {
                ycompStream.Write("clear" + elemKind + "Attr \"" + name + "\" \"" + attrType.OwnerType.Name + "::"
                                  + attrType.Name + " : " + GetKindName(attrType) + "\"\n");
            }
            // set the new attributes
            foreach (AttributeType attrType in newType.AttributeTypes)
            {
                object attr       = newElem.GetAttribute(attrType.Name);
                String attrString = (attr != null) ? attr.ToString() : "<Not initialized>";
                ycompStream.Write("change" + elemKind + "Attr \"" + name + "\" \"" + attrType.OwnerType.Name + "::"
                                  + attrType.Name + " : " + GetKindName(attrType) + "\" \"" + attrString + "\"\n");
            }

            if (isNode)
            {
                String oldNr = GetNodeRealizer((NodeType)oldType);
                String newNr = GetNodeRealizer((NodeType)newType);
                if (oldNr != newNr)
                {
                    ChangeNode((INode)oldElem, newNr);
                }
            }
            else
            {
                String oldEr = GetEdgeRealizer((EdgeType)oldType);
                String newEr = GetEdgeRealizer((EdgeType)newType);
                if (oldEr != newEr)
                {
                    ChangeEdge((IEdge)oldElem, newEr);
                }
            }
            isDirty = true;
        }
示例#32
0
 /// <summary>
 /// Dumps all attributes in the form "kind owner::name = value" into a String List
 /// </summary>
 /// <param name="elem">IGraphElement which attributes are to be dumped</param>
 /// <returns>A String List containing the dumped attributes </returns>
 private static List<String> DumpAttributes(IGraphElement elem)
 {
     List<String> attribs = new List<String>();
     foreach(AttributeType attrType in elem.Type.AttributeTypes)
     {
         object attr = elem.GetAttribute(attrType.Name);
         String attrString = (attr != null) ? attr.ToString() : "<Not initialized>";
         attribs.Add(String.Format("{0}::{1} : {2} = {3}",
             attrType.OwnerType.Name, attrType.Name, attrType.GetKindName(), attrString));
     }
     return attribs;
 }