protected override void InternalValidate()
        {
            base.InternalValidate();
            if (this.IsDefaultAutoGroupPolicyTag && this.IsDefaultModeratedRecipientsPolicyTag)
            {
                base.WriteError(new ArgumentException(Strings.ErrorMultipleDefaultRetentionPolicyTag), ErrorCategory.InvalidArgument, this.DataObject.Identity);
            }
            if (this.IsDefaultAutoGroupPolicyTag)
            {
                this.DataObject.IsDefaultAutoGroupPolicyTag = true;
                this.existingDefaultPolicyTags = ApprovalUtils.GetDefaultRetentionPolicyTag((IConfigurationSession)base.DataSession, ApprovalApplicationId.AutoGroup, int.MaxValue);
            }
            else if (this.IsDefaultModeratedRecipientsPolicyTag)
            {
                this.DataObject.IsDefaultModeratedRecipientsPolicyTag = true;
                this.existingDefaultPolicyTags = ApprovalUtils.GetDefaultRetentionPolicyTag((IConfigurationSession)base.DataSession, ApprovalApplicationId.ModeratedRecipient, int.MaxValue);
            }
            if (base.ParameterSetName == "UpgradeManagedFolder" && this.ElcFolderToUpgrade == null)
            {
                return;
            }
            if (Datacenter.IsMicrosoftHostedOnly(false))
            {
                List <RetentionPolicyTag> allRetentionTags = AdTagReader.GetAllRetentionTags(this.ConfigurationSession, base.OrganizationId);
                if (allRetentionTags.Count >= 500)
                {
                    base.WriteError(new RetentionPolicyTagTaskException(Strings.ErrorTenantRetentionTagLimitReached(500)), ErrorCategory.InvalidOperation, this.DataObject);
                }
            }
            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.contentSettingsObject.MessageClass.Equals(ElcMessageClass.AllMailboxContent))
            {
                base.WriteError(new RetentionPolicyTagTaskException(Strings.ErrorOnlyDefaultTagAllowCustomizedMessageClass), ErrorCategory.InvalidOperation, this.DataObject);
            }
            string tagName;

            if (this.DataObject.RetentionId != Guid.Empty && !(base.DataSession as IConfigurationSession).CheckForRetentionTagWithConflictingRetentionId(this.DataObject.RetentionId, out tagName))
            {
                base.WriteError(new RetentionPolicyTagTaskException(Strings.ErrorRetentionIdConflictsWithRetentionTag(this.DataObject.RetentionId.ToString(), tagName)), ErrorCategory.InvalidOperation, this.DataObject);
            }
            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);
                }
            }
        }
Example #2
0
        private void StampModeratedTransportExpiry()
        {
            byte[]            policyTag         = null;
            string            text              = string.Empty;
            int               retentionPeriod   = 2;
            ADOperationResult adoperationResult = ADNotificationAdapter.TryRunADOperation(delegate()
            {
                IConfigurationSession tenantOrTopologyConfigurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromOrganizationIdWithoutRbacScopesServiceOnly(this.mbxTransportMailItem.OrganizationId), 361, "StampModeratedTransportExpiry", "f:\\15.00.1497\\sources\\dev\\MailboxTransport\\src\\MailboxTransportDelivery\\StoreDriver\\agents\\approval\\ApprovalEngine.cs");
                ADObjectId descendantId = tenantOrTopologyConfigurationSession.GetOrgContainerId().GetDescendantId(ApprovalApplication.ParentPathInternal);
                ADObjectId childId      = descendantId.GetChildId("ModeratedRecipients");
                ApprovalEngine.diag.TraceDebug <ADObjectId>((long)this.GetHashCode(), "Reading ModeratedRecipient app from {0}", childId);
                if (childId != null)
                {
                    ApprovalApplication approvalApplication = tenantOrTopologyConfigurationSession.Read <ApprovalApplication>(childId);
                    if (approvalApplication != null)
                    {
                        ADObjectId elcretentionPolicyTag = approvalApplication.ELCRetentionPolicyTag;
                        ApprovalEngine.diag.TraceDebug <ADObjectId>((long)this.GetHashCode(), "Read ModeratedRecipient, now reading Recipient Policy Tag {0}", elcretentionPolicyTag);
                        RetentionPolicyTag retentionPolicyTag = null;
                        if (elcretentionPolicyTag != null)
                        {
                            retentionPolicyTag = tenantOrTopologyConfigurationSession.Read <RetentionPolicyTag>(elcretentionPolicyTag);
                        }
                        else
                        {
                            IConfigurationSession configurationSession = SharedConfiguration.CreateScopedToSharedConfigADSession(this.mbxTransportMailItem.OrganizationId);
                            if (configurationSession != null)
                            {
                                IList <RetentionPolicyTag> defaultRetentionPolicyTag = ApprovalUtils.GetDefaultRetentionPolicyTag(configurationSession, ApprovalApplicationId.ModeratedRecipient, 1);
                                if (defaultRetentionPolicyTag != null && defaultRetentionPolicyTag.Count > 0)
                                {
                                    retentionPolicyTag = defaultRetentionPolicyTag[0];
                                }
                            }
                        }
                        if (retentionPolicyTag != null)
                        {
                            ADPagedReader <ElcContentSettings> elccontentSettings = retentionPolicyTag.GetELCContentSettings();
                            using (IEnumerator <ElcContentSettings> enumerator = elccontentSettings.GetEnumerator())
                            {
                                if (enumerator.MoveNext())
                                {
                                    ElcContentSettings elcContentSettings = enumerator.Current;
                                    retentionPeriod = (int)elcContentSettings.AgeLimitForRetention.Value.TotalDays;
                                }
                            }
                            policyTag = retentionPolicyTag.RetentionId.ToByteArray();
                        }
                    }
                }
            });

            if (!adoperationResult.Succeeded)
            {
                if (adoperationResult.Exception is TransientException)
                {
                    throw adoperationResult.Exception;
                }
                text = adoperationResult.Exception.ToString();
                ApprovalEngine.diag.TraceError <string>((long)this.GetHashCode(), "Can't get PolicyTag guid {0}, NDRing.", text);
            }
            if (policyTag == null)
            {
                ApprovalEngine.diag.TraceError((long)this.GetHashCode(), "PolicyTag not read. NDRing");
                string text2 = this.mbxTransportMailItem.OrganizationId.ToString();
                StoreDriverDeliveryDiagnostics.LogEvent(MailboxTransportEventLogConstants.Tuple_ApprovalCannotStampExpiry, text2, new object[]
                {
                    text2,
                    text
                });
                throw new SmtpResponseException(AckReason.ApprovalCannotReadExpiryPolicy);
            }
            if (retentionPeriod < 2)
            {
                retentionPeriod = 2;
            }
            else if (retentionPeriod > 30)
            {
                retentionPeriod = 30;
            }
            this.messageItem[ItemSchema.RetentionDate]          = ExDateTime.UtcNow.AddDays((double)retentionPeriod);
            this.messageItem[StoreObjectSchema.RetentionPeriod] = retentionPeriod;
            this.messageItem[StoreObjectSchema.PolicyTag]       = policyTag;
        }
        protected string SubmitApprovalRequest(string command)
        {
            if (this.DataObject.ArbitrationMailbox == null)
            {
                base.WriteError(new RecipientTaskException(Strings.ErrorArbitrationMailboxNotSet(this.Identity.ToString())), ErrorCategory.InvalidArgument, this.Identity);
            }
            ADRecipient adrecipient = (ADRecipient)base.GetDataObject <ADRecipient>(new MailboxIdParameter(this.DataObject.ArbitrationMailbox), base.TenantGlobalCatalogSession, null, new LocalizedString?(Strings.ErrorMailboxNotFound(this.DataObject.ArbitrationMailbox.ToString())), new LocalizedString?(Strings.ErrorMailboxNotUnique(this.DataObject.ArbitrationMailbox.ToString())));

            if (adrecipient.RecipientTypeDetails != RecipientTypeDetails.ArbitrationMailbox)
            {
                base.WriteError(new RecipientTaskException(Strings.ErrorInvalidArbitrationMbxType(adrecipient.Identity.ToString())), ErrorCategory.InvalidData, this.DataObject.Identity);
            }
            if (!adrecipient.IsValid)
            {
                base.WriteError(new RecipientTaskException(Strings.ErrorInvalidArbitrationMailbox(adrecipient.Identity.ToString())), ErrorCategory.InvalidData, this.DataObject.Identity);
            }
            QueryFilter filter = new AndFilter(new QueryFilter[]
            {
                new ComparisonFilter(ComparisonOperator.Equal, ApprovalApplicationSchema.ArbitrationMailboxesBacklink, adrecipient.Id),
                new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.Name, "AutoGroup")
            });

            ApprovalApplication[] array = this.ConfigurationSession.Find <ApprovalApplication>(null, QueryScope.SubTree, filter, null, 1);
            if (array == null || array.Length == 0)
            {
                base.WriteError(new RecipientTaskException(Strings.ErrorNoAutoGroupApprovalApplicationInOrg(adrecipient.OrganizationId.ToString())), ErrorCategory.InvalidData, null);
            }
            Guid policyTag       = Guid.Empty;
            int? retentionPeriod = null;
            RetentionPolicyTag retentionPolicyTag = null;

            if (array[0].ELCRetentionPolicyTag != null)
            {
                this.ConfigurationSession.SessionSettings.IsSharedConfigChecked = true;
                retentionPolicyTag = this.ConfigurationSession.Read <RetentionPolicyTag>(array[0].ELCRetentionPolicyTag);
            }
            else
            {
                IConfigurationSession configurationSession = SharedConfiguration.CreateScopedToSharedConfigADSession(adrecipient.OrganizationId);
                if (configurationSession != null)
                {
                    IList <RetentionPolicyTag> defaultRetentionPolicyTag = ApprovalUtils.GetDefaultRetentionPolicyTag(configurationSession, ApprovalApplicationId.AutoGroup, 1);
                    if (defaultRetentionPolicyTag != null && defaultRetentionPolicyTag.Count > 0)
                    {
                        retentionPolicyTag = defaultRetentionPolicyTag[0];
                    }
                }
            }
            if (retentionPolicyTag == null)
            {
                this.WriteWarning(Strings.WarningRetentionPolicyTagNotFoundForApproval(array[0].Name, adrecipient.OrganizationId.ToString()));
            }
            else
            {
                policyTag = retentionPolicyTag.RetentionId;
                EnhancedTimeSpan?timeSpanForRetention = retentionPolicyTag.TimeSpanForRetention;
                retentionPeriod = ((timeSpanForRetention != null) ? new int?((int)timeSpanForRetention.Value.TotalDays) : null);
            }
            Result <ADRawEntry>[] array2 = base.TenantGlobalCatalogSession.ReadMultiple(this.DataObject.ManagedBy.ToArray(), new PropertyDefinition[]
            {
                ADObjectSchema.Id,
                ADRecipientSchema.PrimarySmtpAddress,
                ADUserSchema.Languages,
                ADRecipientSchema.RecipientTypeDetails
            });
            ADRawEntry[] array3 = new ADRawEntry[array2.Length];
            for (int i = 0; i < array3.Length; i++)
            {
                array3[i] = array2[i].Data;
            }
            SmtpAddress[] array4 = (from approver in array3
                                    where (RecipientTypeDetails)approver[ADRecipientSchema.RecipientTypeDetails] != RecipientTypeDetails.MailUniversalSecurityGroup && (RecipientTypeDetails)approver[ADRecipientSchema.RecipientTypeDetails] != RecipientTypeDetails.UniversalSecurityGroup
                                    select(SmtpAddress) approver[ADRecipientSchema.PrimarySmtpAddress]).ToArray <SmtpAddress>();
            if (array4.Length == 0)
            {
                base.WriteError(new RecipientTaskException(Strings.ErrorApproversNotSet(this.Identity.ToString())), ErrorCategory.InvalidArgument, this.Identity);
            }
            base.WriteVerbose(Strings.VerboseStartToSubmitApprovalRequest(this.DataObject.DisplayName, string.Join <SmtpAddress>(", ", array4)));
            CultureInfo moderatorCommonCulture = this.SelectApproverCommonCulture(array3);
            string      text = ApprovalProcessor.SubmitRequest(0, adrecipient.PrimarySmtpAddress, this.requester.PrimarySmtpAddress, array4, moderatorCommonCulture, policyTag, retentionPeriod, this.ApprovalMessageSubject(), AutoGroupApplication.BuildApprovalData(command, this.DataObject.Id));

            base.WriteVerbose(Strings.VerboseApprovalRequestSubmitted(this.DataObject.DisplayName, text));
            return(text);
        }