コード例 #1
0
 public override void UpdateEnabled(bool?setValue)
 {
     if (setValue.HasValue)
     {
         enabled = setValue.GetValueOrDefault(false);
     }
     else
     {
         enabled = RegexList.State();
     }
     OnEnabledChanged(false);
 }
コード例 #2
0
        protected ANALYSIS_RESULT_TYPE Apply(Rule rule, CompareResult compareResult)
        {
            if (compareResult != null && rule != null)
            {
                var properties = _Properties[compareResult.ResultType];

                foreach (Clause clause in rule.Clauses)
                {
                    PropertyInfo property = properties.FirstOrDefault(iProp => iProp.Name.Equals(clause.Field));
                    if (property == null)
                    {
                        //Custom field logic will go here
                        return(DEFAULT_RESULT_TYPE_MAP[compareResult.ResultType]);
                    }

                    try
                    {
                        var valsToCheck = new List <string>();
                        List <KeyValuePair <string, string> > dictToCheck = new List <KeyValuePair <string, string> >();

                        if (property != null)
                        {
                            if (compareResult.ChangeType == CHANGE_TYPE.CREATED || compareResult.ChangeType == CHANGE_TYPE.MODIFIED)
                            {
                                try
                                {
                                    if (GetValueByPropertyName(compareResult.Compare, property.Name) is List <string> )
                                    {
                                        foreach (var value in (List <string>)(GetValueByPropertyName(compareResult.Compare, property.Name) ?? new List <string>()))
                                        {
                                            valsToCheck.Add(value);
                                        }
                                    }
                                    else if (GetValueByPropertyName(compareResult.Compare, property.Name) is Dictionary <string, string> )
                                    {
                                        dictToCheck = ((Dictionary <string, string>)(GetValueByPropertyName(compareResult.Compare, property.Name) ?? new Dictionary <string, string>())).ToList();
                                    }
                                    else if (GetValueByPropertyName(compareResult.Compare, property.Name) is List <KeyValuePair <string, string> > )
                                    {
                                        dictToCheck = (List <KeyValuePair <string, string> >)(GetValueByPropertyName(compareResult.Compare, property.Name) ?? new List <KeyValuePair <string, string> >());
                                    }
                                    else
                                    {
                                        var val = GetValueByPropertyName(compareResult.Compare, property.Name)?.ToString();
                                        if (!string.IsNullOrEmpty(val))
                                        {
                                            valsToCheck.Add(val);
                                        }
                                    }
                                }
                                catch (Exception e)
                                {
                                    Log.Debug(e, "Error fetching Property {0} of Type {1}", property.Name, compareResult.ResultType);
                                    Log.Debug(Utf8Json.JsonSerializer.ToJsonString(compareResult));
                                    Dictionary <string, string> ExceptionEvent = new Dictionary <string, string>();
                                    ExceptionEvent.Add("Exception Type", e.GetType().ToString());
                                    AsaTelemetry.TrackEvent("ApplyCreatedModifiedException", ExceptionEvent);
                                }
                            }
                            if (compareResult.ChangeType == CHANGE_TYPE.DELETED || compareResult.ChangeType == CHANGE_TYPE.MODIFIED)
                            {
                                try
                                {
                                    if (GetValueByPropertyName(compareResult.Base, property.Name) is List <string> )
                                    {
                                        foreach (var value in (List <string>)(GetValueByPropertyName(compareResult.Base, property.Name) ?? new List <string>()))
                                        {
                                            valsToCheck.Add(value);
                                        }
                                    }
                                    else if (GetValueByPropertyName(compareResult.Base, property.Name) is Dictionary <string, string> )
                                    {
                                        dictToCheck = ((Dictionary <string, string>)(GetValueByPropertyName(compareResult.Base, property.Name) ?? new Dictionary <string, string>())).ToList();
                                    }
                                    else if (GetValueByPropertyName(compareResult.Base, property.Name) is List <KeyValuePair <string, string> > )
                                    {
                                        dictToCheck = (List <KeyValuePair <string, string> >)(GetValueByPropertyName(compareResult.Base, property.Name) ?? new List <KeyValuePair <string, string> >());
                                    }
                                    else
                                    {
                                        var val = GetValueByPropertyName(compareResult.Base, property.Name)?.ToString();
                                        if (!string.IsNullOrEmpty(val))
                                        {
                                            valsToCheck.Add(val);
                                        }
                                    }
                                }
                                catch (Exception e)
                                {
                                    Dictionary <string, string> ExceptionEvent = new Dictionary <string, string>();
                                    ExceptionEvent.Add("Exception Type", e.GetType().ToString());
                                    AsaTelemetry.TrackEvent("ApplyDeletedModifiedException", ExceptionEvent);
                                }
                            }
                        }

                        switch (clause.Operation)
                        {
                        case OPERATION.EQ:
                            if (clause.Data is List <string> EqualsData)
                            {
                                if (EqualsData.Intersect(valsToCheck).Any())
                                {
                                    break;
                                }
                            }
                            return(DEFAULT_RESULT_TYPE_MAP[compareResult.ResultType]);

                        case OPERATION.NEQ:
                            if (clause.Data is List <string> NotEqualsData)
                            {
                                if (!NotEqualsData.Intersect(valsToCheck).Any())
                                {
                                    break;
                                }
                            }
                            return(DEFAULT_RESULT_TYPE_MAP[compareResult.ResultType]);


                        // If *every* entry of the clause data is matched
                        case OPERATION.CONTAINS:
                            if (dictToCheck.Count > 0)
                            {
                                if (clause.DictData is List <KeyValuePair <string, string> > ContainsData)
                                {
                                    if (ContainsData.Where(y => dictToCheck.Where((x) => x.Key == y.Key && x.Value == y.Value).Any()).Count() == ContainsData.Count)
                                    {
                                        break;
                                    }
                                }
                            }
                            else if (valsToCheck.Count > 0)
                            {
                                if (clause.Data is List <string> ContainsDataList)
                                {
                                    if (ContainsDataList.Intersect(valsToCheck).Count() == ContainsDataList.Count)
                                    {
                                        break;
                                    }
                                }
                            }
                            return(DEFAULT_RESULT_TYPE_MAP[compareResult.ResultType]);

                        // If *any* entry of the clause data is matched
                        case OPERATION.CONTAINS_ANY:
                            if (dictToCheck.Count > 0)
                            {
                                if (clause.DictData is List <KeyValuePair <string, string> > ContainsData)
                                {
                                    foreach (KeyValuePair <string, string> value in ContainsData)
                                    {
                                        if (dictToCheck.Where((x) => x.Key == value.Key && x.Value == value.Value).Any())
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                            else if (valsToCheck.Count > 0)
                            {
                                if (clause.Data is List <string> ContainsDataList)
                                {
                                    if (clause.Data.Intersect(valsToCheck).Any())
                                    {
                                        break;
                                    }
                                }
                            }
                            return(DEFAULT_RESULT_TYPE_MAP[compareResult.ResultType]);

                        // If any of the clauses are not contained
                        case OPERATION.DOES_NOT_CONTAIN:
                            if (dictToCheck.Count > 0)
                            {
                                if (clause.DictData is List <KeyValuePair <string, string> > ContainsData)
                                {
                                    if (ContainsData.Where(y => dictToCheck.Where((x) => x.Key == y.Key && x.Value == y.Value).Any()).Any())
                                    {
                                        break;
                                    }
                                    return(DEFAULT_RESULT_TYPE_MAP[compareResult.ResultType]);
                                }
                            }
                            else if (valsToCheck.Count > 0)
                            {
                                if (clause.Data is List <string> ContainsDataList)
                                {
                                    if (ContainsDataList.Intersect(valsToCheck).Any())
                                    {
                                        break;
                                    }
                                    return(DEFAULT_RESULT_TYPE_MAP[compareResult.ResultType]);
                                }
                            }
                            break;

                        // If any of the data values are greater than the first provided data value
                        case OPERATION.GT:
                            if (valsToCheck.Where(val => (int.Parse(val, CultureInfo.InvariantCulture) > int.Parse(clause.Data?[0] ?? $"{int.MinValue}", CultureInfo.InvariantCulture))).Any())
                            {
                                break;
                            }
                            return(DEFAULT_RESULT_TYPE_MAP[compareResult.ResultType]);

                        // If any of the data values are less than the first provided data value
                        case OPERATION.LT:
                            if (valsToCheck.Where(val => (int.Parse(val, CultureInfo.InvariantCulture) < int.Parse(clause.Data?[0] ?? $"{int.MaxValue}", CultureInfo.InvariantCulture))).Any())
                            {
                                break;
                            }
                            return(DEFAULT_RESULT_TYPE_MAP[compareResult.ResultType]);

                        // If any of the regexes match any of the values
                        case OPERATION.REGEX:
                            if (clause.Data is List <string> RegexList)
                            {
                                var regexList = RegexList.Select(x => new Regex(x));

                                if (valsToCheck.Where(x => regexList.Where(y => y.IsMatch(x)).Any()).Any())
                                {
                                    break;
                                }
                            }
                            return(DEFAULT_RESULT_TYPE_MAP[compareResult.ResultType]);

                        // Ignores provided data. Checks if the named property has changed.
                        case OPERATION.WAS_MODIFIED:
                            if ((valsToCheck.Count == 2) && (valsToCheck[0] == valsToCheck[1]))
                            {
                                break;
                            }
                            return(DEFAULT_RESULT_TYPE_MAP[compareResult.ResultType]);

                        // Ends with any of the provided data
                        case OPERATION.ENDS_WITH:
                            if (clause.Data is List <string> EndsWithData)
                            {
                                if (valsToCheck.Where(x => EndsWithData.Where(y => x.EndsWith(y, StringComparison.CurrentCulture)).Any()).Any())
                                {
                                    break;
                                }
                            }
                            return(DEFAULT_RESULT_TYPE_MAP[compareResult.ResultType]);

                        // Starts with any of the provided data
                        case OPERATION.STARTS_WITH:
                            if (clause.Data is List <string> StartsWithData)
                            {
                                if (valsToCheck.Where(x => StartsWithData.Where(y => x.StartsWith(y, StringComparison.CurrentCulture)).Any()).Any())
                                {
                                    break;
                                }
                            }
                            return(DEFAULT_RESULT_TYPE_MAP[compareResult.ResultType]);

                        default:
                            Log.Debug("Unimplemented operation {0}", clause.Operation);
                            return(DEFAULT_RESULT_TYPE_MAP[compareResult.ResultType]);
                        }
                    }
                    catch (Exception e)
                    {
                        Log.Debug(e, $"Hit while parsing {JsonSerializer.Serialize(rule)} onto {JsonSerializer.Serialize(compareResult)}");
                        Dictionary <string, string> ExceptionEvent = new Dictionary <string, string>();
                        ExceptionEvent.Add("Exception Type", e.GetType().ToString());
                        AsaTelemetry.TrackEvent("ApplyOverallException", ExceptionEvent);
                        return(DEFAULT_RESULT_TYPE_MAP[compareResult.ResultType]);
                    }
                }
                compareResult.Rules.Add(rule);
                return(rule.Flag);
            }
            else
            {
                throw new NullReferenceException();
            }
        }
コード例 #3
0
            public string Regex(string xmlitem)
            {
                var ret = RegexList.Find(x => x[0].Contains(xmlitem));

                return(ret[1]);
            }