Exemplo n.º 1
0
        /// <summary>
        /// Creates a new node or updates an existing or delete a node.
        /// </summary>
        /// <param name="kind">Kind of operation.</param>
        /// <param name="key">Key of the node.</param>
        /// <param name="value">Value of the node.</param>
        /// <returns>Async task to indicate the completion of write.</returns>
        internal async Task <bool> Write(NodeOperation.OperationKind kind, string key, ArraySegment <byte> value)
        {
            bool succeeded = false;

            using (var tx = this.StateManager.CreateTransaction())
            {
                var data = await this.fabricDataStore.TryGetValueAsync(tx, key);

                switch (kind)
                {
                case NodeOperation.OperationKind.Create:
                    succeeded = await this.fabricDataStore.TryAddAsync(tx, key, value.ToArray());

                    break;

                case NodeOperation.OperationKind.Delete:
                    succeeded = (await this.fabricDataStore.TryRemoveAsync(tx, key)).HasValue;
                    break;

                case NodeOperation.OperationKind.Update:
                    succeeded = await this.fabricDataStore.TryUpdateAsync(tx, key, value.ToArray(), data.Value);

                    break;
                }

                await tx.CommitAsync().ConfigureAwait(false);
            }

            return(succeeded);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new node or updates an existing or delete a node.
        /// </summary>
        /// <param name="kind">Kind of operation.</param>
        /// <param name="key">Key of the node.</param>
        /// <param name="value">Value of the node.</param>
        /// <param name="onCommit">Action performed when the replication is completed.</param>
        /// <param name="onFailure">Action performed when the replication is failed.</param>
        internal void Write(NodeOperation.OperationKind kind, string key, ArraySegment <byte> value, Action onCommit, Action onFailure)
        {
            var nodeOp    = new NodeOperation(kind, this.lastSequenceNumber, key, value);
            var pendingOp = new PendingOperation {
                Operation = nodeOp, OnCommit = onCommit, OnFailure = onFailure,
            };

            this.pendingOperations.Add(pendingOp);
        }