コード例 #1
0
ファイル: SyncAgent.cs プロジェクト: pedoc/Dotmim.Sync
        /// <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
ファイル: SyncAgent.cs プロジェクト: waelbouchnak/Dotmim.Sync
        /// <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()));
     }
 }
コード例 #8
0
 /// <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
ファイル: SyncAgent.cs プロジェクト: pedoc/Dotmim.Sync
        /// <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
ファイル: SyncAgent.cs プロジェクト: pedoc/Dotmim.Sync
 /// <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
ファイル: SyncAgent.cs プロジェクト: pedoc/Dotmim.Sync
 /// <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);