private XElement TransformRule(XElement ruleElement)
        {
            string value;

            if (!this.CheckElement(ruleElement, "rule") || !this.TryGetAttributeValue(ruleElement, "name", out value) || !RuleUtils.TryParseNullableDateTimeUtc(this.GetAttributeValue(ruleElement, "activationDate"), out this.activationDate) || !RuleUtils.TryParseNullableDateTimeUtc(this.GetAttributeValue(ruleElement, "expiryDate"), out this.expiryDate))
            {
                return(null);
            }
            this.mode = this.TryParseAttribute <RuleMode>(ruleElement, "mode", new ETRToPNRTranslator.TryParse <RuleMode>(Enum.TryParse <RuleMode>), RuleMode.Enforce);
            if (this.mode == RuleMode.Audit)
            {
                return(null);
            }
            string attributeValue = this.GetAttributeValue(ruleElement, "enabled");

            if (!string.IsNullOrEmpty(attributeValue) && !RuleConstants.TryParseEnabled(attributeValue, out this.enabled))
            {
                this.enabled = RuleState.Disabled;
            }
            XElement xelement = this.CheckElement(ruleElement.FirstElement(), "version") ? this.TransformVersion(ruleElement.FirstElement()) : ETRToPNRTranslator.CreateXElement("version", new object[]
            {
                new XAttribute("minRequiredVersion", "15.0.3225.3000"),
                this.TransformRuleContents(ruleElement)
            });

            return(ETRToPNRTranslator.CreateXElement("rule", new object[]
            {
                new XAttribute("name", value),
                xelement
            }));
        }
Exemple #2
0
        public PolicyNudgeRule GetRule(string ruleString, string id, DateTime version)
        {
            ETRToPNRTranslator etrtoPNRTranslator = new ETRToPNRTranslator(ruleString, PolicyNudgeRuleParser.emptyMessageStrings, null, null);

            if (!etrtoPNRTranslator.IsValid)
            {
                return(null);
            }
            return(new PolicyNudgeRule(ruleString, id, version, etrtoPNRTranslator.Enabled, etrtoPNRTranslator.ActivationDate, etrtoPNRTranslator.ExpiryDate));
        }
Exemple #3
0
 public string GetRuleXml(string locale, ETRToPNRTranslator.IMessageStrings messageStrings, ETRToPNRTranslator.IDistributionListResolver distributionListResolver, ETRToPNRTranslator.IDataClassificationResolver dataClassificationResolver, bool needFullPnrXml, out PolicyNudgeRule.References references)
 {
     if (this.localeToPnrMap == null)
     {
         lock (this.etrXml)
         {
             if (this.localeToPnrMap == null)
             {
                 this.localeToPnrMap = new Dictionary <string, PolicyNudgeRule.CacheEntry>();
             }
         }
     }
     PolicyNudgeRule.CacheEntry cacheEntry;
     if (this.localeToPnrMap.TryGetValue(locale, out cacheEntry))
     {
         references = new PolicyNudgeRule.References(cacheEntry.usedMessages, cacheEntry.usedDistributionLists.SelectMany((string dl) => distributionListResolver.Get(dl)));
         if (!needFullPnrXml)
         {
             return(cacheEntry.PnrXml);
         }
         return(cacheEntry.FullPnrXml);
     }
     else
     {
         List <PolicyTipMessage> usedMessagesList          = new List <PolicyTipMessage>();
         List <string>           usedDistributionListsList = new List <string>();
         ETRToPNRTranslator      etrtoPNRTranslator        = new ETRToPNRTranslator(this.etrXml, new ETRToPNRTranslator.MessageStringCallbackImpl(messageStrings.OutlookCultureTag, (ETRToPNRTranslator.OutlookActionTypes action) => PolicyNudgeRule.Track <PolicyTipMessage>(messageStrings.Get(action), usedMessagesList), () => PolicyNudgeRule.Track <PolicyTipMessage>(messageStrings.Url, usedMessagesList)), new ETRToPNRTranslator.DistributionListResolverCallbackImpl(delegate(string distributionList)
         {
             PolicyNudgeRule.Track <string>(distributionList, usedDistributionListsList);
             return(null);
         }, (string distributionList) => distributionListResolver.IsMemberOf(distributionList)), dataClassificationResolver);
         string pnrXml = etrtoPNRTranslator.PnrXml;
         this.IsPnrXmlValid = !string.IsNullOrEmpty(pnrXml);
         string fullPnrXml = etrtoPNRTranslator.FullPnrXml;
         lock (this.localeToPnrMap)
         {
             if (!this.localeToPnrMap.ContainsKey(locale))
             {
                 this.localeToPnrMap.Add(locale, new PolicyNudgeRule.CacheEntry
                 {
                     PnrXml                = pnrXml,
                     FullPnrXml            = fullPnrXml,
                     usedMessages          = usedMessagesList.ToArray(),
                     usedDistributionLists = usedDistributionListsList.ToArray()
                 });
             }
         }
         references = new PolicyNudgeRule.References(usedMessagesList, usedDistributionListsList.SelectMany((string dl) => distributionListResolver.Get(dl)));
         if (!needFullPnrXml)
         {
             return(pnrXml);
         }
         return(fullPnrXml);
     }
 }
        private XElement TransformVersion(XElement versionElement)
        {
            Version v;

            if (!this.CheckElement(versionElement, "version") || !Version.TryParse(this.GetAttributeValue(versionElement, "requiredMinVersion"), out v))
            {
                return(null);
            }
            if (v > ETRToPNRTranslator.HighestHonoredVersion)
            {
                return(null);
            }
            return(ETRToPNRTranslator.CreateXElement("version", new object[]
            {
                new XAttribute("minRequiredVersion", "15.0.3225.3000"),
                this.TransformRuleContents(versionElement)
            }));
        }
        private string TryTransform()
        {
            if (string.IsNullOrEmpty(this.etrXml))
            {
                return(null);
            }
            XDocument xdocument;

            try
            {
                xdocument = ETRToPNRTranslator.CreateXDocument(this.etrXml);
            }
            catch (XmlException)
            {
                return(null);
            }
            XElement xelement = this.TransformRule(xdocument.Root);

            if (xelement == null || !this.hasSenderNotifyAction)
            {
                return(null);
            }
            xdocument = new XDocument(new object[]
            {
                xelement
            });
            ETRToPNRTranslator.OptimizePredicates(xdocument);
            if (this.IsFalseRootCondition(xdocument))
            {
                return(null);
            }
            string result = xdocument.Root.ToString();

            this.pnrXml = result;
            if (this.RemoveVersionedDataClassifications(xdocument))
            {
                ETRToPNRTranslator.OptimizePredicates(xdocument);
                this.pnrXml = (this.IsFalseRootCondition(xdocument) ? null : xdocument.Root.ToString());
            }
            return(result);
        }