Exemple #1
0
        public Client(string username, string port, string cDirUrl)
        {
            //With 0 as port the remoting services will chose an available port automatically
            IDictionary prop = new Hashtable();

            prop["name"]   = "ClientChannel." + username;
            prop["port"]   = port;
            mClientChannel = new TcpChannel(prop, null, null);
            ChannelServices.RegisterChannel(mClientChannel, true);

            string clientName = username;

            RemotingServices.Marshal(this, clientName, typeof(IClient));

            String[] urls = ChannelServices.GetUrlsForObject(this);

            this.URL = urls[0];

            System.Console.WriteLine("Client instantiated with name " + clientName + " and URL " + urls[0]);

            try
            {
                CDIR_URL    = cDirUrl;
                mCentralDir = (ICentralDir)Activator.GetObject(typeof(IClient), CDIR_URL);

                if (mCentralDir == null)
                {
                    System.Console.WriteLine("Cannot get central directory object for " + CDIR_URL);
                    throw new RemoteException("Cannot get central directory object for " + CDIR_URL);
                }
            }
            catch (SocketException)
            {
                throw new RemoteException("Could not connect to central directory: central directory url " + CDIR_URL);
            }

            System.Console.WriteLine("Central Directory with URL " + CDIR_URL);

            isSleep          = false;
            mRegisterManager = new RegisterManager();
            mNodeRouter      = new NodeRouter();
            mClientThread    = new ClientThread();

            System.Console.WriteLine("Register Manager created");
            System.Console.WriteLine("Node Router created");
            System.Console.WriteLine("Client Thread created");

            mActiveTransaction = new TransactionContext();
            System.Console.Write("Transaction Context created with id: " + mActiveTransaction.TxID + " valuesOfKey: ");
            mActiveTransaction.printKeyValues();
            System.Console.WriteLine("state: " + mActiveTransaction.TransactionState);
        }
Exemple #2
0
        public Client(string username, string port, string cDirUrl)
        {
            //With 0 as port the remoting services will chose an available port automatically
            IDictionary prop = new Hashtable();
            prop["name"] = "ClientChannel." + username;
            prop["port"] = port;
            mClientChannel = new TcpChannel(prop, null, null);
            ChannelServices.RegisterChannel(mClientChannel, true);

            string clientName = username;
            RemotingServices.Marshal(this, clientName, typeof(IClient));

            String[] urls = ChannelServices.GetUrlsForObject(this);

            this.URL = urls[0];

            System.Console.WriteLine("Client instantiated with name " + clientName + " and URL " + urls[0]);

            try
            {
                CDIR_URL = cDirUrl;
                mCentralDir = (ICentralDir)Activator.GetObject(typeof(IClient), CDIR_URL);

                if (mCentralDir == null)
                {
                    System.Console.WriteLine("Cannot get central directory object for " + CDIR_URL);
                    throw new RemoteException("Cannot get central directory object for " + CDIR_URL);
                }
            }
            catch (SocketException)
            {
                throw new RemoteException("Could not connect to central directory: central directory url " + CDIR_URL);
            }

            System.Console.WriteLine("Central Directory with URL " + CDIR_URL);

            isSleep = false;
            mRegisterManager = new RegisterManager();
            mNodeRouter = new NodeRouter();
            mClientThread = new ClientThread();

            System.Console.WriteLine("Register Manager created");
            System.Console.WriteLine("Node Router created");
            System.Console.WriteLine("Client Thread created");

            mActiveTransaction = new TransactionContext();
            System.Console.Write("Transaction Context created with id: " + mActiveTransaction.TxID + " valuesOfKey: ");
            mActiveTransaction.printKeyValues();
            System.Console.WriteLine("state: " + mActiveTransaction.TransactionState);
        }
Exemple #3
0
        public Server(string username, string port, string cDirUrl)
        {
            IDictionary prop = new Hashtable();

            prop["name"]   = "ServerChannel." + username;
            prop["port"]   = port;
            mServerChannel = new TcpChannel(prop, null, null);
            ChannelServices.RegisterChannel(mServerChannel, true);

            string serverName = username;

            RemotingServices.Marshal(this, serverName, typeof(IServer));
            String[] urls = ChannelServices.GetUrlsForObject(this);
            this.URL = urls[0];
            System.Console.WriteLine("Server instantiated with name " + serverName + " " + urls[0]);

            try
            {
                CDIR_URL    = cDirUrl;
                mCentralDir = (ICentralDir)Activator.GetObject(typeof(IClient), CDIR_URL);

                if (mCentralDir == null)
                {
                    System.Console.WriteLine("Cannot get central directory object for " + CDIR_URL);
                    throw new RemoteException("Cannot get central directory object for " + CDIR_URL);
                }
            } catch (SocketException) {
                // throw new RemoteException("Could not connect to central directory: central directory url " + CDIR_URL);
                System.Console.WriteLine("Could not connect to central directory: central directory url " + CDIR_URL);
                Environment.Exit(0);
            }

            mKeyManager         = new KeyManager(K);
            mTransactionManager = new TransactionManager(this, mKeyManager, K);
            mNodeRouter         = new NodeRouter(mURL, mKeyManager, this);
            mServerThread       = new ServerThread(mNodeRouter, mKeyManager);
        }
Exemple #4
0
        /// <summary>
        /// Stops the execution of all participants
        /// </summary>
        public void exit()
        {
            foreach(string key in mClients.Keys)
            {
                try
                {
                    mClients[key].exit();
                    //mWindow.mParticipants.Invoke(new DelRemParticipant(mWindow.mParticipants.remServer), new Object[] { key });
                } catch (SocketException) {
                }
                catch (IOException) {
                }
            }
            mClients.Clear();

            foreach(string key in mServers.Keys)
            {
                try
                {
                    mServers[key].exit();
                    //mWindow.mParticipants.Invoke(new DelRemParticipant(mWindow.mParticipants.remClient), new Object[] { key });
                } catch (SocketException) {
                } catch(IOException) {
                }
            }
            mServers.Clear();

            if (mCDir != null)
            {
                try
                {
                    mCDir.exit();
                } catch (SocketException) {
                } catch (IOException) {
                }
            }
            mCDir = null;
            centralURL = null;
        }
Exemple #5
0
        /// <summary>
        /// Executes the process corresponding to a participant
        /// </summary>
        /// <param name="username"></param>
        /// <param name="port"></param>
        /// <param name="exeFile"></param>
        public void executeParticipant(string username, string port, string exeFile)
        {
            try
            {
                if(username.StartsWith("SERVER-"))
                {
                    Process.Start(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName + exeFile,
                                username + " " + port + " " + centralURL);
                    IServer server = (IServer)Activator.GetObject(typeof(IServer), "tcp://localhost:" + port + "/" + username);

                    if (server == null)
                    {
                        //mWindow.Invoke(new DelErrorMsg(mWindow.showErrorMessage),
                        //                        new Object[] { "Could not get participant object for participant with username: "******" on port " + port });
                        addErrorMessage(username, "Could not get participant object for participant with username: "******" on port " + port);
                        return;
                    }
                    server.registerInCentralDirectory();
                    mServers.Add(username, server);
                    //mWindow.mParticipants.Invoke(new DelAddParticipant(mWindow.mParticipants.addServer), new Object[] { username });
                    //Thread.Sleep(1000);
                }
                else if(username.CompareTo("CENTRAL") == 0)
                {
                    Process.Start(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName + exeFile,
                                username + " " + port);
                    centralURL = "tcp://localhost:" + port + "/" + username;
                    ICentralDir central = (ICentralDir)Activator.GetObject(typeof(ICentralDir), centralURL);

                    if (central == null)
                    {
                        //mWindow.Invoke(new DelErrorMsg(mWindow.showErrorMessage),
                        //                        new Object[] { "Could not get participant object for participant with username: "******" on port " + port });
                        addErrorMessage(username, "Could not get participant object for participant with username: "******" on port " + port);
                        return;
                    }
                    mCDir = central;
                    //Thread.Sleep(1000);
                }
                else
                {
                    Process.Start(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName + exeFile,
                                  username + " " + port + " " + centralURL);
                    IClient client = (IClient)Activator.GetObject(typeof(IClient), "tcp://localhost:" + port + "/" + username);

                    if (client == null)
                    {
                        //mWindow.Invoke(new DelErrorMsg(mWindow.showErrorMessage),
                        //                        new Object[] { "Could not get participant object for participant with username: "******" on port " + port });
                        addErrorMessage(username, "Could not get participant object for participant with username: "******" on port " + port);
                        return;
                    }

                    client.registerInCentralDirectory();
                    mClients.Add(username, client);
                    //mWindow.mParticipants.Invoke(new DelAddParticipant(mWindow.mParticipants.addClient), new Object[] { username });
                    //Thread.Sleep(1000);
                }
            }
            catch (Exception ex)
            {
                //mWindow.Invoke(new DelErrorMsg(mWindow.showErrorMessage),
                //                            new Object[] { "Could not create participant - " + ex.Message });
                addErrorMessage(username, "Could not create participant - " + ex.GetBaseException().Message);
            }
            /*catch (ObjectDisposedException ex)
            {
                //mWindow.Invoke(new DelErrorMsg(mWindow.showErrorMessage),
                //                            new Object[] { "Could not create participant - " + ex.Message });
            }
            catch (InvalidOperationException ex)
            {
                //mWindow.Invoke(new DelErrorMsg(mWindow.showErrorMessage),
                //                            new Object[] { "Could not create participant - " + ex.Message });
            }
            catch (RemoteException ex)
            {
                //mWindow.Invoke(new DelErrorMsg(mWindow.showErrorMessage),
                //                            new Object[] { "Could not create participant - " + ex.getMessage() });
            }
            catch (IOException ex)
            {
                //mWindow.Invoke(new DelErrorMsg(mWindow.showErrorMessage),
                //                            new Object[] { "Could not create participant - " + ex.GetBaseException().Message });
            }
            catch (SocketException ex)
            {
                //mWindow.Invoke(new DelErrorMsg(mWindow.showErrorMessage),
                //                            new Object[] { "Could not create participant - " + ex.Message });
            }
            catch (TimeoutException ex)
            {
                mWindow.Invoke(new DelErrorMsg(mWindow.showErrorMessage),
                                            new Object[] { "Could not create participant - " + ex.Message });
            }
            catch (Win32Exception ex)
            {
                mWindow.Invoke(new DelErrorMsg(mWindow.showErrorMessage),
                                            new Object[] { "Could not create participant - " + ex.Message });
            }
            catch (UriFormatException ex)
            {
                mWindow.Invoke(new DelErrorMsg(mWindow.showErrorMessage),
                                            new Object[] { "Could not get participant - " + ex.Message });
            }*/
        }