/// <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);
            }
        }
Ejemplo n.º 2
0
        /// <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);
            }
        }