コード例 #1
0
        public override void UpdatedTransactions(SKPaymentQueue queue, SKPaymentTransaction[] transactions)
        {
            var rt = transactions.Where(pt => pt.TransactionState == SKPaymentTransactionState.Restored);

            // Add our restored transactions to the list
            // We might still get more from the initial request so we won't raise the event until
            // RestoreCompletedTransactionsFinished is called
            if (rt?.Any() ?? false)
            {
                restoredTransactions.AddRange(rt);
            }

            foreach (SKPaymentTransaction transaction in transactions)
            {
                switch (transaction.TransactionState)
                {
                case SKPaymentTransactionState.Purchased:
                    TransactionCompleted?.Invoke(transaction, true);
                    break;

                case SKPaymentTransactionState.Failed:
                    TransactionCompleted?.Invoke(transaction, false);
                    break;

                default:
                    break;
                }
            }
        }
コード例 #2
0
        public static async void WithdrawMoneyAsync(decimal money, Shift shift)
        {
            using (CashboxModel db = new CashboxModel())
            {
                try
                {
                    db.DBConnectionCheck();
                    db.Shifts.Attach(shift);
                    if (shift.CurrentCash >= money)
                    {
                        shift.CurrentCash   -= money;
                        shift.CashWithdrawn += money;
                        await db.SaveChangesAsync();

                        TransactionCompleted?.Invoke(shift, new ShiftTransactionEventArgs("—редства успешно изъ¤ты!", true));
                    }
                    else
                    {
                        TransactionCompleted?.Invoke(shift, new ShiftTransactionEventArgs("Ќевозможно изъ¤ть введенную сумму, так как в кассе находитс¤ меньше средств, чем требуетс¤", false));
                    }
                }
                catch (Exception e)
                {
                    TransactionCompleted?.Invoke(shift, new ShiftTransactionEventArgs(e.Message + "\n—редства изъ¤ты не были!", false));
                }
            }
        }
コード例 #3
0
        public async Task Handle(TransactionCompleted message, IMessageHandlerContext context)
        {
            var scoringId = await _scoringService.StartAsync(Data.ProjectId);

            await SendOffersAsync(context, scoringId);

            MarkAsComplete();
        }
コード例 #4
0
        private async Task CompleteAsync(IMessageHandlerContext context)
        {
            await _ethereumTransactionService.CompleteAsync(Data.TransactionHash);

            var message = new TransactionCompleted {
                TransactionHash = Data.TransactionHash
            };
            await context.Publish(message);

            MarkAsComplete();
        }
コード例 #5
0
 public override void Commit()
 {
     try
     {
         base.Commit();
         this.Logger.TryLogFail(() => TransactionCompleted.Fire(this, new TransactionEventArgs(this)));
     }
     catch (TransactionException e)
     {
         this.Logger.TryLogFail(() => TransactionFailed.Fire(this, new TransactionFailedEventArgs(this, e)));
         throw;
     }
 }
コード例 #6
0
        public override void UpdatedTransactions(SKPaymentQueue queue, SKPaymentTransaction[] transactions)
        {
            var rt = transactions.Where(pt => pt.TransactionState == SKPaymentTransactionState.Restored);

            // Add our restored transactions to the list
            // We might still get more from the initial request so we won't raise the event until
            // RestoreCompletedTransactionsFinished is called
            if (rt?.Any() ?? false)
            {
                restoredTransactions.AddRange(rt);
            }

            foreach (var transaction in transactions)
            {
                if (transaction?.TransactionState == null)
                {
                    break;
                }

                Debug.WriteLine($"Updated Transaction | {transaction.ToStatusString()}");

                switch (transaction.TransactionState)
                {
                case SKPaymentTransactionState.Restored:
                case SKPaymentTransactionState.Purchased:
                    TransactionCompleted?.Invoke(transaction, true);

                    if (TransactionCompleted != null)
                    {
                        onPurchaseSuccess?.Invoke(transaction.ToIABPurchase());
                    }

                    SKPaymentQueue.DefaultQueue.FinishTransaction(transaction);
                    break;

                case SKPaymentTransactionState.Failed:
                    TransactionCompleted?.Invoke(transaction, false);
                    SKPaymentQueue.DefaultQueue.FinishTransaction(transaction);
                    break;

                default:
                    break;
                }
            }
        }
コード例 #7
0
        public static async void AddMoneyAsync(decimal money, Shift shift)
        {
            using (CashboxModel db = new CashboxModel())
            {
                try
                {
                    db.DBConnectionCheck();
                    db.Shifts.Attach(shift);
                    shift.CashAdded   += money;
                    shift.CurrentCash += money;
                    await db.SaveChangesAsync();

                    TransactionCompleted?.Invoke(shift, new ShiftTransactionEventArgs("—редства успешно добавлены!", true));
                }
                catch (Exception e)
                {
                    TransactionCompleted?.Invoke(shift, new ShiftTransactionEventArgs(e.Message + "\n—редства добавлены не были!", false));
                }
            }
        }
コード例 #8
0
        public void Complete()
        {
            if (IsAborted)
            {
                throw new Exception("This transaction is already aborted, probably due to a nested transaction not being completed.");
            }

            IsCompleted = true;

            if (Root == this)
            {
                // I'm the root:
                Connections.Do(x => x.Value.Item2.Commit());
                TransactionCompleted?.Invoke(this, EventArgs.Empty);
            }
            else
            {
                // Ignore, and wait for the parent Completion.
            }
        }
コード例 #9
0
 public void Rollback()
 {
     Status = DeltaTransactionStatus.Aborted;
     TransactionCompleted?.Invoke(this, new DeltaTransactionEventArgs(this));
     DoDispose();
 }
コード例 #10
0
 public void Commit()
 {
     Status = DeltaTransactionStatus.Committed;
     TransactionCompleted?.Invoke(this, new DeltaTransactionEventArgs(this));
     DoDispose();
 }
コード例 #11
0
 public void CompleteTransaction(decimal sum)
 {
     TransactionCompleted?.Invoke(this, new TransactionEventArgs(sum));
 }
コード例 #12
0
 public void Dispose()
 {
     TransactionCompleted?.Invoke(this, null);
 }
コード例 #13
0
 internal virtual void OnTransactionCompleted(TransactionEventArgs e)
 {
     TransactionCompleted?.Invoke(this, e);
 }
コード例 #14
0
        public async Task Handle(TransactionCompleted message, IMessageHandlerContext context)
        {
            await _allotmentEventService.UpdateAsync(Data.AllotmentEventId);

            MarkAsComplete();
        }
コード例 #15
0
        /// <inheritdoc/>
        public void CompleteTransaction(Transaction transaction)
        {
            lock (lockObject)
            {
                try
                {
                    if (transactionsInProgress.Count == 0)
                    {
                        throw new TransactionException("There is not transaction in progress in the transaction stack.");
                    }

                    if (transaction != transactionsInProgress.Pop())
                    {
                        throw new TransactionException("The transaction being completed is not that last created transaction.");
                    }

                    // Check if we're completing the last transaction
                    TransactionInProgress = transactionsInProgress.Count > 0;

                    // Ignore the transaction if it is empty
                    if (transaction.IsEmpty)
                    {
                        return;
                    }

                    // If this transaction has no effect, discard it.
                    if (transaction.Operations.All(x => !x.HasEffect))
                    {
                        return;
                    }

                    // If we're not the last transaction, consider this transaction as an operation of its parent transaction
                    if (TransactionInProgress)
                    {
                        // Avoid useless nested transaction if we have a single operation inside.
                        PushOperation(transaction.Operations.Count == 1 ? transaction.Operations.Single() : transaction);
                        return;
                    }

                    // Remove transactions that will be overwritten by this one
                    if (currentPosition < transactions.Count)
                    {
                        PurgeFromIndex(currentPosition);
                    }

                    if (currentPosition == Capacity)
                    {
                        // If the stack has a capacity of 0, immediately freeze the new transaction.
                        var oldestTransaction = Capacity > 0 ? transactions[0] : transaction;
                        oldestTransaction.Interface.Freeze();

                        for (var i = 1; i < transactions.Count; ++i)
                        {
                            transactions[i - 1] = transactions[i];
                        }
                        if (Capacity > 0)
                        {
                            transactions[--currentPosition] = null;
                        }
                        TransactionDiscarded?.Invoke(this, new TransactionsDiscardedEventArgs(oldestTransaction, DiscardReason.StackFull));
                    }
                    if (Capacity > 0)
                    {
                        if (currentPosition == transactions.Count)
                        {
                            transactions.Add(transaction);
                        }
                        else
                        {
                            transactions[currentPosition] = transaction;
                        }
                        ++currentPosition;
                    }
                }
                finally
                {
                    if (!TransactionInProgress)
                    {
                        TransactionCompleted?.Invoke(this, new TransactionEventArgs(transaction));
                    }
                }
            }
        }
コード例 #16
0
 private void CompletedHandler(object sender, TransactionEventArgs e)
 {
     TransactionCompleted.Fire(this, e);
 }
コード例 #17
0
        public async Task Handle(TransactionCompleted message, IMessageHandlerContext context)
        {
            await _expertService.UpdateExpertAreasAsync(Data.ExpertId);

            MarkAsComplete();
        }