示例#1
0
 private Computation FindOrCreateDependentComputation(object[] input, List <ITraceEntry> computations, Computation comp, Stack <Computation> dependantComputes, GeneralTransformationRule rule)
 {
     lock (computations)
     {
         var comp2 = computations.Where(cmp => cmp.TransformationRule == rule).OfType <Computation>().FirstOrDefault();
         if (comp2 == null)
         {
             comp2 = rule.CreateComputation(input, comp.Context);
             computations.Add(comp2);
             AddTraceEntry(comp2);
             dependantComputes.Push(comp2);
         }
         return(comp2);
     }
 }
示例#2
0
        /// <summary>
        /// Calls the given transformation with the specified input
        /// </summary>
        /// <param name="input">The input for the transformation rule</param>
        /// <param name="transformationRule">The rule that should be applied</param>
        /// <returns>The computation that handles this request</returns>
        public virtual Computation CallTransformation(GeneralTransformationRule transformationRule, object[] input, IEnumerable context)
        {
            if (transformationRule == null)
            {
                throw new ArgumentNullException("transformationRule");
            }

            var c = Trace.TraceIn(transformationRule, input).OfType <Computation>().FirstOrDefault();

            if (c == null)
            {
                c = transformationRule.CreateComputation(input, new ComputationContext(this));
                computations.Add(c);
            }
            return(c);
        }
示例#3
0
        /// <summary>
        /// Calls the given transformation with the specified input
        /// </summary>
        /// <param name="input">The input for the transformation rule</param>
        /// <param name="transformationRule">The rule that should be applied</param>
        /// <param name="context">The callers context</param>
        /// <returns>The computation that handles this request</returns>
        public Computation CallTransformation(GeneralTransformationRule transformationRule, object[] input, IEnumerable context)
        {
            if (transformationRule == null)
            {
                throw new ArgumentNullException("transformationRule");
            }
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            List <ITraceEntry> computations;

            if (!computationsMade.TryGetValue(input, out computations))
            {
                computations = new List <ITraceEntry>();
                if (!computationsMade.TryAdd(input, computations))
                {
                    computations = computationsMade[input];
                }
            }

            var originalTransformationRule = transformationRule;

            while (transformationRule.BaseRule != null)
            {
                transformationRule = transformationRule.BaseRule;
            }

            Computation comp;
            TaskParallelComputationContext compCon = null;
            bool handleComputation;

            if (transformationRule.IsUnique)
            {
                lock (computations)
                {
                    comp = computations.OfType <Computation>().FirstOrDefault(cpt => cpt.TransformationRule == transformationRule);
                    if (comp != null && transformationRule != originalTransformationRule)
                    {
                        transformationRule = originalTransformationRule;
                        while (computations.OfType <Computation>().FirstOrDefault(cpt => cpt.TransformationRule == transformationRule.BaseRule) == null)
                        {
                            transformationRule = transformationRule.BaseRule;
                        }
                        comp = computations.OfType <Computation>().FirstOrDefault(cpt => cpt.TransformationRule == transformationRule);
                    }

                    if (comp == null)
                    {
                        handleComputation = true;
                        compCon           = CreateComputationContext(transformationRule);
                        comp = transformationRule.CreateComputation(input, compCon);
                        computations.Add(comp);
                        compCon.DelayOutput(new OutputDelay());
                    }
                    else
                    {
                        handleComputation = false;
                    }
                }
            }
            else
            {
                lock (computations)
                {
                    handleComputation = true;
                    compCon           = CreateComputationContext(transformationRule);
                    comp = transformationRule.CreateComputation(input, compCon);
                    computations.Add(comp);
                    compCon.DelayOutput(new OutputDelay());
                }
            }
            if (handleComputation)
            {
                AddTraceEntry(comp);

                CallDependencies(comp, true);

                HandleComputation(transformationRule, input, context, computations, originalTransformationRule, comp, compCon);
            }
            return(comp);
        }