Exemplo n.º 1
0
		protected override void StampChangesOn(IConfigurable dataObject)
		{
			ADUser aduser = (ADUser)dataObject;
			this.originalForwardingAddress = aduser.ForwardingAddress;
			this.originalForwardingSmtpAddress = aduser.ForwardingSmtpAddress;
			Mailbox mailbox = (Mailbox)this.GetDynamicParameters();
			bool flag = aduser.IsResource;
			if (this.ApplyMandatoryProperties.IsPresent)
			{
				this.VerifyMandatoryPropertiesAppliable(aduser);
				SetMailboxBase<TIdentity, TPublicObject>.StampMailboxTypeDetails(aduser, this.needApplyMandatoryProperties);
			}
			this.needChangeMailboxSubtype = base.Fields.IsModified("Type");
			if (this.needChangeMailboxSubtype)
			{
				this.originalRecipientTypeDetails = aduser.RecipientTypeDetails;
				this.targetRecipientTypeDetails = (RecipientTypeDetails)this.Type;
				this.needChangeMailboxSubtype = (this.originalRecipientTypeDetails != this.targetRecipientTypeDetails);
				if (!this.needChangeMailboxSubtype)
				{
					TIdentity identity = this.Identity;
					this.WriteWarning(Strings.WarningNoNeedToConvertMailboxType(identity.ToString(), this.Type.ToString()));
				}
				else
				{
					if (!Enum.IsDefined(typeof(ConvertibleMailboxSubType), (long)this.originalRecipientTypeDetails) || !Enum.IsDefined(typeof(ConvertibleMailboxSubType), (long)this.targetRecipientTypeDetails))
					{
						TIdentity identity2 = this.Identity;
						base.WriteError(new TaskInvalidOperationException(Strings.ErrorInvalidMailboxTypeConversion(identity2.ToString(), this.originalRecipientTypeDetails.ToString(), this.targetRecipientTypeDetails.ToString())), ExchangeErrorCategory.Client, aduser.Id);
					}
					RecipientTypeDetails recipientTypeDetails = this.targetRecipientTypeDetails;
					if (recipientTypeDetails <= RecipientTypeDetails.SharedMailbox)
					{
						if (recipientTypeDetails != RecipientTypeDetails.UserMailbox)
						{
							if (recipientTypeDetails == RecipientTypeDetails.SharedMailbox)
							{
								aduser.UserAccountControl |= UserAccountControlFlags.AccountDisabled;
								TPublicObject instance = this.Instance;
								instance[MailboxSchema.MasterAccountSid] = new SecurityIdentifier(WellKnownSidType.SelfSid, null);
								TPublicObject instance2 = this.Instance;
								instance2[MailboxSchema.ResourceType] = null;
								TPublicObject instance3 = this.Instance;
								instance3.ResourceCapacity = null;
								flag = false;
							}
						}
						else
						{
							aduser.UserAccountControl &= ~UserAccountControlFlags.AccountDisabled;
							aduser.UserAccountControl |= UserAccountControlFlags.NormalAccount;
							TPublicObject instance4 = this.Instance;
							instance4[MailboxSchema.MasterAccountSid] = null;
							TPublicObject instance5 = this.Instance;
							instance5[MailboxSchema.ResourceType] = null;
							TPublicObject instance6 = this.Instance;
							instance6.ResourceCapacity = null;
							flag = false;
						}
					}
					else if (recipientTypeDetails != RecipientTypeDetails.RoomMailbox)
					{
						if (recipientTypeDetails == RecipientTypeDetails.EquipmentMailbox)
						{
							aduser.UserAccountControl |= UserAccountControlFlags.AccountDisabled;
							TPublicObject instance7 = this.Instance;
							instance7[MailboxSchema.MasterAccountSid] = new SecurityIdentifier(WellKnownSidType.SelfSid, null);
							TPublicObject instance8 = this.Instance;
							instance8[MailboxSchema.ResourceType] = ExchangeResourceType.Equipment;
							TPublicObject instance9 = this.Instance;
							instance9.ResourceCapacity = mailbox.ResourceCapacity;
							flag = true;
						}
					}
					else
					{
						aduser.UserAccountControl |= UserAccountControlFlags.AccountDisabled;
						TPublicObject instance10 = this.Instance;
						instance10[MailboxSchema.MasterAccountSid] = new SecurityIdentifier(WellKnownSidType.SelfSid, null);
						TPublicObject instance11 = this.Instance;
						instance11[MailboxSchema.ResourceType] = ExchangeResourceType.Room;
						TPublicObject instance12 = this.Instance;
						instance12.ResourceCapacity = mailbox.ResourceCapacity;
						flag = true;
					}
					TPublicObject instance13 = this.Instance;
					instance13[ADRecipientSchema.RecipientTypeDetails] = this.targetRecipientTypeDetails;
				}
			}
			if (!this.needChangeMailboxSubtype)
			{
				if (!flag)
				{
					TPublicObject instance14 = this.Instance;
					if (!instance14.IsModified(ADRecipientSchema.ResourceMetaData))
					{
						TPublicObject instance15 = this.Instance;
						if (!instance15.IsModified(ADRecipientSchema.ResourceSearchProperties))
						{
							TPublicObject instance16 = this.Instance;
							if (!instance16.IsModified(ADRecipientSchema.ResourcePropertiesDisplay))
							{
								TPublicObject instance17 = this.Instance;
								if (!instance17.IsModified(ADRecipientSchema.ResourceType))
								{
									TPublicObject instance18 = this.Instance;
									if (!instance18.IsModified(ADRecipientSchema.ResourceCustom))
									{
										TPublicObject instance19 = this.Instance;
										if (!instance19.IsModified(ADRecipientSchema.ResourceCapacity))
										{
											goto IL_46A;
										}
									}
								}
							}
						}
					}
					base.WriteError(new TaskInvalidOperationException(Strings.ErrorCannotChangeResourceProperties), ExchangeErrorCategory.Client, aduser);
				}
				IL_46A:
				if (!aduser.IsLinked)
				{
					TPublicObject instance20 = this.Instance;
					if (instance20.IsModified(ADRecipientSchema.MasterAccountSid) && aduser.RecipientTypeDetails != RecipientTypeDetails.RoomMailbox)
					{
						base.WriteError(new TaskInvalidOperationException(Strings.ErrorCannotChangeLinkedProperty), ExchangeErrorCategory.Client, aduser);
					}
				}
			}
			if (base.Fields.IsModified(ADRecipientSchema.MailboxPlan) || (base.Fields.IsModified("SKUCapability") && aduser.RecipientTypeDetails != RecipientTypeDetails.MailboxPlan))
			{
				if (base.Fields.IsModified(ADRecipientSchema.MailboxPlan) && this.MailboxPlan == null)
				{
					if (aduser.OrganizationId != null && !aduser.OrganizationId.Equals(OrganizationId.ForestWideOrgId))
					{
						base.WriteError(new TaskInvalidOperationException(Strings.ErrorCannotUnlinkMailboxPlanForTenant), ExchangeErrorCategory.Client, aduser);
					}
				}
				else
				{
					ADUser aduser2 = null;
					if (base.Fields.IsModified(ADRecipientSchema.MailboxPlan))
					{
						ADObjectId adobjectId = (ADObjectId)mailbox[ADRecipientSchema.MailboxPlan];
						if (!adobjectId.Equals(aduser.MailboxPlan))
						{
							aduser2 = (ADUser)base.GetDataObject<ADUser>(new MailboxPlanIdParameter(adobjectId), base.TenantGlobalCatalogSession, null, new LocalizedString?(Strings.ErrorMailboxPlanNotFound(this.MailboxPlan.ToString())), new LocalizedString?(Strings.ErrorMailboxPlanNotUnique(this.MailboxPlan.ToString())), ExchangeErrorCategory.Client);
						}
					}
					else if (base.Fields.IsModified("SKUCapability"))
					{
						bool checkCurrentReleasePlanFirst = RecipientTaskHelper.IsOrganizationInPilot(this.ConfigurationSession, aduser.OrganizationId);
						LocalizedString message;
						aduser2 = MailboxTaskHelper.FindMailboxPlanWithSKUCapability(base.SKUCapability, (IRecipientSession)base.DataSession, out message, checkCurrentReleasePlanFirst);
						if (aduser2 == null && aduser.RecipientTypeDetails != RecipientTypeDetails.MailboxPlan)
						{
							base.WriteError(new RecipientTaskException(message), ExchangeErrorCategory.Client, aduser.Id);
						}
					}
					MailboxTaskHelper.UpdateMailboxPlan(aduser, aduser2, (ADObjectId mbxPlanId) => (ADUser)base.GetDataObject<ADUser>(new MailboxPlanIdParameter(mbxPlanId), base.TenantGlobalCatalogSession, null, new LocalizedString?(Strings.ErrorMailboxPlanNotFound(mbxPlanId.ToString())), new LocalizedString?(Strings.ErrorMailboxPlanNotUnique(mbxPlanId.ToString())), ExchangeErrorCategory.Client));
				}
			}
			base.StampChangesOn(dataObject);
			if (this.needChangeMailboxSubtype && flag && mailbox.ResourceCustom.Count != 0)
			{
				aduser.ResourceCustom = mailbox.ResourceCustom;
			}
			bool flag2 = false;
			if (aduser.IsLinked && aduser.RecipientTypeDetails == RecipientTypeDetails.RoomMailbox)
			{
				flag2 = true;
			}
			if (flag && !aduser.IsResource && !flag2)
			{
				base.WriteError(new TaskInvalidOperationException(Strings.ErrorCannotChangeResourceMailboxToUserMailbox(aduser.Identity.ToString())), ExchangeErrorCategory.Client, aduser);
			}
			SetMailboxBase<TIdentity, TPublicObject>.StampMailboxTypeDetails(aduser, this.needApplyMandatoryProperties);
			MailboxTaskHelper.StampMailboxRecipientDisplayType(aduser);
		}