Esempio n. 1
0
        public override int GetHashCode()
        {
            int result = 17;

            unchecked
            {
                if (RuleId != default(string))
                {
                    result = (result * 31) + RuleId.GetHashCode();
                }

                if (Rule != default(Rule))
                {
                    result = (result * 31) + Rule.GetHashCode();
                }

                if (Guid != default(string))
                {
                    result = (result * 31) + Guid.GetHashCode();
                }

                if (IsActive != default(bool))
                {
                    result = (result * 31) + IsActive.GetHashCode();
                }

                if (Message != default(string))
                {
                    result = (result * 31) + Message.GetHashCode();
                }

                if (StartLine != default(int))
                {
                    result = (result * 31) + StartLine.GetHashCode();
                }

                if (WhenDetectedUtc != default(DateTime))
                {
                    result = (result * 31) + WhenDetectedUtc.GetHashCode();
                }

                if (BaselineState != default(BaselineState))
                {
                    result = (result * 31) + BaselineState.GetHashCode();
                }

                if (Properties != default(IDictionary <String, String>))
                {
                    result = (result * 31) + Properties.GetHashCode();
                }

                if (Tags != default(IList <int>))
                {
                    result = (result * 31) + Tags.GetHashCode();
                }
            }

            return(result);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="status"></param>
        /// <param name="desc"></param>
        /// <returns></returns>
        public RuleResult GetRuleResultInstance(RuleId id, string desc)
        {
            var rr = new RuleResult(id, desc, this.Source, this.HelpUrl, this.MetaInfo.Clone());

            this.Items.Add(rr);

            return(rr);
        }
Esempio n. 3
0
 public static ulong GetRuleIdentity(RuleId ruleId)
 {
     if (ruleId == null)
     {
         throw new ArgumentNullException("ruleId");
     }
     return((ulong)ruleId.StoreRuleId);
 }
Esempio n. 4
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="status"></param>
 /// <param name="desc"></param>
 /// <param name="source"></param>
 /// <param name="url"></param>
 /// <param name="meta"></param>
 internal RuleResult(RuleId id, string desc, string source, HelpUrl url, ScanMetaInfo meta)
 {
     this.Rule        = id;
     this.Description = desc;
     this.Source      = source;
     this.Messages    = new List <string>();
     this.MetaInfo    = meta;
     this.HelpUrl     = url;
 }
 private RuleOutcomeDetailsBuilder(RuleId ruleId, string target)
 {
     _ruleId       = ruleId;
     _totalScore   = 0;
     _outcomeCount = 0;
     _narrative    = new StringBuilder();
     _details      = new List <RuleOutcome>();
     _target       = target;
 }
Esempio n. 6
0
        public RuleWithPolicyData GetRuleById(PolicyId policyId, RuleId ruleId)
        {
            var policy = policyRep.GetRuleBasePolicyById(policyId);
            var rule   = ruleService.GetById(ruleId);

            return(new RuleWithPolicyData {
                Policy = policy, Rule = rule
            });
        }
Esempio n. 7
0
        public IRule CreateRule(RuleId id)
        {
            if (!RuleTypes.TryGetValue(id, out Type type))
            {
                return(null);
            }

            return(Activator.CreateInstance(type) as IRule);
        }
Esempio n. 8
0
        internal static object RuleIdentityGetter(IPropertyBag propertyBag)
        {
            RuleId ruleId = (RuleId)propertyBag[InboxRuleSchema.RuleId];

            if (ruleId != null)
            {
                return(InboxRuleTaskHelper.GetRuleIdentity(ruleId));
            }
            return(null);
        }
Esempio n. 9
0
 public void DeleteRule(PolicyId policyId, RuleId ruleId)
 {
     using (var scope = new TransactionScope())
     {
         var policy = policyRep.GetRuleBasePolicyById(policyId);
         var rule   = ruleService.GetById(ruleId);
         policy.RemoveRule(rule);
         ruleService.DeleteRule(ruleId);
         scope.Complete();
     }
 }
Esempio n. 10
0
        public InboxRuleIdParameter(string inboxRuleId)
        {
            if (string.IsNullOrEmpty(inboxRuleId))
            {
                throw new ArgumentNullException("inboxRuleId");
            }
            this.rawInput = inboxRuleId;
            int num = inboxRuleId.Length;
            int num2;

            do
            {
                num2 = num;
                num  = inboxRuleId.LastIndexOf("\\\\", num2 - 1, num2);
            }while (num != -1);
            int num3 = inboxRuleId.LastIndexOf('\\', num2 - 1, num2);

            if (num3 == 0 || num3 == inboxRuleId.Length - 1)
            {
                throw new ArgumentException(Strings.ErrorInvalidParameterFormat("inboxRuleId"), "inboxRuleId");
            }
            string text;
            string text2;

            if (num3 > 0)
            {
                text  = inboxRuleId.Substring(0, num3);
                text2 = inboxRuleId.Substring(1 + num3);
            }
            else
            {
                text2 = inboxRuleId;
                text  = null;
            }
            if (num2 != inboxRuleId.Length)
            {
                text2 = text2.Replace("\\\\", '\\'.ToString());
            }
            if (!string.IsNullOrEmpty(text))
            {
                this.rawMailbox = new MailboxIdParameter(text);
            }
            ulong value;

            if (ulong.TryParse(text2, out value))
            {
                byte[] array = new byte[8];
                ExBitConverter.Write((long)value, array, 0);
                this.rawRuleId = RuleId.Deserialize(array, 0);
                return;
            }
            this.rawRuleName = text2;
        }
Esempio n. 11
0
        internal static object IdentityGetter(IPropertyBag propertyBag)
        {
            ADObjectId adobjectId = (ADObjectId)propertyBag[XsoMailboxConfigurationObjectSchema.MailboxOwnerId];
            RuleId     ruleId     = (RuleId)propertyBag[InboxRuleSchema.RuleId];
            string     name       = (string)propertyBag[InboxRuleSchema.Name];

            if (adobjectId != null)
            {
                return(new InboxRuleId(adobjectId, name, ruleId));
            }
            return(null);
        }
Esempio n. 12
0
 public static void SetRuleId(Rule rule, RuleId ruleId)
 {
     if (rule == null)
     {
         throw new ArgumentNullException("rule");
     }
     if (ruleId == null)
     {
         throw new ArgumentNullException("ruleId");
     }
     rule.Id = ruleId;
 }
Esempio n. 13
0
 public RuleWithPolicyData UpdateRule(PolicyId policyId, RuleId ruleId, string name, string ruleText, RuleType ruleType, int order)
 {
     using (var scope = new TransactionScope())
     {
         var policy = policyRep.GetRuleBasePolicyById(policyId);
         var rule   = ruleService.UpdateRule(ruleId, name, ruleText, ruleType, order);
         scope.Complete();
         return(new RuleWithPolicyData {
             Policy = policy, Rule = rule
         });
     }
 }
Esempio n. 14
0
        protected override IEnumerable <byte[]> GetItems()
        {
            yield return(RuleId.ToByteArray());

            yield return(BitConverter.GetBytes(Tag));

            yield return(KeyId.ToByteArray());

            yield return(Encoding.UTF8.GetBytes(Condition));

            yield return(BitConverter.GetBytes((int)Action));

            yield return(OwnerId.ToByteArray());
        }
Esempio n. 15
0
        public RuleOutcome(RuleId ruleId, int score, string narrative, string target = NoSpecificTarget, IEnumerable <RuleOutcome> details = null, string data = null)
        {
            Id        = Guid.NewGuid();
            RuleId    = ruleId;
            Score     = Math.Min(score, 100);
            Narrative = narrative;
            Target    = target;
            Data      = data;

            if (details != null)
            {
                Details = details;
            }
        }
Esempio n. 16
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (RuleId.Length != 0)
            {
                hash ^= RuleId.GetHashCode();
            }
            if (RuleOnly != false)
            {
                hash ^= RuleOnly.GetHashCode();
            }
            return(hash);
        }
Esempio n. 17
0
        public string ToText(RuleId ruleId, string data, string fieldName)
        {
            switch (ruleId)
            {
            case RuleId.ProfanityChecks:
                return(ProfanityRuleMessageTemplate.ToText(JsonConvert.DeserializeObject <ProfanityData>(data), fieldName));

            case RuleId.BannedPhraseChecks:
                return(BannedPhraseMessageTemplate.ToText(JsonConvert.DeserializeObject <BannedPhrasesData>(data), fieldName));

            case RuleId.TitlePopularity:
                return(VacancyTitlePopularityRuleMessageTemplate.ToText(JsonConvert.DeserializeObject <TitlePopularityData>(data), fieldName));

            default:
                throw new Exception($"Cannot resolve ruleId: {ruleId} to a rule message template formatter.");
            }
        }
        public static RunResult RunRuleByID(RuleId id, IA11yElement element)
        {
            var rule = Provider.GetRule(id);

            if (rule == null)
            {
                return(new RunResult
                {
                    EvaluationCode = EvaluationCode.RuleExecutionError,
                    ErrorMessage = Invariant($"No rule matching the ID '{id}' was found.")
                });
            }

            var retVal = Rules.RunRule(rule, element);

            return(retVal);
        }
Esempio n. 19
0
        /// <summary>
        /// ctor
        /// </summary>
        /// <param name="element">The element being fingerprinted</param>
        /// <param name="ruleId">The RuleIds value associated with this rule</param>
        /// <param name="status">The status of this rule for this element</param>
        public ScanResultFingerprint(IA11yElement element, RuleId ruleId, ScanStatus status)
        {
            element.ArgumentIsNotNull(nameof(element));

            List <FingerprintContribution> contributions = new List <FingerprintContribution>
            {
                new FingerprintContribution("RuleId", ruleId.ToString()),
                new FingerprintContribution("Level", status.ToResultLevelString()),
            };

            AddRuleSpecificContributions(contributions, ruleId, element);

            IA11yElement parent        = element.Parent;
            IA11yElement grandparent   = parent?.Parent;
            int          ancestorLevel = 0;

            while (true)
            {
                bool ignoreNameProperty = (ancestorLevel > 0) && (grandparent == null);

                AddRuleAgnosticContributions(contributions, element, ancestorLevel++, ignoreNameProperty);

                if (grandparent == null)
                {
                    break;
                }

                element     = parent;
                parent      = grandparent;
                grandparent = parent?.Parent;
            }

            // Sort the list to help with comparisons
            contributions.Sort();
            Contributions = contributions;
        }
Esempio n. 20
0
        public void ExtractIssues_ElementsContainUncertainsWithSameFingerprint_AddsOneUncertainWithTwoLocations()
        {
            const ScanStatus scanStatus = ScanStatus.Uncertain;

            Dictionary <IFingerprint, Issue> store = new Dictionary <IFingerprint, Issue>();

            using (ShimsContext.Create())
            {
                List <ILocation>    actualLocations    = new List <ILocation>();
                List <IFingerprint> actualFingerprints = new List <IFingerprint>();
                List <string>       actualFileNames    = new List <string>();
                List <ScanStatus>   actualStatuses     = new List <ScanStatus>();
                List <string>       actualIssueTypes   = new List <string>();
                List <RuleId>       actualRuleIds      = new List <RuleId>();
                List <A11yElement>  actualElements     = new List <A11yElement>();

                IFingerprint expectedFingerprint = new StubIFingerprint
                {
                    EqualsIFingerprint = (f) => true,
                };
                Issue expectedIssue = new ShimIssue
                {
                    AddLocationILocation = (l) =>
                    {
                        actualLocations.Add(l);
                        return(AddResult.ItemAdded);
                    }
                };

                ILocation expectedLocation1 = new StubILocation();
                ILocation expectedLocation2 = new StubILocation();
                string    expectedIssueType = "ChildUniqueNameOrType_Uncertain";
                RuleId    expectedRuleId    = RuleId.ChildUniqueNameOrType;

                ShimOutputFileIssueStore.BuildFingerprintA11yElementRuleIdScanStatus = (e, r, s) =>
                {
                    actualElements.Add(e);
                    actualRuleIds.Add(r);
                    actualStatuses.Add(s);

                    return(expectedFingerprint);
                };

                List <ILocation> expectedLocations = new List <ILocation> {
                    expectedLocation1, expectedLocation2
                };

                ShimOutputFileIssueStore.BuildLocationA11yElementString = (e, f) =>
                {
                    actualElements.Add(e);
                    actualFileNames.Add(f);
                    ILocation location = expectedLocations[0];
                    expectedLocations.RemoveAt(0);
                    return(location);
                };

                ShimOutputFileIssueStore.BuildIssueStringIFingerprint = (i, f) =>
                {
                    actualIssueTypes.Add(i);
                    actualFingerprints.Add(f);

                    return(expectedIssue);
                };

                ScanResults scanResults = new ShimScanResults
                {
                    StatusGet = () => scanStatus,
                    ItemsGet  = () => new List <ScanResult>
                    {
                        new ShimScanResult
                        {
                            ItemsGet = () => new List <RuleResult>
                            {
                                new ShimRuleResult
                                {
                                    StatusGet = () => scanStatus,
                                    RuleGet   = () => expectedRuleId,
                                }
                            }
                        }
                    },
                };

                A11yElement expectedElement1 = new ShimA11yElement {
                    ScanResultsGet = () => scanResults
                };
                A11yElement expectedElement2 = new ShimA11yElement {
                    ScanResultsGet = () => scanResults
                };

                IEnumerable <A11yElement> elements = new List <A11yElement>
                {
                    expectedElement1,
                    expectedElement2,
                };

                Assert.IsFalse(store.Any());
                OutputFileIssueStore.ExtractIssues(TestFile, elements, store);

                Assert.AreEqual(0, expectedLocations.Count);
                Assert.AreEqual(1, store.Count);
                Assert.AreEqual(4, actualElements.Count);
                Assert.AreSame(expectedElement1, actualElements[0]);
                Assert.AreSame(expectedElement1, actualElements[1]);
                Assert.AreSame(expectedElement2, actualElements[2]);
                Assert.AreSame(expectedElement2, actualElements[3]);
                Assert.AreEqual(2, actualFileNames.Count);
                Assert.AreEqual(TestFile, actualFileNames[0]);
                Assert.AreEqual(TestFile, actualFileNames[1]);
                Assert.AreEqual(1, actualFingerprints.Count);
                Assert.AreSame(expectedFingerprint, actualFingerprints[0]);
                Assert.AreEqual(2, actualStatuses.Count);
                Assert.AreEqual(scanStatus, actualStatuses[0]);
                Assert.AreEqual(scanStatus, actualStatuses[1]);
                Assert.AreEqual(1, actualIssueTypes.Count);
                Assert.AreEqual(expectedIssueType, actualIssueTypes[0]);
                Assert.AreEqual(2, actualLocations.Count);
                Assert.AreSame(expectedLocation1, actualLocations[0]);
                Assert.AreSame(expectedLocation2, actualLocations[1]);
                Assert.AreEqual(2, actualRuleIds.Count);
                Assert.AreEqual(expectedRuleId, actualRuleIds[0]);
                Assert.AreEqual(expectedRuleId, actualRuleIds[1]);
            }
        }
 public static RuleOutcomeDetailsBuilder Create(RuleId ruleId, string target = RuleOutcome.NoSpecificTarget)
 {
     return(new RuleOutcomeDetailsBuilder(ruleId, target));
 }
Esempio n. 22
0
 private static string SynthesizeIssueType(RuleId ruleId, ScanStatus status)
 {
     return(Invariant($"{ruleId}_{status}"));
 }
Esempio n. 23
0
 // Simple factory method. Pulled out so that we can easily shim this for testing
 private static IFingerprint BuildFingerprint(A11yElement element, RuleId ruleId, ScanStatus status)
 {
     return(new ScanResultFingerprint(element, ruleId, status));
 }
Esempio n. 24
0
 protected BaseProfanityChecksRule(RuleId ruleId, ConsolidationOption consolidationOption, decimal weighting = 1.0m) : base(ruleId, weighting)
 {
     _consolidationOption = consolidationOption;
 }
Esempio n. 25
0
 public IRule GetRule(RuleId id)
 {
     return(AllRules.GetOrAdd(id, key => this.RuleFactory.CreateRule(key)));
 }
 public static IFingerprint GetFingerPrint(A11yElement element, RuleId ruleId, ScanStatus status)
 {
     // Very simplistic implementation of the factory. If we decide to add a few more generators will need a switch case and type enum.
     return(new ScanResultFingerprint(element, ruleId, status));
 }
Esempio n. 27
0
 public BaseBannedPhraseChecksRule(
     RuleId ruleId, ConsolidationOption consolidationOption, decimal weighting = 1.0m)
     : base(ruleId, weighting)
 {
     _consolidationOption = consolidationOption;
 }
        /// <summary>
        ///     Returns a string in a format suitable for directly adding to a
        ///     directory, as a value of the particular schema element class.
        /// </summary>
        /// <returns>
        ///     A string representation of the class' definition.
        /// </returns>
        protected internal override string FormatString()
        {
            var valueBuffer = new StringBuilder("( ");

            var token = RuleId.ToString();

            valueBuffer.Append(token);

            var strArray = Names;

            if (strArray != null)
            {
                valueBuffer.Append(" NAME ");
                if (strArray.Length == 1)
                {
                    valueBuffer.Append("'" + strArray[0] + "'");
                }
                else
                {
                    valueBuffer.Append("( ");

                    for (var i = 0; i < strArray.Length; i++)
                    {
                        valueBuffer.Append(" '" + strArray[i] + "'");
                    }

                    valueBuffer.Append(" )");
                }
            }

            if ((token = Description) != null)
            {
                valueBuffer.Append(" DESC ");
                valueBuffer.Append("'" + token + "'");
            }

            if (Obsolete)
            {
                valueBuffer.Append(" OBSOLETE");
            }

            if ((token = NameForm) != null)
            {
                valueBuffer.Append(" FORM ");
                valueBuffer.Append("'" + token + "'");
            }

            if ((strArray = Superiors) != null)
            {
                valueBuffer.Append(" SUP ");
                if (strArray.Length > 1)
                {
                    valueBuffer.Append("( ");
                }

                for (var i = 0; i < strArray.Length; i++)
                {
                    if (i > 0)
                    {
                        valueBuffer.Append(" ");
                    }

                    valueBuffer.Append(strArray[i]);
                }

                if (strArray.Length > 1)
                {
                    valueBuffer.Append(" )");
                }
            }

            IEnumerator en;

            if ((en = QualifierNames) != null)
            {
                string   qualName;
                string[] qualValue;
                while (en.MoveNext())
                {
                    qualName = (string)en.Current;
                    valueBuffer.Append(" " + qualName + " ");
                    if ((qualValue = GetQualifier(qualName)) != null)
                    {
                        if (qualValue.Length > 1)
                        {
                            valueBuffer.Append("( ");
                        }

                        for (var i = 0; i < qualValue.Length; i++)
                        {
                            if (i > 0)
                            {
                                valueBuffer.Append(" ");
                            }

                            valueBuffer.Append("'" + qualValue[i] + "'");
                        }

                        if (qualValue.Length > 1)
                        {
                            valueBuffer.Append(" )");
                        }
                    }
                }
            }

            valueBuffer.Append(" )");
            return(valueBuffer.ToString());
        }
Esempio n. 29
0
        public override int GetHashCode()
        {
            int result = 17;

            unchecked
            {
                if (RuleId != null)
                {
                    result = (result * 31) + RuleId.GetHashCode();
                }

                result = (result * 31) + Kind.GetHashCode();
                if (Message != null)
                {
                    result = (result * 31) + Message.GetHashCode();
                }

                if (FormattedRuleMessage != null)
                {
                    result = (result * 31) + FormattedRuleMessage.GetHashCode();
                }

                if (Locations != null)
                {
                    foreach (var value_0 in Locations)
                    {
                        result = result * 31;
                        if (value_0 != null)
                        {
                            result = (result * 31) + value_0.GetHashCode();
                        }
                    }
                }

                if (CodeSnippet != null)
                {
                    result = (result * 31) + CodeSnippet.GetHashCode();
                }

                if (ToolFingerprint != null)
                {
                    result = (result * 31) + ToolFingerprint.GetHashCode();
                }

                if (Stacks != null)
                {
                    foreach (var value_1 in Stacks)
                    {
                        result = result * 31;
                        if (value_1 != null)
                        {
                            result = (result * 31) + value_1.GetHashCode();
                        }
                    }
                }

                if (CodeFlows != null)
                {
                    foreach (var value_2 in CodeFlows)
                    {
                        result = result * 31;
                        if (value_2 != null)
                        {
                            result = (result * 31) + value_2.GetHashCode();
                        }
                    }
                }

                if (RelatedLocations != null)
                {
                    foreach (var value_3 in RelatedLocations)
                    {
                        result = result * 31;
                        if (value_3 != null)
                        {
                            result = (result * 31) + value_3.GetHashCode();
                        }
                    }
                }

                result = (result * 31) + IsSuppressedInSource.GetHashCode();
                if (Fixes != null)
                {
                    foreach (var value_4 in Fixes)
                    {
                        result = result * 31;
                        if (value_4 != null)
                        {
                            result = (result * 31) + value_4.GetHashCode();
                        }
                    }
                }

                if (Properties != null)
                {
                    // Use xor for dictionaries to be order-independent.
                    int xor_0 = 0;
                    foreach (var value_5 in Properties)
                    {
                        xor_0 ^= value_5.Key.GetHashCode();
                        if (value_5.Value != null)
                        {
                            xor_0 ^= value_5.Value.GetHashCode();
                        }
                    }

                    result = (result * 31) + xor_0;
                }

                if (Tags != null)
                {
                    foreach (var value_6 in Tags)
                    {
                        result = result * 31;
                        if (value_6 != null)
                        {
                            result = (result * 31) + value_6.GetHashCode();
                        }
                    }
                }
            }

            return(result);
        }
Esempio n. 30
0
        /// <summary>
        /// Add contributions for rule-specific properties
        /// </summary>
        /// <param name="contributions">The set of contributions to update</param>
        /// <param name="ruleId">determines which properties to add</param>
        /// <param name="element">Element under consideration</param>
        internal static void AddRuleSpecificContributions(IList <FingerprintContribution> contributions, RuleId ruleId, IA11yElement element)
        {
            switch (ruleId)
            {
            case RuleId.IsKeyboardFocusable:
            case RuleId.IsKeyboardFocusableBasedOnPatterns:
                contributions.Add(new FingerprintContribution("IsKeyboardFocusable", element.IsKeyboardFocusable.ToString(CultureInfo.InvariantCulture)));
                break;

            case RuleId.IsControlElementPropertyCorrect:
                contributions.Add(new FingerprintContribution("IsControlElement", element.IsControlElement.ToString(CultureInfo.InvariantCulture)));
                break;

            case RuleId.IsContentElementPropertyCorrect:
                contributions.Add(new FingerprintContribution("IsContentElement", element.IsContentElement.ToString(CultureInfo.InvariantCulture)));
                break;
            }
        }