Пример #1
0
        internal async Task <HttpMessageEnsureScopesResponse> EnsureScopesAsync(HttpMessageEnsureScopesRequest httpMessage, SessionCache sessionCache,
                                                                                CancellationToken cancellationToken, IProgress <ProgressArgs> progress = null)
        {
            if (httpMessage == null)
            {
                throw new ArgumentException("EnsureScopesAsync message could not be null");
            }

            if (this.Setup == null)
            {
                throw new ArgumentException("You need to set the tables to sync on server side");
            }

            // Get context from request message
            var ctx = httpMessage.SyncContext;

            // Set the context coming from the client
            this.SetContext(ctx);

            // Get schema
            var serverScopeInfo = await this.GetServerScopeAsync(cancellationToken, progress).ConfigureAwait(false);

            // Create http response
            var httpResponse = new HttpMessageEnsureScopesResponse(ctx, serverScopeInfo);

            return(httpResponse);
        }
        InternalGetServerScopeInfoAsync(SyncContext context, SyncSetup setup, DbConnection connection, DbTransaction transaction, CancellationToken cancellationToken, IProgress <ProgressArgs> progress)
        {
            // Create the message to be sent
            var httpMessage = new HttpMessageEnsureScopesRequest(context);

            // serialize message
            var serializer = this.SerializerFactory.GetSerializer <HttpMessageEnsureScopesRequest>();
            var binaryData = await serializer.SerializeAsync(httpMessage);

            // Raise progress for sending request and waiting server response
            await this.InterceptAsync(new HttpGettingScopeRequestArgs(context, this.GetServiceHost()), progress, cancellationToken).ConfigureAwait(false);

            // No batch size submitted here, because the schema will be generated in memory and send back to the user.
            var response = await this.httpRequestHandler.ProcessRequestAsync
                               (this.HttpClient, context, this.ServiceUri, binaryData, HttpStep.EnsureScopes,
                               this.SerializerFactory, this.Converter, 0, this.SyncPolicy, cancellationToken, progress).ConfigureAwait(false);

            HttpMessageEnsureScopesResponse ensureScopesResponse = null;

            using (var streamResponse = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
            {
                if (streamResponse.CanRead)
                {
                    ensureScopesResponse = await this.SerializerFactory.GetSerializer <HttpMessageEnsureScopesResponse>().DeserializeAsync(streamResponse);
                }
            }

            if (ensureScopesResponse == null)
            {
                throw new ArgumentException("Http Message content for Ensure scope can't be null");
            }

            if (ensureScopesResponse.ServerScopeInfo == null)
            {
                throw new ArgumentException("Server scope from EnsureScopesAsync can't be null and may contains a server scope");
            }

            // Re build schema relationships with all tables
            ensureScopesResponse.ServerScopeInfo.Schema?.EnsureSchema();

            // Report Progress
            await this.InterceptAsync(new HttpGettingScopeResponseArgs(ensureScopesResponse.ServerScopeInfo, ensureScopesResponse.SyncContext, this.GetServiceHost()), progress, cancellationToken).ConfigureAwait(false);

            // Return scopes and new shema
            return(context, ensureScopesResponse.ServerScopeInfo);
        }
        internal async Task <HttpMessageEnsureScopesResponse> EnsureScopeAsync(HttpMessageEnsureScopesRequest httpMessage, SessionCache sessionCache, CancellationToken cancellationToken)
        {
            if (httpMessage == null)
            {
                throw new ArgumentException("EnsureScopesAsync message could not be null");
            }

            if (this.Setup == null)
            {
                throw new ArgumentException("You need to set the tables to sync on server side");
            }

            // We can use default options on server
            this.Options = this.Options ?? new WebServerOptions();

            var(syncContext, newSchema) = await this.EnsureSchemaAsync(
                httpMessage.SyncContext, this.Setup, cancellationToken).ConfigureAwait(false);

            this.Schema = newSchema;

            var httpResponse = new HttpMessageEnsureScopesResponse(syncContext, newSchema);

            return(httpResponse);
        }