public static void SendMessageToServer(string message) { IObjectContainer objectContainer = null; try { // connect to the server objectContainer = Db4oFactory.OpenClient(ServerConfiguration.Host, ServerConfiguration.Port, ServerConfiguration.User, ServerConfiguration.Password); } catch (Exception e) { Console.WriteLine(e.ToString()); } if (objectContainer != null) { // get the messageSender for the IObjectContainer IMessageSender messageSender = objectContainer.Ext() .Configure().ClientServer().GetMessageSender(); // send an instance of a StopServer object messageSender.Send(message); // close the IObjectContainer objectContainer.Close(); } }
public bool Stop() { bool bRetorno = true; IObjectContainer Contenedor = null; try { Contenedor = Db4oFactory.OpenClient(MiCliente.Server, Convert.ToInt32(MiCliente.Port), MiCliente.User, MiCliente.Password); if (Contenedor != null) { IMessageSender messageSender = Contenedor.Ext().Configure().ClientServer() .GetMessageSender(); //envio el mensaje messageSender.Send(new StopServer("")); Thread.Sleep(1000);//espero a que llegue el pinci mensaje //cierro el contenedor if (Contenedor != null) { Contenedor.Close(); } Contenedor.Dispose(); } } catch (System.Net.Sockets.SocketException) { //No se conecto, ta cerrado bRetorno = true; //nomas por poner codigo } catch (Exception) { bRetorno = false;//No se pudo detener //Console.WriteLine(e.ToString()); } return(bRetorno); }
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(); } }
public bool Connect() { if (!this.isconnected) { try { db.Close(); } catch (Exception) { } try { db = Db4oFactory.OpenClient(host, port, dbuser, dbpass); } catch (Exception) { return(false); } this.isconnected = true; } return(true); }
public void AddDB2() { IObjectContainer dbcliente2 = Db4oFactory.OpenClient(cliente2.Server, Convert.ToInt32(cliente2.Port), cliente2.User, cliente2.Password); dbcliente2.Set(new Prueba(1, "ABC", true)); dbcliente2.Set(new Prueba(2, "DEF", false)); dbcliente2.Set(new Prueba(3, "GHI", true)); dbcliente2.Set(new Prueba(4, "JKM", false)); dbcliente2.Set(new Prueba(5, "NÑO", true)); dbcliente2.Set(new Prueba(6, "PQR", false)); dbcliente2.Commit(); dbcliente2.Close(); dbcliente2.Dispose(); }
public IObjectContainer GetInstance() { int id = System.Threading.Thread.CurrentThread.ManagedThreadId; if (_containers.Exists(p => p.ThreadId == id)) { return(_containers.Find(p => p.ThreadId == id).Db); } else { var container = new ObjectContainerThread(); container.ThreadId = id; container.Db = Db4oFactory.OpenClient(Connection.HostAddress, Connection.HostPort, Connection.User, Connection.Password); _containers.Add(container); return(container.Db); } }
/// <summary> /// Connects the client to the remote server. /// </summary> /// <param name="configuration">The client configuration.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="configuration"/> is null.</exception> /// <exception cref="AmbienceException">Thrown if the operation failed.</exception> public static AmbienceClient Connect(AmbienceClientConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException("configuration"); } try { IConfiguration db4oConfig = Db4oFactory.NewConfiguration(); IObjectContainer db4oContainer = Db4oFactory.OpenClient(db4oConfig, configuration.HostName, configuration.Port, configuration.Credential.UserName, configuration.Credential.Password); return(new AmbienceClient(new Db4oAmbientDataContainer(db4oContainer))); } catch (Db4oException ex) { throw new AmbienceException("An error occurred while connecting to the server.", ex); } }
public override bool RunJob() { bool bError = false; try { if (servidor.IsRunning()) { IObjectContainer dbcliente = Db4oFactory.OpenClient(this.sServer, Convert.ToInt32(this.sPort), this.sUsuario, this.sPassword); dbcliente.Ext().Backup(sBackupFile); dbcliente.Close(); } } catch (Exception ex) { bError = true; Log.AddToLog(sJobName, ex.Message); } return(bError); }
/// <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"); } }
public IObjectContainer Login(String username, out int id, String password = "******") { IObjectContainer objectContainer; id = -1; try { objectContainer = Db4oFactory.OpenClient(_host, _port, username, password); } catch (System.IO.IOException e) { UnityEngine.Debug.Log(e.Message); return(null); } bool allowedToLogin = false; for (int i = 0; i < MAXIMUM_USERS; i++) { String semaphore = "login_limit_" + (i + 1); if (objectContainer.Ext().SetSemaphore(semaphore, 0)) { allowedToLogin = true; UnityEngine.Debug.Log("Logged in as " + username); UnityEngine.Debug.Log("Acquired semaphore " + semaphore); id = i + 1; break; } } if (!allowedToLogin) { UnityEngine.Debug.Log("Login not allowed for " + username + ": max clients exceeded"); objectContainer.Close(); return(null); } return(objectContainer); }
public IObjectContainer GetNewInstance() { return(Db4oFactory.OpenClient(Connection.HostAddress, Connection.HostPort, Connection.User, Connection.Password)); }