private void WithDatabase(string file, IFunction4 function)
        {
            Configure();
            IExtObjectContainer objectContainer = Db4oFactory.OpenFile(file).Ext();

            try
            {
                function.Apply(objectContainer);
            }
            finally
            {
                objectContainer.Close();
            }
            IObjectServer server = Db4oFactory.OpenServer(ClientServerFileName(file), -1);

            server.GrantAccess(Username, Password);
            objectContainer = Db4oFactory.OpenClient("localhost", server.Ext().Port(), Username
                                                     , Password).Ext();
            try
            {
                function.Apply(objectContainer);
            }
            finally
            {
                objectContainer.Close();
                server.Close();
            }
        }
Esempio n. 2
0
        private IObjectContainer GetStorage()
        {
            if (_db4oServer == null)
            {
                _db4oServer = Db4oFactory.OpenServer(_DBPath, 0);
            }

            return(_db4oServer.OpenClient());
        }
Esempio n. 3
0
 public bool Start()
 {
     if (IsRunning)
     {
         throw new ArgumentException("Storage server already started.");
     }
     EvaluateConnectionProperties();
     _server = Db4oFactory.OpenServer(Connection.File, Connection.HostPort);
     _server.GrantAccess(Connection.User, Connection.Password);
     return(true);
 }
Esempio n. 4
0
        private void InitServer()
        {
            try
            {
                lock (this)
                {
                    IObjectServer server = Db4oFactory.OpenServer(MiCliente.File, Convert.ToInt32(MiCliente.Port));

                    if (ValidoUsuario())
                    {
                        AgregoUsuarios(ref server);
                        server.Ext().Configure().AddAlias(new WildcardAlias("JerarquiaCheckList.*", "JerarquiaCheckList.*,JerarquiaCheckList"));
                        server.Ext().Configure().ClientServer().SetMessageRecipient(this);
                        try
                        {
                            while (!stop)
                            {
                                Monitor.Wait(this);/*wait 60000 ??*/
                            }
                        }
                        catch (ThreadInterruptedException)
                        {
                            server.Close();
                            stop = true;
                        }
                        finally
                        {
                            server.Close();
                            stop = true;
                        }
                    }
                    else
                    {
                        server.Close();
                        stop = true;
                        if (pub != null)
                        {
                            pub.SinAcceso();
                        }
                    }
                }
            }
            catch (DatabaseFileLockedException)
            {//¿Que puedo hacer
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Starts the server.
        /// </summary>
        /// <exception cref="InvalidOperationException">Thrown if the server has already been started.</exception>
        /// <exception cref="ObjectDisposedException">Thrown if the server has been disposed.</exception>
        /// <exception cref="AmbienceException">Thrown if the operation failed.</exception>
        public void Start()
        {
            ThrowIfDisposed();

            Directory.CreateDirectory(Path.GetDirectoryName(databasePath));

            try
            {
                IConfiguration db4oConfig = Db4oFactory.NewConfiguration();
                db4oServer = Db4oFactory.OpenServer(db4oConfig, databasePath, configuration.Port);
                db4oServer.GrantAccess(configuration.Credential.UserName, configuration.Credential.Password);
            }
            catch (Db4oException ex)
            {
                throw new AmbienceException("An error occurred while starting the server.", ex);
            }
        }
Esempio n. 6
0
    //private static IConfiguration _config = Db4oFactory.NewConfiguration();

    public static void WithContainer(Action <IObjectContainer> action)
    {
        string _dbfile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "db4o_linq");

        IObjectServer server = Db4oFactory.OpenServer(_dbfile, 0);

        try
        {
            using (var container = server.OpenClient())
            {
                action(container);
            }
        }
        finally
        {
            server.Close();
        }
    }
Esempio n. 7
0
        public void Initialise()
        {
            _log.Debug("Loading " + Name);

            try
            {
                IConfiguration config = Db4oFactory.CloneConfiguration();
                config.LockDatabaseFile(false);
                config.UpdateDepth(2);

                // open the database connection
                _theDatabase = Db4oFactory.OpenServer(config, Db4oServiceConstants.DB_FILE_NAME, 0);
            }
            catch (Db4oException e)
            {
                throw new InitialisationException("Problem loading " + Name, e);
            }
        }
Esempio n. 8
0
        public void Start(object coreRef)
        {
            _log.Debug("Loading " + Identify());
            _theCore = coreRef as PropagandaCore;

            try
            {
                IConfiguration config = Db4oFactory.CloneConfiguration();
                config.LockDatabaseFile(false);
                config.UpdateDepth(2);

                // open the database connection
                _theDatabase = Db4oFactory.OpenServer(config, DBServiceConstants.DB_FILE_NAME, 0);
            }
            catch (Db4oException e)
            {
                throw new InitialisationException("Problem loading " + Identify(), e);
            }
        }
Esempio n. 9
0
        public static IObjectContainer conectar()
        {
            if (servidor != null)
                servidor.Close();
            IConfiguration config = Db4oFactory.NewConfiguration();
            new TransparentActivationSupport().Prepare(config);
            config.LockDatabaseFile(false);
            config.DetectSchemaChanges(true);
            servidor = Db4oFactory.OpenServer(config, System.Web.HttpContext.Current.Server.MapPath("..\\bdoo\\financas.db4o"), 0);
            //servidor.Ext().Configure().ActivationDepth(2);
            db = servidor.OpenClient();
            db.Ext().Configure().ObjectClass(typeof(Usuario)).CascadeOnUpdate(true);
            db.Ext().Configure().ObjectClass(typeof(Conta)).CascadeOnUpdate(true);
            db.Ext().Configure().ObjectClass(typeof(Categoria)).CascadeOnUpdate(true);
            //db.Ext().Configure().ObjectClass(typeof(Lancamento)).ObjectField("Imagem").CascadeOnActivate(false);
            //db.Ext().Configure().ObjectClass(typeof(Lancamento)).ObjectField("Comprovante").CascadeOnActivate(false);

            return db;
        }
Esempio n. 10
0
        public bool IsRunning()
        {
            bool bRetorno = false;

            try
            {
                //Intento abrir el archivo para ver si esta bloqueado o no sin hacer llamadas a
                // FILE porque no se si funcionara en Linux
                IObjectServer server = Db4oFactory.OpenServer(MiCliente.File, Convert.ToInt32(MiCliente.Port));
                server.Close();
            }
            catch (DatabaseFileLockedException)
            {
                bRetorno = true;
            }
            catch (Db4oIOException)
            {
                bRetorno = true;
            }
            return(bRetorno);
        }
Esempio n. 11
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. 12
0
        /// <summary>
        /// opens the IObjectServer, and waits forever until Close() is called
        /// or a StopServer message is being received.
        /// </summary>
        public void RunServer()
        {
            Console.WriteLine("Server starting");
            lock (this)
            {
                // Using the messaging functionality to redirect all
                // messages to this.processMessage
                IConfiguration configuration = Db4oFactory.NewConfiguration();
                configuration.ClientServer().SetMessageRecipient(this);


                configuration.Add(new TransparentActivationSupport());
                configuration.Add(new TransparentPersistenceSupport());


                server = Db4oFactory.OpenServer(configuration, FileName, Port);
                server.GrantAccess(User, Password);
                server.GrantAccess("server", "serverpass");

                Console.WriteLine("Server started");
                client = Db4oFactory.OpenClient(Host, Port, "server", "serverpass");
                try
                {
                    if (!stop)
                    {
                        // wait forever until Close will change stop variable
                        Console.WriteLine("Server waiting...");
                        Monitor.Wait(this);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
                server.Close();
                Console.WriteLine("Server closed");
            }
        }
Esempio n. 13
0
 protected ServidorSingleton()
 {
     server = Db4oFactory.OpenServer(banco, 0);
 }