c# - 响应式(Reactive)扩展 : Creating a pipeline with Rx that works with files

标签 c# .net system.reactive idisposable ziparchive

我有一个包含三个步骤的流程管道:

  1. 视频转图像:我有一个视频已转换为静态图像 (帧)
  2. 帧到 zip 文件:处理视频中的所有帧后,我应该使用它们创建一个 Zip 文件。
  3. zip 文件 => 上传到 FTP

它涉及两个一次性内容:视频捕获和 zip 文件。

我该如何使用 Rx 来处理它?我不知道如何开始。

最佳答案

您是否必须传递每个步骤的原始对象? 视频捕获或 zip 文件被“处理”应该没问题,因为我确信该操作会产生一些副作用(MemoryStream、写入磁盘的文件等)。 您可以将每个操作结果的指针(Uri 的?)传递到管道的下一部分吗?

void Main()
{
    var video = new Uri("https://www.youtube.com/watch?v=Tp5mRlHwZ7M");
    var query = from frames in TranscodeVideoToImages(video)
        from zipFile in ZipFiles(frames)
        from uploadLocation in UploadFile(zipFile)
        select uploadLocation;
    query.Subscribe(...)
}
private IObservable<Uri[]> TranscodeVideoToImages(Uri imageSource)
{
    //Do some long running (async) work here.
    // Save work to disk
    // Return location of saved work
}
private IObservable<Uri> ZipFiles(Uri[] files)
{
    //Run the zip process on all of the files
    //  Return the location of the zip file
}
private IObservable<Uri> UploadFile(Uri source)
{
    //Upload the File. 
    //Probably as simple as as task based operation with .ToObservable()
}   

关于c# - 响应式(Reactive)扩展 : Creating a pipeline with Rx that works with files,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37923786/

相关文章:

c# - 在 Struct 中存储引用类型

c# - 如何使用 Azure Function HTTP 绑定(bind)执行 REST API 可选字符串 URI 参数?

c# - 线程安全的公共(public)字符串

c# - RX challenge 5 复杂事件处理使用LINQ语言集成查询(剧透警告)

c# - 调度程序调度程序 - Rx

c# - CollectionEditor 的父级

c# - DataGridView CellPainting 绘图文本与符号显示奇怪

c# - RX IObserver 订阅时间

c# - TrySZBinarySearch 在哪里实现的?

.net - Visual Studio 2013 的 XNA