Ejemplo n.º 1
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));
                }
            }
        }
        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;
                }
            }
        }
        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;
                }
            }
        }
Ejemplo n.º 4
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));
                }
            }
        }
Ejemplo n.º 5
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.
            }
        }
Ejemplo n.º 6
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));
                    }
                }
            }
        }
Ejemplo n.º 7
0
 public void Rollback()
 {
     Status = DeltaTransactionStatus.Aborted;
     TransactionCompleted?.Invoke(this, new DeltaTransactionEventArgs(this));
     DoDispose();
 }
Ejemplo n.º 8
0
 public void Commit()
 {
     Status = DeltaTransactionStatus.Committed;
     TransactionCompleted?.Invoke(this, new DeltaTransactionEventArgs(this));
     DoDispose();
 }
Ejemplo n.º 9
0
 public void Dispose()
 {
     TransactionCompleted?.Invoke(this, null);
 }
Ejemplo n.º 10
0
 internal virtual void OnTransactionCompleted(TransactionEventArgs e)
 {
     TransactionCompleted?.Invoke(this, e);
 }
 public void CompleteTransaction(decimal sum)
 {
     TransactionCompleted?.Invoke(this, new TransactionEventArgs(sum));
 }