Esempio n. 1
0
        private void SynchronizeData(ClientTransaction targetTransaction, IEnumerable <Tuple <TransportItem, DataContainer> > sourceToTargetMapping)
        {
            foreach (Tuple <TransportItem, DataContainer> sourceToTargetContainer in sourceToTargetMapping)
            {
                TransportItem   transportItem    = sourceToTargetContainer.Item1;
                DataContainer   targetContainer  = sourceToTargetContainer.Item2;
                PropertyIndexer targetProperties = new PropertyIndexer(targetContainer.DomainObject);

                foreach (KeyValuePair <string, object> sourceProperty in transportItem.Properties)
                {
                    PropertyAccessor targetProperty = targetProperties[sourceProperty.Key, targetTransaction];
                    switch (targetProperty.PropertyData.Kind)
                    {
                    case PropertyKind.PropertyValue:
                        targetProperty.SetValueWithoutTypeCheck(sourceProperty.Value);
                        break;

                    case PropertyKind.RelatedObject:
                        if (!targetProperty.PropertyData.RelationEndPointDefinition.IsVirtual)
                        {
                            var relatedObjectID     = (ObjectID)sourceProperty.Value;
                            var targetRelatedObject = relatedObjectID != null?targetTransaction.GetObject(relatedObjectID, false) : null;

                            targetProperty.SetValueWithoutTypeCheck(targetRelatedObject);
                        }
                        break;
                    }
                }
            }
        }
Esempio n. 2
0
        public void PropertyIndexer_CachesPropertyData()
        {
            Order order   = DomainObjectIDs.Order1.GetObject <Order> (_transaction);
            var   indexer = new PropertyIndexer(order);

            Assert.That(indexer[typeof(Order), "OrderNumber"].PropertyData, Is.SameAs(indexer[typeof(Order), "OrderNumber"].PropertyData));
        }
        protected virtual IEnumerable <Tuple <DomainObject, int> > GetNextTraversedObjects(DomainObject current, int currentDepth, IGraphTraversalStrategy strategy)
        {
            var properties = new PropertyIndexer(current);

            foreach (PropertyAccessor property in properties.AsEnumerable())
            {
                switch (property.PropertyData.Kind)
                {
                case PropertyKind.RelatedObject:
                    if (strategy.ShouldFollowLink(_rootObject, current, currentDepth, property))
                    {
                        var relatedObject = (DomainObject)property.GetValueWithoutTypeCheck();
                        if (relatedObject != null)
                        {
                            yield return(Tuple.Create(relatedObject, currentDepth + 1));
                        }
                    }
                    break;

                case PropertyKind.RelatedObjectCollection:
                    if (strategy.ShouldFollowLink(_rootObject, current, currentDepth, property))
                    {
                        foreach (DomainObject relatedObject in (DomainObjectCollection)property.GetValueWithoutTypeCheck())
                        {
                            if (relatedObject != null)
                            {
                                yield return(Tuple.Create(relatedObject, currentDepth + 1));
                            }
                        }
                    }
                    break;
                }
            }
        }
        public static void SetForeignKeyProperty(IDomainObject domainObject, RelationEndPointDefinition endPointDefinition, ObjectID relatedID)
        {
            var relatedObject = LifetimeService.GetObjectReference(ClientTransaction.Current, relatedID);
            var properties    = new PropertyIndexer(domainObject);

            properties[endPointDefinition.PropertyName].SetValue(relatedObject);
        }
Esempio n. 5
0
        public void Item_WithSpecificTransaction_AllowsPassingAnInactiveParentTransaction()
        {
            var indexer        = new PropertyIndexer(_industrialSector);
            var subTransaction = _transaction.CreateSubTransaction();
            var accessor       = indexer["Remotion.Data.DomainObjects.UnitTests.TestDomain.IndustrialSector.Name", _transaction];

            Assert.That(accessor.ClientTransaction, Is.Not.SameAs(subTransaction));
            Assert.That(accessor.ClientTransaction, Is.SameAs(_transaction));
        }
Esempio n. 6
0
        private void CopyProperties <T> (T source, T clone, ICloneStrategy strategy, CloneContext context)
            where T : IDomainObject
        {
            var sourceTransaction = source.GetDefaultTransactionContext().ClientTransaction;
            var sourceProperties  = new PropertyIndexer(source);
            var cloneProperties   = new PropertyIndexer(clone);

            CopyProperties(sourceProperties, sourceTransaction, cloneProperties.AsEnumerable(CloneTransaction), strategy, context);
        }
Esempio n. 7
0
        private byte[] GetBinaryDataForChangedObject(ObjectID id, string propertyToTouch, object newValue)
        {
            var transporter = new DomainObjectTransporter();

            transporter.Load(id);
            var domainObject = transporter.GetTransportedObject(id);
            var properties   = new PropertyIndexer(domainObject);

            properties[propertyToTouch].SetValueWithoutTypeCheck(newValue);
            return(DomainObjectTransporterTestHelper.GetBinaryDataFor(transporter));
        }
Esempio n. 8
0
        public static bool IsRelation <TDoaminObject> (this RelationChangedEventArgs args, TDoaminObject domainObject, string shortPropertyName)
            where TDoaminObject : IDomainObject
        {
            ArgumentUtility.CheckNotNull("args", args);
            ArgumentUtility.CheckNotNull("domainObject", domainObject);
            ArgumentUtility.CheckNotNullOrEmpty("shortPropertyName", shortPropertyName);

            var properties       = new PropertyIndexer(domainObject);
            var propertyAccessor = properties[typeof(TDoaminObject), shortPropertyName];

            return(args.RelationEndPointDefinition == propertyAccessor.PropertyData.RelationEndPointDefinition);
        }
Esempio n. 9
0
        public void Item_WithShortNotation()
        {
            var indexer  = new PropertyIndexer(_industrialSector);
            var accessor = indexer[typeof(IndustrialSector), "Name"];

            Assert.That(accessor.ClientTransaction, Is.SameAs(_transaction));
            Assert.That(
                accessor.PropertyData.PropertyDefinition,
                Is.SameAs(
                    MappingConfiguration.Current.GetTypeDefinition(typeof(IndustrialSector))
                    .GetPropertyDefinition("Remotion.Data.DomainObjects.UnitTests.TestDomain.IndustrialSector.Name")));
        }
Esempio n. 10
0
        public void Item()
        {
            var indexer  = new PropertyIndexer(_industrialSector);
            var accessor = indexer["Remotion.Data.DomainObjects.UnitTests.TestDomain.IndustrialSector.Name"];

            Assert.That(accessor, Is.Not.Null);
            Assert.That(
                accessor.PropertyData.PropertyDefinition,
                Is.SameAs(
                    MappingConfiguration.Current.GetTypeDefinition(typeof(IndustrialSector))
                    .GetPropertyDefinition("Remotion.Data.DomainObjects.UnitTests.TestDomain.IndustrialSector.Name")));
        }
Esempio n. 11
0
        private void Swap(ClassWithRelationProperties one, ClassWithRelationProperties two, string shortPropertyName)
        {
            var propertiesOne = new PropertyIndexer(one);
            var propertiesTwo = new PropertyIndexer(two);
            var accessorOne   = propertiesOne[typeof(ClassWithRelationProperties), shortPropertyName];
            var accessorTwo   = propertiesTwo[typeof(ClassWithRelationProperties), shortPropertyName];

            var oldValue = accessorOne.GetValueWithoutTypeCheck();

            accessorOne.SetValueWithoutTypeCheck(accessorTwo.GetValueWithoutTypeCheck());
            accessorTwo.SetValueWithoutTypeCheck(oldValue);
        }
Esempio n. 12
0
        public void ShortNameAndTypeWithShadowedProperties()
        {
            var classWithDifferentProperties = (DerivedClassWithDifferentProperties)
                                               LifetimeService.NewObject(_transaction, typeof(DerivedClassWithDifferentProperties), ParamList.Empty);

            var indexer = new PropertyIndexer(classWithDifferentProperties);

            Assert.That(
                indexer[typeof(DerivedClassWithDifferentProperties), "String"],
                Is.EqualTo(indexer[typeof(DerivedClassWithDifferentProperties).FullName + ".String"]));
            Assert.That(
                indexer[typeof(ClassWithDifferentProperties), "String"], Is.EqualTo(indexer[typeof(ClassWithDifferentProperties).FullName + ".String"]));
        }
Esempio n. 13
0
        public void Item_WithShortNotation_WithSpecificTransaction()
        {
            var transaction = _industrialSector.RootTransaction.CreateSubTransaction();

            var indexer   = new PropertyIndexer(_industrialSector);
            var accessor1 = indexer[typeof(IndustrialSector), "Name"];

            Assert.That(accessor1.ClientTransaction, Is.Not.SameAs(transaction));

            var accessor2 = indexer[typeof(IndustrialSector), "Name", transaction];

            Assert.That(accessor2.ClientTransaction, Is.SameAs(transaction));
        }
Esempio n. 14
0
        public void Find_Generic_WithInferredType()
        {
            var classWithDifferentProperties =
                (DerivedClassWithDifferentProperties)LifetimeService.NewObject(_transaction, typeof(DerivedClassWithDifferentProperties), ParamList.Empty);
            var indexer = new PropertyIndexer(classWithDifferentProperties);

            var resultOnDerived = indexer.Find(classWithDifferentProperties, "String");

            Assert.That(resultOnDerived, Is.EqualTo(indexer[typeof(DerivedClassWithDifferentProperties).FullName + ".String"]));

            var resultOnBase = indexer.Find((ClassWithDifferentProperties)classWithDifferentProperties, "String");

            Assert.That(resultOnBase, Is.EqualTo(indexer[typeof(ClassWithDifferentProperties).FullName + ".String"]));
        }
Esempio n. 15
0
        private IEnumerable <DomainObject> LazyLoadWithRelatedObjects(ObjectID objectID)
        {
            IDomainObject sourceObject = _transportTransaction.GetObject(objectID, false);

            yield return(Load(sourceObject.ID));

            using (_transportTransaction.EnterNonDiscardingScope())
            {
                PropertyIndexer            sourceProperties = new PropertyIndexer(sourceObject);
                IEnumerable <DomainObject> relatedObjects   = sourceProperties.GetAllRelatedObjects();
                foreach (DomainObject domainObject in relatedObjects)
                {
                    yield return(Load(domainObject.ID)); // explicitly call load rather than just implicitly loading it into the transaction
                }
            }
        }
Esempio n. 16
0
        public void Item_UsesAssociatedActiveTransactionByDefault()
        {
            var indexer   = new PropertyIndexer(_industrialSector);
            var accessor1 = indexer["Remotion.Data.DomainObjects.UnitTests.TestDomain.IndustrialSector.Name"];

            Assert.That(accessor1.ClientTransaction, Is.SameAs(_transaction));

            var subTransaction = _transaction.CreateSubTransaction();

            var accessor2 = indexer["Remotion.Data.DomainObjects.UnitTests.TestDomain.IndustrialSector.Name"];

            Assert.That(accessor2.ClientTransaction, Is.SameAs(_transaction));

            using (subTransaction.EnterDiscardingScope())
            {
                var accessor3 = indexer["Remotion.Data.DomainObjects.UnitTests.TestDomain.IndustrialSector.Name"];
                Assert.That(accessor3.ClientTransaction, Is.SameAs(subTransaction));
            }
        }
Esempio n. 17
0
 private void CopyProperties(
     PropertyIndexer sourceProperties,
     ClientTransaction sourceTransaction,
     IEnumerable <PropertyAccessor> cloneProperties,
     ICloneStrategy strategy,
     CloneContext context)
 {
     foreach (PropertyAccessor cloneProperty in cloneProperties)
     {
         PropertyAccessor sourceProperty = sourceProperties[cloneProperty.PropertyData.PropertyIdentifier, sourceTransaction];
         if (cloneProperty.PropertyData.Kind == PropertyKind.PropertyValue)
         {
             object sourceValue = sourceProperty.GetValueWithoutTypeCheck();
             cloneProperty.SetValueWithoutTypeCheck(sourceValue);
         }
         else if (strategy != null && !cloneProperty.HasBeenTouched)
         {
             strategy.HandleReference(sourceProperty, cloneProperty, context);
         }
     }
 }
        public bool IsDefaultValue(IBusinessObject obj, PropertyBase property)
        {
            var domainObject = ArgumentUtility.CheckNotNullAndType <IDomainObject> ("obj", obj);

            ArgumentUtility.CheckNotNull("property", property);

            if (domainObject.GetState() != StateType.New)
            {
                return(false);
            }

            var propertyDefinition = domainObject.ID.ClassDefinition.ResolveProperty(property.PropertyInfo);

            if (propertyDefinition != null)
            {
                var properties = new PropertyIndexer(domainObject);
                return(!properties[propertyDefinition.PropertyName].HasBeenTouched);
            }

            return(_innerDefaultValueStrategy.IsDefaultValue(obj, property));
        }
        private TransportedDomainObjects TransportAndChangeObjects(string propertyName, object newValue, params ObjectID[] objectsToLoadAndDelete)
        {
            var transporter = new DomainObjectTransporter();

            foreach (ObjectID id in objectsToLoadAndDelete)
            {
                transporter.Load(id);
            }

            ModifyDatabase(
                delegate
            {
                foreach (var id in objectsToLoadAndDelete)
                {
                    var domainObject = LifetimeService.GetObject(ClientTransaction.Current, id, false);
                    var properties   = new PropertyIndexer(domainObject);
                    properties[propertyName].SetValueWithoutTypeCheck(newValue);
                }
            });

            return(Transport(transporter));
        }
Esempio n. 20
0
 static IncompatibleObject()
 {
     _enumManager     = new PropertyEnumManager <byte>(typeof(SupportedProperties));
     _propertyIndexer = new PropertyIndexer((byte)_enumManager.PropertyIds.Count);
 }
 static SampleClassificationObjectType()
 {
     _enumManager     = new PropertyEnumManager <byte>(typeof(SupportedProperties));
     _propertyIndexer = new PropertyIndexer((byte)_enumManager.PropertyIds.Count);
 }
 static LocResource()
 {
     enumManager     = new PropertyEnumManager <byte>(typeof(LocResourceProps));
     propertyIndexer = new PropertyIndexer((byte)enumManager.PropertyIds.Count);
 }
Esempio n. 23
0
 public UsingIndexers()
 {
     Indexer = new PropertyIndexer <int, int>(Get, Set);
     Getter  = new PropertyIndexerGetter <int, int>(Get);
     Setter  = new PropertyIndexerSetter <int, int>(Set);
 }
Esempio n. 24
0
        public void Item_ThrowsForNonExistingProperty()
        {
            var indexer = new PropertyIndexer(_industrialSector);

            Dev.Null = indexer["Bla"];
        }
Esempio n. 25
0
 public UsingIndexers()
 {
     Indexer = new PropertyIndexer<int, int>(Get, Set);
     Getter = new PropertyIndexerGetter<int, int>(Get);
     Setter = new PropertyIndexerSetter<int, int>(Set);
 }