/// <summary>
            /// Applies the operation to the journal.
            /// </summary>
            /// <param name="table">The journal.</param>
            public override object Apply(PersistentTable <TKey, TValue> table)
            {
                TValue value;
                var    result = table.TryGetValue(this.Key, out value);

                return(new ConditionalResult <TValue>(result, value));
            }
Example #2
0
            /// <summary>
            /// The get next async.
            /// </summary>
            /// <param name="cancellationToken">
            /// The cancellation token.
            /// </param>
            /// <returns>
            /// The <see cref="Task"/>.
            /// </returns>
            public Task <OperationData> GetNextAsync(CancellationToken cancellationToken)
            {
                if (this.values.MoveNext())
                {
                    var element = this.values.Current;
                    var data    =
                        new OperationData(new SetOperation {
                        Key = element.Key, Value = element.Value
                    }.Serialize());
                    return(Task.FromResult(data));
                }

                if (this.table == null)
                {
                    return(Task.FromResult(default(OperationData)));
                }

                this.pool.Return(this.table);
                this.table = null;

                return(Task.FromResult(default(OperationData)));
            }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CopyStream"/> class.
 /// </summary>
 /// <param name="pool">
 /// The table pool.
 /// </param>
 public CopyStream(PersistentTablePool <TKey, TValue> pool)
 {
     this.pool   = pool;
     this.table  = pool.Take();
     this.values = this.table.GetRange().GetEnumerator();
 }
 /// <summary>
 /// Applies the operation to the journal.
 /// </summary>
 /// <param name="table">The journal.</param>
 public override object Apply(PersistentTable <TKey, TValue> table)
 {
     return(null);
 }
            /// <summary>
            /// Applies the operation to the journal.
            /// </summary>
            /// <param name="table">The journal.</param>
            public override object Apply(PersistentTable <TKey, TValue> table)
            {
                TValue value;

                return(table.TryRemove(this.Key, out value));
            }
 /// <summary>
 /// Applies the operation to the table.
 /// </summary>
 /// <param name="table">The table.</param>
 public override object Apply(PersistentTable <TKey, TValue> table)
 {
     table.AddOrUpdate(this.Key, this.Value);
     return(null);
 }
 /// <summary>
 /// Applies the operation to the table.
 /// </summary>
 /// <param name="table">The table.</param>
 /// <returns>The result of applying the operation.</returns>
 public abstract object Apply(PersistentTable <TKey, TValue> table);