コード例 #1
0
        /// <summary>
        /// Attempts to push all actions in the transaction to dropbox asynchronously
        /// </summary>
        /// <param name="retries">How many times to retry committing the actions before giving up</param>
        /// <param name="success">Callback if the method is successful</param>
        /// <param name="failure">Callback if the method fails</param>
        /// <returns>True if the actions in the transaction were pushed to dropbox</returns>
        public void PushAsync(Action <bool> success, Action <Exception> failure, int retries = 1)
        {
            PushAsyncContext context = new PushAsyncContext
            {
                Count   = 0,
                Retries = retries,
                Success = success,
                Failure = failure
            };

            PushAsyncInternal(context);
        }
コード例 #2
0
        private void PushAsyncInternal(PushAsyncContext context)
        {
            if (context.Count > context.Retries)
            {
                context.Success(false);
                return;
            }

            try
            {
                _actions();
            }
            catch (Exception ex)
            {
                context.Failure(ex);
                return;
            }

            _store.PushAsync(pushResult =>
            {
                if (!pushResult)
                {
                    _store.Revert();
                    _store.PullAsync(() =>
                    {
                        ++context.Count;
                        PushAsyncInternal(context);
                    }, ex =>
                    {
                        context.Failure(ex);
                    });
                }
                else
                {
                    context.Success(true);
                }
            }, ex =>
            {
                context.Failure(ex);
            });
        }