Exemplo n.º 1
0
 static IEnumerable<AdWarning> CheckNames(AdShape ad)
 {
     var body = ad.Shape.TextFrame2.TextRange.Text;
     return ad.Row.Pledges
         .Where(p => !HasName(p.Person, body))
         .Select(p => new AdWarning(ad, p.Person.VeryFullName + " does not appear in the ad text"));
 }
Exemplo n.º 2
0
		///<summary>Formats the text of the ad.  Avoid calling this method if the ad has warnings.</summary>
		public void FormatText(AdShape ad) {
			var text = ad.Shape.TextFrame2.TextRange.Text;
			foreach (var rule in rules) {
				foreach (var match in rule.Regexes(ad).SelectMany(r => r.Matches(text).Cast<Match>())) {
					rule.Apply(ad.Shape.TextFrame2.TextRange.Characters[match.Index + 1, match.Length]);
				}
			}
		}
Exemplo n.º 3
0
 static IEnumerable<AdWarning> CheckPayments(AdShape ad)
 {
     var pledges = ad.Row.Pledges.ToDictionary(p => p.Person);
     foreach (var payment in ad.Row.Payments) {
         Pledge pledge;
         if (!pledges.TryGetValue(payment.Person, out pledge))
             yield return new AdWarning(ad, payment.Person.VeryFullName + " has a payment but not a pledge");
         else {
             if (pledge.Amount != payment.Amount)
                 yield return new AdWarning(ad,
                     String.Format(CultureInfo.CurrentCulture,
                                   "{0} has a pledge for {1:c} but a payment for {2:c}",
                                   payment.Person.VeryFullName, pledge.Amount, payment.Amount)
                 );
             if (payment.Method == "Check" && String.IsNullOrWhiteSpace(payment.CheckNumber))
                 yield return new AdWarning(ad,
                     String.Format(CultureInfo.CurrentCulture,
                                   "{0} has a {1:c} check that is missing a check number",
                                   payment.Person.VeryFullName, payment.Amount)
                 );
         }
     }
 }
Exemplo n.º 4
0
 static IEnumerable<AdWarning> CheckPledges(AdShape ad)
 {
     var total = ad.Row.Pledges.Sum(p => p.Amount);
     if (total == 0)
         yield return new AdWarning(ad, "This ad has no pledges");
     else if (total > ad.AdType.DefaultPrice)
         yield return new AdWarning(ad, "This ad's pledges add up to " + total.ToString("c", CultureInfo.CurrentCulture));
 }
Exemplo n.º 5
0
        ///<summary>Creates an AdWarning instance.</summary>
        public AdWarning(AdShape ad, string message)
        {
            if (ad == null) throw new ArgumentNullException("ad");

            Ad = ad;
            Message = message;
            var commentLines = (ad.Row.Comments ?? "").Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            IsSuppressed = commentLines.Any(c => c.StartsWith(Message, StringComparison.CurrentCultureIgnoreCase)); ;
        }
Exemplo n.º 6
0
        static IEnumerable<AdWarning> CheckSlidePosition(AdShape ad)
        {
            var previousSlide = (PowerPoint.Slide)ad.Shape.Parent;
            //The loop is necessary to skip special pages in the middle of the ads
            while (true) {
                if (previousSlide.SlideIndex <= 1)
                    yield break;
                previousSlide = ad.Presentation.Presentation.Slides[previousSlide.SlideIndex - 1];
                var slideType = previousSlide.AdType();

                if (slideType == null) continue;    //Skip special pages in the middle of the ads

                if (slideType.Index > ad.AdType.Index)
                    yield return new AdWarning(ad, "This ad is after a " + slideType.Name.ToLowerInvariant() + " page");
                //Either the ad is preceded by an OK slide or
                //we just gave an error. Either way, stop now
                yield break;
            }
        }