public void Execute(object parameter)
        {
            ITaskProgressionInfo prog = null;

            switch (parameter)
            {
            case IEnumerable <ItemEx> items:
                prog = thumbnailManagementService.CreateAndLinkThumbnail(items.ToArray());
                break;

            case ItemEx item:
                Observable.Start(
                    () => thumbnailManagementService.CreateAndLinkThumbnail(item),
                    RxApp.TaskpoolScheduler
                    );
                break;

            case null:
                throw new NotImplementedException($"{nameof(CreateThumbnailsCommand)}.{nameof(Execute)}: creating thumbnails for all items is not supported yet");

            //prog = thumbnailManagementService.CreateAndLinkThumbnail();
            //break;
            default:
                throw new NotImplementedException($"{nameof(CreateThumbnailsCommand)}.{nameof(Execute)}: invalid parameter {parameter}");
            }
            prog.ErrorChanges.TakeUntil(prog.DoneChanges).Where(ex => ex != null).Subscribe(ex => MessageBox.Show(ex?.ToString(), "thumbnails could not be created"));
        }
示例#2
0
        public static IEnumerable <IObservable <IEnumerable <Tout> > > SelectAsync <Tin, Tout>(this IEnumerable <Tin> list, Func <Tin, Tout> selector, int chunkSize, out ITaskProgressionInfo progress)
        {
            var prog = new TaskProgression()
            {
                State = TaskState.Todo
            };
            var chunkCount = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(list.Count()) / chunkSize));
            var res        = getSubjectList <IEnumerable <Tout> >(chunkCount);

            progress = prog;
            Observable.Start(() =>
            {
                try
                {
                    prog.State            = TaskState.InProgress;
                    var chunks            = list.ChunkBy(chunkSize).ToArray();
                    prog.RequiredProgress = chunks.Length;
                    var i = 0;
                    foreach (var chunk in chunks)
                    {
                        res.ElementAt(i).OnNext(chunk.Select(selector).ToArray());
                        prog.CurrentProgress++;
                        i++;
                    }
                    prog.State = TaskState.Done;
                }
                catch (Exception ex)
                {
                    prog.Details = "failed: " + ex.ToString();
                    prog.Error   = ex;
                    prog.State   = TaskState.Failed;
                }
            }, RxApp.TaskpoolScheduler);
            return(res);
        }