////////// Methods written for remote login and logout:

        // activates a login from a remote site to account #id and returns only the account's balance
        // (and not the account itself).  If  id  is nonexistant/in use, returns  -1
        public object loginRemote(string id)
        {
            int   ans = -1;
            IAcct a   = this.login(id);

            if (a != null)
            {
                ans = a.getBalance();
            }
            return(ans);
        }
        // terminates the use of the opened  acct;  returns string that states outcome
        public string handleLogout()
        {
            string ans = "error";

            if (acct != null)
            {
                database.logout(accountId);
                acct = null; accountId = null;
                ans  = "logged out";
            }
            return(ans);
        }
        // opens acct#  accountID  for access; returns outcome as a string to display
        public string handleLogin(string accountId)
        {
            string ans = accountId + " error";

            if (acct == null)
            {  // no account open at this moment?
                acct = database.login(accountId);
                if (acct != null)
                {  // did  accountID  open ok ?
                    this.accountId = accountId;
                    ans            = accountId + " opened OK";
                }
            }
            return(ans);
        }
Exemplo n.º 4
0
        /// This part of RProxy impersonates the remote database:

        // login to bank account  #id:
        public IAcct login(string id)
        {
            IAcct loggedinAccount = null;

            // call the remote database via RPC to login and receive in return
            //   a handle to the remote bank acct:

            remoteAccount = new Account(id, (int)remoteDatabase.loginRemote(id));   // method  rpcToDatabase is coded below
            if (remoteAccount != null)
            {
                accountid       = id;
                loggedinAccount = this;  // This object here also impersonates the bank account,
                // so that it can execute the RPCs for account lookups.
            }
            return(remoteAccount);
        }
        private string accountId;  // string ID of the account, if any, that is opened for transactions

        public ATMControl(IDB db)
        {
            database = db;
            acct     = null;   // no account opened just yet
        }