protected override void InternalProcessRecord()
        {
            TaskLogger.LogEnter();
            bool advancedHydrateableObjectsSharedEnabled = this.newServicePlanSettings.Organization.AdvancedHydrateableObjectsSharedEnabled;

            base.InternalCreateSharedConfiguration = (this.oldServicePlanSettings.Organization.ShareableConfigurationEnabled && this.newServicePlanSettings.Organization.ShareableConfigurationEnabled && this.tenantCU.SupportedSharedConfigurations.Count == 0);
            base.InternalIsSharedConfigServicePlan = this.config.IsSharedConfigurationAllowedForServicePlan(this.newServicePlanSettings);
            this.monadConnection.RunspaceProxy.SetVariable("TargetServicePlan", this.newServicePlan);
            this.monadConnection.RunspaceProxy.SetVariable("TargetProgramId", this.targetProgramId);
            this.monadConnection.RunspaceProxy.SetVariable("TargetOfferId", this.targetOfferId);
            if (this.tenantCU.ServicePlan == this.newServicePlan)
            {
                base.WriteVerbose(Strings.VerboseWillSkipUpdateServicePlan(this.Identity.ToString()));
            }
            else if (!ServicePlan.CompareAndCalculateDelta(this.oldServicePlanSettings, this.newServicePlanSettings, this.IsCrossSKUMigration, out this.deltaServicePlanSettings, out this.featuresToApply))
            {
                base.WriteVerbose(Strings.VerboseWillUpgradeServicePlan(this.Identity.ToString(), this.tenantCU.ServicePlan, this.newServicePlan));
                if (advancedHydrateableObjectsSharedEnabled)
                {
                    string text;
                    if (!this.config.TryGetHydratedOfferId(this.targetProgramId, this.targetOfferId, out text))
                    {
                        text = this.targetOfferId;
                    }
                    SharedConfigurationInfo sharedConfigurationInfo = SharedConfigurationInfo.FromInstalledVersion(this.targetProgramId, text);
                    OrganizationId          organizationId          = SharedConfiguration.FindOneSharedConfigurationId(sharedConfigurationInfo, this.tenantCU.OrganizationId.PartitionId);
                    if (organizationId == null)
                    {
                        base.WriteError(new SharedConfigurationValidationException(Strings.ErrorSharedConfigurationNotFound(this.targetProgramId, text, sharedConfigurationInfo.CurrentVersion.ToString())), (ErrorCategory)1000, null);
                    }
                    else
                    {
                        this.monadConnection.RunspaceProxy.SetVariable("TargetSharedConfiguration", organizationId.OrganizationalUnit.Name);
                    }
                }
                if (ManageServicePlanMigrationBase.MailboxPlanConfigurationChanged(this.deltaServicePlanSettings))
                {
                    ManageServicePlanMigrationBase.CopyEnabledMailboxPlanRoleAssignmentFeatures(this.deltaServicePlanSettings, this.newServicePlanSettings);
                }
                this.newServicePlanSettings.Name = "new";
                base.InternalProcessRecord();
                if (this.configOnly)
                {
                    this.WriteWarning(Strings.WarningUpgradeIsNotComplete(this.UpgradePhase.ToString()));
                }
            }
            else
            {
                base.WriteVerbose(Strings.VerboseWillSkipUpdateServicePlan(this.Identity.ToString()));
            }
            TaskLogger.LogExit();
        }
 internal static bool MailboxPlanConfigurationChanged(ServicePlan deltaServicePlan)
 {
     return(ManageServicePlanMigrationBase.FeaturesChanged(deltaServicePlan, FeatureCategory.MailboxPlanConfiguration));
 }
 internal static bool RoleToRoleGroupsAssignmentsChanged(ServicePlan deltaServicePlan)
 {
     return(ManageServicePlanMigrationBase.FeaturesChanged(deltaServicePlan, FeatureCategory.RoleGroupRoleAssignment));
 }
 internal static bool CannedRolesChanged(ServicePlan deltaServicePlan)
 {
     return(ManageServicePlanMigrationBase.FeaturesChanged(deltaServicePlan, FeatureCategory.AdminPermissions) || ManageServicePlanMigrationBase.FeaturesChanged(deltaServicePlan, FeatureCategory.MailboxPlanPermissions));
 }
        protected override void FilterComponents()
        {
            base.FilterComponents();
            if (this.deltaServicePlanSettings != null)
            {
                bool recreateCannedRBACRoles             = ManageServicePlanMigrationBase.CannedRolesChanged(this.deltaServicePlanSettings);
                bool rolesToRoleGroupAssignmentsChange   = ManageServicePlanMigrationBase.RoleToRoleGroupsAssignmentsChanged(this.deltaServicePlanSettings);
                bool shareableConfigurationEnabledChange = ManageServicePlanMigrationBase.RBACConfigPresenceChanged(this.deltaServicePlanSettings);
                bool createNewMailboxPlanObject          = (this.conservative || ManageServicePlanMigrationBase.MailboxPlanConfigurationChanged(this.deltaServicePlanSettings)) && !this.IsCrossSKUMigration && !base.InternalPilotEnabled;
                foreach (SetupComponentInfo setupComponentInfo in base.ComponentInfoList)
                {
                    setupComponentInfo.Tasks.RemoveAll(delegate(TaskInfo taskInfo)
                    {
                        ServicePlanTaskInfo servicePlanTaskInfo = taskInfo as ServicePlanTaskInfo;
                        if (servicePlanTaskInfo == null)
                        {
                            return(true);
                        }
                        string featureName;
                        switch (featureName = servicePlanTaskInfo.FeatureName)
                        {
                        case "LoadSetupSnapin":
                        case "ServicePlanUpgradeStart":
                        case "PerMBXPlanRoleAssignmentPolicyEnabled":
                        case "PerMBXPlanRetentionPolicyEnabled":
                        case "PerMBXPlanOWAPolicyEnabled":
                        case "MailboxPlans":
                            return(false);

                        case "RecreateCannedRBACRoleGroups":
                            return(!rolesToRoleGroupAssignmentsChange);

                        case "RecreateCannedRBACRoles":
                            return(!recreateCannedRBACRoles && !shareableConfigurationEnabledChange && !rolesToRoleGroupAssignmentsChange);

                        case "RecreateCannedRBACRoleAssignments":
                            return(!rolesToRoleGroupAssignmentsChange && !shareableConfigurationEnabledChange);

                        case "CreateNewMailboxPlanObject":
                            return(!createNewMailboxPlanObject);

                        case "UpdateMailboxes":
                            {
                                bool flag  = this.UpgradePhase >= UpgradePhase.UpdateMailboxes;
                                bool flag2 = createNewMailboxPlanObject || this.IsCrossSKUMigration;
                                return(!flag || !flag2 || !this.includeUserUpdatePhase);
                            }

                        case "CleanupOldMailboxPlan":
                            {
                                bool flag  = this.UpgradePhase == UpgradePhase.Cleanup;
                                bool flag2 = createNewMailboxPlanObject || this.IsCrossSKUMigration;
                                return(!flag || !flag2);
                            }

                        case "ServicePlanUpgradeEnd":
                            return(this.configOnly);
                        }
                        return(!this.featuresToApply.Contains(servicePlanTaskInfo.FeatureName));
                    });
                }
            }
        }
        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();
        }