Пример #1
0
        protected override IStream <TOut> CreateOutputStream(SubProcessArgs <TIn, TOut> args)
        {
            if (this.ExecutionContext is GetDefinitionExecutionContext)
            {
                var inputStream  = new SingleStream <TIn>(new SubNodeWrapper(this), PushObservable.FromSingle(default(TIn), args.Stream.Observable.CancellationToken));
                var outputStream = args.SubProcess(inputStream);
                // this.ExecutionContext.AddNode(this, outputStream.Observable);
            }
            Synchronizer synchronizer     = new Synchronizer(args.NoParallelisation);
            var          outputObservable = args.Stream.Observable
                                            .FlatMap((i, ct) =>
            {
                // TODO: Solve bug here (this operator makes the process freezing))

                EventWaitHandle waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
                var inputStream            = new SingleStream <TIn>(new SubNodeWrapper(this), PushObservable.FromSingle(i, waitHandle, ct));
                var outputStream           = args.SubProcess(inputStream);
                // this.ExecutionContext.AddNode(this, outputStream.Observable);
                IDisposable awaiter = null;
                outputStream.Observable.Subscribe(j => { }, () => awaiter?.Dispose());
                return(new DeferredWrapperPushObservable <TOut>(outputStream.Observable, () =>
                {
                    awaiter = synchronizer.WaitBeforeProcess();
                    waitHandle.Set();
                }, null, ct));
            });

            return(base.CreateUnsortedStream(outputObservable));
        }
Пример #2
0
        protected override IStream <Correlated <TOut> > CreateOutputStream(GroupByCorrelatedArgs <TIn, TKey, TOut> args)
        {
            if (this.ExecutionContext is GetDefinitionExecutionContext)
            {
                var inputStream  = new SingleStream <Correlated <TIn> >(new SubNodeWrapper(this), PushObservable.FromSingle(default(Correlated <TIn>), null, args.Stream.Observable.CancellationToken));
                var outputStream = args.SubProcess(inputStream, default);
                this.ExecutionContext.AddNode(this, outputStream.Observable);
            }
            var outputObservable = args.Stream.Observable.Group(i => args.GetKey(i.Row), (iS, firstElement) => args.SubProcess(new Stream <Correlated <TIn> >(new SubNodeWrapper(this), iS), firstElement.Row).Observable);

            return(base.CreateUnsortedStream(outputObservable));
        }
Пример #3
0
        protected override IStream <TOut> CreateOutputStream(ToSubProcessesArgs <TIn, TOut> args)
        {
            // Semaphore semaphore = args.NoParallelisation ? new Semaphore(1, 1) : new Semaphore(10, 10);
            Synchronizer synchronizer = new Synchronizer(args.NoParallelisation);

            if (this.ExecutionContext is GetDefinitionExecutionContext)
            {
                var inputStream = new SingleStream <TIn>(new SubNodeWrapper(this), PushObservable.FromSingle(default(TIn), args.Stream.Observable.CancellationToken));
                foreach (var subProcess in args.SubProcesses)
                {
                    var outputStream = subProcess(inputStream);
                    this.ExecutionContext.AddNode(this, outputStream.Observable);
                }
            }

            var outputObservable = args.Stream.Observable
                                   .FlatMap((i, ct) => PushObservable.FromEnumerable(args.SubProcesses.Select(sp => new
            {
                config  = i,
                subProc = sp
            }), ct))
                                   .FlatMap((i, ct) =>
            {
                EventWaitHandle waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
                var inputStream            = new SingleStream <TIn>(new SubNodeWrapper(this), PushObservable.FromSingle(i.config, waitHandle, ct));
                var outputStream           = i.subProc(inputStream);
                IDisposable awaiter        = null;
                outputStream.Observable.Subscribe(j => { }, () => awaiter?.Dispose());
                return(new DeferredWrapperPushObservable <TOut>(outputStream.Observable, () =>
                {
                    awaiter = synchronizer.WaitBeforeProcess();
                    waitHandle.Set();
                }, null, ct));
            });

            return(base.CreateUnsortedStream(outputObservable));
        }