Beispiel #1
0
 internal static void ValidateReadMatchesPatternsPredicate(Pattern[] patterns, bool useLegacyRegex, string name, List <ValidationError> errors)
 {
     if (patterns == null || patterns.Length == 0)
     {
         errors.Add(new RulePhrase.RulePhraseValidationError(RulesTasksStrings.ArgumentNotSet, name));
         return;
     }
     foreach (Pattern pattern in patterns)
     {
         string value = pattern.Value;
         if (!string.IsNullOrEmpty(value))
         {
             int index;
             if (!Utils.CheckIsUnicodeStringWellFormed(value, out index))
             {
                 errors.Add(new RulePhrase.RulePhraseValidationError(RulesTasksStrings.CommentsHaveInvalidChars((int)value[index]), name));
             }
             else
             {
                 try
                 {
                     Pattern.ValidatePattern(value, useLegacyRegex, false);
                 }
                 catch (ValidationArgumentException ex)
                 {
                     LocalizedString description = ValidationError.CombineErrorDescriptions(new List <ValidationError>
                     {
                         new RulePhrase.RulePhraseValidationError(RulesTasksStrings.InvalidRegex(value), name),
                         new RulePhrase.RulePhraseValidationError(ex.LocalizedString, name)
                     });
                     errors.Add(new RulePhrase.RulePhraseValidationError(description, name));
                 }
                 catch (ArgumentException)
                 {
                     errors.Add(new RulePhrase.RulePhraseValidationError(RulesTasksStrings.InvalidRegex(value), name));
                 }
             }
         }
     }
 }
        protected override void InternalValidate()
        {
            TaskLogger.LogEnter();
            Organization orgContainer = base.Session.GetOrgContainer();

            if (OrganizationId.ForestWideOrgId.Equals(orgContainer.OrganizationId) && orgContainer.ObjectVersion < Organization.OrgConfigurationVersion)
            {
                base.WriteError(new InvalidOperationException(Strings.ErrorEnterpriseOrgOutOfDate), (ErrorCategory)1000, null);
            }
            if (this.tenantCU.IsUpdatingServicePlan)
            {
                base.WriteVerbose(Strings.VerbosePendingServicePlanUpgradeDetected(this.Identity.RawIdentity));
            }
            else if (this.tenantCU.OrganizationStatus != OrganizationStatus.Active)
            {
                base.WriteError(new InvalidOperationException(Strings.ErrorTenantOrgInUnexpectedState), (ErrorCategory)1002, null);
            }
            if (string.IsNullOrEmpty(this.tenantCU.ServicePlan))
            {
                base.WriteError(new InvalidOperationException(Strings.ErrorServicePlanIsNotSet), (ErrorCategory)1002, null);
            }
            this.tenantConfigurationSession = this.CreateTenantSession(this.tenantCU.OrganizationId);
            this.tenantFQDN = this.tenantConfigurationSession.GetDefaultAcceptedDomain();
            if (this.tenantFQDN == null)
            {
                throw new ManagementObjectNotFoundException(Strings.ErrorNoDefaultAcceptedDomainFound(this.Identity.ToString()));
            }
            Exception ex = null;

            try
            {
                this.oldServicePlanSettings = this.config.GetServicePlanSettings(this.tenantCU.ServicePlan);
                List <ValidationError> list = new List <ValidationError>();
                list.AddRange(ServicePlan.ValidateFileSchema(this.oldServicePlanSettings.Name));
                list.AddRange(this.oldServicePlanSettings.Validate());
                if (list.Count != 0)
                {
                    base.WriteError(new InvalidOperationException(Strings.ErrorServicePlanInconsistent2(this.tenantCU.ServicePlan, ValidationError.CombineErrorDescriptions(list))), (ErrorCategory)1000, null);
                }
                this.ResolveTargetOffer();
                this.newServicePlan         = this.config.ResolveServicePlanName(this.targetProgramId, this.targetOfferId);
                this.newServicePlanSettings = this.config.GetServicePlanSettings(this.newServicePlan);
                if (!string.IsNullOrEmpty(this.tenantCU.TargetServicePlan) && !this.tenantCU.TargetServicePlan.Equals(this.newServicePlan, StringComparison.OrdinalIgnoreCase))
                {
                    base.WriteError(new InvalidOperationException(Strings.ErrorTargetServicePlanDifferent(this.tenantCU.ServicePlan, this.tenantCU.TargetServicePlan, this.newServicePlan)), (ErrorCategory)1000, null);
                }
                list.Clear();
                list.AddRange(ServicePlan.ValidateFileSchema(this.newServicePlanSettings.Name));
                list.AddRange(this.newServicePlanSettings.Validate());
                if (list.Count != 0)
                {
                    base.WriteError(new InvalidOperationException(Strings.ErrorServicePlanInconsistent(this.newServicePlan, this.targetProgramId, this.targetOfferId, ValidationError.CombineErrorDescriptions(list))), (ErrorCategory)1000, null);
                }
                foreach (ServicePlan.MailboxPlan mailboxPlan in this.oldServicePlanSettings.MailboxPlans)
                {
                    bool flag = false;
                    foreach (ServicePlan.MailboxPlan mailboxPlan2 in this.newServicePlanSettings.MailboxPlans)
                    {
                        if (mailboxPlan.Name == mailboxPlan2.Name && mailboxPlan.MailboxPlanIndex == mailboxPlan2.MailboxPlanIndex)
                        {
                            this.ValidateMailboxPlansCapabilities(mailboxPlan, mailboxPlan2);
                            flag = true;
                            break;
                        }
                    }
                    if (!flag)
                    {
                        if (ManageServicePlanMigrationBase.IsSupportedCrossSKUMigrationScenario(this.tenantCU.ProgramId, this.targetProgramId, this.tenantCU.OfferId, this.targetOfferId))
                        {
                            this.IsCrossSKUMigration = true;
                        }
                        else if (!this.oldServicePlanSettings.Organization.PilotEnabled)
                        {
                            base.WriteError(new InvalidOperationException(Strings.ErrorServicePlanHasNoMatchingMailboxPlan(mailboxPlan.Name)), (ErrorCategory)1000, null);
                        }
                    }
                }
                if (!this.oldServicePlanSettings.Organization.PerMBXPlanRoleAssignmentPolicyEnabled && this.newServicePlanSettings.Organization.PerMBXPlanRoleAssignmentPolicyEnabled)
                {
                    base.WriteError(new InvalidOperationException(Strings.ErrorInvalidServicePlanTransition(this.oldServicePlanSettings.Name, this.newServicePlanSettings.Name, OrganizationSettingsSchema.PerMBXPlanRoleAssignmentPolicyEnabled.Name, this.oldServicePlanSettings.Organization.PerMBXPlanRoleAssignmentPolicyEnabled.ToString(), this.newServicePlanSettings.Organization.PerMBXPlanRoleAssignmentPolicyEnabled.ToString())), (ErrorCategory)1000, null);
                }
                if (this.oldServicePlanSettings.Organization.PerMBXPlanRoleAssignmentPolicyEnabled && this.oldServicePlanSettings.MailboxPlans.Count > 1 && !this.newServicePlanSettings.Organization.PerMBXPlanRoleAssignmentPolicyEnabled)
                {
                    base.WriteError(new InvalidOperationException(Strings.ErrorInvalidServicePlanTransition(this.oldServicePlanSettings.Name, this.newServicePlanSettings.Name, OrganizationSettingsSchema.PerMBXPlanRoleAssignmentPolicyEnabled.Name, this.oldServicePlanSettings.Organization.PerMBXPlanRoleAssignmentPolicyEnabled.ToString(), this.newServicePlanSettings.Organization.PerMBXPlanRoleAssignmentPolicyEnabled.ToString())), (ErrorCategory)1000, null);
                }
                if (this.oldServicePlanSettings.Organization.PerMBXPlanRetentionPolicyEnabled != this.newServicePlanSettings.Organization.PerMBXPlanRetentionPolicyEnabled && this.newServicePlanSettings.MailboxPlans.Count > 1)
                {
                    base.WriteError(new InvalidOperationException(Strings.ErrorInvalidServicePlanTransition(this.oldServicePlanSettings.Name, this.newServicePlanSettings.Name, OrganizationSettingsSchema.PerMBXPlanRetentionPolicyEnabled.Name, this.oldServicePlanSettings.Organization.PerMBXPlanRetentionPolicyEnabled.ToString(), this.newServicePlanSettings.Organization.PerMBXPlanRetentionPolicyEnabled.ToString())), (ErrorCategory)1000, null);
                }
                if (this.oldServicePlanSettings.Organization.PerMBXPlanOWAPolicyEnabled != this.newServicePlanSettings.Organization.PerMBXPlanOWAPolicyEnabled)
                {
                    base.WriteError(new InvalidOperationException(Strings.ErrorInvalidServicePlanTransition(this.oldServicePlanSettings.Name, this.newServicePlanSettings.Name, OrganizationSettingsSchema.PerMBXPlanOWAPolicyEnabled.Name, this.oldServicePlanSettings.Organization.PerMBXPlanOWAPolicyEnabled.ToString(), this.newServicePlanSettings.Organization.PerMBXPlanOWAPolicyEnabled.ToString())), (ErrorCategory)1000, null);
                }
                if (!this.oldServicePlanSettings.Organization.ShareableConfigurationEnabled && this.newServicePlanSettings.Organization.ShareableConfigurationEnabled)
                {
                    base.WriteError(new InvalidOperationException(Strings.ErrorInvalidServicePlanTransition(this.oldServicePlanSettings.Name, this.newServicePlanSettings.Name, OrganizationSettingsSchema.ShareableConfigurationEnabled.Name, this.oldServicePlanSettings.Organization.ShareableConfigurationEnabled.ToString(), this.newServicePlanSettings.Organization.ShareableConfigurationEnabled.ToString())), (ErrorCategory)1000, null);
                }
                if (!this.oldServicePlanSettings.Organization.CommonHydrateableObjectsSharedEnabled && this.newServicePlanSettings.Organization.CommonHydrateableObjectsSharedEnabled)
                {
                    base.WriteError(new InvalidOperationException(Strings.ErrorInvalidServicePlanTransition(this.oldServicePlanSettings.Name, this.newServicePlanSettings.Name, OrganizationSettingsSchema.CommonHydrateableObjectsSharedEnabled.Name, this.oldServicePlanSettings.Organization.CommonHydrateableObjectsSharedEnabled.ToString(), this.newServicePlanSettings.Organization.CommonHydrateableObjectsSharedEnabled.ToString())), (ErrorCategory)1000, null);
                }
                if (!this.oldServicePlanSettings.Organization.AdvancedHydrateableObjectsSharedEnabled && this.newServicePlanSettings.Organization.AdvancedHydrateableObjectsSharedEnabled)
                {
                    base.WriteError(new InvalidOperationException(Strings.ErrorInvalidServicePlanTransition(this.oldServicePlanSettings.Name, this.newServicePlanSettings.Name, OrganizationSettingsSchema.AdvancedHydrateableObjectsSharedEnabled.Name, this.oldServicePlanSettings.Organization.AdvancedHydrateableObjectsSharedEnabled.ToString(), this.newServicePlanSettings.Organization.AdvancedHydrateableObjectsSharedEnabled.ToString())), (ErrorCategory)1000, null);
                }
            }
            catch (ArgumentException ex2)
            {
                ex = ex2;
            }
            catch (IOException ex3)
            {
                ex = ex3;
            }
            if (ex != null)
            {
                base.WriteError(ex, (ErrorCategory)1000, null);
            }
            base.InternalLocalStaticConfigEnabled      = !this.newServicePlanSettings.Organization.AdvancedHydrateableObjectsSharedEnabled;
            base.InternalLocalHydrateableConfigEnabled = !this.newServicePlanSettings.Organization.CommonHydrateableObjectsSharedEnabled;
            base.InternalPilotEnabled = this.newServicePlanSettings.Organization.PilotEnabled;
            TaskLogger.LogExit();
        }
        protected override void InternalBeginProcessing()
        {
            TaskLogger.LogEnter();
            if (this.nameWarning != LocalizedString.Empty)
            {
                this.WriteWarning(this.nameWarning);
            }
            base.InternalBeginProcessing();
            if (this.Administrator != null)
            {
                OrganizationTaskHelper.ValidateParamString("Administrator", this.Administrator.ToString(), new Task.TaskErrorLoggingDelegate(base.WriteError));
            }
            if (this.AdministratorNetID != null)
            {
                OrganizationTaskHelper.ValidateParamString("AdministratorNetID", this.AdministratorNetID.ToString(), new Task.TaskErrorLoggingDelegate(base.WriteError));
            }
            if (this.AdministratorNetID != null && this.Administrator != null && this.Administrator.NetId != null && !this.AdministratorNetID.Equals(this.Administrator.NetId))
            {
                base.WriteError(new RecipientTaskException(Strings.ErrorNetIDValuesDoNotMatch(this.AdministratorNetID.ToString(), this.Administrator.NetId.ToString())), ErrorCategory.InvalidArgument, null);
            }
            if (this.AdministratorNetID != null && this.Administrator == null)
            {
                this.Administrator = new WindowsLiveId(this.AdministratorNetID.ToString());
            }
            if (base.Fields.IsModified("TenantDirSyncServiceInstance") && !string.IsNullOrEmpty(this.DirSyncServiceInstance) && !ServiceInstanceId.IsValidServiceInstanceId(this.DirSyncServiceInstance))
            {
                base.WriteError(new InvalidServiceInstanceIdException(this.DirSyncServiceInstance), ExchangeErrorCategory.Client, null);
            }
            if (this.ServicePlanConfig.IsPilotOffer(this.ProgramId, this.OfferId) && !this.CreateSharedConfiguration)
            {
                base.WriteError(new ArgumentException(Strings.ErrorPilotServicePlanCanBeUsedToCreateSharedOrgsOnly(this.ProgramId, this.OfferId)), (ErrorCategory)1000, null);
            }
            Exception ex   = null;
            string    text = null;

            if (base.Fields["TenantExternalDirectoryOrganizationId"] == null && !this.CreateSharedConfiguration)
            {
                base.Fields["TenantExternalDirectoryOrganizationId"] = Guid.NewGuid();
            }
            try
            {
                bool flag = this.ServicePlanConfig.TryGetHydratedOfferId(this.ProgramId, this.OfferId, out text);
                if (!this.CreateSharedConfiguration && this.Name == null)
                {
                    base.WriteError(new ArgumentException(Strings.ErrorNameNotSet), (ErrorCategory)1000, null);
                }
                this.partition = ((this.AccountPartition != null) ? NewOrganizationTask.ResolvePartitionId(this.AccountPartition, new Task.TaskErrorLoggingDelegate(base.WriteError)) : NewOrganizationTask.ChoosePartition(this.Name, this.CreateSharedConfiguration, new Task.TaskErrorLoggingDelegate(base.WriteError)));
                if (this.CreateSharedConfiguration && flag)
                {
                    this.OfferId         = text;
                    this.shouldCreateSCT = NewOrganizationTask.ShouldCreateSharedConfiguration(this.ProgramId, this.OfferId, this.partition, out this.sctConfigUnit);
                }
                string text2 = this.ServicePlanConfig.ResolveServicePlanName(this.ProgramId, this.OfferId);
                this.servicePlanSettings = this.ServicePlanConfig.GetServicePlanSettings(text2);
                bool flag2 = this.ServicePlanConfig.IsTemplateTenantServicePlan(this.servicePlanSettings);
                if (flag2)
                {
                    this.shouldCreateSCT = NewOrganizationTask.ShouldCreateTenantTemplate(this.ProgramId, this.OfferId, this.partition, out this.sctConfigUnit);
                }
                if (this.CreateSharedConfiguration)
                {
                    if (!this.shouldCreateSCT)
                    {
                        this.WriteWarning(Strings.WarningSharedConfigurationAlreadyExists(this.ProgramId, this.OfferId));
                        return;
                    }
                    if (string.IsNullOrEmpty(this.Name))
                    {
                        this.Name = (flag2 ? TemplateTenantConfiguration.CreateSharedConfigurationName(this.ProgramId, this.OfferId) : SharedConfiguration.CreateSharedConfigurationName(this.ProgramId, this.OfferId));
                    }
                    if (this.DomainName == null)
                    {
                        this.DomainName = (flag2 ? TemplateTenantConfiguration.CreateSharedConfigurationDomainName(this.Name) : SharedConfiguration.CreateSharedConfigurationDomainName(this.Name));
                    }
                }
                OrganizationTaskHelper.ValidateParamString("Name", this.Name, new Task.TaskErrorLoggingDelegate(base.WriteError), true);
                ADOrganizationalUnit adorganizationalUnit = new ADOrganizationalUnit();
                adorganizationalUnit[ADObjectSchema.Name] = this.Name;
                base.InternalIsSharedConfigServicePlan    = this.ServicePlanConfig.IsSharedConfigurationAllowedForServicePlan(this.servicePlanSettings);
                if (this.CreateSharedConfiguration && !base.InternalIsSharedConfigServicePlan && !this.ServicePlanConfig.IsHydratedOffer(text2))
                {
                    base.WriteError(new SharedConfigurationValidationException(Strings.ErrorServicePlanDoesntAllowSharedConfiguration(this.ProgramId, this.OfferId)), (ErrorCategory)1000, null);
                }
                else if (!flag && base.InternalIsSharedConfigServicePlan)
                {
                    text = this.OfferId;
                }
                if (this.CreateSharedConfiguration)
                {
                    base.InternalCreateSharedConfiguration = true;
                }
                else if (!this.CreateSharedConfiguration && base.InternalIsSharedConfigServicePlan)
                {
                    SharedConfigurationInfo sharedConfigurationInfo = SharedConfigurationInfo.FromInstalledVersion(this.ProgramId, text);
                    base.InternalSharedConfigurationId = SharedConfiguration.FindOneSharedConfigurationId(sharedConfigurationInfo, this.partition);
                    if (base.InternalSharedConfigurationId == null)
                    {
                        base.WriteError(new SharedConfigurationValidationException(Strings.ErrorSharedConfigurationNotFound(this.ProgramId, text, sharedConfigurationInfo.CurrentVersion.ToString())), (ErrorCategory)1000, null);
                    }
                    base.InternalCreateSharedConfiguration = false;
                }
                List <ValidationError> list = new List <ValidationError>();
                list.AddRange(ServicePlan.ValidateFileSchema(text2));
                list.AddRange(this.servicePlanSettings.Validate());
                if (list.Count != 0)
                {
                    ex = new ArgumentException(Strings.ErrorServicePlanInconsistent(text2, this.ProgramId, this.OfferId, ValidationError.CombineErrorDescriptions(list)));
                }
            }
            catch (ArgumentException ex2)
            {
                ex = ex2;
            }
            catch (IOException ex3)
            {
                ex = ex3;
            }
            if (ex != null)
            {
                base.WriteError(ex, ErrorCategory.InvalidArgument, null);
            }
            base.InternalLocalStaticConfigEnabled      = (!this.servicePlanSettings.Organization.AdvancedHydrateableObjectsSharedEnabled || this.CreateSharedConfiguration);
            base.InternalLocalHydrateableConfigEnabled = (!this.servicePlanSettings.Organization.CommonHydrateableObjectsSharedEnabled || this.CreateSharedConfiguration);
            TaskLogger.LogExit();
        }