internal static IEnumerable <string> ParseStream(Stream data)
        {
            IEnumerable <string> result;

            try
            {
                XDocument            xdocument = XDocument.Load(data);
                IEnumerable <string> ruleNames = from rule in xdocument.Elements("rules").Elements("rule")
                                                 select rule.Attribute("name").Value;

                string duplicateRuleName = PowershellTransportRuleSerializer.GetDuplicateRuleName(ruleNames);
                if (duplicateRuleName != null)
                {
                    throw new ParserException(RulesStrings.RuleNameExists(duplicateRuleName));
                }
                IEnumerable <string> enumerable = from version in xdocument.Elements("rules").Elements("rule").Elements("version")
                                                  where PowershellTransportRuleSerializer.IsSupportedVersion(version.Attribute("requiredMinVersion").Value)
                                                  select version.Element("commandBlock").Value.Trim();

                result = enumerable;
            }
            catch (NullReferenceException ex)
            {
                throw new XmlException("Malformed XML: " + ex.Message);
            }
            return(result);
        }
Esempio n. 2
0
 internal static Exception TryParseE15Format(Stream contentStream, out IEnumerable <string> cmdlets)
 {
     try
     {
         contentStream.Position = 0L;
         cmdlets = PowershellTransportRuleSerializer.ParseStream(contentStream);
     }
     catch (ParseException result)
     {
         cmdlets = null;
         return(result);
     }
     catch (ArgumentException result2)
     {
         cmdlets = null;
         return(result2);
     }
     catch (XmlException result3)
     {
         cmdlets = null;
         return(result3);
     }
     if (cmdlets == null || cmdlets.Any(new Func <string, bool>(string.IsNullOrEmpty)))
     {
         return(new ArgumentException("File Data - Empty cmdlet block"));
     }
     return(null);
 }
Esempio n. 3
0
        private void WriteFormattedRules()
        {
            ADRuleStorageManager ruleStorageManager = base.RuleStorageManager;

            ruleStorageManager.LoadRuleCollection();
            IEnumerable <TransportRuleHandle> ruleHandles = ruleStorageManager.GetRuleHandles();
            List <Rule> list = new List <Rule>();

            foreach (TransportRuleHandle transportRuleHandle in ruleHandles)
            {
                string text = null;
                try
                {
                    Rule rule = Rule.CreateFromInternalRule(this.supportedPredicates, this.supportedActions, transportRuleHandle.Rule, transportRuleHandle.AdRule.Priority, transportRuleHandle.AdRule);
                    if (base.NeedSuppressingPiiData)
                    {
                        rule.SuppressPiiData(Utils.GetSessionPiiMap(base.ExchangeRunspaceConfig));
                    }
                    list.Add(rule);
                }
                catch (ArgumentException ex)
                {
                    text = ex.Message;
                }
                catch (InvalidOperationException ex2)
                {
                    text = ex2.Message;
                }
                catch (ParserException ex3)
                {
                    text = ex3.Message;
                }
                catch (RulesValidationException ex4)
                {
                    text = ex4.Message;
                }
                if (text != null)
                {
                    base.WriteWarning(Strings.ErrorObjectHasValidationErrorsWithId(transportRuleHandle.AdRule.Identity.ToString()) + " " + text);
                }
            }
            this.WriteResult(new BinaryFileDataObject
            {
                FileData = PowershellTransportRuleSerializer.Serialize(list)
            });
        }