コード例 #1
0
        private void HandleDelayedComputation(Computation computation, ITransformationContext context, OutputDelay delay)
        {
            var inCollection = Selector(computation);

            if (inCollection != null)
            {
                if (Persistor != null)
                {
                    Type  listType = (typeof(List <>)).MakeGenericType(DependencyTransformation.OutputType);
                    IList list     = System.Activator.CreateInstance(listType) as IList;

                    MultipleResultAwaitingPersistor delayPersistor = new MultipleResultAwaitingPersistor()
                    {
                        List      = list,
                        Persistor = Persistor
                    };
                    if (context.IsThreadSafe)
                    {
                        Parallel.ForEach(inCollection, dependencyInput =>
                        {
                            HandleDelayedDependencyInput(computation, context, list, delayPersistor, dependencyInput);
                        });
                    }
                    else
                    {
                        foreach (var dependencyInput in inCollection)
                        {
                            HandleDelayedDependencyInput(computation, context, list, delayPersistor, dependencyInput);
                        }
                    }
                    delay.Persistors.Add(delayPersistor);
                }
                else
                {
                    if (context.IsThreadSafe)
                    {
                        Parallel.ForEach(inCollection, dependencyInput =>
                        {
                            GeneralTransformationRule dependent = DependencyTransformation;
                            var comp2 = context.CallTransformation(dependent, dependencyInput);

                            computation.MarkRequireInternal(comp2, ExecuteBefore, this);
                        });
                    }
                    else
                    {
                        foreach (var dependencyInput in inCollection)
                        {
                            GeneralTransformationRule dependent = DependencyTransformation;
                            var comp2 = context.CallTransformation(dependent, dependencyInput);

                            computation.MarkRequireInternal(comp2, ExecuteBefore, this);
                        }
                    }
                }
            }
        }
コード例 #2
0
        private void HandleNonDelayedComputation(Computation computation, ITransformationContext context)
        {
            var output       = computation.Output;
            var inCollection = Selector(computation);

            if (inCollection != null)
            {
                if (Persistor != null)
                {
                    Type  listType = (typeof(List <>)).MakeGenericType(DependencyTransformation.OutputType);
                    IList list     = System.Activator.CreateInstance(listType) as IList;

                    MultipleResultAwaitingPersistor delayPersistor = new MultipleResultAwaitingPersistor()
                    {
                        List      = list,
                        Persistor = Persistor,
                        Target    = output
                    };
                    bool needDependencyPersistor        = false;
                    GeneralTransformationRule dependent = DependencyTransformation;
                    if (context.IsThreadSafe)
                    {
                        Parallel.ForEach(inCollection, dependencyInput =>
                        {
                            if (HandleNonDelayedPersistedDependencyInput(computation, context, list, delayPersistor, dependent, dependencyInput))
                            {
                                needDependencyPersistor = true;
                            }
                        });
                    }
                    else
                    {
                        foreach (var dependencyInput in inCollection)
                        {
                            if (HandleNonDelayedPersistedDependencyInput(computation, context, list, delayPersistor, dependent, dependencyInput))
                            {
                                needDependencyPersistor = true;
                            }
                        }
                    }
                    if (!needDependencyPersistor)
                    {
                        Persistor(output, list);
                    }
                }
                else
                {
                    GeneralTransformationRule dependent = DependencyTransformation;
                    if (context.IsThreadSafe)
                    {
                        Parallel.ForEach(inCollection, dependencyInput =>
                        {
                            var comp2 = context.CallTransformation(dependent, dependencyInput);
                            computation.MarkRequireInternal(comp2, ExecuteBefore, this);
                        });
                    }
                    else
                    {
                        foreach (var dependencyInput in inCollection)
                        {
                            var comp2 = context.CallTransformation(dependent, dependencyInput);
                            computation.MarkRequireInternal(comp2, ExecuteBefore, this);
                        }
                    }
                }
            }
        }
コード例 #3
0
        private void HandleDelayedDependencyInput(Computation computation, ITransformationContext context, IList list, MultipleResultAwaitingPersistor delayPersistor, object[] dependencyInput)
        {
            GeneralTransformationRule dependent = DependencyTransformation;
            var comp2 = context.CallTransformation(dependent, dependencyInput);

            if (!comp2.IsDelayed)
            {
                if (comp2.Output != null)
                {
                    if (context.IsThreadSafe)
                    {
                        lock (list)
                        {
                            list.Add(comp2.Output);
                        }
                    }
                    else
                    {
                        list.Add(comp2.Output);
                    }
                }
            }
            else
            {
                computation.DelayOutputAtLeast(comp2.Context.MinOutputDelayLevel);
                delayPersistor.WaitFor(comp2);
            }

            if (ExecuteBefore)
            {
                computation.DelayTransformationAtLeast(comp2.Context.MinTransformDelayLevel);
            }
            else
            {
                comp2.DelayTransformationAtLeast(computation.Context.MinTransformDelayLevel);
            }
        }
コード例 #4
0
        private bool HandleNonDelayedPersistedDependencyInput(Computation computation, ITransformationContext context, IList list, MultipleResultAwaitingPersistor delayPersistor, GeneralTransformationRule dependent, object[] dependencyInput)
        {
            var needDelayedPersistor = false;
            var comp2 = context.CallTransformation(dependent, dependencyInput);

            if (!comp2.IsDelayed)
            {
                if (comp2.Output != null)
                {
                    var lockList = context.IsThreadSafe;
                    if (lockList)
                    {
                        lock (list)
                        {
                            list.Add(comp2.Output);
                        }
                    }
                    else
                    {
                        list.Add(comp2.Output);
                    }
                }
            }
            else
            {
                needDelayedPersistor = true;
                delayPersistor.WaitFor(comp2);
            }

            computation.MarkRequireInternal(comp2, ExecuteBefore, this);
            return(needDelayedPersistor);
        }
コード例 #5
0
ファイル: MultipleDependency.cs プロジェクト: FrederikP/NMF
        private void HandleNonDelayedComputation(Computation computation, ITransformationContext context)
        {
            var output = computation.Output;
            var inCollection = Selector(computation);
            if (inCollection != null)
            {
                if (Persistor != null)
                {
                    Type listType = (typeof(List<>)).MakeGenericType(DependencyTransformation.OutputType);
                    IList list = System.Activator.CreateInstance(listType) as IList;

                    MultipleResultAwaitingPersistor delayPersistor = new MultipleResultAwaitingPersistor()
                    {
                        List = list,
                        Persistor = Persistor,
                        Target = output
                    };
                    bool needDependencyPersistor = false;
                    GeneralTransformationRule dependent = DependencyTransformation;
                    if (context.IsThreadSafe)
                    {
                        Parallel.ForEach(inCollection, dependencyInput =>
                        {
                            if (HandleNonDelayedPersistedDependencyInput(computation, context, list, delayPersistor, dependent, dependencyInput))
                            {
                                needDependencyPersistor = true;
                            }
                        });
                    }
                    else
                    {
                        foreach (var dependencyInput in inCollection)
                        {
                            if (HandleNonDelayedPersistedDependencyInput(computation, context, list, delayPersistor, dependent, dependencyInput))
                            {
                                needDependencyPersistor = true;
                            }
                        }
                    }
                    if (!needDependencyPersistor) Persistor(output, list);
                }
                else
                {
                    GeneralTransformationRule dependent = DependencyTransformation;
                    if (context.IsThreadSafe)
                    {
                        Parallel.ForEach(inCollection, dependencyInput =>
                        {
                            var comp2 = context.CallTransformation(dependent, dependencyInput);
                            computation.MarkRequireInternal(comp2, ExecuteBefore, this);
                        });
                    }
                    else
                    {
                        foreach (var dependencyInput in inCollection)
                        {
                            var comp2 = context.CallTransformation(dependent, dependencyInput);
                            computation.MarkRequireInternal(comp2, ExecuteBefore, this);
                        }
                    }
                }
            }
        }
コード例 #6
0
ファイル: MultipleDependency.cs プロジェクト: FrederikP/NMF
        private void HandleDelayedDependencyInput(Computation computation, ITransformationContext context, IList list, MultipleResultAwaitingPersistor delayPersistor, object[] dependencyInput)
        {
            GeneralTransformationRule dependent = DependencyTransformation;
            var comp2 = context.CallTransformation(dependent, dependencyInput);
            if (!comp2.IsDelayed)
            {
                if (comp2.Output != null)
                {
                    if (context.IsThreadSafe)
                    {
                        lock (list)
                        {
                            list.Add(comp2.Output);
                        }
                    }
                    else
                    {
                        list.Add(comp2.Output);
                    }
                }
            }
            else
            {
                computation.DelayOutputAtLeast(comp2.Context.MinOutputDelayLevel);
                delayPersistor.WaitFor(comp2);
            }

            if (ExecuteBefore)
            {
                computation.DelayTransformationAtLeast(comp2.Context.MinTransformDelayLevel);
            }
            else
            {
                comp2.DelayTransformationAtLeast(computation.Context.MinTransformDelayLevel);
            }
        }
コード例 #7
0
ファイル: MultipleDependency.cs プロジェクト: FrederikP/NMF
        private void HandleDelayedComputation(Computation computation, ITransformationContext context, OutputDelay delay)
        {
            var inCollection = Selector(computation);
            if (inCollection != null)
            {
                if (Persistor != null)
                {
                    Type listType = (typeof(List<>)).MakeGenericType(DependencyTransformation.OutputType);
                    IList list = System.Activator.CreateInstance(listType) as IList;

                    MultipleResultAwaitingPersistor delayPersistor = new MultipleResultAwaitingPersistor()
                    {
                        List = list,
                        Persistor = Persistor
                    };
                    if (context.IsThreadSafe)
                    {
                        Parallel.ForEach(inCollection, dependencyInput =>
                        {
                            HandleDelayedDependencyInput(computation, context, list, delayPersistor, dependencyInput);
                        });
                    }
                    else
                    {
                        foreach (var dependencyInput in inCollection)
                        {
                            HandleDelayedDependencyInput(computation, context, list, delayPersistor, dependencyInput);
                        }
                    }
                    delay.Persistors.Add(delayPersistor);
                }
                else
                {
                    if (context.IsThreadSafe)
                    {
                        Parallel.ForEach(inCollection, dependencyInput =>
                        {
                            GeneralTransformationRule dependent = DependencyTransformation;
                            var comp2 = context.CallTransformation(dependent, dependencyInput);

                            computation.MarkRequireInternal(comp2, ExecuteBefore, this);
                        });
                    }
                    else
                    {
                        foreach (var dependencyInput in inCollection)
                        {
                            GeneralTransformationRule dependent = DependencyTransformation;
                            var comp2 = context.CallTransformation(dependent, dependencyInput);

                            computation.MarkRequireInternal(comp2, ExecuteBefore, this);
                        }
                    }
                }
            }
        }
コード例 #8
0
ファイル: MultipleDependency.cs プロジェクト: FrederikP/NMF
        private bool HandleNonDelayedPersistedDependencyInput(Computation computation, ITransformationContext context, IList list, MultipleResultAwaitingPersistor delayPersistor, GeneralTransformationRule dependent, object[] dependencyInput)
        {
            var needDelayedPersistor = false;
            var comp2 = context.CallTransformation(dependent, dependencyInput);
            if (!comp2.IsDelayed)
            {
                if (comp2.Output != null)
                {
                    var lockList = context.IsThreadSafe;
                    if (lockList)
                    {
                        lock (list)
                        {
                            list.Add(comp2.Output);
                        }
                    }
                    else
                    {
                        list.Add(comp2.Output);
                    }
                }
            }
            else
            {
                needDelayedPersistor = true;
                delayPersistor.WaitFor(comp2);
            }

            computation.MarkRequireInternal(comp2, ExecuteBefore, this);
            return needDelayedPersistor;
        }