Example #1
0
        private static void UpdateWittyerVariant(IWittyerSimpleVariant variant, EvaluationMode emode, bool isTruth)
        {
            var sample = variant.Sample;

            var match = emode.Equals(EvaluationMode.Default);

            variant.OverlapInfo.Sort();
            switch (sample)
            {
            case WittyerSampleInternal simple:
                UpdateWittyerVariantHelper(simple, variant, match, isTruth);
                break;

            case WittyerCopyNumberSample cnsample:
                UpdateWittyerVariantHelper(cnsample.BaseSample, variant, match, isTruth);
                break;

            case WittyerGenotypedSample gtSample:
                UpdateWittyerVariantHelper(gtSample.BaseSample, variant, match, isTruth);
                break;

            case WittyerGenotypedCopyNumberSample gtCnSample:
                UpdateWittyerVariantHelper(gtCnSample.BaseSample.BaseSample, variant, match, isTruth);
                break;

            default:
                throw new InvalidDataException(
                          "Not sure how we get here, you must have created some non-existed wittyer sample type, check with developer!");
            }
        }
Example #2
0
        internal static WittyerVcfResult Create(TruthForest truths, EvaluationMode emode)
        {
            var normalVariants = new List <IWittyerVariant>();
            var breakendPairs  = new List <IWittyerBnd>();

            foreach (var variant in truths.Trees.SelectMany(gtree => gtree.Value.Values.SelectMany(v => v)))
            {
                UpdateWittyerVariant(variant, emode, true);
                switch (variant)
                {
                case IWittyerVariant normal:
                    normalVariants.Add(normal);
                    break;

                case IWittyerBnd bnd:
                    breakendPairs.Add(bnd);
                    break;

                default:
                    throw new InvalidDataException(
                              "Not sure why there's a not supported type in query set, check with developer!");
                }
            }

            return(new WittyerVcfResult(normalVariants.ToReadOnlyList(), breakendPairs.ToReadOnlyList(),
                                        truths.LeftOvers.ToReadOnlyList(), truths.SampleName));
        }
Example #3
0
        public void init_cyclic_spline(Vector3[] controls, int count, EvaluationMode m, int cyclic_point)
        {
            m_mode  = m;
            _cyclic = true;

            Init_Spline(controls, count, m);
        }
Example #4
0
        internal static WittyerVcfResult Create(QuerySet updatedQueries, EvaluationMode emode)
        {
            var normalVariants = new List <IWittyerVariant>();
            var breakendPairs  = new List <IWittyerBnd>();

            foreach (var variant in updatedQueries.Query)
            {
                UpdateWittyerVariant(variant, emode, false);
                switch (variant)
                {
                case IWittyerVariant normal:
                    normalVariants.Add(normal);
                    break;

                case IWittyerBnd bnd:
                    breakendPairs.Add(bnd);
                    break;

                default:
                    throw new InvalidDataException(
                              "Not sure why there's a not supported type in query set, check with developer!");
                }
            }
            return(new WittyerVcfResult(normalVariants.ToReadOnlyList(), breakendPairs.ToReadOnlyList(), updatedQueries.NotSupportedVariants, updatedQueries.SampleName));
        }
Example #5
0
        public void Evaluate(EvaluationMode evaluationMode, bool includeArchived = false)
        {
            var dataset = (evaluationMode == EvaluationMode.TESTING) ? this.TestingDataset : this.TrainingDataset;

            for (var i = 0; i < this.Supercluster.Clusters.Count; i++)
            {
                var cluster = this.Supercluster.Clusters[i];

                this.EvaluateNetworks(cluster.Networks, dataset);
            }

            if (includeArchived)
            {
                this.EvaluateNetworks(this.Supercluster.NetworkArchive, dataset);
            }

            var allNetworks = this.Supercluster.GetAllNetworks(true);
            var bestScore   = allNetworks.Max(o => o.Strength);

            if (evaluationMode == EvaluationMode.TRAINING && bestScore > this.BestTrainingScore)
            {
                this.BestTrainingScore = bestScore;
            }
            else if (evaluationMode == EvaluationMode.TESTING && bestScore > this.BestTestingScore)
            {
                this.BestTestingScore = bestScore;
            }
        }
Example #6
0
        public static bool Equals(object x, object y, EvaluationMode evaluationMode)
        {
            var comparisonType = (evaluationMode == EvaluationMode.Strict)
                ? StringComparison.CurrentCulture
                : StringComparison.InvariantCultureIgnoreCase;

            return(string.Equals(x?.ToString(), y?.ToString(), comparisonType));
        }
Example #7
0
        public static bool Contains(object x, object y, EvaluationMode evaluationMode)
        {
            var comparisonType = (evaluationMode == EvaluationMode.Strict)
                ? StringComparison.CurrentCulture
                : StringComparison.InvariantCultureIgnoreCase;

            return((x != null) && x.ToString().IndexOf(y?.ToString() ?? string.Empty, comparisonType) >= 0);
        }
Example #8
0
 private WittyerVcfReader([NotNull] IVcfReader vcfReader, [NotNull] IReadOnlyDictionary <WittyerType, InputSpec> inputSpec,
                          IReadOnlyList <IVcfVariant> baseVariants, EvaluationMode mode)
 {
     _vcfReader    = vcfReader;
     _inputSpec    = inputSpec;
     _baseVariants = baseVariants;
     _mode         = mode;
 }
Example #9
0
        /*
         * The possible parameters are:
         * key - in this case find the attribute
         * if the attribute found is a list
         *  if only one value from the list is requested
         *      return the value according to an index
         *  else return the list
         * else (the value is not a list) return the value
         */

        /**********************************************************************************************//**
        * Evaluate parameter.
        *
        * \author  Ilan Hindy
        * \date    29/09/2016
        *
        * \exception   EvaluationException Thrown when an Evaluation error condition occurs.
        *
        * \param   evaluationMode  The evaluation mode.
        * \param   network         The network.
        * \param   process         The process.
        * \param   channel         The channel.
        * \param   message         The message.
        * \param   parameter       The parameter.
        *
        * \return  An Attribute.
        *  .
        **************************************************************************************************/

        private Attribute EvaluateParameter(EvaluationMode evaluationMode, BaseNetwork network, BaseProcess process, BaseChannel channel, BaseMessage message, Attribute parameter)
        {
            if (parameter.Value.GetType().IsEnum)
            {
                if (!NetworkElementExist(network, process, channel, message))
                {
                    return(new Attribute()
                    {
                        Value = false
                    });
                }
                Attribute attribute = FindAttribute(network, process, channel, message, parameter.Value);
                if (attribute == null)
                {
                    string typeOfHostingElementStr = TypesUtility.GetKeyToString(or[brp.ork.HostingElementType]);
                    throw new EvaluationException("Could not find attribute " + TypesUtility.GetKeyToString(parameter.Value) + " In element of type " + typeOfHostingElementStr);
                }
                else
                {
                    if (Attribute.GetValueCategory(attribute) == Attribute.AttributeCategory.ListOfAttributes)
                    {
                        if (or[brp.ork.ListParameterOneOrAll] == ListParameterOneOrAll.One)
                        {
                            object[] elements       = TypesUtility.InvokeMethodOfList(attribute.Value, "ToArray", new object[0], true);
                            int      requestedIndex = or[brp.ork.IndexInList];
                            if (elements.Count() <= requestedIndex)
                            {
                                throw new EvaluationException("The index requested : " + requestedIndex.ToString() + " is larger or equal to the number of elements in the list : " + elements.Count());
                            }
                            else
                            {
                                if (Attribute.GetValueCategory(attribute) == Attribute.AttributeCategory.ListOfAttributes)
                                {
                                    return((Attribute)elements[requestedIndex]);
                                }
                                else
                                {
                                    return(new Attribute()
                                    {
                                        Value = elements[requestedIndex]
                                    });
                                }
                            }
                        }
                    }
                    return(attribute);
                }
            }
            if (parameter.Value.GetType().Equals(typeof(Breakpoint)))
            {
                return(new Attribute()
                {
                    Value = parameter.Value.Evaluate(evaluationMode, network, process, channel, message)
                });
            }
            return(parameter);
        }
        internal static object GetTypedValue(Type pType, object val, EvaluationMode mode)
        {
            object typedValue = val;
            var    converter  = TypeDescriptor.GetConverter(pType);

            try
            {
                if (val?.GetType().Equals(pType) ?? true)
                {
                    return(val);
                }
                else if (converter.CanConvertFrom(val.GetType()))
                {
                    typedValue = converter.ConvertFrom(null, CultureInfo.InvariantCulture, val);
                }
                else if (pType.IsPrimitive)
                {
                    typedValue = Convert.ChangeType(val, pType);
                }
                else if (!pType.IsAbstract)
                {
                    var method = (MethodBase)pType.GetMethod("Parse", BindingFlags.Static | BindingFlags.Public, null, new[] { val.GetType() }, null);
                    if (method == null)
                    {
                        method = pType.GetConstructor(new[] { val.GetType() });
                    }
                    if (method?.IsConstructor ?? false)
                    {
                        typedValue = Activator.CreateInstance(pType, new[] { val });
                    }
                    else
                    {
                        typedValue = method?.Invoke(null, new[] { val });
                        if (typedValue == null)
                        {
                            if (typeof(string) == pType)
                            {
                                typedValue = val.ToString();
                            }
                            else
                            {
                                typedValue = val;
                            }
                        }
                    }
                }
            }
            catch
            {
                if (mode == EvaluationMode.Strict)
                {
                    throw;
                }
                typedValue = GetDefaultValue(pType);
            }
            return(typedValue);
        }
Example #11
0
 /// <summary>
 /// Rule arg class constructor to abstract the creation of rules
 /// </summary>
 /// <param name="ruleId"></param>
 /// <param name="operands"></param>
 /// <param name="childRules"></param>
 /// <param name="logicType"></param>
 /// <param name="mode"></param>
 /// <param name="failureCode"></param>
 public RuleArguments(Guid ruleId, IReadOnlyList<IOperand> operands, IReadOnlyList<IRule> childRules, LogicType logicType, EvaluationMode mode, string failureCode)
 {
     RuleId = ruleId;
     Operands = operands;
     ChildRules = childRules;
     LogicType = logicType;
     Mode = mode;
     FailureCode = failureCode;
 }
 public ObjectAttributeEvaluation(EvaluationMode lEvaluationMode, int Min, int Max)
 {
     cEvaluationMode = lEvaluationMode;
     if (Min != Max)
     {
         MinCount = Min;
         MaxCount = Max;
     }
     SetAttribueType(AttributeType.Evalution);
     EvaluateFirst();
 }
Example #13
0
 private WittyerSettings([NotNull] DirectoryInfo outputDirectory, [NotNull] FileInfo truthVcf, FileInfo queryVcf,
                         [NotNull] IReadOnlyCollection <ISamplePair> samplePairs, EvaluationMode mode,
                         [NotNull] IReadOnlyDictionary <WittyerType, InputSpec> inputSpecs)
 {
     OutputDirectory = outputDirectory;
     TruthVcf        = truthVcf;
     QueryVcf        = queryVcf;
     SamplePairs     = samplePairs;
     Mode            = mode;
     InputSpecs      = inputSpecs;
 }
Example #14
0
 internal static void HandleException(Exception ex, EvaluationMode evaluationMode)
 {
     if ((evaluationMode & EvaluationMode.Strict) == EvaluationMode.Strict)
     {
         if (ex.InnerException != null)
         {
             throw ex.InnerException;
         }
         ;
         throw ex;
     }
 }
Example #15
0
 public void SetMode(int newmode)
 {
     mode = (EvaluationMode)newmode;
     if (newmode == 1)
     {
         //	ballCtrl.Randomize();
     }
     if (newmode == 3)
     {
         //	manualDiskCtrl.SetManualControl(true);
         //ballCtrl.Randomize();
     }
 }
Example #16
0
 /// <summary>
 /// Rule arg class constructor to abstract the creation of rules
 /// </summary>
 /// <param name="ruleId"></param>
 /// <param name="dataType"></param>
 /// <param name="description"></param>
 /// <param name="operands"></param>
 /// <param name="childRules"></param>
 /// <param name="logicType"></param>
 /// <param name="mode"></param>
 /// <param name="failureCode"></param>
 /// <param name="listProxy"></param>
 /// <param name="tenantId"></param>
 public RuleArguments(Guid ruleId, DataType dataType, string description, IReadOnlyList <IOperand> operands, IReadOnlyList <IRule> childRules,
                      LogicType logicType, EvaluationMode mode, string failureCode, IListProxy listProxy, string tenantId)
 {
     RuleId      = ruleId;
     DataType    = dataType;
     Description = description;
     Operands    = operands;
     ChildRules  = childRules;
     LogicType   = logicType;
     Mode        = mode;
     FailureCode = failureCode;
     ListProxy   = listProxy;
     TenantId    = tenantId;
 }
        /// <inheritdoc />
        public void Finalize(WitDecision falseDecision, EvaluationMode mode,
                             GenomeIntervalTree <IContigAndInterval> includedRegions)
        {
            bool?isIncluded = null;

            if (includedRegions != null)
            {
                isIncluded = includedRegions.TryGetValue(OriginalVariant.Contig, out var tree) &&
                             tree.Search(CiPosInterval).Any() && // or there's overlap in bed regions
                             (ReferenceEquals(OriginalVariant, EndOriginalVariant) ||
                              Equals(OriginalVariant.Contig, EndOriginalVariant.Contig) ||
                              includedRegions.TryGetValue(EndOriginalVariant.Contig, out tree) &&
                              tree.Search(CiEndInterval).Any());       // or end overlaps.
            }
            WittyerVariantInternal.Finalize(this, _overlapInfo, falseDecision, mode, isIncluded);
        }
Example #18
0
 void IXmlSerializable.WriteXml(XmlWriter writer)
 {
     if (DataType != 0)
     {
         writer.WriteAttributeString("DataType", DataType.ToString());
     }
     if (EvaluationMode != 0)
     {
         writer.WriteAttributeString("EvaluationMode", EvaluationMode.ToString());
     }
     if (Value.Length > 0)
     {
         if (Value.Trim().Length == 0)
         {
             writer.WriteAttributeString("xml", "space", null, "preserve");
         }
         writer.WriteString(Value);
     }
 }
Example #19
0
        public void Init_Spline(Vector3[] controls, int count, EvaluationMode m)
        {
            m_mode  = m;
            _cyclic = false;

            switch (m_mode)
            {
            case EvaluationMode.Linear:
            case EvaluationMode.Catmullrom:
                InitCatmullRom(controls, count, _cyclic, 0);
                break;

            case EvaluationMode.Bezier3_Unused:
                InitBezier3(controls, count, _cyclic, 0);
                break;

            default:
                break;
            }
        }
Example #20
0
        public void Init_Spline(Vector3[] controls, int count, EvaluationMode m, int cyclic_point = 0)
        {
            m_mode = m;
            cyclic = cyclic_point != 0;

            switch (m_mode)
            {
            case EvaluationMode.Linear:
            case EvaluationMode.Catmullrom:
                InitCatmullRom(controls, count, cyclic, cyclic_point);
                break;

            case EvaluationMode.Bezier3_Unused:
                InitBezier3(controls, count, cyclic, cyclic_point);
                break;

            default:
                break;
            }
        }
        internal static object caller(Assembly assembly, string myclass, string mymethod, object[] parameters, bool convertParameters, JUSTContext context)
        {
            Type       type       = assembly?.GetType(myclass) ?? Type.GetType(myclass);
            MethodInfo methodInfo = type.GetTypeInfo().GetMethod(mymethod);
            var        instance   = !methodInfo.IsStatic ? Activator.CreateInstance(type) : null;

            try
            {
                return(InvokeCustomMethod(methodInfo, parameters, convertParameters, context));
            }
            catch
            {
                EvaluationMode mode = context.EvaluationMode;
                if (mode == EvaluationMode.Strict)
                {
                    throw;
                }
                return(GetDefaultValue(methodInfo.ReturnType));
            }
        }
Example #22
0
        /// <summary>
        /// Initialize the experiment with some optional XML configuration data.
        /// </summary>
        public void Initialize(string name, XmlElement xmlConfig)
        {
            T GetValueAsEnum <T>(string e)
            {
                string r = XmlUtils.GetValueAsString(xmlConfig, e);

                return((T)System.Enum.Parse(typeof(T), r));
            }

            _name                    = name;
            _populationSize          = XmlUtils.GetValueAsInt(xmlConfig, "PopulationSize");
            _specieCount             = XmlUtils.GetValueAsInt(xmlConfig, "SpecieCount");
            _activationScheme        = ExperimentUtils.CreateActivationScheme(xmlConfig, "Activation");
            _complexityRegulationStr = XmlUtils.TryGetValueAsString(xmlConfig, "ComplexityRegulationStrategy");
            _complexityThreshold     = XmlUtils.TryGetValueAsInt(xmlConfig, "ComplexityThreshold");

            _numberOfGames = XmlUtils.GetValueAsInt(xmlConfig, "IPDGames");
            int seed    = XmlUtils.GetValueAsInt(xmlConfig, "RandomPlayerSeed");
            int randoms = XmlUtils.GetValueAsInt(xmlConfig, "RandomPlayerCount");

            string os = XmlUtils.TryGetValueAsString(xmlConfig, "StaticOpponents");

            _opponentPool = CreatePool(seed, randoms, (os == null) ? new Opponent[0] : System.Array.ConvertAll(os.Split(','), (string o) => { return((Opponent)System.Enum.Parse(typeof(Opponent), o, true)); }));

            _evaluationLimit = (ulong)XmlUtils.GetValueAsInt(xmlConfig, "EvaluationLimit");
            _evaluationMode  = GetValueAsEnum <EvaluationMode>("EvaluationMode");
            _noveltyMetric   = GetValueAsEnum <NoveltyMetric>("NoveltyMetric");
            _noveltyK        = XmlUtils.GetValueAsInt(xmlConfig, "NoveltyK");

            _randomRobustCheck = XmlUtils.GetValueAsInt(xmlConfig, "RandomRobustCheck");
            _pastInputReach    = XmlUtils.GetValueAsInt(xmlConfig, "PastInputReach");

            _description     = XmlUtils.TryGetValueAsString(xmlConfig, "Description");
            _parallelOptions = ExperimentUtils.ReadParallelOptions(xmlConfig);

            _eaParams                         = new NeatEvolutionAlgorithmParameters();
            _eaParams.SpecieCount             = _specieCount;
            _neatGenomeParams                 = new NeatGenomeParameters();
            _neatGenomeParams.FeedforwardOnly = _activationScheme.AcyclicNetwork;
        }
Example #23
0
        /// <inheritdoc />
        public void Finalize(WitDecision falseDecision, EvaluationMode mode,
                             GenomeIntervalTree <IContigAndInterval> includedRegions)
        {
            bool?isIncluded = null;

            if (includedRegions != null)
            {
                isIncluded = false;
                if (includedRegions.TryGetValue(Contig, out var tree))
                {
                    var startPosition = CiPosInterval.Stop - 1;
                    var endPosition   = CiEndInterval.Start;
                    if (startPosition >= endPosition)
                    {
                        // means cipos or ciend goes past each other
                        // so any overlap with Start to Stop should mean included.
                        isIncluded = tree.Search(this).Any();
                    }
                    else
                    {
                        // ReSharper disable once LoopCanBeConvertedToQuery // prevent closure allocation
                        foreach (var overlap in tree.Search(startPosition))
                        {
                            if (!overlap.Contains(endPosition))
                            {
                                continue;
                            }
                            isIncluded = true;
                            break;
                        }
                    }
                }
            }

            Finalize(this, _overlapInfo, falseDecision, mode, isIncluded);
        }
 public abstract AspNetCore.ReportingServices.ReportIntermediateFormat.ExpressionInfo ParseExpression(string expression, ExpressionContext context, EvaluationMode evaluationMode);
Example #25
0
        public static WittyerVcfReader Create([NotNull] IVcfReader vcfReader,
                                              [NotNull] IReadOnlyDictionary <WittyerType, InputSpec> inputSpec, EvaluationMode mode,
                                              [CanBeNull] string sampleName)
        {
            if (inputSpec.SelectMany(kvp => kvp.Value.ExcludedFilters.Concat(kvp.Value.IncludedFilters)).Any(string.IsNullOrWhiteSpace))
            {
                throw new InvalidDataException("Passed in empty or whitespace as a filter!");
            }

            var successVariants = new List <IVcfVariant>();
            var exceptions      = new List <Exception>();

            foreach (var item in vcfReader.GetAllItems())
            {
                item.DoOnSuccess(v =>
                {
                    var variant = v;
                    if (v.Samples.Count > 0)
                    {
                        var sample     = sampleName == null ? v.Samples[0] : v.Samples[sampleName];
                        var sampleDict = SampleDictionaries.CreateBuilder().AddSample(sample.SampleName)
                                         .MoveOnToDictionaries();
                        sample.SampleDictionary.ForEach(kvp =>
                                                        sampleDict.SetSampleField(sample.SampleName, (kvp.Key, kvp.Value)));
                        variant = v.ToBuilder().SetSamples(sampleDict.Build()).Build();
                    }
                    successVariants.Add(variant);
                }).DoOnFailure(e => exceptions.Add(e));
            }

            if (exceptions.Count == 0)
            {
                return(new WittyerVcfReader(vcfReader, inputSpec, successVariants.AsReadOnly(), mode));
            }

            var msg = exceptions.Take(5).Select(x => x.Message)
                      .StringJoin("\n");

            throw new InvalidDataException
                      ($"Found {exceptions.Count} variants cannot be parsed in {vcfReader.FileSource.FullName}: first 5 or less:\n {msg}");
        }
Example #26
0
 internal abstract Microsoft.ReportingServices.ReportIntermediateFormat.ExpressionInfo ParseExpression(string expression, ExpressionContext context, EvaluationMode evaluationMode);
Example #27
0
 internal abstract Microsoft.ReportingServices.ReportIntermediateFormat.ExpressionInfo ParseExpression(string expression, ExpressionContext context, EvaluationMode evaluationMode, out bool userCollectionReferenced);
Example #28
0
        internal static void Finalize([NotNull] IMutableWittyerSimpleVariant variant,
                                      [NotNull] List <OverlapAnnotation> annotations, WitDecision falseDecision, EvaluationMode mode,
                                      bool?isIncluded)
        {
            annotations.Sort();

            WittyerSampleInternal unwrappedSample;

            switch (variant.Sample)
            {
            case WittyerSampleInternal simple:
                unwrappedSample = simple;
                break;

            case WittyerCopyNumberSample cnSample:
                unwrappedSample = cnSample.BaseSample;
                break;

            case WittyerGenotypedSample gtSample:
                unwrappedSample = gtSample.BaseSample;
                break;

            case WittyerGenotypedCopyNumberSample gtCnSample:
                unwrappedSample = gtCnSample.BaseSample.BaseSample;
                break;

            default:
                throw new InvalidDataException(
                          "Not sure how we get here, you must have created some non-existed wittyer sample type, check with developer!");
            }

            // expected results:
            // isIncluded == null means no bedRegion, so everything is normal.
            // isIncluded != null means bedRegion, so if false, override the results as such:
            // Wit = NotAssessed.
            // Why[0] if Unset = OutsideBedRegion
            unwrappedSample.What = ImmutableList <MatchEnum> .Empty;
            unwrappedSample.Why  = ImmutableList <FailedReason> .Empty;
            var isTp = false;

            for (var i = 0; i < variant.OverlapInfo.Count; i++)
            {
                var what = variant.OverlapInfo[i].What;
                unwrappedSample.What = unwrappedSample.What.Add(what);
                isTp = isTp ||
                       what == MatchEnum.AlleleAndGenotypeMatch ||
                       (mode == EvaluationMode.SimpleCounting || mode == EvaluationMode.CrossTypeAndSimpleCounting) &&
                       what == MatchEnum.AlleleMatch;

                var why = variant.OverlapInfo[i].Why;
                if (why == FailedReason.Unset)
                {
                    why = i == 0 && isIncluded == false
                        ? FailedReason.OutsideBedRegion
                        : what == MatchEnum.Unmatched
                            ? FailedReason.NoOverlap
                            : FailedReason.Other;
                }
                unwrappedSample.Why = unwrappedSample.Why.Add(why);
            }

            if (unwrappedSample.What.Count == 0)
            {
                unwrappedSample.What = EmptyWhat;
            }

            if (unwrappedSample.Why.Count == 0)
            {
                unwrappedSample.Why = isIncluded == false ? EmptyOutsideBedWhy : isTp ? EmptyTrueWhy : EmptyFalseWhy;
            }

            unwrappedSample.Wit = isIncluded == null || isIncluded.Value
                ? isTp
                    ? WitDecision.TruePositive
                    : falseDecision
                : WitDecision.NotAssessed;
        }
Example #29
0
 public ReportExpression(string value)
 {
     m_value          = value;
     m_dataType       = DataTypes.String;
     m_evaluationMode = EvaluationMode.Auto;
 }
Example #30
0
 public ReportExpression(string value, EvaluationMode evaluationMode)
 {
     m_value          = value;
     m_dataType       = DataTypes.String;
     m_evaluationMode = evaluationMode;
 }
Example #31
0
 internal static object GetTypedValue(JTokenType jType, object val, EvaluationMode mode)
 {
     return(GetTypedValue(GetType(jType), val, mode));
 }
 public abstract AspNetCore.ReportingServices.ReportIntermediateFormat.ExpressionInfo ParseExpression(string expression, ExpressionContext context, EvaluationMode evaluationMode, out bool userCollectionReferenced);
        /// <summary>
        /// Evaluates the expression component.
        /// </summary>
        /// <param name="component">The component.</param>
        /// <param name="mode">The mode.</param>
        /// <returns>The result of the evaluated expression component.</returns>
        private object EvaluateExpressionComponent(string component, EvaluationMode mode)
        {
            Logger.Instance.WriteMethodEntry(EventIdentifier.ExpressionEvaluatorEvaluateExpressionComponent, "Component: '{0}'. Evaluation Mode: '{1}'.", component, mode);

            object returnValue = null;
            try
            {
                ParameterType type = DetermineParameterType(component);
                if (mode == EvaluationMode.Parse)
                {
                    // When performing a parse,
                    // the function should only return null when the component is valid
                    // Exceptions will be thrown otherwise to indicate invalidity
                    switch (type)
                    {
                        case ParameterType.Lookup:

                            // Load the lookup to the cache
                            if (!this.lookupCache.ContainsKey(component))
                            {
                                this.lookupCache.Add(component, null);
                            }

                            return null;

                        case ParameterType.Variable:

                            // Load the variable to the cache
                            if (!this.variableCache.ContainsKey(component))
                            {
                                this.variableCache.Add(component, null);
                            }

                            return null;

                        case ParameterType.Function:

                            // Evaluate the function to ensure its validity
                            return this.EvaluateFunction(component, mode);

                        default:

                            // For all other types, no further evaluation is needed
                            // and we can return null
                            return null;
                    }
                }

                // When performing a resolution,
                // the function should return the resolved expression component
                switch (type)
                {
                    case ParameterType.String:

                        // Return the string after removing the quotation marks
                        returnValue = EscapeString(component);
                        return returnValue;

                    case ParameterType.Integer:

                        // Return the long as FIM datatype is System.Int64
                        returnValue = long.Parse(component, CultureInfo.InvariantCulture);
                        return returnValue;

                    case ParameterType.Boolean:

                        // Return the Boolean value
                        returnValue = bool.Parse(component);
                        return returnValue;

                    case ParameterType.Lookup:

                        // Check the cache for the lookup and return its value if present
                        if (this.lookupCache.ContainsKey(component))
                        {
                            returnValue = this.lookupCache[component];
                            return returnValue;
                        }

                        throw Logger.Instance.ReportError(EventIdentifier.ExpressionEvaluatorEvaluateExpressionComponentLookupCacheValidationError, new InvalidExpressionException(Messages.ExpressionEvaluator_LookupCacheValidationError, component));

                    case ParameterType.Variable:

                        // Check the cache for the variable and return its value if present
                        if (this.variableCache.ContainsKey(component))
                        {
                            returnValue = this.variableCache[component];
                            return returnValue;
                        }

                        throw Logger.Instance.ReportError(EventIdentifier.ExpressionEvaluatorEvaluateExpressionComponentVariableCacheValidationError, new InvalidExpressionException(Messages.ExpressionEvaluator_VariableCacheValidationError, component));

                    case ParameterType.Function:

                        // Pass the function off to the EvaluateFunction method for resolution
                        // and return the result
                        returnValue = this.EvaluateFunction(component, mode);
                        return returnValue;

                    default:
                        throw Logger.Instance.ReportError(EventIdentifier.ExpressionEvaluatorEvaluateExpressionComponentParameterTypeValidationError, new InvalidExpressionException());
                }
            }
            finally
            {
                Logger.Instance.WriteMethodExit(EventIdentifier.ExpressionEvaluatorEvaluateExpressionComponent, "Component: '{0}'. Evaluation Mode: '{1}'. Return Value: '{2}'.", component, mode, returnValue);
            }
        }
Example #34
0
 private static PledgeRule CreateRule(List<int> indices, DataType dataType, RuleType ruleType, LogicType logicType, List<object> operands, EvaluationMode mode = EvaluationMode.Active)
 {
     return new PledgeRule
     {
         Columns = indices.Select(index => new Column {Index = index}).ToList(),
         DataType = dataType,
         RuleType = ruleType,
         RuleId = Guid.NewGuid(),
         LogicType = logicType,
         Operands = operands,
         Mode = mode,
         Children = new List<PledgeRule>()
     };
 }
        /// <summary>
        /// Evaluates the expression.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="mode">The mode.</param>
        /// <returns>The result of the evaluated expression.</returns>
        private object EvaluateExpression(string expression, EvaluationMode mode)
        {
            Logger.Instance.WriteMethodEntry(EventIdentifier.ExpressionEvaluatorEvaluateExpression, "Expression: '{0}'. Evaluation Mode: '{1}'.", expression, mode);

            object result = null;
            try
            {
                ArrayList components = IdentifyExpressionComponents(expression);

                // If no concatenation is required, return the resolved expression
                if (components.Count == 1)
                {
                    result = this.EvaluateExpressionComponent(expression, mode);
                    return result;
                }

                // If the expression requires concatenation,
                // evaluate each component and resolve, if necessary
                if (mode == EvaluationMode.Parse)
                {
                    foreach (string component in components)
                    {
                        this.EvaluateExpressionComponent(component, mode);
                    }

                    return null;
                }

                StringBuilder concatenated = new StringBuilder();
                foreach (object value in components.Cast<string>().Select(component => this.EvaluateExpressionComponent(component, mode)).Where(value => value != null))
                {
                    concatenated.Append(value);
                }

                result = concatenated.Length > 0 ? concatenated.ToString() : null;
                return result;
            }
            finally
            {
                Logger.Instance.WriteMethodExit(EventIdentifier.ExpressionEvaluatorEvaluateExpression, "Expression: '{0}'. Evaluation Mode: '{1}'. Returning: '{2}'.", expression, mode, result);
            }
        }
Example #36
0
 private static PledgeRule CreateRule(int index, DataType dataType, RuleType ruleType, LogicType logicType, List<object> operands, EvaluationMode mode = EvaluationMode.Active)
 {
     return CreateRule(new List<int> {index}, dataType, ruleType, logicType, operands, mode);
 }
        /// <summary>
        /// Evaluates the function.
        /// </summary>
        /// <param name="function">The function.</param>
        /// <param name="mode">The mode.</param>
        /// <returns>The result of the evaluated function.</returns>
        private object EvaluateFunction(string function, EvaluationMode mode)
        {
            Logger.Instance.WriteMethodEntry(EventIdentifier.ExpressionEvaluatorEvaluateFunction, "Function: '{0}'. Evaluation Mode: '{1}'.", function, mode);

            object result = null;
            try
            {
                // Locate the opening and closing () characters for the function
                // by looking for the first and last instance of each character
                // This will ignore any nested functions which may be used as a parameter
                int open = function.IndexOf('(');
                int close = function.LastIndexOf(')');

                // Break apart the function expression to identify the function name
                // and parameter string (content between parentheses)
                string functionName = function.Substring(0, open);
                string parameterString = function.Substring(open + 1, close - open - 1);

                // Create new array lists to hold the unresolved and resolved parameters for the function
                // Only evaluate parameters if the parameter string is not empty, as it will
                // be for functions like DateTimeNow() and Null()
                ArrayList unresolvedParameters = new ArrayList();
                ArrayList parameters = new ArrayList();
                if (!string.IsNullOrEmpty(parameterString.Trim()))
                {
                    // The function expression could contain nested functions with their own commas
                    // For example, Trim(Left(ReplaceString(attribute, "This", "That"), 8))
                    // Consequently, we can't assume that a split by comma returns each parameter
                    // We need to loop through each and determine if a parameter needs to be reassembled
                    // based on the positioning of ( and ) characters and quotation marks
                    StringBuilder reassembled = new StringBuilder();
                    bool openString = false;
                    int openFunctions = 0;

                    // First, make sure that there are an appropriate number of ( and ) characters
                    // and also make sure there is no open string in the function
                    foreach (char c in parameterString)
                    {
                        if (c.Equals('\"'))
                        {
                            openString = !openString;
                        }

                        if (c.Equals('(') && !openString)
                        {
                            openFunctions += 1;
                        }

                        if (c.Equals(')') && !openString)
                        {
                            openFunctions -= 1;
                        }
                    }

                    // If there is an open string or the number of open and close 
                    // parantheses characters do not match, throw an exception
                    if (openString)
                    {
                        throw Logger.Instance.ReportError(EventIdentifier.ExpressionEvaluatorEvaluateFunctionQuotesValidationError, new InvalidFunctionFormatException(Messages.ExpressionEvaluator_FunctionParameterQuotesValidationError, functionName));
                    }

                    if (openFunctions != 0)
                    {
                        throw Logger.Instance.ReportError(EventIdentifier.ExpressionEvaluatorEvaluateFunctionParenthesisValidationError, new InvalidFunctionFormatException(Messages.ExpressionEvaluator_FunctionParameterParenthesisValidationError, functionName));
                    }

                    // Loop through each parameter fragment, split by comma,
                    // and determine if reassembly is required
                    foreach (string s in parameterString.Split(','))
                    {
                        // Count the number of ( and ) characters in the current string
                        // Only consider the parentheses relevent if it is not in an open string
                        foreach (char c in s)
                        {
                            if (c.Equals('\"'))
                            {
                                openString = !openString;
                            }
                            else if (c.Equals('(') && !openString)
                            {
                                openFunctions += 1;
                            }
                            else if (c.Equals(')') && !openString)
                            {
                                openFunctions -= 1;
                            }
                        }

                        // Add the string to the reassembled string builder
                        // and determine how to proceed based on whether or not
                        // we are currently reassembling parameter fragments
                        reassembled.Append(s);
                        if (openFunctions > 0 || openString)
                        {
                            reassembled.Append(",");
                        }
                        else
                        {
                            // If a parameter is not open, it either means that no
                            // reassembly was required or we have completed reassembly
                            // Either way, add the parameter to the list of unresolved parameters
                            // and reset the string builder
                            unresolvedParameters.Add(reassembled.ToString().Trim());
                            reassembled = new StringBuilder();
                        }
                    }

                    foreach (string s in unresolvedParameters)
                    {
                        Logger.Instance.WriteVerbose(EventIdentifier.ExpressionEvaluatorEvaluateFunction, "Resolving unresolved function parameter '{0}'.", s);

                        ParameterType type = DetermineParameterType(s);

                        switch (type)
                        {
                            case ParameterType.String:
                                // Add the string value after trimming the quotes
                                parameters.Add(EscapeString(s));
                                break;
                            case ParameterType.Integer:
                                // Add the parsed value as long as FIM datatype is System.Int64
                                parameters.Add(long.Parse(s, CultureInfo.InvariantCulture));
                                break;
                            case ParameterType.Boolean:
                                // Add the parsed Boolean value
                                parameters.Add(bool.Parse(s));
                                break;
                            case ParameterType.Lookup:
                                if (mode == EvaluationMode.Parse)
                                {
                                    // For parse, add the lookup to the cache 
                                    // Mark the grammar in the parameter list by adding the appropriate enum value
                                    if (!this.lookupCache.ContainsKey(s))
                                    {
                                        this.lookupCache.Add(s, null);
                                    }

                                    parameters.Add(ParameterType.Lookup);
                                }
                                else
                                {
                                    // For resolution, pull the value from the lookup cache and
                                    // add it to the parameter list
                                    if (this.lookupCache.ContainsKey(s))
                                    {
                                        parameters.Add(this.lookupCache[s]);
                                    }
                                    else
                                    {
                                        throw Logger.Instance.ReportError(EventIdentifier.ExpressionEvaluatorEvaluateFunctionLookupCacheValidationError, new InvalidFunctionFormatException(Messages.ExpressionEvaluator_LookupCacheValidationError, s));
                                    }
                                }

                                break;
                            case ParameterType.Variable:
                                if (mode == EvaluationMode.Parse)
                                {
                                    // For parse, add the variable to the cache 
                                    // Mark the variable in the parameter list by adding the appropriate enum value
                                    if (!this.variableCache.ContainsKey(s))
                                    {
                                        this.variableCache.Add(s, null);
                                    }

                                    parameters.Add(ParameterType.Variable);
                                }
                                else
                                {
                                    // For resolution, pull the value from the variable cache and
                                    // add it to the parameter list
                                    if (this.variableCache.ContainsKey(s))
                                    {
                                        parameters.Add(this.variableCache[s]);
                                    }
                                    else
                                    {
                                        throw Logger.Instance.ReportError(EventIdentifier.ExpressionEvaluatorEvaluateFunctionVariableCacheValidationError, new InvalidFunctionFormatException(Messages.ExpressionEvaluator_VariableCacheValidationError, s));
                                    }
                                }

                                break;
                            case ParameterType.Function:
                                if (mode == EvaluationMode.Parse)
                                {
                                    // For parse, recursively evaluate the function and any nested functions
                                    // Mark the function in the parameter list by adding the appropriate enum value
                                    this.EvaluateFunction(s, mode);
                                    parameters.Add(ParameterType.Function);
                                }
                                else
                                {
                                    // For resolution, recursively resolve the function and any nested functions
                                    // and add the end result to the parameter list for the current function
                                    parameters.Add(this.EvaluateFunction(s, mode));
                                }

                                break;
                            case ParameterType.Expression:

                                if (mode == EvaluationMode.Parse)
                                {
                                    // For parse, recursively evaluate the expression and any nested functions
                                    // Mark the expression in the paramter list by adding the appropriate enum value
                                    this.EvaluateExpression(s, mode);
                                    parameters.Add(ParameterType.Expression);
                                }
                                else
                                {
                                    // For resolution, recursively resolve the expression and any nested functions
                                    // and add the end result to the parameter list for the current function
                                    parameters.Add(this.EvaluateExpression(s, mode));
                                }

                                break;
                            default:
                                throw Logger.Instance.ReportError(EventIdentifier.ExpressionEvaluatorEvaluateFunctionParameterTypeValidationError, new InvalidFunctionFormatException());
                        }
                    }
                }

                // Special handling for EvaluateExpression() function so that the lookups in the expression to evaluate are resolved
                // Assumption: the lookups used in the expression are already used in some other expressions
                // e.g. Consider [//Query/Site/xUserTemplateExpression] returning IIF(Eq([//Target/Department],"HR"),"Template1","Template2")
                // We want EvaluateExpression([//Query/Site/xUserTemplateExpression]). 
                // In this case caller activity need to ensure that [//Target/Department] is already used any other expression
                // so that it's part of LookupCache.
                if (functionName.Equals(ParameterType.EvaluateExpression.ToString(), StringComparison.OrdinalIgnoreCase))
                {
                    Logger.Instance.WriteWarning(EventIdentifier.ExpressionEvaluatorEvaluateFunctionDeprecatedFunctionWarning, Messages.ExpressionFunction_DeprecatedFunctionWarning, ParameterType.EvaluateExpression.ToString(), "Resolve Dynamic Grammar capability of UpdateResources activity");

                    string expression = this.EvaluateExpression(parameterString, mode) as string; // so e.g. IIF(Eq([//Target/Department],"HR"),"Template1","Template2")
                    if (mode != EvaluationMode.Parse && !string.IsNullOrEmpty(expression))
                    {
                        // now evalaute the actual expression i.e. e.g. IIF(Eq([//Target/Department],"HR"),"Template1","Template2")
                        result = this.EvaluateExpression(expression, mode);
                    }
                }
                else
                {
                    // Evaluate the function to make sure it is properly formatted,
                    // all required parameters are available, and parameters are of the appropriate type
                    // For most functions, the root value is allowed to be null to handle 
                    // scenarios when an attribute or expression is resolved to null
                    // In this circumstance, an exception should not be thrown but the function should resolve to null
                    ExpressionFunction expressionFunction = new ExpressionFunction(functionName, parameters, mode);
                    result = expressionFunction.Run();
                }

                return result;
            }
            finally
            {
                Logger.Instance.WriteMethodExit(EventIdentifier.ExpressionEvaluatorEvaluateFunction, "Function: '{0}'. Evaluation Mode: '{1}'. Returning: '{2}'.", function, mode, result);
            }
        }
 /// <summary>
 /// ObjectAttributeEvaluation constructor.
 /// </summary>
 /// <param name="lEvaluationMode">Are we evaluationg biggest or smallest value?</param>
 /// <param name="Min">Minimal accepted value. Default 0.</param>
 /// <param name="Max">Maximal accepted value. Default int.MaxValue.</param>
 public ObjectAttributeEvaluation(EvaluationMode lEvaluationMode, int Min=0, int Max=int.MaxValue)
     : this()
 {
     cEvaluationMode = lEvaluationMode;
     if (Min != Max)
     {
         MinValue = Min;
         MaxValue = Max;
     }
 }