Esempio n. 1
0
        private void AddOperation(IOperation operation)
        {
            var transation = Transaction.Current;

            if ((transation != null) && (transation.TransactionInformation.Status == TransactionStatus.Active))
            {
                Journal journal;
                lock (_lock)
                {
                    var id = transation.TransactionInformation.LocalIdentifier;
                    if (!_journals.ContainsKey(id))
                    {
                        journal = _journals.AddAndReturn(new KeyValuePair <string, Journal>(id, new Journal(this)))
                                  .Value;
                        transation.EnlistVolatile(journal, EnlistmentOptions.None);
                    }
                    else
                    {
                        journal = _journals[id];
                    }
                }

                journal.Add(operation);
                return;
            }

            operation.Commit();
        }
 public static V AddOrUpdate <K, V>(this IDictionary <K, V> dictionary, K key, V value)
     where K : notnull
 {
     if (!dictionary.ContainsKey(key))
     {
         return(dictionary.AddAndReturn(key, value));
     }
     else
     {
         return(dictionary[key] = value);
     }
 }
        public static V AddOrUpdate <K, V>(this IDictionary <K, V> dictionary, K key, V value, Func <V, V> repalceValue)
            where K : notnull
        {
            repalceValue = repalceValue ?? throw new ArgumentNullException(nameof(repalceValue));

            if (dictionary.TryGetValue(key, out var dictionaryValue))
            {
                if (repalceValue != null)
                {
                    return(dictionary[key] = repalceValue(dictionaryValue));
                }

                return(dictionaryValue);
            }

            return(dictionary.AddAndReturn(key, value));
        }