Пример #1
0
        public override async Task Initialize()
        {
            await base.Initialize();

            await CalendarViewModel.Initialize();

            WorkspacesObservable
            .Subscribe(data => Workspaces = data)
            .DisposedBy(disposeBag);

            var user = await dataSource.User.Get();

            userId = user.Id;

            IInteractor <IObservable <IThreadSafeWorkspace> > workspaceInteractor;

            workspaceInteractor = interactorFactory.GetDefaultWorkspace();

            var workspace = await workspaceInteractor
                            .TrackException <InvalidOperationException, IThreadSafeWorkspace>("ReportsViewModel.Initialize")
                            .Execute();

            workspaceId = workspace.Id;
            workspaceSubject.OnNext(workspace);

            CalendarViewModel.SelectedDateRangeObservable
            .Subscribe(changeDateRange)
            .DisposedBy(disposeBag);

            reportSubject
            .AsObservable()
            .Do(setLoadingState)
            .SelectMany(_ =>
                        startDate == default(DateTimeOffset) || endDate == default(DateTimeOffset)
                       ? Observable.Empty <ProjectSummaryReport>()
                       : interactorFactory.GetProjectSummary(workspaceId, startDate, endDate).Execute())
            .Catch(Observable.Return <ProjectSummaryReport>(null))
            .Subscribe(onReport)
            .DisposedBy(disposeBag);

            dataSource.Preferences.Current
            .Subscribe(onPreferencesChanged)
            .DisposedBy(disposeBag);

            dataSource.User.Current
            .Select(currentUser => currentUser.BeginningOfWeek)
            .Subscribe(onBeginningOfWeekChanged)
            .DisposedBy(disposeBag);

            interactorFactory.ObserveDefaultWorkspaceId()
            .Execute()
            .Where(newWorkspaceId => newWorkspaceId != workspaceId)
            .SelectMany(id => interactorFactory.GetWorkspaceById(id).Execute())
            .Where(ws => !ws.IsInaccessible)
            .Subscribe(updateWorkspace)
            .DisposedBy(disposeBag);
        }