//---------------------------------------------------------------------------------------
            // Straightforward IEnumerator<T> methods.
            //

            internal override bool MoveNext([MaybeNullWhen(false), AllowNull] ref TOutput currentElement, ref TKey currentKey)
            {
                // So long as the source has a next element, we have an element.
                TInput element = default(TInput) !;

                if (_source.MoveNext(ref element !, ref currentKey))
                {
                    Debug.Assert(_selector != null, "expected a compiled operator");
                    currentElement = _selector(element);
                    return(true);
                }

                return(false);
            }
            //---------------------------------------------------------------------------------------
            // Straightforward IEnumerator<T> methods.
            //

            internal override bool MoveNext(ref TOutput currentElement, ref TKey currentKey)
            {
                // So long as the source has a next element, we have an element.
                TInput element = default(TInput);

                if (m_source.MoveNext(ref element, ref currentKey))
                {
                    Contract.Assert(m_selector != null, "expected a compiled operator");
                    currentElement = m_selector(element);
                    return(true);
                }

                return(false);
            }
Example #3
0
        internal void Activity_GetInputTest()
        {
            var activity = Substitute.ForPartsOf <ActivityBase <TOutput, TOutput> >("SimpleActivity", "taskList");         // { Version = "1.0" };

            var exptected = new TOutput {
                Value = "correct value"
            };

            ((IActivity)activity).Input = Utils.SerializeToJSON(exptected);

            var result = activity.Input;

            AssertObjectEquals.PropertyValuesAreEqual(result, exptected);
        }
Example #4
0
            public void ProcessWithoutBuffer(ref TInput input, ref TOutput output)
            {
                if (InitialWindowedBuffer.Count < InitialWindowSize)
                {
                    InitialWindowedBuffer.AddLast(input);
                    SetNaOutput(ref output);

                    if (InitialWindowedBuffer.Count == InitialWindowSize)
                    {
                        LearnStateFromDataCore(InitialWindowedBuffer);
                    }
                }
                else
                {
                    TransformCore(ref input, WindowedBuffer, RowCounter - InitialWindowSize, ref output);
                    IncrementRowCounter();
                }
            }
            /// <summary>
            /// Tries get the value for the given key.
            /// </summary>
            /// <param name="key">The key.</param>
            /// <param name="input">???</param>
            /// <param name="output">The output containing the value if record of the given exists.</param>
            /// <returns>true if the record of the key exists; false otherwise.</returns>
            public bool TryGet(ref TKey key, ref TInput input, ref TOutput output)
            {
                var context = new StoreContext <TOutput>();
                var status  = _session.Read(ref key, ref input, ref output, context, 0);

                if (status == Status.PENDING)
                {
                    _session.CompletePending(true);
                    context.FinalizeRead(ref status, ref output);
                }
                if (status == Status.NOTFOUND)
                {
                    return(false);
                }
                if (status != Status.OK)
                {
                    throw new InvalidOperationException("Error ocurred when reading data.");
                }
                return(true);
            }
            /// <summary>
            /// Tests if the store contains the given key.
            /// </summary>
            /// <param name="key">The key.</param>
            /// <returns>true if the given key is in the store; false otherwise.</returns>
            public bool ContainsKey(ref TKey key)
            {
                var input   = new TInput();
                var output  = new TOutput();
                var context = new StoreContext <TOutput>();
                var status  = _session.Read(ref key, ref input, ref output, context, 0);

                if (status == Status.PENDING)
                {
                    _session.CompletePending(true);
                    context.FinalizeRead(ref status, ref output);
                }
                if (status == Status.NOTFOUND || status == Status.ERROR)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
Example #7
0
            public void ProcessWithoutBuffer(ref TInput input, ref TOutput output)
            {
                if (PreviousPosition == -1)
                {
                    UpdateStateCore(ref input, false);
                }

                if (InitialWindowedBuffer.Count < InitialWindowSize)
                {
                    SetNaOutput(ref output);

                    if (InitialWindowedBuffer.Count == InitialWindowSize)
                    {
                        LearnStateFromDataCore(InitialWindowedBuffer);
                    }
                }
                else
                {
                    TransformCore(ref input, WindowedBuffer, RowCounter - InitialWindowSize, ref output);
                }
            }
Example #8
0
 internal override bool MoveNext(ref TOutput currentElement, ref Pair <TLeftKey, int> currentKey)
 {
     while (true)
     {
         if (this.m_currentRightSource == null)
         {
             this.m_mutables = new Mutables <TLeftInput, TRightInput, TOutput, TLeftKey>();
             if ((this.m_mutables.m_lhsCount++ & 0x3f) == 0)
             {
                 CancellationState.ThrowIfCanceled(this.m_cancellationToken);
             }
             if (!this.m_leftSource.MoveNext(ref this.m_mutables.m_currentLeftElement, ref this.m_mutables.m_currentLeftKey))
             {
                 return(false);
             }
             this.m_currentRightSource = this.m_selectManyOperator.m_rightChildSelector(this.m_mutables.m_currentLeftElement).GetEnumerator();
             if (this.m_selectManyOperator.m_resultSelector == null)
             {
                 this.m_currentRightSourceAsOutput = (IEnumerator <TOutput>) this.m_currentRightSource;
             }
         }
         if (this.m_currentRightSource.MoveNext())
         {
             this.m_mutables.m_currentRightSourceIndex++;
             if (this.m_selectManyOperator.m_resultSelector != null)
             {
                 currentElement = this.m_selectManyOperator.m_resultSelector(this.m_mutables.m_currentLeftElement, this.m_currentRightSource.Current);
             }
             else
             {
                 currentElement = this.m_currentRightSourceAsOutput.Current;
             }
             currentKey = new Pair <TLeftKey, int>(this.m_mutables.m_currentLeftKey, this.m_mutables.m_currentRightSourceIndex);
             return(true);
         }
         this.m_currentRightSource.Dispose();
         this.m_currentRightSource         = null;
         this.m_currentRightSourceAsOutput = null;
     }
 }
Example #9
0
            public void ProcessWithoutBuffer(ref TInput input, ref TOutput output)
            {
                //Using prediction engine will not evaluate the below condition to true.
                if (PreviousPosition == -1)
                {
                    UpdateStateCore(ref input);
                }

                if (InitialWindowedBuffer.Count < InitialWindowSize)
                {
                    SetNaOutput(ref output);

                    if (InitialWindowedBuffer.Count == InitialWindowSize)
                    {
                        LearnStateFromDataCore(InitialWindowedBuffer);
                    }
                }
                else
                {
                    TransformCore(ref input, WindowedBuffer, RowCounter - InitialWindowSize, ref output);
                }
            }
Example #10
0
        public static void Level <TData, TOutput>() where TOutput : AOutput <TData>, new()
        {
            var data = DeserializeFile <TData>();

            if (data == null)
            {
                Console.WriteLine("Une erreur est survenue lors de la récupération des données, veuillez vérifier que le fichier 'data.json' est présent et correct.");
                return;
            }
            try
            {
                var output     = new TOutput().FromData(data);
                var serialized = SerializeFile(output);
                if (serialized == false)
                {
                    Console.WriteLine("Une erreur est survenue lors de la création des données, un fichier 'output.json' doit pouvoir être créé.");
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Une erreur est survenue lors du traitement des données, veuillez vérifier que le fichier 'data.json' contient des données valides.");
            }
        }
            //---------------------------------------------------------------------------------------
            // Straightforward IEnumerator<T> methods.
            //

            internal override bool MoveNext(ref TOutput currentElement, ref Pair <TLeftKey, int> currentKey)
            {
                while (true)
                {
                    if (_currentRightSource == null)
                    {
                        _mutables = new Mutables();

                        // Check cancellation every few lhs-enumerations in case none of them are producing
                        // any outputs.  Otherwise, we rely on the consumer of this operator to be performing the checks.
                        if ((_mutables._lhsCount++ & CancellationState.POLL_INTERVAL) == 0)
                        {
                            CancellationState.ThrowIfCanceled(_cancellationToken);
                        }

                        // We don't have a "current" right enumerator to use. We have to fetch the next
                        // one. If the left has run out of elements, however, we're done and just return
                        // false right away.

                        if (!_leftSource.MoveNext(ref _mutables._currentLeftElement, ref _mutables._currentLeftKey))
                        {
                            return(false);
                        }

                        // Use the source selection routine to create a right child.
                        IEnumerable <TRightInput> rightChild = _selectManyOperator._rightChildSelector(_mutables._currentLeftElement);

                        Debug.Assert(rightChild != null);
                        _currentRightSource = rightChild.GetEnumerator();

                        Debug.Assert(_currentRightSource != null);

                        // If we have no result selector, we will need to access the Current element of the right
                        // data source as though it is a TOutput. Unfortunately, we know that TRightInput must
                        // equal TOutput (we check it during operator construction), but the type system doesn't.
                        // Thus we would have to cast the result of invoking Current from type TRightInput to
                        // TOutput. This is no good, since the results could be value types. Instead, we save the
                        // enumerator object as an IEnumerator<TOutput> and access that later on.
                        if (_selectManyOperator._resultSelector == null)
                        {
                            _currentRightSourceAsOutput = (IEnumerator <TOutput>)_currentRightSource;
                            Debug.Assert(_currentRightSourceAsOutput == _currentRightSource,
                                         "these must be equal, otherwise the surrounding logic will be broken");
                        }
                    }

                    if (_currentRightSource.MoveNext())
                    {
                        _mutables._currentRightSourceIndex++;

                        // If the inner data source has an element, we can yield it.
                        if (_selectManyOperator._resultSelector != null)
                        {
                            // In the case of a selection function, use that to yield the next element.
                            currentElement = _selectManyOperator._resultSelector(_mutables._currentLeftElement, _currentRightSource.Current);
                        }
                        else
                        {
                            // Otherwise, the right input and output types must be the same. We use the
                            // casted copy of the current right source and just return its current element.
                            Debug.Assert(_currentRightSourceAsOutput != null);
                            currentElement = _currentRightSourceAsOutput.Current;
                        }
                        currentKey = new Pair <TLeftKey, int>(_mutables._currentLeftKey, _mutables._currentRightSourceIndex);

                        return(true);
                    }
                    else
                    {
                        // Otherwise, we have exhausted the right data source. Loop back around and try
                        // to get the next left element, then its right, and so on.
                        _currentRightSource.Dispose();
                        _currentRightSource         = null;
                        _currentRightSourceAsOutput = null;
                    }
                }
            }
Example #12
0
 /// <summary>
 /// The abstract method that specifies the NA value for the dst type.
 /// </summary>
 /// <returns></returns>
 private protected virtual void SetNaOutput(ref TOutput dst)
 {
 }
Example #13
0
 /// <summary>
 /// The abstract method that realizes the main logic for the transform.
 /// </summary>
 /// <param name="input">A reference to the input object.</param>
 /// <param name="dst1">A reference to the dst object.</param>
 /// <param name="dst2"></param>
 /// <param name="dst3"></param>
 /// <param name="windowedBuffer">A reference to the windowed buffer.</param>
 /// <param name="iteration">A long number that indicates the number of times TransformCore has been called so far (starting value = 0).</param>
 private protected virtual void TransformCore(ref TInput input, FixedSizeQueue <TInput> windowedBuffer, long iteration,
                                              ref TOutput dst1, ref TOutput dst2, ref TOutput dst3)
 {
 }
Example #14
0
 public virtual void ConfidenceIntervalUpperBound(ref TOutput dst)
 {
 }
Example #15
0
 public virtual void Forecast(ref TOutput dst)
 {
 }
Example #16
0
 /// <summary>
 /// The abstract method that realizes the main logic for the transform.
 /// </summary>
 /// <param name="input">A reference to the input object.</param>
 /// <param name="dst">A reference to the dst object.</param>
 /// <param name="windowedBuffer">A reference to the windowed buffer.</param>
 /// <param name="iteration">A long number that indicates the number of times TransformCore has been called so far (starting value = 0).</param>
 public virtual void TransformCore(ref TInput input, FixedSizeQueue <TInput> windowedBuffer, long iteration, ref TOutput dst)
 {
 }
Example #17
0
 /// <summary>
 /// The abstract method that specifies the NA value for <paramref name="dst"/>'s type.
 /// </summary>
 /// <returns></returns>
 private protected abstract void SetNaOutput(ref TOutput dst);
 public OfferedMessage(ISourceBlock <TInput> source, DataflowMessageHeader sourceHeader, TOutput transformedValue)
 {
     this.Source           = source;
     this.SourceHeader     = sourceHeader;
     this.TransformedValue = transformedValue;
 }
Example #19
0
 public void OnCompleted <TInput>(Action continuation, TInput task) where TInput : TOutput
 {
     _task = task;
     continuation();
 }
Example #20
0
        //like class template member partical specialize
        public TOutput Converter <TOutput>()
        {
            TOutput output = (TOutput)Convert.ChangeType(data, typeof(TOutput));

            return(output);
        }
Example #21
0
        public TOutput Converter <TOutput>()
        {
            TOutput result = (TOutput)Convert.ChangeType(m_value, typeof(TOutput));

            return(result);
        }
Example #22
0
 /// <summary>
 /// The abstract method that realizes the main logic for the transform.
 /// </summary>
 /// <param name="input">A reference to the input object.</param>
 /// <param name="dst">A reference to the dst object.</param>
 /// <param name="windowedBuffer">A reference to the windowed buffer.</param>
 /// <param name="iteration">A long number that indicates the number of times TransformCore has been called so far (starting value = 0).</param>
 private protected abstract void TransformCore(ref TInput input, FixedSizeQueue <TInput> windowedBuffer, long iteration, ref TOutput dst);
            public void OnNext(TSource value)
            {
                TOutput selectedValue = this.selection(value);

                this.observer.OnNext(selectedValue);
            }