Example #1
0
        protected override void InternalValidate()
        {
            TaskLogger.LogEnter();
            if (!base.Fields.Contains("Mailbox"))
            {
                SharedConfigurationTaskHelper.VerifyIsNotTinyTenant(base.CurrentOrgState, new Task.ErrorLoggerDelegate(base.WriteError));
            }
            if (base.ParameterSetName == "ParameterSetMailboxTask")
            {
                return;
            }
            if (base.Fields.IsModified("LegacyManagedFolder"))
            {
                if (this.LegacyManagedFolder != null)
                {
                    ELCFolder elcfolder = (ELCFolder)base.GetDataObject <ELCFolder>(this.LegacyManagedFolder, base.DataSession, null, new LocalizedString?(Strings.ErrorElcFolderNotFound(this.LegacyManagedFolder.ToString())), new LocalizedString?(Strings.ErrorAmbiguousElcFolderId(this.LegacyManagedFolder.ToString())));
                    this.DataObject.LegacyManagedFolder = elcfolder.Id;
                }
                else
                {
                    this.DataObject.LegacyManagedFolder = null;
                }
            }
            base.InternalValidate();
            if (this.contentSettingsObject.IsChanged(ElcContentSettingsSchema.RetentionAction))
            {
                RetentionActionType[] source = new RetentionActionType[]
                {
                    RetentionActionType.MoveToFolder
                };
                if (source.Any((RetentionActionType x) => x == this.contentSettingsObject.RetentionAction))
                {
                    base.WriteError(new RetentionPolicyTagTaskException(Strings.ErrorRetentionActionNowAllowed), ErrorCategory.InvalidOperation, null);
                }
                if (this.DataObject.Type == ElcFolderType.RecoverableItems && !this.contentSettingsObject.RetentionAction.Equals(RetentionActionType.MoveToArchive))
                {
                    base.WriteError(new ArgumentException(Strings.ErrorDumpsterTagWrongRetentionAction), ErrorCategory.InvalidArgument, this);
                }
                if (this.DataObject.Type != ElcFolderType.All && this.DataObject.Type != ElcFolderType.Personal && this.DataObject.Type != ElcFolderType.RecoverableItems && this.RetentionAction == RetentionActionType.MoveToArchive)
                {
                    base.WriteError(new RetentionPolicyTagTaskException(Strings.ErrorMoveToArchiveAppliedToSystemFolder), ErrorCategory.InvalidArgument, null);
                }
            }
            if (this.contentSettingsObject.IsChanged(ElcContentSettingsSchema.MessageClass) && this.DataObject.Type != ElcFolderType.All && !this.contentSettingsObject.MessageClass.Equals(ElcMessageClass.AllMailboxContent))
            {
                base.WriteError(new RetentionPolicyTagTaskException(Strings.ErrorOnlyDefaultTagAllowCustomizedMessageClass), ErrorCategory.InvalidOperation, this.DataObject);
            }
            string tagName;

            if (this.DataObject.IsChanged(RetentionPolicyTagSchema.RetentionId) && !(base.DataSession as IConfigurationSession).CheckForRetentionTagWithConflictingRetentionId(this.DataObject.RetentionId, this.DataObject.Identity.ToString(), out tagName))
            {
                base.WriteError(new RetentionPolicyTagTaskException(Strings.ErrorRetentionIdConflictsWithRetentionTag(this.DataObject.RetentionId.ToString(), tagName)), ErrorCategory.InvalidOperation, this.DataObject);
            }
            if (this.contentSettingsObject.IsChanged(ElcContentSettingsSchema.RetentionAction) || this.contentSettingsObject.IsChanged(ElcContentSettingsSchema.RetentionEnabled) || this.contentSettingsObject.IsChanged(ElcContentSettingsSchema.MessageClass))
            {
                this.ValidateRetentionPolicy();
            }
            if (base.Fields.IsModified("AddressForJournaling"))
            {
                if (this.AddressForJournaling != null)
                {
                    ADRecipient adrecipient = (ADRecipient)base.GetDataObject <ADRecipient>(this.AddressForJournaling, base.TenantGlobalCatalogSession, null, new LocalizedString?(Strings.ErrorMailboxAddressNotFound(this.AddressForJournaling.ToString())), new LocalizedString?(Strings.ErrorMailboxAddressNotUnique(this.AddressForJournaling.ToString())));
                    if (!this.DataObject.OrganizationId.Equals(OrganizationId.ForestWideOrgId))
                    {
                        RecipientTaskHelper.CheckRecipientInSameOrganizationWithDataObject(this.DataObject, adrecipient, new Task.ErrorLoggerDelegate(base.WriteError));
                    }
                    if (adrecipient.EmailAddresses == null || adrecipient.EmailAddresses.FindPrimary(ProxyAddressPrefix.Smtp) == null)
                    {
                        base.WriteError(new ArgumentException(Strings.SmtpAddressMissingForAutocopy(this.AddressForJournaling.ToString()), "AddressForJournaling"), ErrorCategory.InvalidData, this);
                    }
                    this.contentSettingsObject.AddressForJournaling = adrecipient.Id;
                }
                else
                {
                    this.contentSettingsObject.AddressForJournaling = null;
                }
            }
            ValidationError[] array = this.contentSettingsObject.Validate();
            if (array.Length > 0)
            {
                for (int i = 0; i < array.Length; i++)
                {
                    this.WriteError(new DataValidationException(array[i]), (ErrorCategory)1003, this.contentSettingsObject.Identity, array.Length - 1 == i);
                }
            }
            if (base.HasErrors)
            {
                return;
            }
            TaskLogger.LogExit();
        }
        private ElcContentSettings[] GetUpgradedConentSettings(ElcContentSettings[] folderContentSettings, bool defaultTag)
        {
            List <ElcContentSettings> upgradedSettings = new List <ElcContentSettings>();

            ElcContentSettings[] array = (from x in folderContentSettings
                                          where x.RetentionEnabled || x.JournalingEnabled
                                          select x).ToArray <ElcContentSettings>();
            folderContentSettings.Except(array).ForEach(delegate(ElcContentSettings x)
            {
                this.WriteWarning(Strings.CouldNotUpgradeDisabledContentSettings(x.Name));
            });
            RetentionActionType[] allowedRetentionActions = new RetentionActionType[]
            {
                RetentionActionType.PermanentlyDelete,
                RetentionActionType.DeleteAndAllowRecovery,
                RetentionActionType.MoveToDeletedItems
            };
            if (!defaultTag)
            {
                ElcContentSettings elcContentSettings = new ElcContentSettings();
                elcContentSettings.JournalingEnabled = false;
                elcContentSettings.RetentionEnabled  = false;
                elcContentSettings.RetentionAction   = RetentionActionType.PermanentlyDelete;
                ElcContentSettings[] array2 = (from x in array
                                               where x.RetentionEnabled
                                               select x).ToArray <ElcContentSettings>();
                ElcContentSettings[] array3 = (from x in array2
                                               where allowedRetentionActions.Any((RetentionActionType y) => x.RetentionAction == y)
                                               select x).ToArray <ElcContentSettings>();
                array2.Except(array3).ForEach(delegate(ElcContentSettings x)
                {
                    this.WriteWarning(Strings.CouldNotUpgradeSpecificContentSetting(x.Name));
                });
                ElcContentSettings[] array4 = (from x in array3
                                               where x.TriggerForRetention == RetentionDateType.WhenDelivered
                                               select x).ToArray <ElcContentSettings>();
                array3.Except(array4).ForEach(delegate(ElcContentSettings x)
                {
                    this.WriteWarning(Strings.CouldNotUpgradeRetentionTrigger(x.TriggerForRetention.ToString(), x.Name, RetentionDateType.WhenDelivered.ToString()));
                });
                array4.Aggregate(elcContentSettings, delegate(ElcContentSettings a, ElcContentSettings x)
                {
                    if (a.AgeLimitForRetention == null)
                    {
                        a.AgeLimitForRetention = x.AgeLimitForRetention;
                    }
                    else if (x.AgeLimitForRetention != null && a.AgeLimitForRetention < x.AgeLimitForRetention)
                    {
                        a.AgeLimitForRetention = x.AgeLimitForRetention;
                    }
                    if (Array.FindIndex <RetentionActionType>(allowedRetentionActions, (RetentionActionType y) => y == a.RetentionAction) < Array.FindIndex <RetentionActionType>(allowedRetentionActions, (RetentionActionType y) => y == x.RetentionAction))
                    {
                        a.RetentionAction = x.RetentionAction;
                    }
                    a.RetentionEnabled = true;
                    return(a);
                });
                if (elcContentSettings.RetentionEnabled)
                {
                    elcContentSettings.TriggerForRetention = RetentionDateType.WhenDelivered;
                    elcContentSettings.MessageClass        = ElcMessageClass.AllMailboxContent;
                    (from x in array4
                     where string.Compare(x.MessageClass, ElcMessageClass.AllMailboxContent, StringComparison.OrdinalIgnoreCase) != 0
                     select x).ForEach(delegate(ElcContentSettings x)
                    {
                        this.WriteWarning(Strings.ChangedMessageClass(x.Name, x.MessageClass));
                    });
                }
                ElcContentSettings[] array5 = (from x in array
                                               where x.JournalingEnabled
                                               select x).ToArray <ElcContentSettings>();
                if (array5.Length > 0)
                {
                    elcContentSettings.JournalingEnabled          = true;
                    elcContentSettings.MessageFormatForJournaling = array5[0].MessageFormatForJournaling;
                    elcContentSettings.AddressForJournaling       = array5[0].AddressForJournaling;
                    elcContentSettings.LabelForJournaling         = array5[0].LabelForJournaling;
                    array5.Skip(1).ForEach(delegate(ElcContentSettings x)
                    {
                        this.WriteWarning(Strings.CouldNotUpgradeJournaling(x.Name));
                    });
                }
                if (elcContentSettings.RetentionEnabled || elcContentSettings.JournalingEnabled)
                {
                    upgradedSettings.Add(elcContentSettings);
                }
            }
            else
            {
                array.ForEach(delegate(ElcContentSettings x)
                {
                    ElcContentSettings elcContentSettings2 = new ElcContentSettings();
                    if (x.RetentionEnabled)
                    {
                        if (allowedRetentionActions.Any((RetentionActionType y) => x.RetentionAction == y))
                        {
                            if (x.TriggerForRetention != RetentionDateType.WhenDelivered)
                            {
                                this.WriteWarning(Strings.CouldNotUpgradeRetentionTrigger(x.TriggerForRetention.ToString(), x.Name, RetentionDateType.WhenDelivered.ToString()));
                            }
                            else
                            {
                                elcContentSettings2.RetentionAction      = x.RetentionAction;
                                elcContentSettings2.AgeLimitForRetention = x.AgeLimitForRetention;
                                elcContentSettings2.TriggerForRetention  = RetentionDateType.WhenDelivered;
                                elcContentSettings2.RetentionEnabled     = x.RetentionEnabled;
                                if (x.MessageClass.Equals(ElcMessageClass.AllMailboxContent, StringComparison.OrdinalIgnoreCase) || x.MessageClass.Equals(ElcMessageClass.VoiceMail, StringComparison.OrdinalIgnoreCase))
                                {
                                    elcContentSettings2.MessageClass = x.MessageClass;
                                }
                                else
                                {
                                    elcContentSettings2.MessageClass = ElcMessageClass.AllMailboxContent;
                                    this.WriteWarning(Strings.ChangedMessageClass(x.Name, x.MessageClass));
                                }
                            }
                        }
                        else
                        {
                            this.WriteWarning(Strings.CouldNotUpgradeSpecificContentSetting(x.Name));
                        }
                    }
                    if (x.JournalingEnabled)
                    {
                        elcContentSettings2.MessageFormatForJournaling = x.MessageFormatForJournaling;
                        elcContentSettings2.JournalingEnabled          = x.JournalingEnabled;
                        elcContentSettings2.AddressForJournaling       = x.AddressForJournaling;
                        elcContentSettings2.LabelForJournaling         = x.LabelForJournaling;
                        if (x.MessageClass.Equals(ElcMessageClass.AllMailboxContent, StringComparison.OrdinalIgnoreCase) || x.MessageClass.Equals(ElcMessageClass.VoiceMail, StringComparison.OrdinalIgnoreCase))
                        {
                            elcContentSettings2.MessageClass = x.MessageClass;
                        }
                        else
                        {
                            elcContentSettings2.MessageClass = ElcMessageClass.AllMailboxContent;
                            this.WriteWarning(Strings.ChangedMessageClass(x.Name, x.MessageClass));
                        }
                    }
                    if (elcContentSettings2.RetentionEnabled || elcContentSettings2.JournalingEnabled)
                    {
                        upgradedSettings.Add(elcContentSettings2);
                    }
                });
            }
            return(upgradedSettings.ToArray());
        }