Ejemplo n.º 1
0
        internal bool NotifyChanging(object sender, XObjectChangeEventArgs e)
        {
            bool    flag   = false;
            XObject parent = this;

            while (true)
            {
                while ((parent != null) && (parent.annotations == null))
                {
                    parent = parent.parent;
                }
                if (parent == null)
                {
                    return(flag);
                }
                XObjectChangeAnnotation annotation = parent.Annotation <XObjectChangeAnnotation>();
                if (annotation != null)
                {
                    flag = true;
                    if (annotation.changing != null)
                    {
                        annotation.changing(sender, e);
                    }
                }
                parent = parent.parent;
            }
        }
Ejemplo n.º 2
0
        internal bool NotifyChanging(object sender, XObjectChangeEventArgs e)
        {
            bool    notify = false;
            XObject o      = this;

            while (true)
            {
                while (o != null && o.annotations == null)
                {
                    o = o.parent;
                }
                if (o == null)
                {
                    break;
                }
                XObjectChangeAnnotation a = o.Annotation <XObjectChangeAnnotation>();
                if (a != null)
                {
                    notify = true;
                    if (a.changing != null)
                    {
                        a.changing(sender, e);
                    }
                }
                o = o.parent;
            }
            return(notify);
        }
Ejemplo n.º 3
0
 public void OnChanging(object sender, XObjectChangeEventArgs e)
 {
     Console.WriteLine();
     Console.WriteLine("OnChanging:");
     Console.WriteLine("EventType: {0}", e.ObjectChange);
     Console.WriteLine("Object: {0}", ((XNode)sender).ToString(SaveOptions.None));
 }
        void document_Changed(object sender, XObjectChangeEventArgs e)
        {
            if (UseAutoSaveOperationHistory)
            {
                XObject senderObject = (XObject)sender;

                if (senderObject is XAttribute)
                {
                    switch (e.ObjectChange)
                    {
                        case XObjectChange.Add:
                        case XObjectChange.Remove:
                        case XObjectChange.Value:
                            AddOperationHistory(new AttributeChangedCache((XAttribute)senderObject));
                            break;
                    }
                }
                else if (senderObject is XElement && e.ObjectChange == XObjectChange.Add)
                {
                    AddOperationHistory(new ElementAddedCache((XElement)senderObject));
                }
                else if (senderObject is XText && e.ObjectChange == XObjectChange.Add)
                {
                    AddOperationHistory(new XTextChangedCache((XText)senderObject));
                }
            }
        }
Ejemplo n.º 5
0
 public void Changed(object sender, XObjectChangeEventArgs e)
 {
     TestLog.Compare(_pending.Sender, sender, "Mismatch in changed and changing events");
     TestLog.Compare(_pending.EventArgs, e, "Mismatch in changed and changing events");
     _events.Enqueue(_pending);
     _pending = null;
 }
Ejemplo n.º 6
0
 private static void ElementChangedHandler(object sender, XObjectChangeEventArgs e)
 {
     XDocument xDocument = ((XObject)sender).Document;
     if (xDocument != null)
     {
         xDocument.Changing -= ElementChanged;
         xDocument.Changed -= ElementChanged;
         xDocument.AddAnnotation(new ChangedSemaphore());
     }
 }
Ejemplo n.º 7
0
 void OnChanged(object sender, XObjectChangeEventArgs args)
 {
     if (Changed != null)
     {
         Changed(sender, args);
     }
     if (Owner != null)
     {
         Owner.OnChanged(sender, args);
     }
 }
Ejemplo n.º 8
0
 void OnChanged(object sender, XObjectChangeEventArgs args)
 {
     if (Changed != null)
     {
         Changed(sender, args);
     }
     if (Parent != null)
     {
         Parent.OnChanged(sender, args);
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Fire the changed event.
        /// </summary>
        internal void NotifyChanged(object sender, XObjectChangeEventArgs args)
        {
            var x = this;

            while (x != null)
            {
                var ann = x.Annotation <XObjectChangeAnnotation>();
                if ((ann != null) && (ann.Changed != null))
                {
                    ann.Changed(sender, args);
                }
                x = x.Parent;
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Fire the changing event.
        /// </summary>
        /// <return>true if any eventhandler is found.</return>
        internal bool NotifyChanging(object sender, XObjectChangeEventArgs args)
        {
            var x      = this;
            var result = false;

            while (x != null)
            {
                var ann = x.Annotation <XObjectChangeAnnotation>();
                if (ann != null)
                {
                    result = true;
                    if (ann.Changing != null)
                    {
                        ann.Changing(sender, args);
                    }
                }
                x = x.Parent;
            }
            return(result);
        }
Ejemplo n.º 11
0
 // Changingイベントハンドラ
 private void OnNodeChanging(object sender, XObjectChangeEventArgs e)
 {
     Output.WriteLine("Changing: sender--{0}:{1}, ObjectChange--{2}", sender.GetType().Name, sender, e.ObjectChange);
 }
Ejemplo n.º 12
0
 private void document_Changed(object sender, XObjectChangeEventArgs e)
 {
     this.isDirty = true;
 }
 protected void OnBeforeChangingCurrent(object sender, XObjectChangeEventArgs e)
 {
     _hasCurrentChanged = true;
 }
Ejemplo n.º 14
0
        private void OnAfterChange(object sender, XObjectChangeEventArgs e)
        {
            var valid = false;

            if (_trustedExtension)
            {
                valid = true;
            }
            else
            {
                var node = sender as XObject;
                if (node is XElement
                    || node is XAttribute)
                {
                    // this was validated by the 'before' event
                    valid = true;
                }
                else
                {
                    if (node.Parent == null
                        && e == XObjectChangeEventArgs.Remove)
                    {
                        // we are removing something besides an element or attribute
                        // and we don't have a parent so assume we are ok ('before' event
                        // would have caught a bad edit)
                        valid = true;
                    }
                    else
                    {
                        // might be a text node, whitespace node, etc., so find its first XElement parent
                        while (node.Parent != null)
                        {
                            node = node.Parent;
                            var xElement = node as XElement;
                            if (xElement != null)
                            {
                                valid = VerifyUserEdit(xElement);
                                break;
                            }
                        }
                    }
                }
            }

            if (!valid)
            {
                throw new InvalidOperationException(Resources.Extensibility_ChangeScope_EditingWrongNamespace);
            }
        }
Ejemplo n.º 15
0
 public void ChangedDelegate(object sender, XObjectChangeEventArgs e) { }
Ejemplo n.º 16
0
        void document_Changed(object sender, XObjectChangeEventArgs args)
        {
            Contract.Requires<ArgumentNullException>(sender != null);
            Contract.Requires<ArgumentNullException>(args != null);

            // store parent for subtree dispatch
            var obj = (XObject)sender;
            var par = (XNode)obj.Parent ?? (XNode)obj.Document;
            if (par != null)
                subtreeDispatchList.AddLast(par);

            switch (args.ObjectChange)
            {
                case XObjectChange.Add:
                    OnAdded(obj);
                    break;
                case XObjectChange.Remove:
                    break;
                case XObjectChange.Value:
                    break;
                case XObjectChange.Name:
                    break;
            }
        }
        void document_Changing(object sender, XObjectChangeEventArgs e)
        {
            if (this.UseAutoSaveOperationHistory)
            {
                XObject senderObject = (XObject)sender;

                switch (e.ObjectChange)
                {
                    case XObjectChange.Remove:
                        if (senderObject is XText)
                        {
                            // 削除されるオブジェクトをキャッシュしておく.
                            XTextChangedCache.SetOldValue((XText)senderObject);
                        }
                        else if (senderObject is XAttribute)
                        {
                            AttributeChangedCache.SetOldValue((XAttribute)senderObject);
                        }
                        else if (sender is XElement)
                        {
                            AddOperationHistory(new ElementRemovedCache((XElement)sender));
                        }

                        break;
                    case XObjectChange.Value:
                        if (senderObject is XAttribute)
                        {
                            AttributeChangedCache.SetOldValue((XAttribute)senderObject);
                        }
                        break;
                }
            }
        }
Ejemplo n.º 18
0
 public void Changing(object sender, XObjectChangeEventArgs e)
 {
     if (_pending != null)
         throw new NotImplementedException();
     _pending = new EventItem((XObject)sender, e);
 }
Ejemplo n.º 19
0
 void Changed(object sender, XObjectChangeEventArgs e)
 {
     _pending.Group = _lastGroup;
     if (_undoing)
     {
         _redos.Push(_pending);
     }
     else
     {
         _undos.Push(_pending);
     }
     _pending = null;
 }
Ejemplo n.º 20
0
 void Changing(object sender, XObjectChangeEventArgs e)
 {
     if (_pending != null) throw new NotImplementedException();
     switch (e.ObjectChange)
     {
         case XObjectChange.Add:
             _pending = new AddUnit((XObject)sender);
             break;
         case XObjectChange.Remove:
             XContainer parent = ((XObject)sender).Parent;
             if (parent == null)
             {
                 parent = ((XObject)sender).Document;
             }
             XObject next = null;
             if (sender is XNode)
             {
                 next = ((XNode)sender).NextNode;
             }
             else if (sender is XAttribute)
             {
                 next = ((XAttribute)sender).NextAttribute;
             }
             _pending = new RemoveUnit((XObject)sender, parent, next);
             break;
         case XObjectChange.Name:
             object name = null;
             if (sender is XNode)
             {
                 switch (((XNode)sender).NodeType)
                 {
                     case XmlNodeType.Element:
                         name = ((XElement)sender).Name;
                         break;
                     case XmlNodeType.ProcessingInstruction:
                         name = ((XProcessingInstruction)sender).Target;
                         break;
                     default:
                         throw new NotImplementedException();
                 }
             }
             _pending = new NameUnit((XNode)sender, name);
             break;
         case XObjectChange.Value:
             string value = null;
             if (sender is XNode)
             {
                 switch (((XNode)sender).NodeType)
                 {
                     case XmlNodeType.Element:
                         value = ((XElement)sender).IsEmpty ? null : string.Empty;
                         break;
                     case XmlNodeType.Text:
                     case XmlNodeType.CDATA:
                         value = ((XText)sender).Value;
                         break;
                     case XmlNodeType.ProcessingInstruction:
                         value = ((XProcessingInstruction)sender).Data;
                         break;
                     case XmlNodeType.Comment:
                         value = ((XComment)sender).Value;
                         break;
                     default:
                         throw new NotImplementedException();
                 }
             }
             else if (sender is XAttribute)
             {
                 value = ((XAttribute)sender).Value;
             }
             _pending = new ValueUnit((XObject)sender, value);
             break;
     }
 }
Ejemplo n.º 21
0
 public EventItem(XObject sender, XObjectChangeEventArgs eventArgs)
 {
     _sender = sender;
     _eventArgs = eventArgs;
 }
Ejemplo n.º 22
0
 private void PatternDocument_Changed(object sender, XObjectChangeEventArgs e)
 {
     _needsDocumentUpdate = true;
 }
Ejemplo n.º 23
0
 private void OnBeforeChange(object sender, XObjectChangeEventArgs e)
 {
     if (XmlModelProvider.CurrentTransaction == null)
     {
         //throw new InvalidOperationException(Resources.ChangingModelOutsideTransaction);
     }
 }
Ejemplo n.º 24
0
 private void MasterXDocument_Changed(object sender, XObjectChangeEventArgs e)
 {
     // TODO: Do we need to check if Text is dirty?  Not like we could revert the XDocumentChange
     if (!_textChanging)
     {
         _documentChanging = true;
         Text = XDocument.ToString();
         _documentChanging = false;
     }
 }
 private void OnLibraryDocumentChanged( object sender, XObjectChangeEventArgs args )
 {
     if( args.ObjectChange == XObjectChange.Add || args.ObjectChange == XObjectChange.Remove )
     {
         SaveLibrary();
     }
 }
 private void OnBeforeChange(object sender, XObjectChangeEventArgs e)
 {
     throw new InvalidOperationException(Resources.Extensibility_CantEditOriginalOnSave);
 }
Ejemplo n.º 27
0
        void AnnotationElement_Changed(object sender, XObjectChangeEventArgs e)
        {
            //nb: the e.ObjectChange arg appears to be about what happened inside the element, not
            //really what we care about here. So we just say its modified and don't worry about
            //what it was

            var element = sender as XElement;
            XElement annotationElement = element.AncestorsAndSelf("annotation").First();
            _observers.ForEach(index => index.NotifyOfModification(new Annotation(annotationElement)));
            _isDirty = true;
        }
 void parentChanged(object sender, XObjectChangeEventArgs e)
 {
     var change = e.ObjectChange;
 }
        private void OnAfterChange(object sender, XObjectChangeEventArgs e)
        {
            var node = sender as XObject;
            var action = e.ObjectChange;
            XmlModelCommand commandToAdd = null;

            XElement element = null;
            XAttribute attribute = null;
            XText text = null;
            XProcessingInstruction pi = null;
            XComment comment = null;

            switch (action)
            {
                case XObjectChange.Add:
                    var addChange = currentChange as AddNodeChangeInternal;
                    addChange.Parent = node.Parent;
                    if (addChange.Parent == null)
                    {
                        addChange.Parent = node.Document;
                    }
                    var attrib = (node as XAttribute);
                    if (attrib != null)
                    {
                        addChange.NextNode = attrib.NextAttribute;
                        var stableAttr = attrib.PreviousAttribute;
                        while (stableAttr != null
                               && nodesAdded.ContainsKey(stableAttr))
                        {
                            stableAttr = stableAttr.PreviousAttribute;
                        }
                        addChange.lastStableAttribute = stableAttr;
                    }
                    else
                    {
                        addChange.NextNode = (node as XNode).NextNode;
                    }

                    commandToAdd = cmdFactory.CreateAddNodeCommand((VanillaXmlModelProvider)tx.Provider, addChange);
                    break;
                case XObjectChange.Remove:
                    var removeChange = currentChange as RemoveNodeChange;
                    commandToAdd = cmdFactory.CreateRemoveNodeCommand((VanillaXmlModelProvider)tx.Provider, removeChange);
                    break;
                case XObjectChange.Name:
                    var nameChange = currentChange as NodeNameChange;
                    if ((element = node as XElement) != null)
                    {
                        nameChange.NewName = element.Name;
                    }
                    else if ((pi = node as XProcessingInstruction) != null)
                    {
                        nameChange.NewName = XName.Get(pi.Target);
                    }
                    commandToAdd = cmdFactory.CreateSetNameCommand((VanillaXmlModelProvider)tx.Provider, nameChange);
                    break;
                case XObjectChange.Value:
                    var valueChange = currentChange as NodeValueChange;
                    if ((element = node as XElement) != null)
                    {
                        valueChange.NewValue = element.Value;
                    }
                    else if ((attribute = node as XAttribute) != null)
                    {
                        valueChange.NewValue = attribute.Value;
                    }
                    else if ((text = node as XText) != null)
                    {
                        valueChange.NewValue = text.Value;
                    }
                    else if ((comment = node as XComment) != null)
                    {
                        valueChange.NewValue = comment.Value;
                    }
                    else if ((pi = node as XProcessingInstruction) != null)
                    {
                        valueChange.NewValue = pi.Data;
                    }

                    commandToAdd = cmdFactory.CreateSetValueCommand((VanillaXmlModelProvider)tx.Provider, valueChange);
                    break;
            }
            AddCommand(commandToAdd);
            undoCommands.Add(commandToAdd); // always record full undo command list.
        }
Ejemplo n.º 30
0
        private void OnBeforeChange(object sender, XObjectChangeEventArgs e)
        {
            if (_isComplete)
            {
                throw new InvalidOperationException(Resources.Extensibility_ChangeScope_AlreadyComplete);
            }

            var valid = false;

            if (_trustedExtension)
            {
                valid = true;
            }
            else
            {
                var node = sender as XObject;
                if (node is XElement)
                {
                    valid = VerifyUserEdit(node as XElement);
                }
                else if (node is XAttribute)
                {
                    valid = VerifyUserEdit(node as XAttribute);
                }
                else
                {
                    if (node.Parent == null
                        && e == XObjectChangeEventArgs.Add)
                    {
                        // if we aren't an element or attribute, and we don't have
                        // a parent yet, assume we are valid for now ('after' event will check
                        // since it will be hooked up to its parent then)
                        valid = true;
                    }
                    else
                    {
                        // might be a text node, whitespace node, etc., so find its first XElement parent
                        while (node.Parent != null)
                        {
                            node = node.Parent;
                            if (node is XElement)
                            {
                                valid = VerifyUserEdit(node as XElement);
                                break;
                            }
                        }
                    }
                }
            }

            if (!valid)
            {
                throw new InvalidOperationException(Resources.Extensibility_ChangeScope_EditingWrongNamespace);
            }
        }
 protected void OnBeforeChange(object sender, XObjectChangeEventArgs e)
 {
     throw new InvalidOperationException(Resources.Extensibility_CantEditModel);
 }
        private void OnBeforeChange(object sender, XObjectChangeEventArgs e)
        {
            var node = sender as XObject;

            // We do not allow editing DTDs through XmlModel
            if (node is XDocumentType)
            {
                var msg = String.Format(CultureInfo.CurrentCulture, Resources.VanillaProvider_DtdNodesReadOnly);
                throw new NotSupportedException(msg);
            }
            var action = e.ObjectChange;
            currentChange = null;

            XElement element = null;
            XAttribute attribute = null;
            XText text = null;
            XProcessingInstruction pi = null;
            XComment comment = null;

            switch (action)
            {
                case XObjectChange.Add:
                    var addChange = new AddNodeChangeInternal(node, action);
                    currentChange = addChange;
                    break;
                case XObjectChange.Remove:
                    var removeChange = new RemoveNodeChange(node, action);
                    removeChange.Parent = node.Parent;
                    if (removeChange.Parent == null)
                    {
                        removeChange.Parent = node.Document;
                    }
                    var attrib = (node as XAttribute);
                    if (attrib != null)
                    {
                        removeChange.NextNode = attrib.NextAttribute;
                    }
                    else
                    {
                        removeChange.NextNode = (node as XNode).NextNode;
                    }
                    currentChange = removeChange;
                    break;
                case XObjectChange.Name:
                    var nameChange = new NodeNameChange(node, action);
                    if ((element = node as XElement) != null)
                    {
                        nameChange.OldName = element.Name;
                    }
                    else if ((pi = node as XProcessingInstruction) != null)
                    {
                        nameChange.OldName = XName.Get(pi.Target);
                    }
                    else
                    {
                        Debug.Assert(false, "The name of something changed that we're not handling here!");
                        throw new NotSupportedException();
                    }
                    currentChange = nameChange;
                    break;
                case XObjectChange.Value:
                    var valueChange = new NodeValueChange(node, action);
                    if ((element = node as XElement) != null)
                    {
                        valueChange.OldValue = element.Value;
                    }
                    else if ((attribute = node as XAttribute) != null)
                    {
                        valueChange.OldValue = attribute.Value;
                    }
                    else if ((text = node as XText) != null)
                    {
                        valueChange.OldValue = text.Value;
                        if (text.Parent != null)
                        {
                            valueChange.Parent = text.Parent;
                        }
                        else
                        {
                            valueChange.Parent = text.Document;
                        }
                    }
                    else if ((comment = node as XComment) != null)
                    {
                        valueChange.OldValue = comment.Value;
                    }
                    else if ((pi = node as XProcessingInstruction) != null)
                    {
                        valueChange.OldValue = pi.Data;
                    }
                    else
                    {
                        Debug.Assert(false, "The value of something changed that we're not handling here!");
                        throw new NotSupportedException();
                    }
                    currentChange = valueChange;
                    break;
            }
        }