public void WireupTaskFileServices(PrimaryTaskFileService ptfs, ArchiveTaskFileService atfs)
        {
            _archiveFileService = atfs;

            _taskFileService = ptfs;

            TaskList = _taskFileService.TaskList;

            _loadingStateObserver = Observable.FromEvent <LoadingStateChangedEventArgs>(
                _taskFileService, "LoadingStateChanged");

            _loadingStateObserver.Subscribe(e => LoadingState = e.EventArgs.LoadingState);

            _taskListChangedObserver = Observable.FromEvent <TaskListChangedEventArgs>(
                _taskFileService, "TaskListChanged");

            _taskListChangedObserver.Subscribe(e =>
            {
                RaisePropertyChanged(AllTasksPropertyName);
                RaisePropertyChanged(CompletedTasksPropertyName);
                RaisePropertyChanged(ContextsPropertyName);
                RaisePropertyChanged(ProjectsPropertyName);
            });

            Observable.FromEvent <SynchronizationErrorEventArgs>(_taskFileService, "SynchronizationError")
            .Subscribe(e => Messenger.Default.Send(new SynchronizationErrorMessage(e.EventArgs.Exception)));

            _taskFileService.LocalHasChangesChanged += TaskFileServiceOnLocalHasChangesChanged;
        }
Exemple #2
0
        private static void Initialize(ApplicationSettings settings)
        {
            var ptfs = new PrimaryTaskFileService(_dropBoxService, settings);
            var atfs = new ArchiveTaskFileService(_dropBoxService, settings);

            if (_main == null)
            {
                _main = new MainViewModel(ptfs, atfs, settings);
            }
            else
            {
                _main.WireupTaskFileServices(ptfs, atfs);
            }
        }
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(PrimaryTaskFileService taskFileService, ArchiveTaskFileService archiveFileService, ApplicationSettings applicationSettings)
        {
            _applicationSettings = applicationSettings;

            if (IsInDesignMode)
            {
                // Code runs in Blend --> create design time data.
                TaskList = new TaskList
                {
                    new Task("A", null, null,
                             "This is a designer task that might be really long the quick brown fox jumped over the lazy dogs"),
                    new Task("", null, null, "This is a designer task2"),
                    new Task("", null, null,
                             "This is a designer task3 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
                };

                var b = new Task("B", null, null, "This is a designer task4", DateTime.Now.AddDays(-1), null, false, null);
                b.ToggleCompleted();
                TaskList.Add(b);
                TaskList.Add(new Task("C", null, null, "This is a designer task5"));

                TaskList.Add(new Task("This task has two contexts @home @work"));
                TaskList.Add(new Task("This task has two projects +planvacation +fixstove"));
                TaskList.Add(new Task("This task has one of each @home +fixstove"));
                TaskList.Add(new Task(""));         // Blank task line

                SelectedTask = TaskList[3];
                ViewTask();
            }
            else
            {
                // Code runs "for real"
                WireupTaskFileServices(taskFileService, archiveFileService);

                Messenger.Default.Register <DrillDownMessage>(this, Filter);
                Messenger.Default.Register <ApplicationStartedMessage>(this, message =>
                {
                    LocalHasChanges = _taskFileService.LocalHasChanges;

                    if (StartupSyncCommand.CanExecute(null))
                    {
                        StartupSyncCommand.Execute(null);
                    }
                });

                WireUpCommands();
            }
        }