コード例 #1
0
        public IObservable <TResult> Generate()
        {
            var source = Observable.Create <ONIManagedFrame <TData> >(async observer =>
            {
                var cd = await ONIContextManager.ReserveOpenContextAsync(DeviceAddress.HardwareSlot);

                var in_table = cd.Context.DeviceTable.TryGetValue((uint)DeviceAddress.Address, out var device);
                if (!in_table || device.ID != (int)ID)
                {
                    throw new WorkflowException("Selected device address is invalid.");
                }

                EventHandler <FrameReceivedEventArgs> frame_received = (sender, e) =>
                {
                    if (e.Frame.DeviceAddress == DeviceAddress.Address)
                    {
                        ONIManagedFrame <TData> frame = new ONIManagedFrame <TData>(e.Frame);
                        observer.OnNext(frame);
                    }
                };

                cd.Context.FrameReceived += frame_received;
                return(Disposable.Create(() =>
                {
                    cd.Context.FrameReceived -= frame_received;
                    cd.Dispose();
                }));
            });

            ulong frameOffset = FrameClockOffset;

            return(Process(source, frameOffset));
        }
コード例 #2
0
 public IObservable <TSource> Process(IObservable <TSource> source)
 {
     return(Observable.Using(
                cancellationToken => ONIContextManager.ReserveOpenContextAsync(DeviceAddress.HardwareSlot),
                (contextDisposable, cancellationToken) =>
     {
         return ONIXDeviceDescriptor.IsValid(ID, DeviceAddress)
                 ? Task.FromResult(source
                                   .Do(input => { OnNext(contextDisposable.Context, input); })
                                   .Finally(() => OnFinally(contextDisposable.Context)))
                 : throw new WorkflowException("Selected device address is invalid.");
     }
                ));
 }
コード例 #3
0
        public IObservable <TResult> Generate(IObservable <TSource> source)
        {
            return(Observable.Create <TResult>(async observer =>
            {
                var cd = await ONIContextManager.ReserveOpenContextAsync(DeviceAddress.HardwareSlot);

                var in_table = cd.Context.DeviceTable.TryGetValue((uint)DeviceAddress.Address, out var device);
                if (!in_table || device.ID != (int)ID)
                {
                    throw new WorkflowException("Selected device address is invalid.");
                }

                var source_sub = source.Subscribe(
                    input =>
                {
                    try
                    {
                        Write(cd.Context, input);
                    }
                    catch (Exception ex)
                    {
                        observer.OnError(ex);
                    }
                },
                    observer.OnError,
                    () => { });

                return new CompositeDisposable(
                    Generate().SubscribeSafe(observer),
                    Disposable.Create(() =>
                {
                    cd.Dispose();
                    source_sub.Dispose();
                })
                    );
            }));
        }