Пример #1
0
        public async Task <RavenJToken> WaitForCompletionAsync()
        {
            if (done)
            {
                return(state);
            }
            if (asyncServerClient == null)
            {
                throw new InvalidOperationException("Cannot use WaitForCompletionAsync() when the operation was executed syncronously");
            }

            while (true)
            {
                var status = await asyncServerClient.GetOperationStatusAsync(id).ConfigureAwait(false);

                if (status == null)
                {
                    return(null);
                }
                if (status.Value <bool>("Completed"))
                {
                    return(status.Value <RavenJToken>("State"));
                }

#if NET45
                await Task.Delay(500).ConfigureAwait(false);
#else
                await TaskEx.Delay(500).ConfigureAwait(false);
#endif
            }
        }
Пример #2
0
        public async Task <RavenJToken> WaitForCompletionAsync()
        {
            if (asyncServerClient == null)
            {
                return(state);
            }

            while (true)
            {
                var status = await asyncServerClient.GetOperationStatusAsync(id);

                if (status == null)
                {
                    return(null);
                }
                if (status.Value <bool>("Completed"))
                {
                    return(status.Value <RavenJToken>("State"));
                }

#if NET45
                await Task.Delay(500);
#else
                await TaskEx.Delay(500);
#endif
            }
        }
Пример #3
0
        /// <summary>
        /// Since operation might complete before we subscribe to it,
        /// fetch operation status but only once  to avoid race condition
        /// If we receive notification using changes API meanwhile, ignore fetched status
        /// to avoid issues with non monotonic increasing progress
        /// </summary>
        private async Task FetchOperationStatus()
        {
            var operationStatusJson = await _asyncServerClient.GetOperationStatusAsync(_id).ConfigureAwait(false);

            var operationStatus = _asyncServerClient.convention
                                  .CreateSerializer()
                                  .Deserialize <OperationState>(new RavenJTokenReader(operationStatusJson));

            // using deserializer from Conventions to properly handle $type mapping

            OnNext(new OperationStatusChangeNotification
            {
                OperationId = _id,
                State       = operationStatus
            });
        }
Пример #4
0
        public async Task <RavenJToken> WaitForCompletionAsync()
        {
            if (done)
            {
                return(state);
            }
            if (asyncServerClient == null)
            {
                throw new InvalidOperationException("Cannot use WaitForCompletionAsync() when the operation was executed syncronously");
            }

            while (true)
            {
                var status = await asyncServerClient.GetOperationStatusAsync(id).ConfigureAwait(false);

                if (status == null)
                {
                    return(null);
                }

                if (status.Value <bool>("Completed"))
                {
                    var faulted = status.Value <bool>("Faulted");
                    if (faulted)
                    {
                        var error        = status.Value <RavenJObject>("State");
                        var errorMessage = error.Value <string>("Error");
                        throw new InvalidOperationException("Operation failed: " + errorMessage);
                    }

                    return(status.Value <RavenJToken>("State"));
                }


                await Task.Delay(500).ConfigureAwait(false);
            }
        }
Пример #5
0
 private Task <RavenJToken> GetOperationStatus(long operationId)
 {
     return(operationClient.GetOperationStatusAsync(operationId));
 }