// Token: 0x06000E74 RID: 3700 RVA: 0x000452C4 File Offset: 0x000434C4 public static ADRawEntry FindADRawEntryByPuid(ulong puid, Guid mdbGuid, bool readOnly, IEnumerable <MbxPropertyDefinition> properties) { Guid exchangeGuidFromPuid = ConsumerIdentityHelper.GetExchangeGuidFromPuid(puid); ADObjectId adobjectIdFromPuid = ConsumerIdentityHelper.GetADObjectIdFromPuid(puid); List <ValidationError> errors = new List <ValidationError>(); return(MbxRecipientSession.ReadUserInformationRecord(adobjectIdFromPuid, mdbGuid, exchangeGuidFromPuid, readOnly, properties, errors)); }
private static bool TrySaveChanges(IRecipientSession session, ulong puid, ADPropertyDefinition prop, object addedValue, object removedValue, Action <string> logAction, Action <string> warningLogAction) { if (addedValue != null && removedValue != null) { throw new InvalidOperationException("You must set a value to addedValue or removedValue, not both."); } object obj = addedValue; bool result; try { ADUser aduser = new ADUser(); aduser.SetId(ConsumerIdentityHelper.GetADObjectIdFromPuid(puid)); if (prop.IsMultivalued) { if (addedValue != null) { ((MultiValuedPropertyBase)aduser[prop]).Add(addedValue); } else if (removedValue != null) { ((MultiValuedPropertyBase)aduser[prop]).Remove(removedValue); obj = removedValue; } } else { aduser[prop] = addedValue; } session.Save(aduser); result = true; } catch (Exception ex) { logAction(string.Format("Error writing value. PUID: {0} Property: {1} Value: {2} Error: {3}", new object[] { ConsumerIdentityHelper.GetExchangeGuidFromPuid(puid), prop.Name, obj ?? "<NULL>", ex.ToString() })); warningLogAction(string.Format("Error writing value. PUID: {0} Property: {1} Value: {2} Error: {3}", new object[] { ConsumerIdentityHelper.GetExchangeGuidFromPuid(puid), prop.Name, obj ?? "<NULL>", ex.Message })); result = false; } return(result); }
public static ADUser ReadUser(IRecipientSession session, ulong puid, bool mservOnly) { ADUser result; try { ((IAggregateSession)session).MbxReadMode = (mservOnly ? MbxReadMode.NoMbxRead : MbxReadMode.OnlyIfLocatorDataAvailable); ((IAggregateSession)session).BackendWriteMode = BackendWriteMode.NoWrites; result = session.FindADUserByExternalDirectoryObjectId(ConsumerIdentityHelper.GetExchangeGuidFromPuid(puid).ToString()); } catch (ADDriverStoreAccessPermanentException ex) { if (!(ex.InnerException is MapiExceptionMdbOffline) && !(ex.InnerException is MapiExceptionUserInformationNotFound)) { throw; } ((IAggregateSession)session).MbxReadMode = MbxReadMode.NoMbxRead; ((IAggregateSession)session).BackendWriteMode = BackendWriteMode.NoWrites; result = session.FindADUserByExternalDirectoryObjectId(ConsumerIdentityHelper.GetExchangeGuidFromPuid(puid).ToString()); } return(result); }
public static void CreateOrUpdateConsumerMailbox(WriteOperationType writeOperationType, PropertyBag propertyValuesBag, IRecipientSession session, Action <string> logAction, Action <string> warningLogAction = null) { MbxReadMode mbxReadMode = ((IAggregateSession)session).MbxReadMode; BackendWriteMode backendWriteMode = ((IAggregateSession)session).BackendWriteMode; try { if (logAction == null) { throw new ArgumentNullException("logAction"); } if (warningLogAction == null) { throw new ArgumentNullException("warningLogAction"); } if (!propertyValuesBag.IsModified(ADUserSchema.NetID)) { throw new ArgumentException(string.Format(CultureInfo.CurrentUICulture, "Property 'ADUserSchema.NetID' must be set", new object[0])); } ulong puid = ((NetID)propertyValuesBag[ADUserSchema.NetID]).ToUInt64(); string text = ((NetID)propertyValuesBag[ADUserSchema.NetID]).ToString(); bool flag = propertyValuesBag.IsModified("MakeExoPrimary") && (bool)propertyValuesBag["MakeExoPrimary"]; bool flag2 = propertyValuesBag.IsModified("MakeExoSecondary") && (bool)propertyValuesBag["MakeExoSecondary"]; bool flag3 = propertyValuesBag.IsModified("SkipMigration") && (bool)propertyValuesBag["SkipMigration"]; ADUser aduser = ConsumerMailboxHelper.ReadUser(session, puid, true); if (aduser == null && (writeOperationType == WriteOperationType.Update || writeOperationType == WriteOperationType.RepairUpdate)) { throw new ADNoSuchObjectException(new LocalizedString(string.Format(CultureInfo.CurrentUICulture, "Cannot update object. Mserv entry for PUID: '{0}' not found", new object[] { text }))); } if (aduser != null && writeOperationType == WriteOperationType.Create && !flag2 && (!flag || !flag3)) { throw new ADObjectAlreadyExistsException(new LocalizedString(string.Format(CultureInfo.CurrentUICulture, "Cannot create object. Mserv entry for PUID: '{0}' already exists", new object[] { text }))); } if (aduser != null && aduser.Database != null && propertyValuesBag.IsModified(ADMailboxRecipientSchema.Database) && !aduser.Database.Equals((ADObjectId)propertyValuesBag[ADMailboxRecipientSchema.Database])) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, "Cannot update database of an existing consumer mailbox in EXO. PUID: '{0}' Existing database: {1}", new object[] { text, aduser.Database })); } if (flag && flag2) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, "Cannot set MakeExoPrimary and MakeExoSecondary at the same time. PUID: '{0}'", new object[] { text })); } if (aduser == null) { aduser = new ADUser(); } if (flag) { if (writeOperationType == WriteOperationType.Create && aduser.PrimaryMailboxSource() == PrimaryMailboxSourceType.None) { logAction("Current state: No mserv footprint - i.e. no mailbox in EXO and Hotmail."); logAction("Action requested: MakeExoPrimary: Create a brand new primary consumer mailbox in EXO. "); } else if (writeOperationType == WriteOperationType.RepairCreate && (aduser.PrimaryMailboxSource() == PrimaryMailboxSourceType.None || aduser.PrimaryMailboxSource() == PrimaryMailboxSourceType.Exo)) { logAction("Current state: Either no mserv footprint exists or a primary mailbox exists in EXO."); logAction("Action requested: MakeExoPrimary: Retry creation of primary consumer mailbox in EXO. "); } else if ((writeOperationType == WriteOperationType.Update || writeOperationType == WriteOperationType.RepairUpdate) && aduser.Database != null && aduser.PrimaryMailboxSource() == PrimaryMailboxSourceType.Hotmail) { logAction("Current state: Primary mailbox exists in Hotmail and Secondary mailbox exists in EXO."); logAction("Action requested: MakeExoPrimary: Switch from hotmail to EXO. "); } else { if ((writeOperationType != WriteOperationType.Create && writeOperationType != WriteOperationType.RepairCreate) || aduser.PrimaryMailboxSource() != PrimaryMailboxSourceType.Hotmail || aduser.Database != null || !flag3) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, "Cannot proceed with MakeExoPrimary operation. Invalid state detected. PUID: '{0}' Current primary mailbox source: {1} Write operation type: {2}", new object[] { text, aduser.PrimaryMailboxSource(), writeOperationType })); } logAction("Current state: Primary mailbox exists in Hotmail and no secondary mailbox exists in EXO."); logAction("Action requested: MakeExoPrimary: Switch directly from hotmail to EXO w/o migrating email contents and SkipMigration flag is supplied. "); } } if (flag2) { if (writeOperationType == WriteOperationType.Create && aduser.PrimaryMailboxSource() == PrimaryMailboxSourceType.Hotmail) { logAction("Current state: An existing primary mailbox in Hotmail."); logAction("Action requested: MakeExoSecondary: Create a brand new secondary consumer mailbox in EXO. "); } else { if (writeOperationType != WriteOperationType.RepairCreate || aduser.PrimaryMailboxSource() != PrimaryMailboxSourceType.Hotmail) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, "Invalid state detected. Cannot proceed with MakeExoSecondary operation. A hotmail account must exist for PUID: '{0}'. Current primary mailbox source: {1} Write operation type: {2}", new object[] { text, aduser.PrimaryMailboxSource(), writeOperationType })); } logAction("Current state: An existing primary mailbox in Hotmail with or without a secondary mailbox in EXO."); logAction("Action requested: MakeExoSecondary: Retry creating a brand new secondary consumer mailbox in EXO. "); } propertyValuesBag[ADUserSchema.IsMigratedConsumerMailbox] = true; } if ((flag || flag2) && aduser.Database == null && !propertyValuesBag.IsModified(ADMailboxRecipientSchema.Database)) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, "You must specify Database for creating a new mailbox. PUID: '{0}'", new object[] { text })); } if (!flag && !flag2 && aduser.Database == null) { throw new ADNoSuchObjectException(new LocalizedString(string.Format(CultureInfo.CurrentUICulture, "Cannot perform this operation. No consumer mailbox (primary/secondary) exists for this user in EXO. PUID: '{0}'", new object[] { text }))); } ADRawEntry adrawEntry = new ADRawEntry(); ADObjectId adobjectId = aduser.Database ?? (propertyValuesBag[ADMailboxRecipientSchema.Database] as ADObjectId); if (adobjectId != null && ConsumerMailboxHelper.PopulateStoreOnlyProperties(adrawEntry, puid, propertyValuesBag, true)) { logAction(string.Format("Saving store properties for user - puid: {0}", text)); AggregationHelper.PerformMbxModification(adobjectId.ObjectGuid, ConsumerIdentityHelper.GetExchangeGuidFromPuid(puid), adrawEntry.propertyBag as ADPropertyBag, false); } if (ConsumerMailboxHelper.PopulateMservPuidRecordProperties(aduser, puid, flag, flag2, propertyValuesBag)) { logAction(string.Format("Saving PUID records in Mserv for user - puid: {0}", text)); ((IAggregateSession)session).MbxReadMode = MbxReadMode.NoMbxRead; ((IAggregateSession)session).BackendWriteMode = BackendWriteMode.WriteToMServ; session.Save(aduser); aduser = ConsumerMailboxHelper.ReadUser(session, puid, true); } if (writeOperationType == WriteOperationType.RepairCreate || writeOperationType == WriteOperationType.RepairUpdate) { ((IAggregateSession)session).MbxReadMode = MbxReadMode.NoMbxRead; ((IAggregateSession)session).BackendWriteMode = BackendWriteMode.WriteToMServ; ConsumerMailboxHelper.SaveChangesInRepairMode(session, puid, ConsumerMailboxHelper.MServAliasAndOtherRecordProperties, propertyValuesBag, logAction, warningLogAction); } else if (ConsumerMailboxHelper.PopulateAliasAndOtherRecordProperties(aduser, puid, propertyValuesBag)) { logAction(string.Format("Saving Aliases and other records in Mserv for user - puid: {0}", text)); ((IAggregateSession)session).MbxReadMode = MbxReadMode.NoMbxRead; ((IAggregateSession)session).BackendWriteMode = BackendWriteMode.WriteToMServ; session.Save(aduser); } } finally { ((IAggregateSession)session).MbxReadMode = mbxReadMode; ((IAggregateSession)session).BackendWriteMode = backendWriteMode; } }
private static object ExchangeGuidGetter(IPropertyBag propertyBag) { ulong puid = (ulong)propertyBag[MServRecipientSchema.Puid]; return(ConsumerIdentityHelper.GetExchangeGuidFromPuid(puid)); }
private ADUser GetADUser(ulong puid, string emailAddress) { ADUser result; try { ADUser aduser = ((ADUser)this.tenantRecipientSession.FindByObjectGuid(ConsumerIdentityHelper.GetExchangeGuidFromPuid(puid))) ?? this.tenantRecipientSession.FindByProxyAddress <ADUser>(ProxyAddress.Parse(emailAddress)); FBLPerfCounters.NumberOfSuccessfulMSERVReadRequests.Increment(); result = aduser; } catch (Exception ex) { FBLPerfCounters.NumberOfFailedMSERVReadRequests.Increment(); LoggingUtilities.LogEvent(ClientsEventLogConstants.Tuple_TransientFblErrorReadingMServ, new object[] { ex.InnerException ?? ex }); throw; } return(result); }
private ADRawEntry GetADRawEntry(ulong puid, string emailAddress) { ADRawEntry result; try { List <ADPropertyDefinition> properties = new List <ADPropertyDefinition>(new ADPropertyDefinition[] { ADMailboxRecipientSchema.ExchangeGuid, ADUserSchema.NetID, ADMailboxRecipientSchema.Database, ADUserSchema.PrimaryMailboxSource, ADUserSchema.SatchmoClusterIp, ADUserSchema.SatchmoDGroup, ADUserSchema.FblEnabled }); ADRawEntry adrawEntry = this.tenantRecipientSession.FindByExchangeGuid(ConsumerIdentityHelper.GetExchangeGuidFromPuid(puid), properties) ?? this.tenantRecipientSession.FindByProxyAddress(ProxyAddress.Parse(emailAddress), properties); FBLPerfCounters.NumberOfSuccessfulMSERVReadRequests.Increment(); result = adrawEntry; } catch (Exception ex) { FBLPerfCounters.NumberOfFailedMSERVReadRequests.Increment(); LoggingUtilities.LogEvent(ClientsEventLogConstants.Tuple_TransientFblErrorReadingMServ, new object[] { ex.InnerException ?? ex }); throw; } return(result); }
internal override IEnumerable <T> GetObjects <T>(ADObjectId rootId, IDirectorySession session, IDirectorySession subTreeSession, OptionalIdentityData optionalData, out LocalizedString?notFoundReason) { notFoundReason = null; if (typeof(T) != typeof(ADUser)) { throw new ArgumentException(Strings.ErrorInvalidType(typeof(T).Name), "type"); } List <ADUser> list = new List <ADUser>(); ADUser aduser = null; Guid exchangeGuid; WindowsLiveId windowsLiveId; if (Guid.TryParse(base.RawIdentity, out exchangeGuid)) { aduser = ((IRecipientSession)session).FindByExchangeGuidIncludingAlternate <ADUser>(exchangeGuid); } else if (ConsumerMailboxIdParameter.TryParseWindowsLiveId(base.RawIdentity, out windowsLiveId)) { if (windowsLiveId.NetId != null) { aduser = ((IRecipientSession)session).FindByExchangeGuidIncludingAlternate <ADUser>(ConsumerIdentityHelper.GetExchangeGuidFromPuid(windowsLiveId.NetId.ToUInt64())); } else { aduser = ((IRecipientSession)session).FindByProxyAddress <ADUser>(new SmtpProxyAddress(windowsLiveId.SmtpAddress.ToString(), true)); } } else if (base.InternalADObjectId != null) { aduser = ((IRecipientSession)session).FindADUserByObjectId(base.InternalADObjectId); } if (aduser != null) { list.Add(aduser); } return(list as IEnumerable <T>); }