internal string Serialize()
        {
            ValidationError[] array = this.Validate();
            if (array != null && array.Length > 0)
            {
                throw new DataValidationException(array[0]);
            }
            OutlookProtectionRule outlookProtectionRule = new OutlookProtectionRule(base.Name);

            outlookProtectionRule.Enabled         = (this.Enabled ? RuleState.Enabled : RuleState.Disabled);
            outlookProtectionRule.UserOverridable = this.UserCanOverride;
            outlookProtectionRule.Condition       = new AndCondition
            {
                SubConditions =
                {
                    this.CreateAllInternalCondition(),
                    new AndCondition
                    {
                        SubConditions =
                        {
                            this.CreateSenderDepartmentCondition(),
                            this.CreateRecipientIsCondition()
                        }
                    }
                }
            };
            outlookProtectionRule.Actions.Add(this.CreateRightsProtectMessageAction());
            OutlookProtectionRuleSerializer outlookProtectionRuleSerializer = new OutlookProtectionRuleSerializer();

            return(outlookProtectionRuleSerializer.SaveRuleToString(outlookProtectionRule));
        }
        public OutlookProtectionRulePresentationObject(TransportRule transportRule) : base(transportRule)
        {
            if (transportRule == null || string.IsNullOrEmpty(transportRule.Xml))
            {
                return;
            }
            OutlookProtectionRule outlookProtectionRule = (OutlookProtectionRule)OutlookProtectionRuleParser.Instance.GetRule(transportRule.Xml);

            this.enabled         = (outlookProtectionRule.Enabled == RuleState.Enabled);
            this.userCanOverride = outlookProtectionRule.UserOverridable;
            PredicateCondition senderDepartmentPredicate = outlookProtectionRule.GetSenderDepartmentPredicate();

            if (senderDepartmentPredicate != null && senderDepartmentPredicate.Value != null)
            {
                this.fromDepartment = new List <string>(senderDepartmentPredicate.Value.RawValues);
            }
            PredicateCondition recipientIsPredicate = outlookProtectionRule.GetRecipientIsPredicate();

            if (recipientIsPredicate != null && recipientIsPredicate.Value != null)
            {
                this.sentTo = new List <SmtpAddress>(from s in recipientIsPredicate.Value.RawValues
                                                     select SmtpAddress.Parse(s));
            }
            PredicateCondition allInternalPredicate = outlookProtectionRule.GetAllInternalPredicate();

            if (allInternalPredicate != null)
            {
                this.sentToScope = ToUserScope.InOrganization;
            }
            RightsProtectMessageAction rightsProtectMessageAction = outlookProtectionRule.GetRightsProtectMessageAction();

            if (rightsProtectMessageAction != null)
            {
                this.applyRightsProtectionTemplate = new RmsTemplateIdentity(new Guid(rightsProtectMessageAction.TemplateId), rightsProtectMessageAction.TemplateName);
            }
        }