public async Task <(SyncContext, DmSet)> EnsureSchemaAsync(SyncContext ctx, MessageEnsureSchema message) => await this.LocalProvider.EnsureSchemaAsync(ctx, message);
/// <summary> /// Ensure configuration is correct on both server and client side /// </summary> public virtual async Task <(SyncContext, DmSet)> EnsureSchemaAsync(SyncContext context, MessageEnsureSchema message) { try { context.SyncStage = SyncStage.SchemaApplying; // Get cache manager and try to get configuration from cache //var cacheManager = this.CacheManager; //// if we don't pass config object (configuration == null), we may be in proxy mode, so the config object is handled by a local configuration object. //if (syncConfiguration == null && this.syncConfiguration == null) // throw new ArgumentNullException("syncConfiguration", "You try to set a provider with no configuration object"); //// the configuration has been set from the proxy server itself, use it. //if (syncConfiguration == null && this.syncConfiguration != null) // syncConfiguration = this.syncConfiguration; // Raise event before context.SyncStage = SyncStage.SchemaApplying; var beforeArgs2 = new SchemaApplyingEventArgs(this.ProviderTypeName, context.SyncStage, message.Schema); this.TryRaiseProgressEvent(beforeArgs2, this.SchemaApplying); bool overWriteConfiguration = beforeArgs2.OverwriteConfiguration; // if we dont have already read the tables || we want to overwrite the current config if ((message.Schema.HasTables && !message.Schema.HasColumns)) { await this.ReadSchemaAsync(message.Schema); } context.SyncStage = SyncStage.SchemaApplied; var afterArgs = new SchemaAppliedEventArgs(this.ProviderTypeName, context.SyncStage, message.Schema); this.TryRaiseProgressEvent(afterArgs, this.SchemaApplied); return(context, message.Schema); } catch (SyncException) { throw; } catch (Exception ex) { throw new SyncException(ex, SyncStage.SchemaApplying, this.ProviderTypeName); } }
/// <summary> /// Ensure configuration is correct on both server and client side /// </summary> public virtual async Task <(SyncContext, DmSet)> EnsureSchemaAsync(SyncContext context, MessageEnsureSchema message) { try { context.SyncStage = SyncStage.SchemaReading; using (var connection = this.CreateConnection()) { await connection.OpenAsync(); using (var transaction = connection.BeginTransaction()) { // if we dont have already read the tables || we want to overwrite the current config if (message.Schema.HasTables && !message.Schema.HasColumns) { await this.ReadSchemaAsync(message.Schema, connection, transaction); } // Progress & Interceptor context.SyncStage = SyncStage.SchemaRead; var schemaArgs = new SchemaArgs(context, message.Schema, connection, transaction); this.ReportProgress(context, schemaArgs); await this.InterceptAsync(schemaArgs); transaction.Commit(); } connection.Close(); } return(context, message.Schema); } catch (SyncException) { throw; } catch (Exception ex) { throw new SyncException(ex, SyncStage.SchemaReading); } }
public async Task <(SyncContext, DmSet)> EnsureSchemaAsync(SyncContext context, MessageEnsureSchema message) { HttpMessage httpMessage = new HttpMessage { SyncContext = context, Step = HttpStep.EnsureConfiguration, Content = new HttpMessageEnsureSchema { Schema = message.Schema == null ? null : new DmSetSurrogate(message.Schema), SerializationFormat = message.SerializationFormat } }; //Post request and get response var httpMessageResponse = await this.httpRequestHandler.ProcessRequest(httpMessage, message.SerializationFormat, cancellationToken); if (httpMessageResponse == null) { throw new Exception("Can't have an empty body"); } HttpMessageEnsureSchema httpMessageContent; if (httpMessageResponse.Content is HttpMessageEnsureSchema) { httpMessageContent = httpMessageResponse.Content as HttpMessageEnsureSchema; } else { httpMessageContent = (httpMessageResponse.Content as JObject).ToObject <HttpMessageEnsureSchema>(); } if (httpMessageContent == null || httpMessageContent.Schema == null || httpMessageContent.Schema.Tables.Count <= 0) { throw new ArgumentException("Schema can't be null"); } // get schema & deserialize the surrogate message.Schema = httpMessageContent.Schema.ConvertToDmSet(); httpMessageContent.Schema.Clear(); httpMessageContent.Schema.Dispose(); httpMessageContent.Schema = null; // get context var syncContext = httpMessageResponse.SyncContext; return(syncContext, message.Schema); }
/// <summary> /// Ensure configuration is correct on both server and client side /// </summary> public virtual async Task <(SyncContext, DmSet)> EnsureSchemaAsync(SyncContext context, MessageEnsureSchema message) { try { context.SyncStage = SyncStage.SchemaApplying; using (var connection = this.CreateConnection()) { await connection.OpenAsync(); using (var transaction = connection.BeginTransaction()) { // Raise event before context.SyncStage = SyncStage.SchemaApplying; var beforeArgs2 = new SchemaApplyingEventArgs(this.ProviderTypeName, context.SyncStage, message.Schema, connection, transaction); this.TryRaiseProgressEvent(beforeArgs2, this.SchemaApplying); var overWriteConfiguration = beforeArgs2.OverwriteConfiguration; // if we dont have already read the tables || we want to overwrite the current config if (message.Schema.HasTables && !message.Schema.HasColumns) { await this.ReadSchemaAsync(message.Schema, connection, transaction); } context.SyncStage = SyncStage.SchemaApplied; var afterArgs = new SchemaAppliedEventArgs(this.ProviderTypeName, context.SyncStage, message.Schema, connection, transaction); this.TryRaiseProgressEvent(afterArgs, this.SchemaApplied); transaction.Commit(); } connection.Close(); } return(context, message.Schema); } catch (SyncException) { throw; } catch (Exception ex) { throw new SyncException(ex, SyncStage.SchemaApplying, this.ProviderTypeName); } }