Exemplo n.º 1
0
 internal void Validate()
 {
     if (string.IsNullOrEmpty(this.Name) || string.IsNullOrEmpty(this.Version))
     {
         throw new DlpPolicyParsingException(Strings.DlpPolicyXmlMissingElements);
     }
     if (new Version(this.Version) > DlpUtils.MaxSupportedVersion)
     {
         throw new DlpPolicyParsingException(Strings.DlpPolicyVersionUnsupported);
     }
     if (this.Keywords.Any(new Func <string, bool>(string.IsNullOrEmpty)))
     {
         throw new DlpPolicyParsingException(Strings.DlpPolicyContainsEmptyKeywords);
     }
     DlpPolicyTemplateMetaData.ValidateFieldSize("name", this.Name, 64);
     DlpPolicyTemplateMetaData.ValidateFieldSize("version", this.Version, 16);
     DlpPolicyTemplateMetaData.ValidateFieldSize("contentVersion", this.ContentVersion, 16);
     DlpPolicyTemplateMetaData.ValidateFieldSize("publisherName", this.PublisherName, 256);
     DlpPolicyTemplateMetaData.ValidateFieldSize("description", this.Description, 1024);
     this.Keywords.ForEach(delegate(string x)
     {
         DlpPolicyTemplateMetaData.ValidateFieldSize("keyword", x, 64);
     });
     this.PolicyCommands.ForEach(delegate(string command)
     {
         DlpPolicyTemplateMetaData.ValidateFieldSize("commandBlock", command, 4096);
     });
     this.PolicyCommands.ForEach(delegate(string command)
     {
         DlpPolicyTemplateMetaData.ValidateCmdletParameters(command);
     });
 }
Exemplo n.º 2
0
        public override void Validate()
        {
            Exception exception = null;

            this.ValidateParameterSets();
            DlpPolicyTemplateMetaData dlpPolicyTemplateMetaData = null;

            if (this.taskObject.Fields.IsModified("TemplateData"))
            {
                dlpPolicyTemplateMetaData = this.LoadDlpPolicyFromCustomTemplateData();
            }
            if (this.taskObject.Fields.IsModified("Template"))
            {
                dlpPolicyTemplateMetaData = this.LoadDlpPolicyFromInstalledTemplate();
            }
            if (this.taskObject.Fields.IsModified("Name"))
            {
                this.dlpPolicy.Name = this.taskObject.Name;
            }
            if (dlpPolicyTemplateMetaData != null)
            {
                this.dlpPolicy = new DlpPolicyMetaData(dlpPolicyTemplateMetaData, this.taskObject.CommandRuntime.Host.CurrentCulture);
                if (!string.IsNullOrEmpty(this.taskObject.Name))
                {
                    this.dlpPolicy.Name = this.taskObject.Name;
                }
                this.dlpPolicy.PolicyCommands = NewDlpPolicyImpl.ParameterizeCmdlets(this.dlpPolicy.Name, dlpPolicyTemplateMetaData.PolicyCommands, dlpPolicyTemplateMetaData.RuleParameters, this.taskObject.Parameters, new NewDlpPolicy.WarningWriterDelegate(this.taskObject.WriteWarning), out exception);
                this.WriteParameterErrorIfExceptionOccurred(exception, "Parameters");
                this.dlpPolicy.PolicyCommands = DlpPolicyTemplateMetaData.LocalizeCmdlets(this.dlpPolicy.PolicyCommands, dlpPolicyTemplateMetaData.LocalizedPolicyCommandResources, this.taskObject.CommandRuntime.Host.CurrentCulture).ToList <string>();
                this.dlpPolicy.PolicyCommands.ForEach(delegate(string command)
                {
                    DlpPolicyTemplateMetaData.ValidateCmdletParameters(command);
                });
            }
            if (this.taskObject.Fields.IsModified("State"))
            {
                this.dlpPolicy.State = this.taskObject.State;
            }
            if (this.taskObject.Fields.IsModified("Mode"))
            {
                this.dlpPolicy.Mode = this.taskObject.Mode;
            }
            if (this.taskObject.Fields.IsModified("Description"))
            {
                this.dlpPolicy.Description = this.taskObject.Description;
            }
            this.ValidateDlpPolicyName();
        }
        internal void Validate()
        {
            if (this.LocalizedNames == null || !this.LocalizedNames.Any <KeyValuePair <string, string> >() || string.IsNullOrEmpty(this.Version) || this.ImmutableId == Guid.Empty || string.IsNullOrEmpty(this.ContentVersion) || string.IsNullOrEmpty(this.PublisherName) || this.LocalizedDescriptions == null || !this.LocalizedDescriptions.Any <KeyValuePair <string, string> >() || this.PolicyCommands == null || !this.PolicyCommands.Any <string>())
            {
                throw new DlpPolicyParsingException(Strings.DlpPolicyXmlMissingElements);
            }
            if (new Version(this.Version) > DlpUtils.MaxSupportedVersion)
            {
                throw new DlpPolicyParsingException(Strings.DlpPolicyVersionUnsupported);
            }
            if (this.LocalizedKeywords.Any((Dictionary <string, string> keywords) => keywords.Any((KeyValuePair <string, string> keyword) => string.IsNullOrEmpty(keyword.Value))))
            {
                throw new DlpPolicyParsingException(Strings.DlpPolicyContainsEmptyKeywords);
            }
            DlpPolicyTemplateMetaData.ValidateFieldSize("version", this.Version, 16);
            DlpPolicyTemplateMetaData.ValidateFieldSize("contentVersion", this.ContentVersion, 16);
            DlpPolicyTemplateMetaData.ValidateFieldSize("publisherName", this.PublisherName, 256);
            this.LocalizedNames.Values.ToList <string>().ForEach(delegate(string x)
            {
                DlpPolicyTemplateMetaData.ValidateFieldSize("name", x, 64);
            });
            this.LocalizedDescriptions.Values.ToList <string>().ForEach(delegate(string x)
            {
                DlpPolicyTemplateMetaData.ValidateFieldSize("description", x, 1024);
            });
            this.LocalizedKeywords.ToList <Dictionary <string, string> >().ForEach(delegate(Dictionary <string, string> keywords)
            {
                keywords.Values.ToList <string>().ForEach(delegate(string keyword)
                {
                    DlpPolicyTemplateMetaData.ValidateFieldSize("keyword", keyword, 64);
                });
            });
            List <DlpTemplateRuleParameter> list = this.RuleParameters.ToList <DlpTemplateRuleParameter>();

            list.ForEach(delegate(DlpTemplateRuleParameter x)
            {
                DlpPolicyTemplateMetaData.ValidateFieldSize("type", x.Type, 32);
            });
            list.ForEach(delegate(DlpTemplateRuleParameter x)
            {
                DlpPolicyTemplateMetaData.ValidateFieldSize("token", x.Token, 32);
            });
            list.ForEach(delegate(DlpTemplateRuleParameter x)
            {
                x.LocalizedDescriptions.ToList <KeyValuePair <string, string> >().ForEach(delegate(KeyValuePair <string, string> y)
                {
                    DlpPolicyTemplateMetaData.ValidateFieldSize("description", y.Value, 1024);
                });
            });
            this.LocalizedPolicyCommandResources.Values.ToList <Dictionary <string, string> >().ForEach(delegate(Dictionary <string, string> resources)
            {
                resources.Values.ToList <string>().ForEach(delegate(string resource)
                {
                    DlpPolicyTemplateMetaData.ValidateFieldSize("resource", resource, 1024);
                });
            });
            List <string> list2 = this.PolicyCommands.ToList <string>();

            list2.ForEach(delegate(string x)
            {
                DlpPolicyTemplateMetaData.ValidateFieldSize("commandBlock", x, 4096);
            });
            list2.ForEach(delegate(string command)
            {
                DlpPolicyTemplateMetaData.ValidateCmdletParameters(command);
            });
        }