private static IStateResult configurePushTransitionsForTimeEntries( TransitionHandlerProvider transitions, ITogglDatabase database, ITogglApi api, ITogglDataSource dataSource, IRetryDelayService apiDelay, IScheduler scheduler, IStateResult entryPoint, IObservable <Unit> delayCancellation) { var rnd = new Random(); var statusDelay = new RetryDelayService(rnd); var push = new PushTimeEntriesState(database.TimeEntries); var pushOne = new PushOneEntityState <IDatabaseTimeEntry>(); var create = new CreateTimeEntryState(api, dataSource.TimeEntries); var update = new UpdateTimeEntryState(api, dataSource.TimeEntries); var delete = new DeleteTimeEntryState(api, database.TimeEntries); var deleteLocal = new DeleteLocalTimeEntryState(database.TimeEntries); var tryResolveClientError = new TryResolveClientErrorState <IDatabaseTimeEntry>(); var unsyncable = new UnsyncableTimeEntryState(dataSource.TimeEntries); var checkServerStatus = new CheckServerStatusState(api, scheduler, apiDelay, statusDelay, delayCancellation); var finished = new ResetAPIDelayState(apiDelay); return(configurePush(transitions, entryPoint, push, pushOne, create, update, delete, deleteLocal, tryResolveClientError, unsyncable, checkServerStatus, finished)); }
public CheckServerStatusState(ITogglApi api, IScheduler scheduler, IRetryDelayService apiDelay, IRetryDelayService statusDelay) { this.api = api; this.scheduler = scheduler; this.apiDelay = apiDelay; this.statusDelay = statusDelay; }
public CheckServerStatusState(ITogglApi api, IScheduler scheduler, IRetryDelayService apiDelay, IRetryDelayService statusDelay, IObservable <Unit> delayCancellation) { this.api = api; this.scheduler = scheduler; this.apiDelay = apiDelay; this.statusDelay = statusDelay; this.delayCancellation = delayCancellation; }
public CheckServerStatusStateTests() { api = Substitute.For <ITogglApi>(); scheduler = new TestScheduler(); apiDelay = Substitute.For <IRetryDelayService>(); statusDelay = Substitute.For <IRetryDelayService>(); state = new CheckServerStatusState(api, scheduler, apiDelay, statusDelay); }
public CheckServerStatusStateTests() { api = Substitute.For <ITogglApi>(); scheduler = new TestScheduler(); apiDelay = Substitute.For <IRetryDelayService>(); statusDelay = Substitute.For <IRetryDelayService>(); delayCancellation = new Subject <Unit>(); state = new CheckServerStatusState(api, scheduler, apiDelay, statusDelay, delayCancellation.AsObservable()); }
private void runDelays(IRetryDelayService delay, bool[] slowOrFast) { foreach (var nextIsSlow in slowOrFast) { if (nextIsSlow) { delay.NextSlowDelay(); } else { delay.NextFastDelay(); } } }
public static void ConfigureTransitions( TransitionHandlerProvider transitions, ITogglDatabase database, ITogglApi api, ITogglDataSource dataSource, IRetryDelayService apiDelay, IScheduler scheduler, ITimeService timeService, StateMachineEntryPoints entryPoints, IObservable <Unit> delayCancellation) { configurePullTransitions(transitions, database, api, dataSource, timeService, scheduler, entryPoints.StartPullSync, delayCancellation); configurePushTransitions(transitions, database, api, dataSource, apiDelay, scheduler, entryPoints.StartPushSync, delayCancellation); }
public static void ConfigureTransitions( ITransitionConfigurator transitions, ITogglDatabase database, ITogglApi api, ITogglDataSource dataSource, IRetryDelayService apiDelay, IScheduler scheduler, ITimeService timeService, IAnalyticsService analyticsService, StateMachineEntryPoints entryPoints, IObservable <Unit> delayCancellation) { configurePullTransitions(transitions, database, api, dataSource, timeService, analyticsService, scheduler, entryPoints.StartPullSync, delayCancellation); configurePushTransitions(transitions, api, dataSource, analyticsService, apiDelay, scheduler, entryPoints.StartPushSync, delayCancellation); configureCleanUpTransitions(transitions, timeService, dataSource, entryPoints.StartCleanUp); }
private static void configurePushTransitions( TransitionHandlerProvider transitions, ITogglApi api, ITogglDataSource dataSource, IRetryDelayService apiDelay, IScheduler scheduler, StateResult entryPoint, IObservable <Unit> delayCancellation) { var pushingUsersFinished = configurePushSingleton(transitions, entryPoint, dataSource.User, api.User, User.Clean, User.Unsyncable, api, scheduler, delayCancellation); var pushingPreferencesFinished = configurePushSingleton(transitions, pushingUsersFinished, dataSource.Preferences, api.Preferences, Preferences.Clean, Preferences.Unsyncable, api, scheduler, delayCancellation); var pushingTagsFinished = configureCreateOnlyPush(transitions, pushingPreferencesFinished, dataSource.Tags, api.Tags, Tag.Clean, Tag.Unsyncable, api, scheduler, delayCancellation); var pushingClientsFinished = configureCreateOnlyPush(transitions, pushingTagsFinished, dataSource.Clients, api.Clients, Client.Clean, Client.Unsyncable, api, scheduler, delayCancellation); var pushingProjectsFinished = configureCreateOnlyPush(transitions, pushingClientsFinished, dataSource.Projects, api.Projects, Project.Clean, Project.Unsyncable, api, scheduler, delayCancellation); configurePush(transitions, pushingProjectsFinished, dataSource.TimeEntries, api.TimeEntries, api.TimeEntries, api.TimeEntries, TimeEntry.Clean, TimeEntry.Unsyncable, api, apiDelay, scheduler, delayCancellation); }
private static void configurePushTransitions( TransitionHandlerProvider transitions, ITogglDatabase database, ITogglApi api, ITogglDataSource dataSource, IRetryDelayService apiDelay, IScheduler scheduler, StateResult entryPoint, IObservable <Unit> delayCancellation) { var pushingUsersFinished = configurePushTransitionsForUsers(transitions, database, api, scheduler, entryPoint, delayCancellation); var pushingPreferencesFinished = configurePushTransitionsForPreferences(transitions, database, api, scheduler, pushingUsersFinished, delayCancellation); var pushingTagsFinished = configurePushTransitionsForTags(transitions, database, api, scheduler, pushingPreferencesFinished, delayCancellation); var pushingClientsFinished = configurePushTransitionsForClients(transitions, database, api, scheduler, pushingTagsFinished, delayCancellation); var pushingProjectsFinished = configurePushTransitionsForProjects(transitions, database, api, scheduler, pushingClientsFinished, delayCancellation); configurePushTransitionsForTimeEntries(transitions, database, api, dataSource, apiDelay, scheduler, pushingProjectsFinished, delayCancellation); }
public ResetAPIDelayState(IRetryDelayService delay) { this.delay = delay; }
private static IStateResult configurePush <TModel, TDatabase, TThreadsafe>( ITransitionConfigurator transitions, IStateResult entryPoint, IDataSource <TThreadsafe, TDatabase> dataSource, IAnalyticsService analyticsService, ICreatingApiClient <TModel> creatingApi, IUpdatingApiClient <TModel> updatingApi, IDeletingApiClient <TModel> deletingApi, Func <TModel, TThreadsafe> toClean, Func <TThreadsafe, string, TThreadsafe> toUnsyncable, ITogglApi api, IRetryDelayService apiDelay, IScheduler scheduler, IObservable <Unit> delayCancellation) where TModel : class, IIdentifiable, ILastChangedDatable where TDatabase : class, TModel, IDatabaseSyncable where TThreadsafe : class, TDatabase, IThreadSafeModel { var rnd = new Random(); var statusDelay = new RetryDelayService(rnd); var push = new PushState <TDatabase, TThreadsafe>(dataSource); var pushOne = new PushOneEntityState <TThreadsafe>(); var create = new CreateEntityState <TModel, TThreadsafe>(creatingApi, dataSource, analyticsService, toClean); var update = new UpdateEntityState <TModel, TThreadsafe>(updatingApi, dataSource, analyticsService, toClean); var delete = new DeleteEntityState <TModel, TDatabase, TThreadsafe>(deletingApi, dataSource, analyticsService); var deleteLocal = new DeleteLocalEntityState <TDatabase, TThreadsafe>(dataSource); var tryResolveClientError = new TryResolveClientErrorState <TThreadsafe>(); var unsyncable = new UnsyncableEntityState <TThreadsafe>(dataSource, toUnsyncable); var checkServerStatus = new CheckServerStatusState(api, scheduler, apiDelay, statusDelay, delayCancellation); var finished = new ResetAPIDelayState(apiDelay); transitions.ConfigureTransition(entryPoint, push); transitions.ConfigureTransition(push.PushEntity, pushOne); transitions.ConfigureTransition(pushOne.CreateEntity, create); transitions.ConfigureTransition(pushOne.UpdateEntity, update); transitions.ConfigureTransition(pushOne.DeleteEntity, delete); transitions.ConfigureTransition(pushOne.DeleteEntityLocally, deleteLocal); transitions.ConfigureTransition(create.ClientError, tryResolveClientError); transitions.ConfigureTransition(update.ClientError, tryResolveClientError); transitions.ConfigureTransition(delete.ClientError, tryResolveClientError); transitions.ConfigureTransition(create.ServerError, checkServerStatus); transitions.ConfigureTransition(update.ServerError, checkServerStatus); transitions.ConfigureTransition(delete.ServerError, checkServerStatus); transitions.ConfigureTransition(create.UnknownError, checkServerStatus); transitions.ConfigureTransition(update.UnknownError, checkServerStatus); transitions.ConfigureTransition(delete.UnknownError, checkServerStatus); transitions.ConfigureTransition(tryResolveClientError.UnresolvedTooManyRequests, checkServerStatus); transitions.ConfigureTransition(tryResolveClientError.Unresolved, unsyncable); transitions.ConfigureTransition(checkServerStatus.Retry, checkServerStatus); transitions.ConfigureTransition(checkServerStatus.ServerIsAvailable, push); transitions.ConfigureTransition(create.CreatingFinished, finished); transitions.ConfigureTransition(update.UpdatingSucceeded, finished); transitions.ConfigureTransition(delete.DeletingFinished, finished); transitions.ConfigureTransition(deleteLocal.Deleted, finished); transitions.ConfigureTransition(deleteLocal.DeletingFailed, finished); transitions.ConfigureTransition(finished.Continue, push); return(push.NothingToPush); }