我有一系列图像(IObservable<ImageSource>
)通过这个“管道”。
问题在于,当用户必须进行交互时,我不知道如何处理这种情况。我就是不能这样做
subscription = images
.Do(source => source.Freeze())
.Select(image => OcrService.Recognize(image))
.Subscribe(ocrResults => Upload(ocrResults));
...因为当用户必须修复ocrResults时,应该保持流程直到接受有效值(即用户可以执行命令单击按钮)
我怎么说:如果结果无效,请等到用户修复它们?
答案 0 :(得分:2)
我假设您的UploadAsync
方法返回Task
以允许您等待它完成?如果是这样,有SelectMany
的重载处理任务。
images.Select(originalImage => ImageOperations.Resize(originalImage))
.SelectMany(resizedImg => imageUploader.UploadAsync(resizedImg))
.Subscribe();
答案 1 :(得分:2)
假设您有一个实现“用户修复过程”的异步方法:
/tmp/
然后您的观察结果变为:
/* show the image to the user, which fixes it, returns true if fixed, false if should be skipped */
async Task UserFixesTheOcrResults(ocrResults);
答案 2 :(得分:2)
这似乎是UX,WPF和Rx的混合,都包含在一个问题中。试图用Rx解决它可能会让你进入尾部旋转。我相信你可以只用Rx解决它,而不再考虑它,但你想要吗?它是可测试的,松散耦合的并且易于维护吗?
在我对问题的理解中,你必须遵循以下步骤
但这可能更好地描述为
所以这对我来说似乎需要基于任务/队列的UI,以便用户可以看到他们需要处理的无效OCR结果。这也告诉我,如果涉及一个人,它应该在Rx查询之外。
subscription = images
.Subscribe(image=>
{
//image.Freeze() --probably should be done by the source sequence
var result = _ocrService.Recognize(image);
_validator.Enqueue(result);
});
//In the Enqueue method, if queue is empty, ProcessHead();
//Else add to queue.
//When Head item is updated, ProcessHead();
//ProcessHead method checks if the head item is valid, and if it is uploads it and remove from queue. Once removed from queue, if(!IsEmpty) {ProcessHead();}
//Display Head of the Queue (and probably queue depth) to user so they can interact with it.
Upload(ocrResults)
所以这里Rx只是我们军火库中的一个工具,而不是需要解决所有问题的锤子。我发现大多数&#34; Rx&#34;大小增加的问题,Rx只是各种Queue
结构的入口和出口点。这允许我们在我们的系统中显式排队而不是隐式(即隐藏在Rx运算符内)。