Esempio n. 1
0
 public TransactionInformation(Transaction transaction, TKey key, TValue previousValue, bool newEntry, ConcurrentTransactionalDictionary <TKey, TValue> owner)
 {
     this.key           = key;
     this.NewEntry      = newEntry;
     this.owner         = owner;
     this.PreviousValue = previousValue;
     this.transaction   = transaction;
     this.transaction.TransactionCompleted += Fx.ThunkTransactionEventHandler((object s, TransactionEventArgs e) => {
         bool status   = e.Transaction.TransactionInformation.Status == TransactionStatus.Committed;
         bool flag     = false;
         TValue tValue = default(TValue);
         lock (this.owner.syncLock)
         {
             this.owner.pendingTransactions.Remove(this.key);
             if (!status)
             {
                 if (!this.NewEntry)
                 {
                     this.owner.internalDictionary[this.key] = this.PreviousValue;
                 }
                 else
                 {
                     this.owner.internalDictionary.Remove(this.key);
                 }
             }
             if (this.waiters != null)
             {
                 flag = this.owner.internalDictionary.TryGetValue(this.key, out tValue);
             }
         }
         if (this.waiters != null)
         {
             while (this.waiters.Count > 0)
             {
                 ConcurrentTransactionalDictionary <TKey, TValue> .TransactionalAsyncWaiter transactionalAsyncWaiter = this.waiters.Dequeue();
                 ActionItem.Schedule((object w) => ((ConcurrentTransactionalDictionary <TKey, TValue> .TransactionalAsyncWaiter)w).Signal(flag, tValue), transactionalAsyncWaiter);
             }
         }
     });
 }
        public void RegisterForTransactionalResult(Action <object, TransactionEventArgs, TransactionResult> onTransactionCompleted)
        {
            TransactionResult transactionResult1;

            if (onTransactionCompleted != null)
            {
                Transaction current = Transaction.Current;
                if (current != null)
                {
                    string localIdentifier = current.TransactionInformation.LocalIdentifier;
                    lock (this.syncLock)
                    {
                        if (!this.transactionResults.TryGetValue(localIdentifier, out transactionResult1))
                        {
                            transactionResult1 = new TransactionResult();
                            this.transactionResults.Add(localIdentifier, transactionResult1);
                        }
                        TransactionResult transactionResult2 = transactionResult1;
                        transactionResult2.ReferenceCount = transactionResult2.ReferenceCount + 1;
                    }
                    current.TransactionCompleted += Fx.ThunkTransactionEventHandler((object s, TransactionEventArgs e) => {
                        TransactionResult item;
                        lock (this.syncLock)
                        {
                            item = this.transactionResults[localIdentifier];
                            TransactionResult transactionResult = item;
                            int referenceCount = transactionResult.ReferenceCount - 1;
                            int num            = referenceCount;
                            transactionResult.ReferenceCount = referenceCount;
                            if (num == 0)
                            {
                                this.transactionResults.Remove(localIdentifier);
                            }
                        }
                        onTransactionCompleted(s, e, item);
                    });
                }
            }
        }