示例#1
0
        private void OnSerializing(StreamingContext context)
        {
            DataElement.CloneContext ctx = context.Context as DataElement.CloneContext;
            if (ctx == null)
            {
                return;
            }

            if (DataElement.DebugClone)
            {
                logger.Debug("Serializing From={0}, Of={1}",
                             _of == null ? "(null) " + _ofName : _of.fullName,
                             _from == null ? "(null) " + _fromName : _from.fullName);
            }

            System.Diagnostics.Debug.Assert(_fullNames == null);
            System.Diagnostics.Debug.Assert(!ctx.metadata.ContainsKey(this));

            string relName;

            _fullNames = new FullNames();
            Metadata m = new Metadata();

            if (ctx.rename.Contains(_of))
            {
                m.ofName = _ofName;
                _ofName  = ctx.newName;
            }
            else if (_of != null && !_of.isChildOf(ctx.root, out relName))
            {
                _fullNames.of = relName;
                ctx.elements[_fullNames.of] = _of;
                m.of = _of;
                _of  = null;
            }
            else if (_ofName == ctx.oldName && parent.find(_ofName) == null)
            {
                if (_of == null && ctx.oldName == _ofName)
                {
                    _of = ctx.root;
                }

                m.ofName = _ofName;
                _ofName  = ctx.newName;
            }

            if (ctx.rename.Contains(_from))
            {
                m.fromName = _fromName;
                _fromName  = ctx.newName;
            }
            else if (_from != null && !_from.isChildOf(ctx.root, out relName))
            {
                _fullNames.from = relName;
                ctx.elements[_fullNames.from] = _from;
                m.from = _from;
                _from  = null;
            }
            else if (_fromName == ctx.oldName && parent.find(_fromName) == null)
            {
                if (_from == null && ctx.oldName == _fromName)
                {
                    _from = ctx.root;
                }

                m.fromName = _fromName;
                _fromName  = ctx.newName;
            }

            if (ctx.rename.Contains(_parent))
            {
                if (_of == null && _ofName == ctx.oldName)
                {
                    m.ofName = _ofName;
                    _ofName  = ctx.newName;
                }
                if (_from == null && _fromName == ctx.oldName)
                {
                    m.fromName = _fromName;
                    _fromName  = ctx.newName;
                }
            }
            else if (_parent != null && !_parent.isChildOf(ctx.root, out relName))
            {
                _fullNames.parent = relName;
                ctx.elements[_fullNames.parent] = _parent;
                m.parent = _parent;
                _parent  = null;
            }

            if (m.from != null || m.of != null || m.parent != null || m.ofName != null || m.fromName != null)
            {
                ctx.metadata.Add(this, m);
            }
        }
示例#2
0
            private bool InSourceGraph(DataElement elem)
            {
                var top = root.getRoot();

                return(elem == top || elem.isChildOf(top));
            }