예제 #1
0
        internal async Task <HttpMessageEnsureSchemaResponse> EnsureSchemaAsync(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.EnsureSchemaAsync(cancellationToken, progress).ConfigureAwait(false);

            this.Schema = serverScopeInfo.Schema;
            this.Schema.EnsureSchema();

            var httpResponse = new HttpMessageEnsureSchemaResponse(ctx, serverScopeInfo);

            return(httpResponse);
        }
예제 #2
0
        /// <summary>
        /// Send a request to remote web proxy for First step : Ensure scopes and schema
        /// </summary>
        internal override async Task <ServerScopeInfo> EnsureSchemaAsync(DbConnection connection = default, DbTransaction transaction = default, CancellationToken cancellationToken = default, IProgress <ProgressArgs> progress = null)
        {
            // Get context or create a new one
            var ctx = this.GetContext();

            ctx.SyncStage = SyncStage.SchemaReading;

            if (!this.StartTime.HasValue)
            {
                this.StartTime = DateTime.UtcNow;
            }

            // Create the message to be sent
            var httpMessage = new HttpMessageEnsureScopesRequest(ctx);

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

            // Raise progress for sending request and waiting server response
            var sendingRequestArgs = new HttpGettingSchemaRequestArgs(ctx, this.GetServiceHost());

            await this.InterceptAsync(sendingRequestArgs, cancellationToken).ConfigureAwait(false);

            this.ReportProgress(ctx, progress, sendingRequestArgs);

            // No batch size submitted here, because the schema will be generated in memory and send back to the user.
            var ensureScopesResponse = await this.httpRequestHandler.ProcessRequestAsync <HttpMessageEnsureSchemaResponse>
                                           (this.HttpClient, this.ServiceUri, binaryData, HttpStep.EnsureSchema, ctx.SessionId, this.ScopeName,
                                           this.SerializerFactory, this.Converter, 0, cancellationToken).ConfigureAwait(false);

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

            if (ensureScopesResponse.ServerScopeInfo == null || ensureScopesResponse.Schema == null || ensureScopesResponse.Schema.Tables.Count <= 0)
            {
                throw new ArgumentException("Schema from EnsureScope can't be null and may contains at least one table");
            }

            ensureScopesResponse.Schema.EnsureSchema();
            ensureScopesResponse.ServerScopeInfo.Schema = ensureScopesResponse.Schema;

            // Affect local setup
            this.Setup = ensureScopesResponse.ServerScopeInfo.Setup;

            // Reaffect context
            this.SetContext(ensureScopesResponse.SyncContext);

            // Report progress
            var args = new HttpGettingSchemaResponseArgs(ensureScopesResponse.ServerScopeInfo, ensureScopesResponse.Schema, ensureScopesResponse.SyncContext, this.GetServiceHost());

            await this.InterceptAsync(args, cancellationToken).ConfigureAwait(false);

            // Return scopes and new shema
            return(ensureScopesResponse.ServerScopeInfo);
        }
        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);
        }
예제 #4
0
        /// <summary>
        /// Get server scope from server, by sending an http request to the server
        /// </summary>
        public override async Task <ServerScopeInfo> GetServerScopeAsync(CancellationToken cancellationToken = default, IProgress <ProgressArgs> progress = null)
        {
            // Get context or create a new one
            var ctx = this.GetContext();

            if (!this.StartTime.HasValue)
            {
                this.StartTime = DateTime.UtcNow;
            }

            // Create the message to be sent
            var httpMessage = new HttpMessageEnsureScopesRequest(ctx);

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

            await this.InterceptAsync(new HttpMessageEnsureScopesRequestArgs(binaryData), cancellationToken).ConfigureAwait(false);

            // No batch size submitted here, because the schema will be generated in memory and send back to the user.
            var ensureScopesResponse = await this.httpRequestHandler.ProcessRequestAsync <HttpMessageEnsureScopesResponse>
                                           (this.HttpClient, this.ServiceUri, binaryData, HttpStep.EnsureScopes, ctx.SessionId, this.ScopeName,
                                           this.SerializerFactory, this.Converter, 0, cancellationToken).ConfigureAwait(false);

            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");
            }

            // Affect local setup
            this.Setup = ensureScopesResponse.ServerScopeInfo.Setup;

            // Reaffect context
            this.SetContext(ensureScopesResponse.SyncContext);

            // Return scopes and new shema
            return(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);
        }