//FilteringSqlServerSync sqlServerSync = null; private bool InitializePhotoSyncProviders(EventTDO ev, string scopeName, string[] staticSyncTables, string[] dynamicSyncTables) { if (string.IsNullOrEmpty(AppConfig.PhotoDbServerSyncClass)) { FotoShoutUtils.Log.LogManager.Error(_logger, "The type of the database server upload sync need to be defined in app config."); return(false); } //sqlServerSync = new FilteringSqlServerSync(); //sqlServerSync.Configure(AppConfig.SyncAction, scopeName, AppConfig.ServerConnection, staticSyncTables, dynamicSyncTables); _sqlPhotoServerSync = new SqlServerSyncProviderProxy(AppConfig.SyncAction, scopeName, AppConfig.ServerConnection, staticSyncTables, dynamicSyncTables, AppConfig.PhotoDbServerSyncClass, SyncEngine.WFC_SERVICE_SQLSERVER); FotoShoutUtils.Log.LogManager.Info(_logger, "Server Upload Sync - " + _sqlPhotoServerSync.Ping()); DbSyncScopeDescription scopeDescription = _sqlPhotoServerSync.GetScopeDescription(scopeName); //DbSyncScopeDescription scopeDescription = sqlServerSync.GetScopeDescription(scopeName); _sqlPhotoClientSync = InitiateSyncScope(scopeName, scopeDescription, (SyncDirectionOrder)Enum.Parse(typeof(SyncDirectionOrder), AppConfig.PhotoSyncDirection)); if (_sqlPhotoClientSync != null) { _sqlPhotoClientSync.Synchronized += new FotoShoutUtils.Sync.Db.SynchronizedEventHandler(OnDbUploadSynchronized); } return(_sqlPhotoClientSync != null); }
private DbClientSync InitiateSyncScope(string scopeName, DbSyncScopeDescription scopeDescription, SyncDirectionOrder syncDirection) { Type type = Type.GetType(AppConfig.DbClientSyncClass); if (type == null) { FotoShoutUtils.Log.LogManager.Error(_logger, "The type of the database client sync is not supported."); return(null); } DbClientSync clientSync = (DbClientSync)Activator.CreateInstance(type); // clientSync.ServerConnection = AppConfig.ServerConnection; clientSync.ServerScopeDescription = scopeDescription; clientSync.Configure(AppConfig.SyncAction, scopeName, AppConfig.ClientConnection); if (string.IsNullOrEmpty(AppConfig.SyncAction) || AppConfig.SyncAction.Equals(FotoShoutUtils.Constants.ASV_SYNCACTION_PROVISION, StringComparison.InvariantCultureIgnoreCase)) { // Asign sync direction clientSync.SyncDirection = syncDirection; // Register event handlers for db sync FotoShoutUtils.Log.LogManager.Info(_logger, "Registering event handlers for database sync parties..."); clientSync.ApplyChangeFailed += new ApplyChangeFailedEventHandler(OnDbApplyChangeFailed); clientSync.ItemConflicting += new FotoShoutUtils.Sync.Db.ItemConflictingEventHandler(OnDbItemConflicting); clientSync.ItemConstraint += new FotoShoutUtils.Sync.Db.ItemConstraintEventHandler(OnDbItemConstraint); FotoShoutUtils.Log.LogManager.Info(_logger, "Successfully registered event handlers for database sync parties..."); return(clientSync); } return(null); }
private void RemoveClientUploadSyncEventHandlers(DbClientSync sqlClientUploadSync) { if (sqlClientUploadSync != null) { sqlClientUploadSync.ApplyChangeFailed -= new ApplyChangeFailedEventHandler(OnDbApplyChangeFailed); sqlClientUploadSync.ItemConflicting -= new FotoShoutUtils.Sync.Db.ItemConflictingEventHandler(OnDbItemConflicting); sqlClientUploadSync.ItemConstraint -= new FotoShoutUtils.Sync.Db.ItemConstraintEventHandler(OnDbItemConstraint); sqlClientUploadSync.Synchronized -= new FotoShoutUtils.Sync.Db.SynchronizedEventHandler(OnDbUploadSynchronized); } }
public override void Execute() { try { string syncAction = AppConfig.SyncAction; if (string.IsNullOrEmpty(syncAction) || !syncAction.Equals(FotoShoutUtils.Constants.ASV_SYNCACTION_DEPROVISIONSTORE, StringComparison.InvariantCultureIgnoreCase)) { // Initialize paramerters for FotoShout API if (!InitializeApi(_fsServerService, true)) { return; } if (InitializeApi(_fsClientService, false)) { FotoShoutUtils.Log.LogManager.Info(_logger, "Synchronizing events' data from local to central server..."); UploadEventsData(); FotoShoutUtils.Log.LogManager.Info(_logger, "Done synchronized events' data."); } } // Initialize parameters for Sync database if (!InitializeEventSyncProviders()) { return; } FotoShoutUtils.Log.LogManager.Info(_logger, "Downloading database records from central server to local..."); _sqlEventClientSync.Synchronize(_sqlEventServerSync); //_sqlEventClientSync.Synchronize(sqlServerSync.Provider); FotoShoutUtils.Log.LogManager.Info(_logger, "Done downloaded database.\n"); } catch (Exception ex) { if (ex is CommunicationObjectFaultedException) { _sqlEventServerSync = null; _sqlEventClientSync = null; FotoShoutUtils.Log.LogManager.Error(_logger, ex.Message + "\n The service will be re-initiated in the next round."); } else { FotoShoutUtils.Log.LogManager.Error(_logger, ex.ToString() + "\n"); } } }