// Token: 0x060000B9 RID: 185 RVA: 0x00008144 File Offset: 0x00006344 private void CleanUpOldDevices(MailboxSession mailboxSession) { int num = 0; try { IThrottlingPolicy throttlingPolicy = (this.budget != null) ? this.budget.ThrottlingPolicy : null; if (throttlingPolicy == null || throttlingPolicy.EasMaxInactivityForDeviceCleanup.IsUnlimited || GlobalSettings.MaxNoOfPartnershipToAutoClean == 0) { AirSyncDiagnostics.TraceInfo <string, int>(ExTraceGlobals.RequestsTracer, null, "No cleanUp required for stale devices. Reason:{0}, MaxNoOfPartnershipsToAutoClean:{1}", (throttlingPolicy == null) ? "No throttling policy set." : "EasMaxInactivityForDeviceCleanup set to Unlimited.", GlobalSettings.MaxNoOfPartnershipToAutoClean); } else { TimeSpan timeSpan = TimeSpan.FromDays(throttlingPolicy.EasMaxInactivityForDeviceCleanup.Value); ExDateTime utcNow = ExDateTime.UtcNow; MobileDevice[] easDevices = null; ADOperationResult adoperationResult = ADNotificationAdapter.TryRunADOperation(delegate() { easDevices = this.session.Find <MobileDevice>(MobileDevice.GetRootId(this.userId), QueryScope.OneLevel, null, null, 0); }); if (!adoperationResult.Succeeded) { AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, null, "Exception occurred during AD Operation during . Message:{0}", adoperationResult.Exception.Message); } else { if (easDevices != null) { List <MobileDevice> list = new List <MobileDevice>(easDevices); if (!this.CleanUpMangledDevices(list, out num)) { goto IL_271; } using (List <MobileDevice> .Enumerator enumerator = list.GetEnumerator()) { while (enumerator.MoveNext()) { MobileDevice device = enumerator.Current; if (device.WhenChangedUTC == null || !(ExDateTime.UtcNow.Subtract(new ExDateTime(ExTimeZone.UtcTimeZone, device.WhenChangedUTC.Value)) < timeSpan)) { if (DeviceInfo.CleanUpMobileDevice(mailboxSession, DeviceIdentity.FromMobileDevice(device), timeSpan)) { AirSyncDiagnostics.TraceDebug <MobileClientType, string, string>(ExTraceGlobals.RequestsTracer, null, "Delete device from AD as it doesn't exist in sync state. ClientType :{0} , DeviceType:{1}, DeviceId:{2}", device.ClientType, device.DeviceType, device.DeviceId); adoperationResult = ADNotificationAdapter.TryRunADOperation(delegate() { this.session.Delete(device); }); if (!adoperationResult.Succeeded) { AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, null, "Exception occurred during AD Operation during . Message:{0}", adoperationResult.Exception.Message); } num++; } TimeSpan t = ExDateTime.UtcNow.Subtract(utcNow); if (num >= GlobalSettings.MaxNoOfPartnershipToAutoClean || t >= GlobalSettings.MaxCleanUpExecutionTime) { AirSyncDiagnostics.TraceDebug <int, double>(ExTraceGlobals.RequestsTracer, null, "Done Cleaning up stale devices. DevicesCleaned:{0}, ExecutionTime(in ms):{1}", num, t.TotalMilliseconds); break; } } } goto IL_271; } } AirSyncDiagnostics.TraceInfo(ExTraceGlobals.RequestsTracer, null, "No devices in AD for current user."); IL_271 :; } } } finally { if (this.clientType != MobileClientType.MOWA && Command.CurrentCommand != null) { Command.CurrentCommand.ProtocolLogger.SetValue(ProtocolLoggerData.NoOfDevicesRemoved, num); } } }