Example #1
0
 internal AnchorJobProcessorResult InternalProcessEntry(ICacheEntry cacheEntryProxy)
 {
     this.queriedCount         = 0;
     this.tenantUpdatedCount   = 0;
     this.workItemUpdatedCount = 0;
     using (UpgradeHandlerSyncLog upgradeHandlerSyncLog = new UpgradeHandlerSyncLog("UpgradeHandlerSync"))
     {
         foreach (UpgradeRequestTypes upgradeRequestTypes in UpgradeHandlerScheduler.RequestTypes)
         {
             foreach (WorkItemStatus workItemStatus in UpgradeHandlerScheduler.WorkItemStatuses)
             {
                 base.Context.Logger.Log(MigrationEventType.Information, "Querying UpgradeRequestType '{0}' and WorkItemStatus '{1}'", new object[]
                 {
                     upgradeRequestTypes,
                     workItemStatus
                 });
                 WorkItemInfo[] array;
                 try
                 {
                     array = this.QueryWorkItems(workItemStatus, upgradeRequestTypes.ToString());
                 }
                 catch (ErrorQueryingWorkItemException ex)
                 {
                     base.Context.Logger.Log(MigrationEventType.Error, "Error Querying WorkItems of Status: {0} Type: {1} Error: {2}", new object[]
                     {
                         workItemStatus,
                         upgradeRequestTypes,
                         ex.Message
                     });
                     return(AnchorJobProcessorResult.Deleted);
                 }
                 foreach (WorkItemInfo workItemInfo in array)
                 {
                     TenantOrganizationPresentationObjectWrapper tenantOrganizationPresentationObjectWrapper = null;
                     RecipientWrapper recipientWrapper = null;
                     try
                     {
                         if (cacheEntryProxy is CacheEntryProxy)
                         {
                             AnchorJobProcessorResult anchorJobProcessorResult = base.ShouldProcessEntry(((CacheEntryProxy)cacheEntryProxy).CacheEntryBase);
                             if (anchorJobProcessorResult != AnchorJobProcessorResult.Working)
                             {
                                 base.Context.Logger.Log(MigrationEventType.Information, "Returning to anchor service because cacheEntry is '{0}'.", new object[]
                                 {
                                     anchorJobProcessorResult
                                 });
                                 return(anchorJobProcessorResult);
                             }
                         }
                         UpgradeRequestTypes upgradeRequestTypes2 = (UpgradeRequestTypes)Enum.Parse(typeof(UpgradeRequestTypes), workItemInfo.WorkItemType, true);
                         string text  = workItemInfo.Tenant.TenantId.ToString();
                         string text2 = (upgradeRequestTypes2 == UpgradeRequestTypes.PilotUpgrade) ? workItemInfo.PilotUser.PilotUserId.ToString() : null;
                         base.Context.Logger.Log(MigrationEventType.Information, "Processing workitemId '{0}' Type '{1}' Status '{2}' for TenantId '{3}'{4}", new object[]
                         {
                             workItemInfo.WorkItemId,
                             workItemInfo.WorkItemType,
                             workItemInfo.WorkItemStatus.Status,
                             text,
                             (text2 != null) ? (" PilotUserId '" + text2 + "'") : string.Empty
                         });
                         tenantOrganizationPresentationObjectWrapper = this.orgOperationProxy.GetOrganization(text);
                         base.Context.Logger.Log(MigrationEventType.Information, "Found organization '{0}' ('{1}') with UpgradeRequest '{2}' UpgradeStatus '{3}'", new object[]
                         {
                             text,
                             tenantOrganizationPresentationObjectWrapper.Name,
                             tenantOrganizationPresentationObjectWrapper.UpgradeRequest,
                             tenantOrganizationPresentationObjectWrapper.UpgradeStatus
                         });
                         if (tenantOrganizationPresentationObjectWrapper.UpgradeStatus == UpgradeStatusTypes.Error)
                         {
                             this.UpdateWIStatus(workItemInfo, WorkItemStatus.Error, tenantOrganizationPresentationObjectWrapper.UpgradeMessage);
                         }
                         else
                         {
                             if (tenantOrganizationPresentationObjectWrapper.AdminDisplayVersion.ExchangeBuild.Major != ExchangeObjectVersion.Exchange2012.ExchangeBuild.Major && (tenantOrganizationPresentationObjectWrapper.AdminDisplayVersion.ExchangeBuild.Major != ExchangeObjectVersion.Exchange2010.ExchangeBuild.Major || tenantOrganizationPresentationObjectWrapper.AdminDisplayVersion.ExchangeBuild.Minor < 16))
                             {
                                 throw new InvalidOrganizationVersionException(text, tenantOrganizationPresentationObjectWrapper.AdminDisplayVersion);
                             }
                             if (tenantOrganizationPresentationObjectWrapper.UpgradeRequest == UpgradeRequestTypes.TenantUpgradeDryRun)
                             {
                                 throw new OrganizationInDryRunModeException(text, workItemInfo.WorkItemType);
                             }
                             if (upgradeRequestTypes2 != UpgradeRequestTypes.CancelPrestageUpgrade)
                             {
                                 TenantData tenantData = new TenantData(text);
                                 tenantData.UpdateFromTenant(tenantOrganizationPresentationObjectWrapper);
                                 if (tenantData.Constraints != null && tenantData.Constraints.Length > 0)
                                 {
                                     throw new OrganizationHasConstraintsException(upgradeRequestTypes2, text, tenantOrganizationPresentationObjectWrapper.Name, string.Join(",", tenantData.Constraints));
                                 }
                             }
                             RecipientWrapper recipientWrapper2 = null;
                             if (!this.orgOperationProxy.TryGetAnchorMailbox(text, out recipientWrapper2))
                             {
                                 base.Context.Logger.Log(MigrationEventType.Information, "AnchorMailbox for '{0}' not found. Need to create it.", new object[]
                                 {
                                     tenantOrganizationPresentationObjectWrapper.Name
                                 });
                                 this.orgOperationProxy.CreateAnchorMailbox(tenantOrganizationPresentationObjectWrapper.Name);
                             }
                             else if (!recipientWrapper2.PersistedCapabilities.Contains(Capability.OrganizationCapabilityTenantUpgrade))
                             {
                                 base.Context.Logger.Log(MigrationEventType.Information, "Anchor mbx for organization '{0}' exists, but need to set TenantUpgrade capability", new object[]
                                 {
                                     text
                                 });
                                 this.orgOperationProxy.SetTenantUpgradeCapability(recipientWrapper2.Identity, true);
                             }
                             WorkItemStatus newStatus = WorkItemStatus.InProgress;
                             string         comment   = string.Empty;
                             if (upgradeRequestTypes2 == UpgradeRequestTypes.PilotUpgrade && tenantOrganizationPresentationObjectWrapper.UpgradeRequest != UpgradeRequestTypes.TenantUpgrade)
                             {
                                 recipientWrapper = this.orgOperationProxy.GetUser(text, text2);
                                 if (recipientWrapper.RecipientType != RecipientType.UserMailbox)
                                 {
                                     string text3 = string.Format("Pilot user '{0}' cannot be piloted because it is of type '{1}' instead of 'UserMailbox', completing WI", text2, recipientWrapper.RecipientType.ToString());
                                     base.Context.Logger.Log(MigrationEventType.Information, text3, new object[0]);
                                     this.orgOperationProxy.SetUser(recipientWrapper, UpgradeStatusTypes.Complete, UpgradeRequestTypes.PilotUpgrade, text3, string.Empty, new UpgradeStage?(UpgradeStage.SyncedWorkItem));
                                 }
                                 if (recipientWrapper.UpgradeRequest != UpgradeRequestTypes.PilotUpgrade)
                                 {
                                     base.Context.Logger.Log(MigrationEventType.Information, "PilotUpgrade. initializing user '{0}' to PilotUpgrade InProgress", new object[]
                                     {
                                         text2
                                     });
                                     this.orgOperationProxy.SetUser(recipientWrapper, UpgradeStatusTypes.InProgress, UpgradeRequestTypes.PilotUpgrade, string.Empty, string.Empty, new UpgradeStage?(UpgradeStage.SyncedWorkItem));
                                     upgradeHandlerSyncLog.Write(tenantOrganizationPresentationObjectWrapper, recipientWrapper, string.Empty, string.Empty);
                                 }
                                 else
                                 {
                                     if (!Enum.TryParse <WorkItemStatus>(recipientWrapper.UpgradeStatus.ToString(), out newStatus))
                                     {
                                         throw new InvalidUpgradeStatusException(recipientWrapper.Id.ToString(), recipientWrapper.UpgradeStatus);
                                     }
                                     comment = recipientWrapper.UpgradeMessage;
                                 }
                                 this.UpdateWIStatus(workItemInfo, newStatus, comment);
                             }
                             else
                             {
                                 if (upgradeRequestTypes2 != UpgradeRequestTypes.TenantUpgrade && ((upgradeRequestTypes2 != UpgradeRequestTypes.PrestageUpgrade && upgradeRequestTypes2 != UpgradeRequestTypes.CancelPrestageUpgrade) || tenantOrganizationPresentationObjectWrapper.UpgradeRequest == UpgradeRequestTypes.TenantUpgrade))
                                 {
                                     throw new InvalidRequestedTypeException(text, tenantOrganizationPresentationObjectWrapper.UpgradeRequest, workItemInfo.WorkItemType);
                                 }
                                 if (upgradeRequestTypes2 != tenantOrganizationPresentationObjectWrapper.UpgradeRequest)
                                 {
                                     base.Context.Logger.Log(MigrationEventType.Information, "Changing organization '{0}' from '{1}','{2}' to '{3}','InProgress'", new object[]
                                     {
                                         text,
                                         tenantOrganizationPresentationObjectWrapper.UpgradeRequest,
                                         tenantOrganizationPresentationObjectWrapper.UpgradeStatus,
                                         upgradeRequestTypes2
                                     });
                                     this.SetOrganization(tenantOrganizationPresentationObjectWrapper, UpgradeStatusTypes.InProgress, upgradeRequestTypes2, UpgradeStage.SyncedWorkItem);
                                     upgradeHandlerSyncLog.Write(tenantOrganizationPresentationObjectWrapper, null, string.Empty, string.Empty);
                                 }
                                 else
                                 {
                                     if (tenantOrganizationPresentationObjectWrapper.UpgradeStatus == UpgradeStatusTypes.Complete || tenantOrganizationPresentationObjectWrapper.UpgradeStatus == UpgradeStatusTypes.ForceComplete)
                                     {
                                         base.Context.Logger.Log(MigrationEventType.Information, "organization '{0}' has UpgradeStatus '{1}'. Removing Upgrade capability", new object[]
                                         {
                                             text,
                                             tenantOrganizationPresentationObjectWrapper.UpgradeStatus
                                         });
                                         this.orgOperationProxy.SetTenantUpgradeCapability(recipientWrapper2.Identity, false);
                                     }
                                     if (!Enum.TryParse <WorkItemStatus>(tenantOrganizationPresentationObjectWrapper.UpgradeStatus.ToString(), out newStatus))
                                     {
                                         throw new InvalidUpgradeStatusException(text, tenantOrganizationPresentationObjectWrapper.UpgradeStatus);
                                     }
                                     comment = tenantOrganizationPresentationObjectWrapper.UpgradeMessage;
                                 }
                                 this.UpdateWIStatus(workItemInfo, newStatus, comment);
                             }
                         }
                     }
                     catch (Exception ex2)
                     {
                         base.Context.Logger.Log(MigrationEventType.Error, "Processing workitem id '{0}' failed due to: {1}", new object[]
                         {
                             workItemInfo.WorkItemId,
                             ex2.ToString()
                         });
                         upgradeHandlerSyncLog.Write(tenantOrganizationPresentationObjectWrapper, recipientWrapper, ex2.GetType().ToString(), ex2.Message);
                         try
                         {
                             this.UpdateWIStatus(workItemInfo, (ex2 is MigrationTransientException) ? WorkItemStatus.Warning : WorkItemStatus.Error, ex2.Message);
                         }
                         catch (Exception ex3)
                         {
                             base.Context.Logger.Log(MigrationEventType.Error, "Could not report exception for workitemId '{0}' due to: {1}", new object[]
                             {
                                 workItemInfo.WorkItemId,
                                 ex3
                             });
                             upgradeHandlerSyncLog.Write(tenantOrganizationPresentationObjectWrapper, recipientWrapper, ex3.GetType().ToString(), ex3.Message);
                         }
                         try
                         {
                             if (recipientWrapper != null && recipientWrapper.UpgradeStatus != UpgradeStatusTypes.Warning && recipientWrapper.UpgradeStatus != UpgradeStatusTypes.Error)
                             {
                                 this.orgOperationProxy.SetUser(recipientWrapper, UpgradeStatusTypes.Warning, recipientWrapper.UpgradeRequest, ex2.Message, ex2.ToString(), recipientWrapper.UpgradeStage);
                             }
                             else if (tenantOrganizationPresentationObjectWrapper != null && tenantOrganizationPresentationObjectWrapper.UpgradeStatus != UpgradeStatusTypes.Warning && tenantOrganizationPresentationObjectWrapper.UpgradeStatus != UpgradeStatusTypes.Error)
                             {
                                 this.orgOperationProxy.SetOrganization(tenantOrganizationPresentationObjectWrapper, UpgradeStatusTypes.Warning, tenantOrganizationPresentationObjectWrapper.UpgradeRequest, ex2.Message, ex2.ToString(), tenantOrganizationPresentationObjectWrapper.UpgradeStage, -1, -1);
                             }
                         }
                         catch (Exception ex4)
                         {
                             base.Context.Logger.Log(MigrationEventType.Error, "Could not report exception for workitemId '{0}' for '{1}' due to: {2}", new object[]
                             {
                                 workItemInfo.WorkItemId,
                                 (recipientWrapper != null) ? recipientWrapper.ToString() : tenantOrganizationPresentationObjectWrapper.ToString(),
                                 ex4
                             });
                             upgradeHandlerSyncLog.Write(tenantOrganizationPresentationObjectWrapper, recipientWrapper, ex4.GetType().ToString(), ex4.Message);
                         }
                         if (!(ex2 is LocalizedException))
                         {
                             throw;
                         }
                     }
                 }
             }
         }
     }
     base.Context.Logger.Log(MigrationEventType.Information, "Total WorkItems Queried: {0} Total Tenants Updated: {1} Total WorkItems Updated: {2}", new object[]
     {
         this.queriedCount,
         this.tenantUpdatedCount,
         this.workItemUpdatedCount
     });
     return(AnchorJobProcessorResult.Deleted);
 }