private static void configurePullTransitions( ITransitionConfigurator transitions, ITogglDatabase database, ITogglApi api, ITogglDataSource dataSource, ITimeService timeService, IAnalyticsService analyticsService, IScheduler scheduler, StateResult entryPoint, IObservable <Unit> delayCancellation) { var rnd = new Random(); var apiDelay = new RetryDelayService(rnd); var statusDelay = new RetryDelayService(rnd); var fetchAllSince = new FetchAllSinceState(database, api, timeService); var persistWorkspaces = new PersistListState <IWorkspace, IDatabaseWorkspace, IThreadSafeWorkspace>(dataSource.Workspaces, Workspace.Clean); var updateWorkspacesSinceDate = new SinceDateUpdatingState <IWorkspace, IDatabaseWorkspace>(database.SinceParameters); var detectNoWorkspaceState = new NoWorkspaceDetectingState(); var persistWorkspaceFeatures = new PersistListState <IWorkspaceFeatureCollection, IDatabaseWorkspaceFeatureCollection, IThreadSafeWorkspaceFeatureCollection>( dataSource.WorkspaceFeatures, WorkspaceFeatureCollection.From); var persistUser = new PersistSingletonState <IUser, IDatabaseUser, IThreadSafeUser>(dataSource.User, User.Clean); var noDefaultWorkspaceTrackingState = new NoDefaultWorkspaceTrackingState(analyticsService); var persistTags = new PersistListState <ITag, IDatabaseTag, IThreadSafeTag>(dataSource.Tags, Tag.Clean); var updateTagsSinceDate = new SinceDateUpdatingState <ITag, IDatabaseTag>(database.SinceParameters); var persistClients = new PersistListState <IClient, IDatabaseClient, IThreadSafeClient>(dataSource.Clients, Client.Clean); var updateClientsSinceDate = new SinceDateUpdatingState <IClient, IDatabaseClient>(database.SinceParameters); var persistPreferences = new PersistSingletonState <IPreferences, IDatabasePreferences, IThreadSafePreferences>(dataSource.Preferences, Preferences.Clean); var persistProjects = new PersistListState <IProject, IDatabaseProject, IThreadSafeProject>(dataSource.Projects, Project.Clean); var updateProjectsSinceDate = new SinceDateUpdatingState <IProject, IDatabaseProject>(database.SinceParameters); var createGhostProjects = new CreateGhostProjectsState(dataSource.Projects, analyticsService); var persistTimeEntries = new PersistListState <ITimeEntry, IDatabaseTimeEntry, IThreadSafeTimeEntry>(dataSource.TimeEntries, TimeEntry.Clean); var updateTimeEntriesSinceDate = new SinceDateUpdatingState <ITimeEntry, IDatabaseTimeEntry>(database.SinceParameters); var persistTasks = new PersistListState <ITask, IDatabaseTask, IThreadSafeTask>(dataSource.Tasks, Task.Clean); var updateTasksSinceDate = new SinceDateUpdatingState <ITask, IDatabaseTask>(database.SinceParameters); var refetchInaccessibleProjects = new TryFetchInaccessibleProjectsState(dataSource.Projects, timeService, api.Projects); var retryOrThrow = new SevereApiExceptionsRethrowingState(); var checkServerStatus = new CheckServerStatusState(api, scheduler, apiDelay, statusDelay, delayCancellation); var finished = new ResetAPIDelayState(apiDelay); var deleteOlderEntries = new DeleteOldEntriesState(timeService, dataSource.TimeEntries); var deleteNonReferencedGhostProjects = new DeleteNonReferencedProjectGhostsState(dataSource.Projects, dataSource.TimeEntries); transitions.ConfigureTransition(entryPoint, fetchAllSince); transitions.ConfigureTransition(fetchAllSince.FetchStarted, persistWorkspaces); transitions.ConfigureTransition(persistWorkspaces.FinishedPersisting, updateWorkspacesSinceDate); transitions.ConfigureTransition(updateWorkspacesSinceDate.Finished, detectNoWorkspaceState); transitions.ConfigureTransition(detectNoWorkspaceState.Continue, persistUser); transitions.ConfigureTransition(persistUser.FinishedPersisting, noDefaultWorkspaceTrackingState); transitions.ConfigureTransition(noDefaultWorkspaceTrackingState.Continue, persistWorkspaceFeatures); transitions.ConfigureTransition(persistWorkspaceFeatures.FinishedPersisting, persistPreferences); transitions.ConfigureTransition(persistPreferences.FinishedPersisting, persistTags); transitions.ConfigureTransition(persistTags.FinishedPersisting, updateTagsSinceDate); transitions.ConfigureTransition(updateTagsSinceDate.Finished, persistClients); transitions.ConfigureTransition(persistClients.FinishedPersisting, updateClientsSinceDate); transitions.ConfigureTransition(updateClientsSinceDate.Finished, persistProjects); transitions.ConfigureTransition(persistProjects.FinishedPersisting, updateProjectsSinceDate); transitions.ConfigureTransition(updateProjectsSinceDate.Finished, persistTasks); transitions.ConfigureTransition(persistTasks.FinishedPersisting, updateTasksSinceDate); transitions.ConfigureTransition(updateTasksSinceDate.Finished, createGhostProjects); transitions.ConfigureTransition(createGhostProjects.FinishedPersisting, persistTimeEntries); transitions.ConfigureTransition(persistTimeEntries.FinishedPersisting, updateTimeEntriesSinceDate); transitions.ConfigureTransition(updateTimeEntriesSinceDate.Finished, refetchInaccessibleProjects); transitions.ConfigureTransition(refetchInaccessibleProjects.FetchNext, refetchInaccessibleProjects); transitions.ConfigureTransition(refetchInaccessibleProjects.FinishedPersisting, deleteOlderEntries); transitions.ConfigureTransition(deleteOlderEntries.FinishedDeleting, deleteNonReferencedGhostProjects); transitions.ConfigureTransition(persistWorkspaces.ErrorOccured, retryOrThrow); transitions.ConfigureTransition(persistUser.ErrorOccured, retryOrThrow); transitions.ConfigureTransition(persistWorkspaceFeatures.ErrorOccured, retryOrThrow); transitions.ConfigureTransition(persistPreferences.ErrorOccured, retryOrThrow); transitions.ConfigureTransition(persistTags.ErrorOccured, retryOrThrow); transitions.ConfigureTransition(persistClients.ErrorOccured, retryOrThrow); transitions.ConfigureTransition(persistProjects.ErrorOccured, retryOrThrow); transitions.ConfigureTransition(persistTasks.ErrorOccured, retryOrThrow); transitions.ConfigureTransition(createGhostProjects.ErrorOccured, retryOrThrow); transitions.ConfigureTransition(persistTimeEntries.ErrorOccured, retryOrThrow); transitions.ConfigureTransition(refetchInaccessibleProjects.ErrorOccured, retryOrThrow); transitions.ConfigureTransition(retryOrThrow.Retry, checkServerStatus); transitions.ConfigureTransition(checkServerStatus.Retry, checkServerStatus); transitions.ConfigureTransition(checkServerStatus.ServerIsAvailable, finished); transitions.ConfigureTransition(finished.Continue, fetchAllSince); }
public SevereApiExceptionsRethrowingStateTests() { state = new SevereApiExceptionsRethrowingState(); }