コード例 #1
0
 public FinishJobBuilder SetSecurityOptions(SecurityOptions securityOptions)
 {
     _security = securityOptions;
     return(this);
 }
コード例 #2
0
        internal async Task <BuildJobResult> FinishAsync(JobExecutionOptions executionOptions, SecurityOptions securityOptions, CancellationToken cancellationToken)
        {
            var inputByteArrays = await Task.WhenAll(_inputs.Select(async pair => new KeyValuePair <int, ArraySegment <byte> >(pair.Key, await pair.Value.GetBytesAsync(cancellationToken))));

            using (var ctx = new JobContext())
            {
                foreach (var pair in inputByteArrays)
                {
                    ctx.AddInputBytesPinned(pair.Key, pair.Value);
                }

                foreach (var outId in _outputs.Keys)
                {
                    ctx.AddOutputBuffer(outId);
                }

                //TODO: Use a Semaphore to limit concurrency

                var message = new
                {
                    security  = securityOptions?.ToImageflowDynamic(),
                    framewise = ToFramewise()
                };

                var response = executionOptions.OffloadCpuToThreadPool
                    ? await Task.Run(() => ctx.Execute(message), cancellationToken)
                    : ctx.Execute(message);

                using (response)
                {
                    foreach (var pair in _outputs)
                    {
                        using (var stream = ctx.GetOutputBuffer(pair.Key))
                        {
                            await pair.Value.CopyFromStreamAsync(stream, cancellationToken);
                        }
                    }
                    return(BuildJobResult.From(response, _outputs));
                }
            }
        }