Exemple #1
0
        protected override void InternalValidate()
        {
            MailboxIdParameter mailboxIdParameter = null;

            try
            {
                base.InternalValidate();
            }
            catch (ManagementObjectNotFoundException)
            {
                if (this.Identity == null || !this.TryGetMailboxIdFromIdentity(this.Identity.ToString(), out mailboxIdParameter))
                {
                    throw;
                }
                this.deviceExistsinAD = false;
            }
            if (base.HasErrors)
            {
                return;
            }
            if (MobileDeviceTaskHelper.IsRunningUnderMyOptionsRole(this, base.TenantGlobalCatalogSession, base.SessionSettings))
            {
                ADObjectId adobjectId;
                if (!base.TryGetExecutingUserId(out adobjectId))
                {
                    throw new ExecutingUserPropertyNotFoundException("executingUserid");
                }
                if (!base.DataObject.Id.Parent.Parent.Equals(adobjectId) || (mailboxIdParameter != null && !mailboxIdParameter.Equals(adobjectId)))
                {
                    base.WriteError(new LocalizedException(Strings.ErrorObjectNotFound(this.Identity.ToString())), ErrorCategory.InvalidArgument, null);
                }
            }
            Exception ex = null;

            if (mailboxIdParameter == null)
            {
                mailboxIdParameter = this.Identity.GetMailboxId();
            }
            if (mailboxIdParameter == null && base.DataObject != null)
            {
                this.Identity      = new MobileDeviceIdParameter(base.DataObject);
                mailboxIdParameter = this.Identity.GetMailboxId();
            }
            if (mailboxIdParameter == null)
            {
                base.WriteError(new LocalizedException(Strings.ErrorObjectNotFound(this.Identity.ToString())), ErrorCategory.InvalidArgument, null);
            }
            this.principal = MobileDeviceTaskHelper.GetExchangePrincipal(base.SessionSettings, this.CreateTenantGlobalCatalogSession(base.SessionSettings), mailboxIdParameter, "Remove-MobileDevice", out ex);
            if (ex != null)
            {
                base.WriteError(ex, ErrorCategory.InvalidArgument, null);
            }
            if (DeviceInfo.IsThrottlingLimitsExceeded((IConfigurationSession)base.DataSession, this.principal, out this.activeSyncDevices))
            {
                uint maxDeviceDeleteCount = 0U;
                using (IBudget budget = StandardBudget.Acquire(this.principal.Sid, BudgetType.Eas, this.principal.MailboxInfo.OrganizationId.ToADSessionSettings()))
                {
                    IThrottlingPolicy throttlingPolicy = budget.ThrottlingPolicy;
                    maxDeviceDeleteCount = throttlingPolicy.EasMaxDeviceDeletesPerMonth.Value;
                }
                base.WriteError(new LocalizedException(Strings.MaxDeviceDeletesPerMonthReached(this.activeSyncDevices.ObjectsDeletedThisPeriod, maxDeviceDeleteCount)), ErrorCategory.WriteError, null);
            }
        }