Esempio n. 1
0
        /// <exception cref="System.IO.IOException"></exception>
        public virtual void Test()
        {
            var originalFilePath = OriginalFilePath();
            var dbFilePath       = DbFilePath();

            if (!File.Exists(originalFilePath))
            {
                TestPlatform.EmitWarning(originalFilePath + " does not exist. Can not run " + GetType
                                             ().FullName);
                return;
            }
            File4.Copy(originalFilePath, dbFilePath);
            Db4oFactory.Configure().AllowVersionUpdates(true);
            Db4oFactory.Configure().ExceptionsOnNotStorable(false);
            var oc = Db4oFactory.OpenFile(dbFilePath);

            try
            {
                Assert.IsNotNull(oc);
            }
            finally
            {
                oc.Close();
                Db4oFactory.Configure().ExceptionsOnNotStorable(true);
                Db4oFactory.Configure().AllowVersionUpdates(false);
            }
        }
Esempio n. 2
0
        public override void Initialize(string name, NameValueCollection config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            if (String.IsNullOrEmpty(name))
            {
                name = PROVIDER_NAME;
            }

            if (String.IsNullOrEmpty(config["description"]))
            {
                config.Remove("description");
                config.Add("description", "db4o ASP.NET Profile provider");
            }

            base.Initialize(name, config);

            applicationName = Utils.DefaultIfBlank(config["applicationName"], HostingEnvironment.ApplicationVirtualPath);

            connectionString = ConnectionStringStore.GetConnectionString(config["connectionStringName"]);
            if (connectionString == null)
            {
                throw new ProviderException("Connection string cannot be blank.");
            }

            Db4oFactory.Configure().ObjectClass(new Profile("", "", false, DateTime.MinValue, DateTime.MinValue)).
            CascadeOnUpdate(true);
        }
Esempio n. 3
0
        public db4oCharacterDB(string host, int port, string user, string pass)
        {
            this.host        = host;
            this.port        = port;
            this.dbuser      = user;
            this.dbpass      = pass;
            this.isconnected = false;

            Db4oFactory.Configure().GenerateVersionNumbers(System.Int32.MaxValue);
            Db4oFactory.Configure().GenerateUUIDs(System.Int32.MaxValue);
            Db4oFactory.Configure().ObjectClass(typeof(SagaDB.Actors.ActorPC)).CascadeOnActivate(true);
            Db4oFactory.Configure().ObjectClass(typeof(SagaDB.Actors.ActorPC)).CascadeOnUpdate(true);
            Db4oFactory.Configure().ObjectClass(typeof(SagaDB.Actors.ActorPC)).CascadeOnDelete(true);
            Db4oFactory.Configure().ObjectClass(typeof(SagaDB.Actors.ActorPC)).StoreTransientFields(false);

            Db4oFactory.Configure().ObjectClass(typeof(SagaDB.Actors.ActorNPC)).CascadeOnActivate(true);
            Db4oFactory.Configure().ObjectClass(typeof(SagaDB.Actors.ActorNPC)).CascadeOnUpdate(true);
            Db4oFactory.Configure().ObjectClass(typeof(SagaDB.Actors.ActorNPC)).CascadeOnDelete(true);
            Db4oFactory.Configure().ObjectClass(typeof(SagaDB.Actors.ActorNPC)).StoreTransientFields(false);

            Db4oFactory.Configure().ObjectClass(typeof(SagaDB.Items.Inventory)).CascadeOnActivate(true);
            Db4oFactory.Configure().ObjectClass(typeof(SagaDB.Items.Inventory)).CascadeOnUpdate(true);
            Db4oFactory.Configure().ObjectClass(typeof(SagaDB.Items.Inventory)).CascadeOnDelete(true);

            Db4oFactory.Configure().ObjectClass(typeof(SagaDB.Items.Item)).CascadeOnActivate(true);
            Db4oFactory.Configure().ObjectClass(typeof(SagaDB.Items.Item)).CascadeOnUpdate(true);
            Db4oFactory.Configure().ObjectClass(typeof(SagaDB.Items.Item)).CascadeOnDelete(true);
        }
Esempio n. 4
0
        private AppHost()
        {
            LogManager.LogFactory = new Log4NetFactory(true);

            var factory         = new FactoryProvider(FactoryUtils.ObjectFactory, LogManager.LogFactory);
            var providerManager = new Db4oFileProviderManager(Config.ConnectionString);

            var configDb4o = Db4oFactory.Configure();

            configDb4o.ActivationDepth(5);
            configDb4o.UpdateDepth(5);
            configDb4o.OptimizeNativeQueries(true);

            factory.Register(providerManager);             //Keep the manager from disposing providers it created
            factory.Register(providerManager.GetProvider());

            // Create the ApplicationContext injected with the static service implementations
            ApplicationContext.SetInstanceContext(new ApplicationContext {
                Factory   = factory,
                Cache     = new MemoryCacheClient(),
                Resources = new ConfigurationResourceManager(),
            });

            SetConfig(new EndpointHostConfig {
                ServiceName         = Config.ServiceName,
                OperationsNamespace = Config.OperationNamespace,
                ServiceModelFinder  = ServiceModelFinder.Instance,
                ServiceController   = new ServiceController(new ServiceResolver()),
            });
        }
Esempio n. 5
0
        private void InitDatabase()
        {
#if DB4O_8_0
            DatabaseConfiguration = Db4oEmbedded.NewConfiguration();
            DatabaseConfiguration.Common.AllowVersionUpdates = true;
            DatabaseConfiguration.Common.ActivationDepth     = 0;
            //DatabaseConfiguration.Common.Queries.EvaluationMode(QueryEvaluationMode.Lazy);
            DatabaseConfiguration.Common.WeakReferenceCollectionInterval = 60 * 1000;
            //DatabaseConfiguration.Common.Diagnostic.AddListener(new DiagnosticToConsole());
            var msgConf = DatabaseConfiguration.Common.ObjectClass(typeof(MessageModel));
            msgConf.CascadeOnActivate(true);
            msgConf.CascadeOnDelete(true);
            msgConf.Indexed(true);
            msgConf.ObjectField("f_TimeStamp").Indexed(true);
#else
            DatabaseConfiguration = Db4oFactory.Configure();
            DatabaseConfiguration.AllowVersionUpdates(true);
            DatabaseConfiguration.ObjectClass(typeof(MessageModel)).
            ObjectField("f_TimeStamp").Indexed(true);
#endif
            try {
                OpenDatabase();
            } catch (Exception ex) {
#if LOG4NET
                Logger.Error("InitDatabase(): failed to open message " +
                             "database: " + DatabaseFile, ex);
#endif
                throw;
            }
        }
        public virtual void Configure()
        {
            IConfiguration config = Db4oFactory.Configure();

            config.AllowVersionUpdates(true);
            ConfigureForTest(config);
        }
        private void Deconfigure()
        {
            IConfiguration config = Db4oFactory.Configure();

            config.AllowVersionUpdates(false);
            DeconfigureForTest(config);
        }
        public virtual void CreateDatabaseFor(string versionName)
        {
            _db4oVersion = versionName;
            IConfiguration config = Db4oFactory.Configure();

            try
            {
                ConfigureForStore(config);
            }
            catch
            {
            }
            // Some old database engines may throw NoSuchMethodError
            // for configuration methods they don't know yet. Ignore,
            // but tell the implementor:
            // System.out.println("Exception in configureForStore for " + versionName + " in " + getClass().getName());
            try
            {
                CreateDatabase(FileName(versionName));
            }
            finally
            {
                DeconfigureForStore(config);
            }
        }
Esempio n. 9
0
 private void SetDeleteCascadeOptions()
 {
     foreach (Type type in GetTypes())
     {
         Db4oFactory.Configure().ObjectClass(type).CascadeOnDelete(true);
     }
 }
Esempio n. 10
0
 private static IConfiguration SafeConfig(IConfiguration config)
 {
     if (config != null)
     {
         return(config);
     }
     return(Db4oFactory.Configure());
 }
        /*
         * Registers an alias for persistent classes namespace and assembly. The current assembly is temporary
         * and renamed after each recompilation, that is why it can not be used for persistence. An alias name is used
         * to persist the classes
         */
        public static IConfiguration Configure()
        {
            Assembly       assembly      = Assembly.GetExecutingAssembly();
            String         assemblyName  = "Db4objects.StarterKit.Data.*, " + assembly.GetName().ToString().Substring(0, assembly.GetName().ToString().LastIndexOf("Version") - 2);
            IConfiguration configuration = Db4oFactory.Configure();

            configuration.AddAlias(new WildcardAlias("Db4objects.StarterKit.Data.*, Db4oSiteCS2", assemblyName));
            return(configuration);
        }
Esempio n. 12
0
 public static void ThrowRuntimeException(int code, string msg, Exception cause, bool
                                          doLog)
 {
     if (doLog)
     {
         Messages.LogErr(Db4oFactory.Configure(), code, msg, cause
                         );
     }
     throw new Db4oException(Messages.Get(code, msg));
 }
Esempio n. 13
0
        public static void Open()
        {
            Db4oFactory.Configure().Queries().EvaluationMode(QueryEvaluationMode.Snapshot);
            _Current = Db4oFactory.OpenFile("yapFile.yap");
            IEventRegistry eventRegistry = EventRegistryFactory.ForObjectContainer(_Current);

            eventRegistry.Creating   += eventRegistry_Validate;
            eventRegistry.Updating   += eventRegistry_Validate;
            eventRegistry.Committing += eventRegistry_Committing;
            _Validators = new Dictionary <Type, ObjectValidator>();
        }
        public static IQuestionRepository CreateObjectDatabaseRespository(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path is null or empty");
            }

            Db4oFactory.Configure().ObjectClass(typeof(QuizQuestion))
            .CascadeOnUpdate(true);

            return(new ObjectDatabaseQuestionRepository(Db4oFactory.OpenFile(path)));
        }
Esempio n. 15
0
 public static IObjectContainer GetContainer(string fileName)
 {
     if (container == null || fileName != containerFileName)
     {
         //Db4oFactory.Configure().Add(new TransparentActivationSupport());
         //Db4oFactory.Configure().ActivationDepth(1);
         Db4oFactory.Configure().ObjectClass(typeof(sbcore.Model.Livro)).MaximumActivationDepth(3);
         Db4oFactory.Configure().ObjectClass(typeof(sbcore.Model.Versiculo)).MaximumActivationDepth(3);
         container         = Db4oFactory.OpenFile(fileName);
         containerFileName = fileName;
     }
     return(container);
 }
Esempio n. 16
0
 private void Start()
 {
     DontDestroyOnLoad(this);
     Db4oFactory.Configure().Add(new TransparentActivationSupport());
     Db4oFactory.Configure().Add(new TransparentPersistenceSupport());
     Db4oFactory.Configure().ObjectClass(typeof(Player)).CascadeOnUpdate(true);
     Db4oFactory.Configure().ObjectClass(typeof(Pawn)).CascadeOnUpdate(true);
     Db4oFactory.Configure().ObjectClass(typeof(Position)).CascadeOnUpdate(true);
     Db4oFactory.Configure().ObjectClass(typeof(FinishPoint)).CascadeOnUpdate(true);
     Db4oFactory.Configure().ObjectClass(typeof(HomePoint)).CascadeOnUpdate(true);
     Db4oFactory.Configure().ObjectClass(typeof(PlayerColor)).CascadeOnUpdate(true);
     Db4oFactory.Configure().ObjectClass(typeof(GameConfiguration)).CascadeOnUpdate(true);
 }
Esempio n. 17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Db4oDatabaseService"/> class.
        /// </summary>
        /// <param name="dbPath">The db path.</param>
        public Db4oDatabaseService(string dbPath)
        {
            this.dbPath = FileUtility.ConvertToFullPath(dbPath);
            if (!Directory.Exists(this.dbPath))
            {
                Directory.CreateDirectory(this.dbPath);
            }

            Db4oFactory.Configure().UpdateDepth(Int32.MaxValue);
            Db4oFactory.Configure().OptimizeNativeQueries(true);
            Db4oFactory.Configure().DetectSchemaChanges(true); // 自动探测数据库模式的变化
            Db4oFactory.Configure().ExceptionsOnNotStorable(true);
        }
        public virtual void TestOpenWithStaticConfiguration()
        {
            Db4oFactory.Configure().ReadOnly(true);
            Assert.Expect(typeof(DatabaseReadOnlyException), new _ICodeBlock_53(this));
            Db4oFactory.Configure().ReadOnly(false);
            IObjectContainer db = Db4oFactory.OpenFile(TempFile());

            db.Store(new GlobalVsNonStaticConfigurationTestCase.Data(1));
            db.Close();
            db = Db4oFactory.OpenFile(TempFile());
            Assert.AreEqual(1, db.Query(typeof(GlobalVsNonStaticConfigurationTestCase.Data)).
                            Count);
            db.Close();
        }
Esempio n. 19
0
        private IEmbeddedConfiguration GetConfiguration()
        {
            IEmbeddedConfiguration config = NewConfiguration();

            config.Common.ActivationDepth  = int.MaxValue;
            config.Common.CallConstructors = true;
            config.File.Storage            = new DefragEncryptedFileTestCase.MockStorage(config.File.Storage
                                                                                         , "db4o");
            config.Common.ReflectWith(Platform4.ReflectorForType(typeof(DefragEncryptedFileTestCase.Item
                                                                        )));
            Db4oFactory.Configure().Password("encrypted");
            Db4oFactory.Configure().Encrypt(true);
            //TODO: CHECK ENCRYPTION
            return(config);
        }
Esempio n. 20
0
        public db4oUserDB(string host, int port, string user, string pass)
        {
            this.host        = host;
            this.port        = port;
            this.user        = user;
            this.pass        = pass;
            this.isconnected = false;

            Db4oFactory.Configure().GenerateVersionNumbers(System.Int32.MaxValue);
            Db4oFactory.Configure().GenerateUUIDs(System.Int32.MaxValue);
            Db4oFactory.Configure().ObjectClass(typeof(SagaDB.User)).GenerateVersionNumbers(false);
            Db4oFactory.Configure().ObjectClass(typeof(SagaDB.User)).GenerateUUIDs(false);
            Db4oFactory.Configure().ObjectClass(typeof(SagaDB.User)).CascadeOnActivate(true);
            Db4oFactory.Configure().ObjectClass(typeof(SagaDB.User)).CascadeOnUpdate(true);
            Db4oFactory.Configure().ObjectClass(typeof(SagaDB.User)).CascadeOnDelete(true);
        }
Esempio n. 21
0
        //
        public string dbConnection(ConnParams login)
        {
            try
            {
                Db4oFactory.Configure().AllowVersionUpdates(true);
                Db4oClient.conn = login;

                dbConn = Db4oClient.Client;
                return(Db4oClient.exceptionConnection);
            }
            catch (Exception oEx)
            {
                LoggingHelper.HandleException(oEx);
                return("");
            }
        }
Esempio n. 22
0
    public static void RemoveCurrentPlayer(Player currentPlayer)
    {
        const int timeOutInMilliSec = 1000;

        try
        {
            Client.mConnection.Ext().SetSemaphore("players", timeOutInMilliSec);
            Player player = (Player)Client.mConnection.QueryByExample(currentPlayer).Next();
            Db4oFactory.Configure().ObjectClass(typeof(Player)).CascadeOnDelete(true);
            Client.mConnection.Delete(player);
            Client.mConnection.Commit();
        }
        finally
        {
            Client.mConnection.Ext().ReleaseSemaphore("players");
        }
    }
Esempio n. 23
0
 public virtual void Test()
 {
     if (WorkspaceServices.WorkspaceRoot == null)
     {
         Sharpen.Runtime.Err.WriteLine("Build environment not available. Skipping test case..."
                                       );
         return;
     }
     if (!System.IO.File.Exists(SourceFile()))
     {
         Sharpen.Runtime.Err.WriteLine("Test source file " + SourceFile() + " not available. Skipping test case..."
                                       );
         return;
     }
     Db4oFactory.Configure().AllowVersionUpdates(false);
     Db4oFactory.Configure().ReflectWith(Platform4.ReflectorForType(typeof(COR234TestCase
                                                                           )));
     Assert.Expect(typeof(OldFormatException), new _ICodeBlock_36(this));
 }
Esempio n. 24
0
        public DataHelper(string database)
        {
            IConfiguration config = Db4oFactory.Configure();

            //config.LockDatabaseFile(false);
            config.ObjectClass(typeof(Itop.MapView.Tables.MapClass)).ObjectField("_picUrl").Indexed(true);
            if (db != null)
            {
                db.Close();
            }
            if (database == "")
            {
                storeImgPath = GetDatabse();
            }
            else
            {
                storeImgPath = database;
            }
            db = Db4oFactory.OpenFile(Application.StartupPath + "\\" + storeImgPath);
        }
Esempio n. 25
0
        void ConfigureDatabase()
        {
#if DB4O_8_0
            DatabaseConfiguration = Db4oEmbedded.NewConfiguration();
            DatabaseConfiguration.Common.AllowVersionUpdates = true;
            DatabaseConfiguration.Common.ActivationDepth     = 0;
            //DatabaseConfiguration.Common.Queries.EvaluationMode(QueryEvaluationMode.Lazy);
            DatabaseConfiguration.Common.WeakReferenceCollectionInterval = 60 * 1000;
            //DatabaseConfiguration.Common.Diagnostic.AddListener(new DiagnosticToConsole());
            var msgConf = DatabaseConfiguration.Common.ObjectClass(typeof(MessageModel));
            msgConf.CascadeOnActivate(true);
            msgConf.CascadeOnDelete(true);
            msgConf.Indexed(true);
            msgConf.ObjectField("f_TimeStamp").Indexed(true);
#else
            DatabaseConfiguration = Db4oFactory.Configure();
            DatabaseConfiguration.AllowVersionUpdates(true);
            DatabaseConfiguration.ObjectClass(typeof(MessageModel)).
            ObjectField("f_TimeStamp").Indexed(true);
#endif
        }
Esempio n. 26
0
        public void Setup()
        {
            if (File.Exists(_databasePath))
            {
                File.Delete(_databasePath);
            }

            //Configure Db4o to cascade updates on Order and Customer entities. (Since they are our Aggregate Roots)
            var configuration = Db4oFactory.Configure();

            configuration.ObjectClass(typeof(Order)).CascadeOnUpdate(true);
            configuration.ObjectClass(typeof(Customer)).CascadeOnDelete(true);

            _db4oServer = Db4oFactory.OpenServer(_databasePath, 0);
            Db4oUnitOfWorkFactory.SetContainerProvider(() => _db4oServer.OpenClient());
            _mockLocator = MockRepository.GenerateMock <IServiceLocator>();
            _mockLocator.Expect(x => x.GetInstance <IUnitOfWorkFactory>())
            .Return(new Db4oUnitOfWorkFactory())
            .Repeat.Any();
            ServiceLocator.SetLocatorProvider(() => _mockLocator);
        }
Esempio n. 27
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="databaseService">数据库服务</param>
 /// <param name="loggerFactory">日志服务工厂</param>
 public UpgradeService(IDb4oDatabaseService databaseService, ILoggerFactory loggerFactory)
 {
     logger = loggerFactory.CreateLogger <UpgradeService>();
     Db4oFactory.Configure().ObjectClass(typeof(UpgradeProject)).CascadeOnDelete(true); // 设置级联删除
     db = databaseService.Open(UPGRADE_CONFIGURATION_FILE);
 }
Esempio n. 28
0
        public void CreateDemoDb(string filepath)
        {
            if (File.Exists(filepath))
            {
                File.Delete(filepath);
            }

            #region creation


            Db4oFactory.Configure().BlockSize(8);
            IObjectContainer objContainer = Db4oFactory.OpenFile(filepath);

            for (int i = 0; i < 75; i++)
            {
                try
                {
                    Pilot p1 = new Pilot("John " + i, i + 2);
                    Car   c1 = new Car("Ferrari " + i);
                    c1.Count = i;
                    c1.List  = new ArrayList();
                    for (int l = 0; l < 15; l++)
                    {
                        c1.List.Add(l + 77);
                    }

                    c1.Pilot = p1;
                    Children ch1 = new Children();
                    ch1.Child_name      = "Baby " + i;
                    ch1.Child_no        = 1;
                    ch1.DateOfBirth     = DateTime.Now;
                    c1.Pilot.Children   = new Children();
                    c1.Pilot.Children   = ch1;
                    c1.Pilot.Dbl        = i / 3;
                    c1.Pilot.ByteProp   = (Byte)(1.1 * i * 255.0);
                    c1.Pilot.SbyteProp  = (SByte)(1.23 * i * 55.0);
                    c1.Pilot.SingleProp = 2;
                    c1.Htbl             = new Hashtable();

                    for (int m = 0; m < 10; m++)
                    {
                        c1.Htbl.Add(m + 7, "value " + m + 9);
                    }


                    c1.CharArr    = new char[2];
                    c1.CharArr[0] = '$';
                    c1.CharArr[1] = '*';

                    c1.DblArr = new float[6];
                    for (int n = 0; n < 6; n++)
                    {
                        c1.DblArr[n] = n + 33;
                    }
                    if (i % 2 == 0)
                    {
                        c1.Pilot.HasWon = false;
                    }
                    else
                    {
                        c1.Pilot.HasWon = true;
                    }

                    c1.IntArrl     = new int[] { 1 + i, 2 + i, 3 + i };
                    c1.Int16       = 12;
                    c1.String      = "String Ferrari" + i;
                    c1.Character   = '!';
                    c1.DecimalProp = 0.7M;

                    objContainer.Store(c1);
                    objContainer.Commit();
                }

                catch { }
            }
            for (int i = 0; i < 75; i++)
            {
                try
                {
                    Pilot p1 = new Pilot("Michael " + i, i + 2);
                    Car   c1 = new Car("BMW " + i);
                    c1.Count = i;
                    c1.List  = new ArrayList();
                    for (int k = 0; k < 3; k++)
                    {
                        c1.List.Add(k + 55);
                    }

                    c1.Pilot = p1;
                    Children ch1 = new Children();
                    ch1.Child_name      = "Child " + i;
                    ch1.Child_no        = 1;
                    c1.Pilot.Children   = new Children();
                    c1.Pilot.Children   = ch1;
                    c1.Pilot.Dbl        = i / 3;
                    c1.Pilot.ByteProp   = (Byte)(1.5 * i * 255.0);
                    c1.Pilot.SbyteProp  = (SByte)(1.4 * i * 55.0);
                    c1.Pilot.SingleProp = 2;
                    c1.Htbl             = new Hashtable();
                    for (int l = 0; l < 10; l++)
                    {
                        c1.Htbl.Add("key no" + l + 34, "Value " + l + 12);
                    }

                    c1.CharArr    = new char[3];
                    c1.CharArr[0] = '!';
                    c1.CharArr[1] = '&';
                    c1.CharArr[2] = '^';

                    c1.DblArr = new float[8];
                    for (int m = 0; m < 8; m++)
                    {
                        c1.DblArr[m] = m + 21;
                    }
                    if (i % 2 == 0)
                    {
                        c1.Pilot.HasWon = true;
                    }
                    else
                    {
                        c1.Pilot.HasWon = false;
                    }

                    c1.IntArrl     = new int[] { 4 + i, 5 + i, 7 + i };
                    c1.Int16       = 12;
                    c1.String      = "String BMW" + i;
                    c1.Character   = '(';
                    c1.DecimalProp = 0.4M;

                    objContainer.Store(c1);
                    objContainer.Commit();
                }
                catch { }
            }

            objContainer.Close();
            objContainer = null;
            #endregion

            RefreshConnectionData(filepath);
        }
Esempio n. 29
0
 /// <summary>
 /// 打开数据库
 /// </summary>
 /// <param name="dbName">数据名称</param>
 /// <returns>打开的数据库对象</returns>
 public IDb4oDatabase Open(string dbName)
 {
     return(Open(dbName, Db4oFactory.Configure()));
 }