Beispiel #1
0
        private async Task <LastEtagsInfo> GetLastStateByOperationId(long operationId, TransactionOperationContext context)
        {
            var retries = 0;

            while (true)
            {
                if (++retries > 15)
                {
                    return(null);
                }

                var operationStatus = await GetOperationStatus(DatabaseName, operationId, context);

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

                if (operationStatus.TryGet("Completed", out bool completed) == false)
                {
                    return(null);
                }

                if (completed == false)
                {
                    await Task.Delay(1000, CancelToken.Token);

                    continue;
                }

                if (operationStatus.TryGet("OperationState", out BlittableJsonReaderObject operationStateBlittable) == false)
                {
                    // OperationState was added in the latest release of v3.5
                    return(null);
                }

                operationStateBlittable.TryGet(nameof(LastEtagsInfo.LastDocsEtag), out string lastDocsEtag);
                operationStateBlittable.TryGet(nameof(LastEtagsInfo.LastDocDeleteEtag), out string lastDocsDeleteEtag);
                operationStateBlittable.TryGet(nameof(LastEtagsInfo.LastAttachmentsEtag), out string lastAttachmentsEtag);
                operationStateBlittable.TryGet(nameof(LastEtagsInfo.LastAttachmentsDeleteEtag), out string lastAttachmentsDeleteEtag);

                var lastEtagsInfo = new LastEtagsInfo
                {
                    ServerUrl                 = ServerUrl,
                    DatabaseName              = DatabaseName,
                    LastDocsEtag              = lastDocsEtag,
                    LastDocDeleteEtag         = lastDocsDeleteEtag,
                    LastAttachmentsEtag       = lastAttachmentsEtag,
                    LastAttachmentsDeleteEtag = lastAttachmentsDeleteEtag
                };

                return(lastEtagsInfo);
                //operationStateBlittable.Modifications = new DynamicJsonValue
                //{
                //    [nameof(ImportInfo.ServerUrl)] = ServerUrl,
                //    [nameof(ImportInfo.DatabaseName)] = DatabaseName
                //};
                //var blittableCopy = context.ReadObject(operationStateBlittable, MigrationStateKey);
                //return blittableCopy;
            }
        }