Example #1
0
        public void TestRemove()
        {
            ShortList list = new ShortList();

            for (short j = 0; j < 1000; j++)
            {
                list.Add(j);
            }
            for (short j = 0; j < 1000; j++)
            {
                Assert.AreEqual(j, list.Remove(0));
                Assert.AreEqual((short)(999 - j), list.Count);
            }
            for (short j = 0; j < 1000; j++)
            {
                list.Add(j);
            }
            for (short j = 0; j < 1000; j++)
            {
                Assert.AreEqual((short)(999 - j),
                                list.Remove((short)(999 - j)));
                Assert.AreEqual(999 - j, list.Count);
            }
            try
            {
                list.Remove(0);
                Assert.Fail("should have caught IndexOutOfRangeException");
            }
            catch (IndexOutOfRangeException)
            {
                // as expected
            }
        }
Example #2
0
        public void TestEquals()
        {
            ShortList list = new ShortList();

            //Assert.AreEqual(list, list);
            Assert.IsTrue(list.Equals(list));
            Assert.IsTrue(!list.Equals(null));
            ShortList list2 = new ShortList(200);

            //Assert.AreEqual(list, list2);
            Assert.IsTrue(list.Equals(list2));
            //Assert.AreEqual(list2, list);
            Assert.IsTrue(list2.Equals(list));
            Assert.AreEqual(list.GetHashCode(), list2.GetHashCode());
            list.Add((short)0);
            list.Add((short)1);
            list2.Add((short)1);
            list2.Add((short)0);
            Assert.IsTrue(!list.Equals(list2));
            list2.RemoveValue((short)1);
            list2.Add((short)1);
            //Assert.AreEqual(list, list2);
            Assert.IsTrue(list.Equals(list2));
            //Assert.AreEqual(list2, list);
            Assert.IsTrue(list2.Equals(list));
            list2.Add((short)2);
            Assert.IsTrue(!list.Equals(list2));
            Assert.IsTrue(!list2.Equals(list));
        }
Example #3
0
        public void TestConstructors()
        {
            ShortList list = new ShortList();

            Assert.IsTrue(list.IsEmpty());
            list.Add((short)0);
            list.Add((short)1);
            ShortList list2 = new ShortList(list);

            //Assert.AreEqual(list, list2);
            Assert.IsTrue(list.Equals(list2));
            ShortList list3 = new ShortList(2);

            Assert.IsTrue(list3.IsEmpty());
        }
        // Token: 0x06001A23 RID: 6691 RVA: 0x0005EFE8 File Offset: 0x0005D1E8
        internal static ShortList <string> ValidateAndGetEmailAddressStrings(EmailAddressWrapper[] recipients, PolicyTipRequestLogger policyTipRequestLogger)
        {
            if (recipients == null || recipients.Length == 0)
            {
                return(null);
            }
            ShortList <string> shortList     = new ShortList <string>();
            StringBuilder      stringBuilder = null;

            foreach (EmailAddressWrapper emailAddressWrapper in recipients)
            {
                if (emailAddressWrapper != null && !string.IsNullOrEmpty(emailAddressWrapper.EmailAddress) && SmtpAddress.IsValidSmtpAddress(emailAddressWrapper.EmailAddress))
                {
                    shortList.Add(emailAddressWrapper.EmailAddress);
                }
                else
                {
                    if (stringBuilder == null)
                    {
                        stringBuilder = new StringBuilder();
                    }
                    stringBuilder.Append((emailAddressWrapper == null || emailAddressWrapper.EmailAddress == null) ? "NullRecipientOrEmptyEmail" : PolicyTipRequestLogger.MarkAsPII(emailAddressWrapper.EmailAddress));
                    stringBuilder.Append("|");
                }
            }
            if (stringBuilder != null)
            {
                policyTipRequestLogger.AppendData("InvalidRecipients", stringBuilder.ToString());
            }
            return(shortList);
        }
Example #5
0
        internal override Condition ToInternalCondition()
        {
            ShortList <string> shortList = new ShortList <string>();

            shortList.Add(this.Size.ToBytes().ToString());
            return(TransportRuleParser.Instance.CreatePredicate("greaterThanOrEqual", TransportRuleParser.Instance.CreateProperty(this.propertyName), shortList));
        }
        private Microsoft.Exchange.MessagingPolicies.Rules.Condition CreateRecipientCondition()
        {
            if (this.recipient == null)
            {
                return(null);
            }
            Property           property  = JournalingRuleParser.Instance.CreateProperty("Message.Sender");
            ShortList <string> shortList = new ShortList <string>();

            shortList.Add(this.recipient.ToString());
            PredicateCondition predicateCondition  = JournalingRuleParser.Instance.CreatePredicate("isMemberOf", property, shortList);
            PredicateCondition predicateCondition2 = JournalingRuleParser.Instance.CreatePredicate("isSameUser", property, shortList);

            Microsoft.Exchange.MessagingPolicies.Rules.Condition condition = this.CombineUsingOr(new Microsoft.Exchange.MessagingPolicies.Rules.Condition[]
            {
                predicateCondition,
                predicateCondition2
            });
            Property           property2           = JournalingRuleParser.Instance.CreateProperty("Message.EnvelopeRecipients");
            PredicateCondition predicateCondition3 = JournalingRuleParser.Instance.CreatePredicate("isMemberOf", property2, shortList);
            PredicateCondition predicateCondition4 = JournalingRuleParser.Instance.CreatePredicate("isSameUser", property2, shortList);

            Microsoft.Exchange.MessagingPolicies.Rules.Condition condition2 = this.CombineUsingOr(new Microsoft.Exchange.MessagingPolicies.Rules.Condition[]
            {
                predicateCondition3,
                predicateCondition4
            });
            return(this.CombineUsingOr(new Microsoft.Exchange.MessagingPolicies.Rules.Condition[]
            {
                condition,
                condition2
            }));
        }
Example #7
0
        public void TestRetainAll()
        {
            ShortList list = new ShortList();

            for (short j = 0; j < 1000; j++)
            {
                list.Add(j);
            }
            ShortList listCopy = new ShortList(list);
            ShortList listOdd  = new ShortList();
            ShortList listEven = new ShortList();

            for (short j = 0; j < 1000; j++)
            {
                if (j % 2 == 0)
                {
                    listEven.Add(j);
                }
                else
                {
                    listOdd.Add(j);
                }
            }
            list.RetainAll(listOdd);
            Assert.IsTrue(list.Equals(listOdd));// Assert.AreEqual(list, listOdd);
            list.RetainAll(listEven);
            Assert.IsTrue(list.IsEmpty());
            listCopy.RetainAll(listEven);
            //Assert.AreEqual(listCopy, listEven);
            Assert.IsTrue(listCopy.Equals(listEven));
            listCopy.RetainAll(listOdd);
            Assert.IsTrue(listCopy.IsEmpty());
        }
Example #8
0
        public void TestSet()
        {
            ShortList list = new ShortList();

            for (short j = 0; j < 1000; j++)
            {
                list.Add(j);
            }
            for (short j = 0; j < 1001; j++)
            {
                try
                {
                    list.Set(j, (short)(j + 1));
                    if (j == 1000)
                    {
                        Assert.Fail("Should have gotten exception");
                    }
                    Assert.AreEqual(j + 1, list.Get(j));
                }
                catch (IndexOutOfRangeException)
                {
                    if (j != 1000)
                    {
                        Assert.Fail("premature exception");
                    }
                }
            }
        }
Example #9
0
        public void TestGet()
        {
            ShortList list = new ShortList();

            for (short j = 0; j < 1000; j++)
            {
                list.Add(j);
            }
            for (short j = 0; j < 1001; j++)
            {
                try
                {
                    Assert.AreEqual(j, list.Get(j));
                    if (j == 1000)
                    {
                        Assert.Fail("should have gotten exception");
                    }
                }
                catch (IndexOutOfRangeException)
                {
                    if (j != 1000)
                    {
                        Assert.Fail("unexpected IndexOutOfRangeException");
                    }
                }
            }
        }
        private Microsoft.Exchange.MessagingPolicies.Rules.Action CreateAction()
        {
            Value item = new Value(this.journalEmailAddress.ToString());
            ShortList <Argument> shortList = new ShortList <Argument>();

            shortList.Add(item);
            return(JournalingRuleParser.Instance.CreateAction("Journal", shortList, null));
        }
        private Microsoft.Exchange.MessagingPolicies.Rules.Condition CreatePropertyEqualsOneCheck(string propertyNameToCheck)
        {
            Property           property  = JournalingRuleParser.Instance.CreateProperty("Message.ExtendedProperties:" + propertyNameToCheck, "integer");
            ShortList <string> shortList = new ShortList <string>();

            shortList.Add("1");
            return(JournalingRuleParser.Instance.CreatePredicate("equal", property, shortList, new RulesCreationContext()));
        }
        internal override Action ToInternalAction()
        {
            ShortList <Argument> shortList = new ShortList <Argument>
            {
                new Value(this.ReportDestination.ToString())
            };

            foreach (IncidentReportContent incidentReportContent in this.IncidentReportContent)
            {
                shortList.Add(new Value(Enum.GetName(typeof(IncidentReportContent), incidentReportContent)));
            }
            if (this.IncidentReportOriginalMail == IncidentReportOriginalMail.IncludeOriginalMail && !this.IncidentReportContent.Contains(Microsoft.Exchange.MessagingPolicies.Rules.IncidentReportContent.AttachOriginalMail))
            {
                this.AddIncidentReportContentItem(Microsoft.Exchange.MessagingPolicies.Rules.IncidentReportContent.AttachOriginalMail);
                shortList.Add(new Value(Enum.GetName(typeof(IncidentReportContent), Microsoft.Exchange.MessagingPolicies.Rules.IncidentReportContent.AttachOriginalMail)));
            }
            return(TransportRuleParser.Instance.CreateAction("GenerateIncidentReport", shortList, null));
        }
Example #13
0
        internal override Condition ToInternalCondition()
        {
            ShortList <string> shortList = new ShortList <string>();

            foreach (Word word in this.words)
            {
                shortList.Add(word.ToString());
            }
            return(TransportRuleParser.Instance.CreatePredicate("attachmentPropertyContains", null, shortList));
        }
Example #14
0
        internal override Condition ToInternalCondition()
        {
            IEnumerable <TargetDataClassification> enumerable = MessageContainsDataClassificationsPredicate.HashtablesToDataClassifications(this.DataClassifications);
            ShortList <ShortList <KeyValuePair <string, string> > > shortList = new ShortList <ShortList <KeyValuePair <string, string> > >();

            foreach (TargetDataClassification targetDataClassification in enumerable)
            {
                shortList.Add(targetDataClassification.ToKeyValueCollection());
            }
            return(TransportRuleParser.Instance.CreatePredicate("containsDataClassification", TransportRuleParser.Instance.CreateProperty("Message.DataClassifications"), shortList));
        }
Example #15
0
        public void TestContainsAll()
        {
            ShortList list = new ShortList();

            Assert.IsTrue(list.ContainsAll(list));
            for (short j = 0; j < 10; j++)
            {
                list.Add(j);
            }
            ShortList list2 = new ShortList(list);

            Assert.IsTrue(list2.ContainsAll(list));
            Assert.IsTrue(list.ContainsAll(list2));
            list2.Add((short)10);
            Assert.IsTrue(list2.ContainsAll(list));
            Assert.IsTrue(!list.ContainsAll(list2));
            list.Add((short)11);
            Assert.IsTrue(!list2.ContainsAll(list));
            Assert.IsTrue(!list.ContainsAll(list2));
        }
Example #16
0
        internal override Condition ToInternalCondition()
        {
            ShortList <string> shortList = new ShortList <string>();

            foreach (Pattern pattern in this.patterns)
            {
                shortList.Add(pattern.ToString());
            }
            string name = base.UseLegacyRegex ? "senderAttributeMatches" : "senderAttributeMatchesRegex";

            return(TransportRuleParser.Instance.CreatePredicate(name, null, shortList));
        }
Example #17
0
        public void TestClear()
        {
            ShortList list = new ShortList();

            for (short j = 0; j < 500; j++)
            {
                list.Add(j);
            }
            Assert.AreEqual(500, list.Count);
            list.Clear();
            Assert.AreEqual(0, list.Count);
            for (short j = 0; j < 500; j++)
            {
                list.Add((short)(j + 1));
            }
            Assert.AreEqual(500, list.Count);
            for (short j = 0; j < 500; j++)
            {
                Assert.AreEqual(j + 1, list.Get(j));
            }
        }
        private Condition CreateSenderDepartmentCondition()
        {
            if (this.fromDepartment == null || this.fromDepartment.Count == 0)
            {
                return(Condition.True);
            }
            ShortList <string> shortList = new ShortList <string>();

            foreach (string item in this.fromDepartment)
            {
                shortList.Add(item);
            }
            return(new IsPredicate(new StringProperty("Message.Sender.Department"), shortList, new RulesCreationContext()));
        }
        private Condition CreateRecipientIsCondition()
        {
            if (this.sentTo == null || this.sentTo.Count == 0)
            {
                return(Condition.True);
            }
            ShortList <string> shortList = new ShortList <string>();

            foreach (SmtpAddress smtpAddress in this.sentTo)
            {
                shortList.Add(smtpAddress.ToString());
            }
            return(new RecipientIsPredicate(shortList, new RulesCreationContext()));
        }
Example #20
0
        internal override Condition ToInternalCondition()
        {
            ShortList <string> shortList = new ShortList <string>();

            foreach (SmtpAddress smtpAddress in this.Addresses)
            {
                string text = smtpAddress.ToString();
                if (string.IsNullOrEmpty(text))
                {
                    throw new ArgumentException(RulesTasksStrings.InvalidRecipient(text), "Address");
                }
                shortList.Add(text);
            }
            return(TransportRuleParser.Instance.CreatePredicate(this.internalPredicateName, TransportRuleParser.Instance.CreateProperty(this.internalPropertyName), shortList));
        }
Example #21
0
        public void TestSize()
        {
            ShortList list = new ShortList();

            for (short j = 0; j < 1000; j++)
            {
                Assert.AreEqual(j, list.Count);
                list.Add(j);
                Assert.AreEqual(j + 1, list.Count);
            }
            for (short j = 0; j < 1000; j++)
            {
                Assert.AreEqual(1000 - j, list.Count);
                list.RemoveValue(j);
                Assert.AreEqual(999 - j, list.Count);
            }
        }
Example #22
0
        public void TestRemoveValue()
        {
            ShortList list = new ShortList();

            for (short j = 0; j < 1000; j++)
            {
                list.Add((short)(j / 2));
            }
            for (short j = 0; j < 1000; j++)
            {
                if (j < 500)
                {
                    Assert.IsTrue(list.RemoveValue(j));
                    Assert.IsTrue(list.RemoveValue(j));
                }
                Assert.IsTrue(!list.RemoveValue(j));
            }
        }
Example #23
0
        internal override Action[] ToInternalActions()
        {
            List <Action> list = new List <Action>();

            foreach (SmtpAddress smtpAddress in this.Addresses)
            {
                ShortList <Argument> shortList = new ShortList <Argument>();
                string text = smtpAddress.ToString();
                if (string.IsNullOrEmpty(text))
                {
                    throw new ArgumentException(RulesTasksStrings.InvalidRecipient(text), "Addresses");
                }
                shortList.Add(new Value(text));
                Action item = TransportRuleParser.Instance.CreateAction(this.internalActionName, shortList, Utils.GetActionName(this));
                list.Add(item);
            }
            return(list.ToArray());
        }
Example #24
0
        internal override Condition ToInternalCondition()
        {
            ShortList <string> shortList = new ShortList <string>();

            foreach (Word word in this.Words)
            {
                shortList.Add(word.ToString());
            }
            PredicateCondition item  = TransportRuleParser.Instance.CreatePredicate("contains", TransportRuleParser.Instance.CreateProperty("Message.Subject"), shortList);
            PredicateCondition item2 = TransportRuleParser.Instance.CreatePredicate("contains", TransportRuleParser.Instance.CreateProperty("Message.Body"), shortList);

            return(new OrCondition
            {
                SubConditions =
                {
                    item,
                    item2
                }
            });
        }
Example #25
0
        public void TestContains()
        {
            ShortList list = new ShortList();

            for (short j = 0; j < 1000; j += 2)
            {
                list.Add(j);
            }
            for (short j = 0; j < 1000; j++)
            {
                if (j % 2 == 0)
                {
                    Assert.IsTrue(list.Contains(j));
                }
                else
                {
                    Assert.IsTrue(!list.Contains(j));
                }
            }
        }
Example #26
0
        public void TestLastIndexOf()
        {
            ShortList list = new ShortList();

            for (short j = 0; j < 1000; j++)
            {
                list.Add((short)(j / 2));
            }
            for (short j = 0; j < 1000; j++)
            {
                if (j < 500)
                {
                    Assert.AreEqual(1 + j * 2, list.LastIndexOf(j));
                }
                else
                {
                    Assert.AreEqual(-1, list.IndexOf(j));
                }
            }
        }
Example #27
0
        public void TestToArray()
        {
            ShortList list = new ShortList();

            for (short j = 0; j < 1000; j++)
            {
                list.Add(j);
            }
            short[] a1 = list.ToArray();

            Assert.AreEqual(a1.Length, list.Count);
            for (short j = 0; j < 1000; j++)
            {
                Assert.AreEqual(a1[j], list.Get(j));
            }
            short[] a2 = new short[list.Count];
            short[] a3 = list.ToArray(a2);

            Assert.AreSame(a2, a3);
            for (short j = 0; j < 1000; j++)
            {
                Assert.AreEqual(a2[j], list.Get(j));
            }
            short[] ashort = new short[list.Count - 1];
            short[] aLong  = new short[list.Count + 1];
            short[] a4     = list.ToArray(ashort);
            short[] a5     = list.ToArray(aLong);

            Assert.IsTrue(a4 != ashort);
            Assert.IsTrue(a5 != aLong);
            Assert.AreEqual(a4.Length, list.Count);
            for (short j = 0; j < 1000; j++)
            {
                Assert.AreEqual(a3[j], list.Get(j));
            }
            Assert.AreEqual(a5.Length, list.Count);
            for (short j = 0; j < 1000; j++)
            {
                Assert.AreEqual(a5[j], list.Get(j));
            }
        }
Example #28
0
        public static ShortList <string> GetAllEmailAddresses(ShortList <string> addressesToExpand, OrganizationId organizationId)
        {
            if (addressesToExpand == null)
            {
                return(null);
            }
            ShortList <string> shortList = new ShortList <string>();

            foreach (string emailAddress in addressesToExpand)
            {
                string[] allEmailAddresses = ADUtils.GetAllEmailAddresses(emailAddress, organizationId);
                if (allEmailAddresses != null)
                {
                    foreach (string item in allEmailAddresses)
                    {
                        shortList.Add(item);
                    }
                }
            }
            return(shortList);
        }
        internal override Condition ToInternalCondition()
        {
            ShortList <string> shortList = new ShortList <string>();

            foreach (Pattern pattern in this.Patterns)
            {
                shortList.Add(pattern.ToString());
            }
            string             name  = base.UseLegacyRegex ? "matches" : "matchesRegex";
            PredicateCondition item  = TransportRuleParser.Instance.CreatePredicate(name, TransportRuleParser.Instance.CreateProperty("Message.Subject"), shortList);
            PredicateCondition item2 = TransportRuleParser.Instance.CreatePredicate(name, TransportRuleParser.Instance.CreateProperty("Message.Body"), shortList);

            return(new OrCondition
            {
                SubConditions =
                {
                    item,
                    item2
                }
            });
        }
Example #30
0
        public void TestIsEmpty()
        {
            ShortList list1 = new ShortList();
            ShortList list2 = new ShortList(1000);
            ShortList list3 = new ShortList(list1);

            Assert.IsTrue(list1.IsEmpty());
            Assert.IsTrue(list2.IsEmpty());
            Assert.IsTrue(list3.IsEmpty());
            list1.Add((short)1);
            list2.Add((short)2);
            list3 = new ShortList(list2);
            Assert.IsTrue(!list1.IsEmpty());
            Assert.IsTrue(!list2.IsEmpty());
            Assert.IsTrue(!list3.IsEmpty());
            list1.Clear();
            list2.Remove(0);
            list3.RemoveValue((short)2);
            Assert.IsTrue(list1.IsEmpty());
            Assert.IsTrue(list2.IsEmpty());
            Assert.IsTrue(list3.IsEmpty());
        }