예제 #1
0
파일: Bank.cs 프로젝트: yonglehou/PSharp
        void DoCloseAccount()
        {
            var transaction = (this.ReceivedEvent as CloseAccountEvent).Transaction;

            if (!this.Accounts.ContainsKey(transaction.GetAccountNumber()))
            {
                this.Send(transaction, new FailureResponse("No such account."));
                return;
            }

            var acccount = this.Accounts[transaction.GetAccountNumber()];

            this.Send(acccount, new Account.Close(this.Id));
            this.TransBeingProcessed = transaction;

            this.Goto(typeof(WaitingAccountToClose));
        }
예제 #2
0
파일: Bank.cs 프로젝트: yonglehou/PSharp
        void DoCloseAccountAck()
        {
            var result = (this.ReceivedEvent as Account.CloseAck).Result;

            if (result.BooleanValue())
            {
                this.Accounts.Remove(this.TransBeingProcessed.GetAccountNumber());
                this.Send(this.TransBeingProcessed, new SuccessResponse("Account closed."));
                this.TransBeingProcessed = null;
            }
            else
            {
                this.Send(this.TransBeingProcessed, new FailureResponse("Account not closed: nonzero balance."));
                this.TransBeingProcessed = null;
            }

            this.Goto(typeof(Active));
        }
예제 #3
0
파일: Account.cs 프로젝트: yonglehou/PSharp
 public WithdrawEvent(Transaction transaction, Boolean multiples)
     : base()
 {
     this.Transaction = transaction;
     this.Multiples = multiples;
 }
예제 #4
0
파일: Account.cs 프로젝트: yonglehou/PSharp
 public UnlockEvent(Transaction transaction)
     : base()
 {
     this.Transaction = transaction;
 }
예제 #5
0
파일: Account.cs 프로젝트: yonglehou/PSharp
 public DepositEvent(Transaction transaction)
     : base()
 {
     this.Transaction = transaction;
 }
예제 #6
0
파일: Account.cs 프로젝트: yonglehou/PSharp
 public BalanceInquiryEvent(Transaction transaction)
     : base()
 {
     this.Transaction = transaction;
 }
예제 #7
0
파일: Account.cs 프로젝트: yonglehou/PSharp
 private void Send(Transaction trans, Response resp)
 {
     this.Send(trans.GetMachine(), Activator.CreateInstance(trans.GetCallback(), resp) as Event);
 }
예제 #8
0
파일: Account.cs 프로젝트: yonglehou/PSharp
        void DoTransfer()
        {
            var fromAccount = (this.ReceivedEvent as Account.TransferEvent).Account;
            var transfer = (this.ReceivedEvent as Account.TransferEvent).Transfer;

            if (this.IsLocked)
            {
                this.Send(transfer, new FailureResponse("Destination account is locked."));
                return;
            }

            if (this.TransferTransaction != null)
            {
                this.Send(transfer, new FailureResponse("Transaction cannot be completed at this time."));
                return;
            }

            this.TransferTransaction = transfer;
            var wTrans = new Transaction(this.Id, typeof(TransferComplete), new Integer(0),
                transfer.GetAmount(), transfer.GetPin(), 0, 0.0);

            this.Send(fromAccount, new Account.WithdrawEvent(wTrans, new Boolean(false)));
        }
예제 #9
0
파일: Bank.cs 프로젝트: yonglehou/PSharp
 public WithdrawEvent(Transaction transaction)
     : base()
 {
     this.Transaction = transaction;
 }
예제 #10
0
파일: Bank.cs 프로젝트: yonglehou/PSharp
 public CreateAccountEvent(Transaction transaction)
     : base()
 {
     this.Transaction = transaction;
 }
예제 #11
0
파일: Bank.cs 프로젝트: yonglehou/PSharp
        void InitOnEntry()
        {
            this.Driver = (this.ReceivedEvent as Config).Driver;
            this.Accounts = new Dictionary<Integer, MachineId>();
            this.TransBeingProcessed = null;

            this.Goto(typeof(Active));
        }