Пример #1
0
        /// <summary>
        /// Gets the config from attributes.
        /// </summary>
        /// <param name="commonConfig">The common config.</param>
        /// <param name="entityTypes">The entity types.</param>
        public static void GetConfigFromAttributes(ICommonConfiguration commonConfig, Collection <Type> entityTypes)
        {
            if (entityTypes == null || entityTypes.Count == 0)
            {
                return;
            }

            if (commonConfig == null)
            {
                return;
            }

            commonConfig.MarkTransient(typeof(TransientFieldAttribute).FullName);

            foreach (var entityType in entityTypes)
            {
                var objectClass = commonConfig.ObjectClass(entityType);

                var uuidAttrib = entityType.GetAttribute <UuidClassAttribute>();
                if (uuidAttrib != null)
                {
                    objectClass.GenerateUUIDs(true);
                }

                var versionAttrib = entityType.GetAttribute <VersionNumberClassAttribute>();
                if (versionAttrib != null)
                {
                    objectClass.GenerateVersionNumbers(true);
                }

                var fields = entityType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance)
                             .Where(prop => prop.GetCustomAttributes(typeof(IndexedFieldAttribute), false).Length > 0 ||
                                    prop.GetCustomAttributes(typeof(UniqueFieldValueConstraintAttribute), false).Length > 0
                                    ).ToList();

                if (fields.Count == 0)
                {
                    continue;
                }

                foreach (var field in from field in fields
                         let indexAttrib = field.GetAttribute <IndexedFieldAttribute>()
                                           where indexAttrib != null
                                           select field)
                {
                    objectClass.ObjectField(field.Name).Indexed(true);

                    //No UniqueFieldValue WithOut Indexed
                    var uniqueAttrib = field.GetAttribute <UniqueFieldValueConstraintAttribute>();

                    if (uniqueAttrib != null)
                    {
                        commonConfig.Add(new UniqueFieldValueConstraint(entityType, field.Name));
                    }
                }
            }
        }
Пример #2
0
 protected virtual void ConfigureAliases(ICommonConfiguration configuration)
 {
     configuration.MarkTransient(typeof(Limaki.Common.TransientAttribute).FullName);
 }
Пример #3
0
            public virtual void Test()
            {
                ICommonConfigurationProvider config = ((ICommonConfigurationProvider)Subject());
                Config4Impl          legacy         = Db4oLegacyConfigurationBridge.AsLegacy(config);
                ICommonConfiguration common         = config.Common;

                common.ActivationDepth = 42;
                Assert.AreEqual(42, legacy.ActivationDepth());
                Assert.AreEqual(42, common.ActivationDepth);
                // TODO: assert
                common.Add(new _IConfigurationItem_41());
                TypeAlias alias = new TypeAlias("foo", "bar");

                common.AddAlias(alias);
                Assert.AreEqual("bar", legacy.ResolveAliasStoredName("foo"));
                Assert.AreEqual("foo", legacy.ResolveAliasRuntimeName("bar"));
                common.RemoveAlias(alias);
                Assert.AreEqual("foo", legacy.ResolveAliasStoredName("foo"));
                common.AllowVersionUpdates = false;
                Assert.IsFalse(legacy.AllowVersionUpdates());
                common.AutomaticShutDown = false;
                Assert.IsFalse(legacy.AutomaticShutDown());
                common.BTreeNodeSize = 42;
                Assert.AreEqual(42, legacy.BTreeNodeSize());
                common.Callbacks = false;
                Assert.AreEqual(CallBackMode.None, legacy.CallbackMode());
                common.CallConstructors = false;
                Assert.IsTrue(legacy.CallConstructors().DefiniteNo());
                common.DetectSchemaChanges = false;
                Assert.IsFalse(legacy.DetectSchemaChanges());
                DiagnosticCollector collector = new DiagnosticCollector();

                common.Diagnostic.AddListener(collector);
                IDiagnostic diagnostic = DummyDiagnostic();

                legacy.DiagnosticProcessor().OnDiagnostic(diagnostic);
                collector.Verify(new object[] { diagnostic });
                common.ExceptionsOnNotStorable = true;
                Assert.IsTrue(legacy.ExceptionsOnNotStorable());
                common.InternStrings = true;
                Assert.IsTrue(legacy.InternStrings());
                // TODO: assert
                common.MarkTransient("Foo");
                common.MessageLevel = 3;
                Assert.AreEqual(3, legacy.MessageLevel());
                IObjectClass objectClass = common.ObjectClass(typeof(CommonAndLocalConfigurationTestSuite.BaseConfigurationProviderTestUnit.Item
                                                                     ));

                objectClass.CascadeOnDelete(true);
                Assert.IsTrue(((Config4Class)legacy.ObjectClass(typeof(CommonAndLocalConfigurationTestSuite.BaseConfigurationProviderTestUnit.Item
                                                                       ))).CascadeOnDelete().DefiniteYes());
                Assert.IsTrue(((Config4Class)common.ObjectClass(typeof(CommonAndLocalConfigurationTestSuite.BaseConfigurationProviderTestUnit.Item
                                                                       ))).CascadeOnDelete().DefiniteYes());
                common.OptimizeNativeQueries = false;
                Assert.IsFalse(legacy.OptimizeNativeQueries());
                Assert.IsFalse(common.OptimizeNativeQueries);
                common.Queries.EvaluationMode(QueryEvaluationMode.Lazy);
                Assert.AreEqual(QueryEvaluationMode.Lazy, legacy.EvaluationMode());
                // TODO: test reflectWith()
                // TODO: this probably won't sharpen :/
                TextWriter outStream = Sharpen.Runtime.Out;

                common.OutStream = outStream;
                Assert.AreEqual(outStream, legacy.OutStream());
                IStringEncoding stringEncoding = new _IStringEncoding_113();

                common.StringEncoding = stringEncoding;
                Assert.AreEqual(stringEncoding, legacy.StringEncoding());
                common.TestConstructors = false;
                Assert.IsFalse(legacy.TestConstructors());
                common.TestConstructors = true;
                Assert.IsTrue(legacy.TestConstructors());
                common.UpdateDepth = 1024;
                Assert.AreEqual(1024, legacy.UpdateDepth());
                common.WeakReferences = false;
                Assert.IsFalse(legacy.WeakReferences());
                common.WeakReferenceCollectionInterval = 1024;
                Assert.AreEqual(1024, legacy.WeakReferenceCollectionInterval());
            }