Exemplo n.º 1
0
        internal void RegisterNewItem(ClientXObject <TKind> _child, Guid _collectionOwnerUid, int _fieldId)
        {
            var ownerDescriptor = GetDescriptor(_collectionOwnerUid);
            ClientXObjectDescriptor <TKind> childDescriptor;

            if (m_descriptors.TryGetValue(_child.Uid, out childDescriptor))
            {
                if (!childDescriptor.CollectionOwnerUid.Equals(_collectionOwnerUid))
                {
                    throw new ApplicationException("Object owned by another parent");
                }
                ProcessAddedToCollection(_child, ownerDescriptor, _fieldId);
                return;
                //throw new ApplicationException("Object is not unique");
            }

            var kindId = KindToInt(_child.Kind);
            var report = new XReport(_child.Uid, _child.GetChanges(), kindId, EState.SINGLE);

            m_transport.AddNew(report, m_sessionId, _collectionOwnerUid);

            var descriptor = new ClientXObjectDescriptor <TKind>(_child, this, kindId, _collectionOwnerUid);

            m_descriptors.Add(_child.Uid, descriptor);

            ProcessAddedToCollection(_child, ownerDescriptor, _fieldId);
            _child.SetClientInternal(this);
            _child.OnInstantiationFinished();
        }
Exemplo n.º 2
0
        internal TO GetInternal <TO>(Guid _uid, IXObjectFactory <TKind> _factory) where TO : ClientXObject <TKind>
        {
            if (_factory == null && typeof(TO).IsAbstract)
            {
                var xFactoryAttribute = typeof(TO).GetCustomAttributes(typeof(XFactoryAttribute), true).Cast <XFactoryAttribute>().SingleOrDefault();
                if (xFactoryAttribute == null)
                {
                    throw new ApplicationException("Can't instantiate abstract type");
                }
                _factory = (IXObjectFactory <TKind>)Activator.CreateInstance(xFactoryAttribute.FactoryType);
            }

            ClientXObjectDescriptor <TKind> descriptor;

            if (m_descriptors.TryGetValue(_uid, out descriptor))
            {
                return(descriptor.Get <TO>(_factory));
            }
            var collectionOwnerUid = m_transport.GetСollectionOwnerUid(_uid);

            descriptor = new ClientXObjectDescriptor <TKind>(_uid, this, collectionOwnerUid);
            m_descriptors.Add(_uid, descriptor);
            var result = descriptor.Get <TO>(_factory);

            return(result);
        }
Exemplo n.º 3
0
        private void ProcessAddedToCollection(ClientXObject <TKind> _child, ClientXObjectDescriptor <TKind> ownerDescriptor, int _fieldId)
        {
            List <TKind> alsoKnownAsList;

            if (ownerDescriptor == RootDescriptor && m_abstractRootKindMap.TryGetValue(_child.Kind, out alsoKnownAsList))
            {
                var alsoKnownAs = new List <TKind>(alsoKnownAsList)
                {
                    _child.Kind
                };
                ownerDescriptor.AddedToCollection(_child, alsoKnownAs.Select(KindToInt));
            }
            else
            {
                ownerDescriptor.AddedToCollection(_child, new[] { _fieldId });
            }
        }
Exemplo n.º 4
0
        internal TO GetInternal <TO>(Guid _uid, IXObjectFactory <TKind> _factory, Guid _collectionOwnerUid)
            where TO : ClientXObject <TKind>
        {
            ClientXObjectDescriptor <TKind> descriptor;
            TO result;

            if (!m_descriptors.TryGetValue(_uid, out descriptor))
            {
                descriptor = new ClientXObjectDescriptor <TKind>(_uid, this, _collectionOwnerUid);
                m_descriptors.Add(_uid, descriptor);
                result = descriptor.Get <TO>(_factory);
            }
            else
            {
                if (!descriptor.ContainsInstanceOf(out result))
                {
                    result = descriptor.Get <TO>(_factory);
                }
            }
            return(result);
        }