Пример #1
0
        /// <summary>
        /// SyncAgent manage both server and client provider
        /// the tables array represents the tables you want to sync
        /// Don't work on the proxy provider
        /// </summary>
        public SyncAgent(string scopeName, CoreProvider clientProvider, IProvider serverProvider, string[] tables)
            : this(scopeName, clientProvider, serverProvider)
        {
            if (tables == null || tables.Length <= 0)
            {
                throw new ArgumentException("you need to pass at lease one table name");
            }

            if (!(this.RemoteProvider is CoreProvider remoteCoreProvider))
            {
                throw new ArgumentException("Since the remote provider is a web proxy, you have to configure the server side");
            }

            if (!remoteCoreProvider.CanBeServerProvider)
            {
                throw new NotSupportedException();
            }

            this.LocalProvider.SetConfiguration(c =>
            {
                foreach (var tbl in tables)
                {
                    c.Add(tbl);
                }
            });
            this.RemoteProvider.SetConfiguration(c =>
            {
                foreach (var tbl in tables)
                {
                    c.Add(tbl);
                }
            });
        }
Пример #2
0
        /// <summary>
        /// SyncAgent manage both server and client provider
        /// It's the main object to launch the Sync process
        /// </summary>
        public SyncAgent(string scopeName, CoreProvider localProvider, IProvider remoteProvider)
        {
            this.LocalProvider  = localProvider ?? throw new ArgumentNullException("ClientProvider");
            this.RemoteProvider = remoteProvider ?? throw new ArgumentNullException("ServerProvider");

            this.Configuration = new SyncConfiguration
            {
                ScopeName = scopeName ?? throw new ArgumentNullException("scopeName")
            };
            this.LocalProvider.SyncProgress          += (s, e) => this.SyncProgress?.Invoke(s, e);
            this.LocalProvider.BeginSession          += (s, e) => this.BeginSession?.Invoke(s, e);
            this.LocalProvider.EndSession            += (s, e) => this.EndSession?.Invoke(s, e);
            this.LocalProvider.TableChangesApplied   += (s, e) => this.TableChangesApplied?.Invoke(s, e);
            this.LocalProvider.TableChangesApplying  += (s, e) => this.TableChangesApplying?.Invoke(s, e);
            this.LocalProvider.TableChangesSelected  += (s, e) => this.TableChangesSelected?.Invoke(s, e);
            this.LocalProvider.TableChangesSelecting += (s, e) => this.TableChangesSelecting?.Invoke(s, e);
            this.LocalProvider.SchemaApplied         += (s, e) => this.SchemaApplied?.Invoke(s, e);
            this.LocalProvider.SchemaApplying        += (s, e) => this.SchemaApplying?.Invoke(s, e);
            this.LocalProvider.DatabaseApplied       += (s, e) => this.DatabaseApplied?.Invoke(s, e);
            this.LocalProvider.DatabaseApplying      += (s, e) => this.DatabaseApplying?.Invoke(s, e);
            this.LocalProvider.DatabaseTableApplied  += (s, e) => this.DatabaseTableApplied?.Invoke(s, e);
            this.LocalProvider.DatabaseTableApplying += (s, e) => this.DatabaseTableApplying?.Invoke(s, e);
            this.LocalProvider.ScopeLoading          += (s, e) => this.ScopeLoading?.Invoke(s, e);
            this.LocalProvider.ScopeSaved            += (s, e) => this.ScopeSaved?.Invoke(s, e);

            this.RemoteProvider.ApplyChangedFailed += this.RemoteProvider_ApplyChangedFailed;
        }
Пример #3
0
 public DbMigrationTable(CoreProvider provider, SyncTable currentTable, SyncTable newTable, bool preserveTracking = true)
 {
     this.currentTable     = currentTable ?? throw new ArgumentNullException(nameof(currentTable));
     this.newTable         = newTable ?? throw new ArgumentNullException(nameof(newTable));
     this.preserveTracking = preserveTracking;
     this.provider         = provider;
 }
Пример #4
0
        // 9
        /// <summary>
        /// Creates a synchronization agent that will handle a full synchronization between a client and a server.
        /// </summary>
        /// <param name="clientProvider">local provider to your client database</param>
        /// <param name="remoteOrchestrator">Remote Orchestrator already configured with a SyncProvider</param>
        /// <param name="options">Sync Options defining options used by your local provider (and remote provider if type of remoteOrchestrator is not a WebRemoteOrchestrator)</param>
        public SyncAgent(CoreProvider clientProvider, RemoteOrchestrator remoteOrchestrator, SyncOptions options = default)
            : this()
        {
            if (clientProvider is null)
            {
                throw new ArgumentNullException(nameof(clientProvider));
            }
            if (remoteOrchestrator is null)
            {
                throw new ArgumentNullException(nameof(remoteOrchestrator));
            }
            if (options == default)
            {
                options = new SyncOptions();
            }

            // Override remote orchestrator options, setup and scope name
            remoteOrchestrator.Options = options;

            var localOrchestrator = new LocalOrchestrator(clientProvider, options);

            this.LocalOrchestrator  = localOrchestrator;
            this.RemoteOrchestrator = remoteOrchestrator;
            this.EnsureOptionsAndSetupInstances();
        }
Пример #5
0
 /// <summary>
 /// Create a local orchestrator, used to orchestrates the whole sync on the client side
 /// </summary>
 public LocalOrchestrator(CoreProvider provider) : base(provider, new SyncOptions())
 {
     if (provider == null)
     {
         throw GetSyncError(null, new MissingProviderException(nameof(LocalOrchestrator)));
     }
 }
Пример #6
0
 public DbMigrationTools(CoreProvider provider, SyncOptions options, SyncSetup setup, string currentScopeInfoTableName = null)
 {
     this.provider   = provider;
     this.newOptions = options;
     this.newSetup   = setup;
     this.currentScopeInfoTableName = currentScopeInfoTableName;
 }
Пример #7
0
 /// <summary>
 /// Create a remote orchestrator, used to orchestrates the whole sync on the server side
 /// </summary>
 public RemoteOrchestrator(CoreProvider provider) : base(provider, new SyncOptions())
 {
     if (this.Provider != null && !this.Provider.CanBeServerProvider)
     {
         throw GetSyncError(null, new UnsupportedServerProviderException(this.Provider.GetProviderTypeName()));
     }
 }
 /// <summary>
 /// Create a remote orchestrator, used to orchestrates the whole sync on the server side
 /// </summary>
 public RemoteOrchestrator(CoreProvider provider, SyncOptions options, SyncSetup setup, string scopeName = SyncOptions.DefaultScopeName)
     : base(provider, options, setup, scopeName)
 {
     if (!this.Provider.CanBeServerProvider)
     {
         throw new UnsupportedServerProviderException(this.Provider.GetProviderTypeName());
     }
 }
Пример #9
0
        /// <summary>
        /// Create a local orchestrator, used to orchestrates the whole sync on the client side
        /// </summary>
        public BaseOrchestrator(CoreProvider provider, SyncOptions options, SyncSetup setup, string scopeName = SyncOptions.DefaultScopeName)
        {
            this.ScopeName = scopeName ?? throw new ArgumentNullException(nameof(scopeName));
            this.Provider  = provider ?? throw new ArgumentNullException(nameof(provider));
            this.Options   = options ?? throw new ArgumentNullException(nameof(options));
            this.Setup     = setup ?? throw new ArgumentNullException(nameof(setup));

            this.Provider.Orchestrator = this;
            this.Logger = options.Logger;
        }
Пример #10
0
        /// <summary>
        /// SyncAgent manage both server and client provider
        /// It's the main object to launch the Sync process
        /// </summary>
        public SyncAgent(string scopeName, CoreProvider localProvider, IProvider remoteProvider)
        {
            if (string.IsNullOrEmpty(scopeName))
            {
                throw new ArgumentNullException("scopeName");
            }
            this.LocalProvider  = localProvider ?? throw new ArgumentNullException("ClientProvider");
            this.RemoteProvider = remoteProvider ?? throw new ArgumentNullException("ServerProvider");

            this.LocalProvider.SetConfiguration(c => c.ScopeName  = scopeName);
            this.RemoteProvider.SetConfiguration(c => c.ScopeName = scopeName);

            this.Parameters = new SyncParameterCollection();
        }
Пример #11
0
        // 4
        /// <summary>
        /// Creates a synchronization agent that will handle a full synchronization between a client and a server.
        /// </summary>
        /// <param name="clientProvider">Local Provider connecting to your client database</param>
        /// <param name="serverProvider">Local Provider connecting to your server database</param>
        /// <param name="options">Sync Options defining options used by your local and remote provider</param>
        public SyncAgent(CoreProvider clientProvider, CoreProvider serverProvider, SyncOptions options = default)
            : this()
        {
            if (clientProvider is null)
            {
                throw new ArgumentNullException(nameof(clientProvider));
            }
            if (serverProvider is null)
            {
                throw new ArgumentNullException(nameof(serverProvider));
            }
            if (options == null)
            {
                options = new SyncOptions();
            }

            // Affect local and remote orchestrators
            this.LocalOrchestrator  = new LocalOrchestrator(clientProvider, options);
            this.RemoteOrchestrator = new RemoteOrchestrator(serverProvider, options);

            this.EnsureOptionsAndSetupInstances();
        }
Пример #12
0
        public async Task RunAsync(T args)
        {
            if (runFunc == null && runAction == null)
            {
                await Task.CompletedTask;
            }
            else
            {
                if (this.isAction)
                {
                    runAction(args);
                }
                else
                {
                    await runFunc(args);
                }

                if (args.Action == ChangeApplicationAction.Rollback)
                {
                    CoreProvider.RaiseRollbackException(args.Context, "Rollback by user during a progress event");
                }
            }
        }
Пример #13
0
 /// <summary>
 /// Intercept the provider action when session begin is called
 /// </summary>
 public static void InterceptOutdated(this CoreProvider coreProvider, Action <OutdatedArgs> func)
 => coreProvider.SetInterceptor(func);
Пример #14
0
 /// <summary>
 /// Intercept the provider when an apply change is failing
 /// </summary>
 public static void InterceptApplyChangesFailed(this CoreProvider coreProvider, Action <ApplyChangesFailedArgs> func)
 => coreProvider.SetInterceptor(func);
Пример #15
0
 /// <summary>
 /// Intercept the provider when an apply change is failing
 /// </summary>
 public static void InterceptApplyChangesFailed(this CoreProvider coreProvider, Func <ApplyChangesFailedArgs, Task> func)
 => coreProvider.SetInterceptor(func);
Пример #16
0
 /// <summary>
 /// Intercept the provider action when session end is called
 /// </summary>
 public static void InterceptSessionEnd(this CoreProvider coreProvider, Action <SessionEndArgs> func)
 => coreProvider.SetInterceptor(func);
Пример #17
0
 /// <summary>
 /// Intercept the provider action when session end is called
 /// </summary>
 public static void InterceptSessionEnd(this CoreProvider coreProvider, Func <SessionEndArgs, Task> func)
 => coreProvider.SetInterceptor(func);
Пример #18
0
 /// <summary>
 /// Local orchestrator used as a client
 /// </summary>
 public LocalOrchestrator(CoreProvider provider) => this.Provider = provider;
Пример #19
0
 /// <summary>
 /// Create an agent where the remote orchestrator could be of type RemoteOrchestrator (TCP connection) or WebClientOrchestrator (Http connection)
 /// </summary>
 /// <param name="clientProvider">local provider to your client database</param>
 /// <param name="remoteOrchestrator">remote orchestrator : RemoteOrchestrator or WebClientOrchestrator) </param>
 /// <param name="setup">Contains list of your tables. Not used if remote orchestrator is WebClientOrchestrator</param>
 /// <param name="options">Options. Only used on locally if remote orchestrator is WebClientOrchestrator</param>
 public SyncAgent(CoreProvider clientProvider, IRemoteOrchestrator remoteOrchestrator,
                  SyncSetup setup = null, SyncOptions options = null)
     : this(new LocalOrchestrator(clientProvider), remoteOrchestrator, setup, options)
 {
 }
Пример #20
0
 public static void SetInterceptor <T>(this CoreProvider coreProvider, Func <T, Task> func) where T : ProgressArgs
 {
     coreProvider.SetInterceptor(new Interceptor <T>(func));
 }
Пример #21
0
 /// <summary>
 /// Create an agent based on TCP connection
 /// </summary>
 /// <param name="clientProvider">local provider to your client database</param>
 /// <param name="serverProvider">local provider to your server database</param>
 /// <param name="tables">tables list</param>
 public SyncAgent(CoreProvider clientProvider, CoreProvider serverProvider, string[] tables)
     : this(new LocalOrchestrator(clientProvider), new RemoteOrchestrator(serverProvider), new SyncSetup(tables))
 {
 }
Пример #22
0
 /// <summary>
 /// Intercept the provider when schema is readed
 /// </summary>
 public static void InterceptSchema(this CoreProvider coreProvider, Func <SchemaArgs, Task> func)
 => coreProvider.SetInterceptor(func);
Пример #23
0
 /// <summary>
 /// SyncAgent manage both server and client provider
 /// the tables array represents the tables you want to sync
 /// Don't work on the proxy provider
 /// </summary>
 public SyncAgent(CoreProvider clientProvider, IProvider serverProvider, string[] tables)
     : this("DefaultScope", clientProvider, serverProvider, tables)
 {
 }
Пример #24
0
 /// <summary>
 /// SyncAgent used in a web proxy sync session. No need to set tables, it's done from the server web api side.
 /// </summary>
 public SyncAgent(CoreProvider localProvider, IProvider remoteProvider)
     : this("DefaultScope", localProvider, remoteProvider)
 {
 }
Пример #25
0
 /// <summary>
 /// Intercept the provider when schema is readed
 /// </summary>
 public static void InterceptSchema(this CoreProvider coreProvider, Action <SchemaArgs> func)
 => coreProvider.SetInterceptor(func);
Пример #26
0
 /// <summary>
 /// Intercept the provider before it begins a database deprovisioning
 /// </summary>
 public static void InterceptDatabaseDeprovisioning(this CoreProvider coreProvider, Action <DatabaseDeprovisioningArgs> func)
 => coreProvider.SetInterceptor(func);
Пример #27
0
 /// <summary>
 /// Intercept the provider action when changes are applied on each table defined in the configuration schema
 /// </summary>
 public static void InterceptTableChangesApplied(this CoreProvider coreProvider, Action <TableChangesAppliedArgs> func)
 => coreProvider.SetInterceptor(func);
Пример #28
0
 /// <summary>
 /// Create an agent based on TCP connection
 /// </summary>
 /// <param name="clientProvider">local provider to your client database</param>
 /// <param name="serverProvider">local provider to your server database</param>
 /// <param name="setup">Contains list of your tables.</param>
 public SyncAgent(CoreProvider clientProvider, CoreProvider serverProvider, SyncSetup setup)
     : this(new LocalOrchestrator(clientProvider), new RemoteOrchestrator(serverProvider), setup)
 {
 }
Пример #29
0
 /// <summary>
 /// Create a local orchestrator, used to orchestrates the whole sync on the client side
 /// </summary>
 public LocalOrchestrator(CoreProvider provider, SyncOptions options, SyncSetup setup, string scopeName = SyncOptions.DefaultScopeName)
     : base(provider, options, setup, scopeName)
 {
 }
Пример #30
0
 /// <summary>
 /// Intercept the provider after it has deprovisioned a database
 /// </summary>
 public static void InterceptDatabaseDeprovisioned(this CoreProvider coreProvider, Func <DatabaseDeprovisionedArgs, Task> func)
 => coreProvider.SetInterceptor(func);