예제 #1
0
        private ISaveFileProgression applyFile(MasterDTO dto, SaveFileProgression progression)
        {
            Observable.Start(() =>
            {
                try
                {
                    _directoryDataService.Clear();
                    _fileDataService.Clear();
                    fileItemLinkService.Clear();
                    _itemService.Clear();

                    var dir   = _directoryDataService.Set(dto.Directories.Select(dto => dto.ToEntity()), RxApp.TaskpoolScheduler);
                    dir.Title = "loading directories";
                    progression.DirectoryTaskState = dir;
                    progression.DirectoryTaskState.DoneChanges.Subscribe(
                        dirState =>
                    {
                        if (dirState != TaskState.Done)
                        {
                            return;
                        }
                        var file   = _fileDataService.Set(dto.Files.Select(dto => dto.ToEntity()), RxApp.TaskpoolScheduler, settingsService.LoadingPatchSize);
                        file.Title = "loading files";
                        progression.FileTaskState = file;
                        progression.FileTaskState.DoneChanges.Subscribe(fileState =>
                        {
                            if (fileState != TaskState.Done)
                            {
                                return;
                            }
                            var link   = fileItemLinkService.Set(dto.FileItemLinks.Select(dto => dto.ToEntity()), RxApp.TaskpoolScheduler);
                            link.Title = "loading links";
                            progression.LinkTaskState = link;
                            progression.LinkTaskState.DoneChanges.Subscribe(linkState =>
                            {
                                if (linkState != TaskState.Done)
                                {
                                    return;
                                }
                                var item   = _itemService.Set(dto.Items.Select(dto => dto.ToEntity()));
                                item.Title = "loading links";
                                progression.ItemTaskState = item;
                                progression.ItemTaskState.DoneChanges.Subscribe(itemState =>
                                {
                                    if (itemState != TaskState.Done)
                                    {
                                        return;
                                    }
                                });
                            });
                        });
                    });
                }
                catch (Exception ex)
                {
                    progression.OnError(ex);
                }
            }, Scheduler.Default);
            return(progression);
        }
예제 #2
0
        public ISaveFileProgression Load(string file)
        {
            var progression = new SaveFileProgression();

            try
            {
                Observable.Start(() => loadFile(file))
                .Subscribe(dto => applyFile(dto, progression));
            }
            catch (Exception ex)
            {
                progression.OnError(ex);
            }
            return(progression);
        }