Ejemplo n.º 1
0
 public static object GetAttributeOrElementOfMatch(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
     {
         IAttributeBearer attributeBearer = (IAttributeBearer)source;
         object           value           = attributeBearer.GetAttribute(attributeOrElementName);
         value = attributeBearer is ITransientObject ? value : ContainerHelper.IfAttributeOfElementIsContainerThenCloneContainer(
             attributeBearer, attributeOrElementName, value);
         return(value);
     }
 }
Ejemplo n.º 2
0
        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
        }
Ejemplo n.º 3
0
        public readonly IGraph _graph; // for ToString only

        public LGSPUndoAttributeChanged(IAttributeBearer elem, AttributeType attrType,
                                        AttributeChangeType changeType, object newValue, object keyValue,
                                        LGSPGraphProcessingEnvironment procEnv)
        {
            _elem     = elem;
            _attrType = attrType;
            if (procEnv.graph is LGSPNamedGraph)
            {
                if (_elem is IGraphElement)
                {
                    _name = ((LGSPNamedGraph)procEnv.graph).GetElementName((IGraphElement)_elem);
                }
                else
                {
                    _name = "hash" + _elem.GetHashCode();
                }
            }
            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);
            }
        }