// Token: 0x06000590 RID: 1424 RVA: 0x000210DC File Offset: 0x0001F2DC private static void ProcessForADAdds(IConfigurationSession scopedSession, DeviceClassCache.DeviceClassDataSet localDataSet, DeviceClassCache.DeviceClassDataSet dataSetFromAD, ref int totalADWriteCount, int perOrgDeleteCount) { int num = 0; foreach (DeviceClassCache.DeviceClassData deviceClassData in localDataSet) { if (totalADWriteCount >= GlobalSettings.DeviceClassCacheMaxADUploadCount) { AirSyncDiagnostics.TraceDebug <int>(ExTraceGlobals.RequestsTracer, null, "2. Stop updating AD because the cap is reached: adUpdateCount={0}", totalADWriteCount); break; } if (!dataSetFromAD.Contains(deviceClassData)) { if (dataSetFromAD.Count + num - perOrgDeleteCount >= GlobalSettings.DeviceClassPerOrgMaxADCount) { AirSyncDiagnostics.TraceDebug <int, int>(ExTraceGlobals.RequestsTracer, null, "Stop adding new device class node to AD because the cap is reached: dataSetFromAD.Count={0}, DeviceClassPerOrgMaxADCount={1}", dataSetFromAD.Count, GlobalSettings.DeviceClassPerOrgMaxADCount); break; } if (dataSetFromAD.Count + num >= DeviceClassCache.ADCapWarningThreshold) { AirSyncDiagnostics.TraceDebug <int, int>(ExTraceGlobals.RequestsTracer, null, "Still adding new device class node to AD but the cap is close to be reached: dataSetFromAD.Count={0}, DeviceClassPerOrgMaxADCount={1}", dataSetFromAD.Count, DeviceClassCache.ADCapWarningThreshold); AirSyncDiagnostics.LogPeriodicEvent(AirSyncEventLogConstants.Tuple_TooManyDeviceClassNodes, localDataSet.OrganizationId.ToString(), new string[] { dataSetFromAD.Count.ToString(), localDataSet.OrganizationId.ToString(), GlobalSettings.DeviceClassPerOrgMaxADCount.ToString() }); } DeviceClassCache.CreateOrUpdateActiveSyncDeviceClass(scopedSession, deviceClassData, localDataSet.OrganizationId); num++; totalADWriteCount++; } } }
// Token: 0x06000591 RID: 1425 RVA: 0x00021220 File Offset: 0x0001F420 private static void ProcessForADCleanup(IConfigurationSession scopedSession, DeviceClassCache.DeviceClassDataSet localDataSet, DeviceClassCache.DeviceClassDataSet dataSetFromAD, ref int totalADWriteCount, ref int perOrgDeleteCount) { foreach (DeviceClassCache.DeviceClassData deviceClassData in dataSetFromAD) { if (totalADWriteCount >= GlobalSettings.DeviceClassCacheMaxADUploadCount) { AirSyncDiagnostics.TraceDebug <int>(ExTraceGlobals.RequestsTracer, null, "3. Stop updating AD because the cap is reached: adUpdateCount={0}", totalADWriteCount); break; } if (localDataSet.Contains(deviceClassData)) { if ((ExDateTime.UtcNow - deviceClassData.LastUpdateTime).Days >= TimeSpan.FromDays((double)GlobalSettings.DeviceClassCacheADCleanupInterval).Days) { AirSyncDiagnostics.TraceDebug <ExDateTime, int>(ExTraceGlobals.RequestsTracer, null, "Update or Create DeviceClass in AD. LastUpdateTime :{0}. adUpdateCount: {1}", deviceClassData.LastUpdateTime, totalADWriteCount); DeviceClassCache.CreateOrUpdateActiveSyncDeviceClass(scopedSession, deviceClassData, localDataSet.OrganizationId); totalADWriteCount++; } } else if ((ExDateTime.UtcNow - deviceClassData.LastUpdateTime).Days > TimeSpan.FromDays((double)GlobalSettings.DeviceClassCacheADCleanupInterval).Days * 2) { AirSyncDiagnostics.TraceDebug <ExDateTime, int>(ExTraceGlobals.RequestsTracer, null, "Delete DeviceClass in AD. LastUpdateTime :{0}, adUpdateCount: {1} ", deviceClassData.LastUpdateTime, totalADWriteCount); DeviceClassCache.DeleteActiveSyncDeviceClass(scopedSession, deviceClassData, localDataSet.OrganizationId); perOrgDeleteCount++; totalADWriteCount++; } } }
// Token: 0x06000599 RID: 1433 RVA: 0x00021738 File Offset: 0x0001F938 private void Refresh(object state) { try { AirSyncDiagnostics.TraceDebug <ExDateTime>(ExTraceGlobals.RequestsTracer, this, "Refresh is being call at '{0}-UTC'.", ExDateTime.UtcNow); AirSyncDiagnostics.TraceDebug <int>(ExTraceGlobals.RequestsTracer, this, "DeviceClassCache contains '{0}' elements.", this.cache.Values.Count); List <DeviceClassCache.DeviceClassDataSet> list; lock (this.thisLock) { if (this.cache.Values.Count < 1) { return; } list = new List <DeviceClassCache.DeviceClassDataSet>(this.cache.Values); } int num = 0; foreach (DeviceClassCache.DeviceClassDataSet deviceClassDataSet in list) { if (this.realTimeRefresh || !(ExDateTime.UtcNow - deviceClassDataSet.StartTime < TimeSpan.FromSeconds((double)GlobalSettings.DeviceClassCachePerOrgRefreshInterval))) { if (num >= GlobalSettings.DeviceClassCacheMaxADUploadCount) { AirSyncDiagnostics.TraceDebug <int>(ExTraceGlobals.RequestsTracer, this, "1. Stop updating AD because the cap is reached: adUpdateCount={0}", num); break; } lock (this.thisLock) { if (!this.cache.ContainsKey(deviceClassDataSet.OrganizationId)) { AirSyncDiagnostics.TraceDebug <OrganizationId>(ExTraceGlobals.RequestsTracer, this, "Organization {0} is already removed from the cache by another thread", deviceClassDataSet.OrganizationId); continue; } this.cache.Remove(deviceClassDataSet.OrganizationId); } using (deviceClassDataSet) { IConfigurationSession scopedSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(false, ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromOrganizationIdWithoutRbacScopesServiceOnly(deviceClassDataSet.OrganizationId), 930, "Refresh", "f:\\15.00.1497\\sources\\dev\\AirSync\\src\\AirSync\\DeviceClassCache.cs"); ActiveSyncDeviceClasses deviceClassContainer = DeviceClassCache.GetActiveSyncDeviceClassContainer(scopedSession, deviceClassDataSet.OrganizationId); if (deviceClassContainer != null) { ADPagedReader <ActiveSyncDeviceClass> deviceClassReader = null; ADNotificationAdapter.RunADOperation(delegate() { deviceClassReader = scopedSession.FindPaged <ActiveSyncDeviceClass>(deviceClassContainer.Id, QueryScope.OneLevel, null, null, 0); }); DeviceClassCache.UpdateProtocolLogLastUsedDC(scopedSession); if (deviceClassReader != null) { using (DeviceClassCache.DeviceClassDataSet deviceClassDataSet3 = new DeviceClassCache.DeviceClassDataSet(deviceClassDataSet.OrganizationId)) { foreach (ActiveSyncDeviceClass activeSyncDeviceClass in deviceClassReader) { if (!string.IsNullOrEmpty(activeSyncDeviceClass.DeviceType) && !string.IsNullOrEmpty(activeSyncDeviceClass.DeviceModel) && activeSyncDeviceClass.LastUpdateTime != null) { string commonName = ActiveSyncDeviceClass.GetCommonName(activeSyncDeviceClass.DeviceType, activeSyncDeviceClass.DeviceModel); if (DeviceClassCache.DnIsMangled(activeSyncDeviceClass, commonName)) { AirSyncDiagnostics.TraceDebug <ADObjectId>(ExTraceGlobals.RequestsTracer, this, "Delete the Mangled DeviceClassCache {0}.", activeSyncDeviceClass.Id); DeviceClassCache.DeleteObject(scopedSession, activeSyncDeviceClass); num++; } else { deviceClassDataSet3.Add(new DeviceClassCache.DeviceClassData(activeSyncDeviceClass)); } } else { AirSyncDiagnostics.TraceDebug <string, string, DateTime?>(ExTraceGlobals.RequestsTracer, this, "Delete the DeviceClassCache. Either DeviceType, DeviceModel or LastupdatTime is null. DeviceType:{0}, DeviceModel:{1}, LastUpdateTime:{2}.", activeSyncDeviceClass.DeviceType, activeSyncDeviceClass.DeviceModel, activeSyncDeviceClass.LastUpdateTime); DeviceClassCache.DeleteObject(scopedSession, activeSyncDeviceClass); num++; } } DeviceClassCache.UpdateProtocolLogLastUsedDC(scopedSession); AirSyncDiagnostics.TraceDebug <int, OrganizationId>(ExTraceGlobals.RequestsTracer, this, "'{0}' device classes are loaded from AD for org '{1}'", deviceClassDataSet3.Count, deviceClassDataSet.OrganizationId); int perOrgDeleteCount = 0; DeviceClassCache.ProcessForADCleanup(scopedSession, deviceClassDataSet, deviceClassDataSet3, ref num, ref perOrgDeleteCount); DeviceClassCache.ProcessForADAdds(scopedSession, deviceClassDataSet, deviceClassDataSet3, ref num, perOrgDeleteCount); } } } } } } } catch (Exception ex) { AirSyncUtility.ProcessException(ex); } }
// Token: 0x0600058D RID: 1421 RVA: 0x00020E58 File Offset: 0x0001F058 public void Add(OrganizationId organizationId, string deviceType, string deviceModel) { AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "Adding device class: orgId={0}, deviceType={1}, deviceModel={2}, started={3}.", new object[] { organizationId, deviceType, deviceModel, this.Started }); if (!this.Started) { return; } if (string.IsNullOrEmpty(deviceType) || deviceType.Length > 32) { throw new ArgumentException("Invalid deviceType: " + deviceType); } if (string.IsNullOrEmpty(deviceModel)) { throw new ArgumentNullException("deviceModel"); } try { DeviceClassCache.DeviceClassData data = new DeviceClassCache.DeviceClassData(DeviceClassCache.EnforceLengthLimit(deviceType, DeviceClassCache.ADPropertyConstraintLength.MaxDeviceTypeLength, false), DeviceClassCache.EnforceLengthLimit(deviceModel, DeviceClassCache.ADPropertyConstraintLength.MaxDeviceModelLength, false)); lock (this.thisLock) { DeviceClassCache.DeviceClassDataSet deviceClassDataSet; if (this.cache.TryGetValue(organizationId, out deviceClassDataSet)) { if (!deviceClassDataSet.Contains(data)) { if (deviceClassDataSet.Count >= GlobalSettings.DeviceClassPerOrgMaxADCount) { AirSyncDiagnostics.TraceDebug <OrganizationId, int>(ExTraceGlobals.RequestsTracer, this, "Device class will not be added to the cache since it already reaches the cap:orgId={0}, count={1}.", organizationId, deviceClassDataSet.Count); } else { deviceClassDataSet.Add(data); AirSyncDiagnostics.TraceDebug <OrganizationId>(ExTraceGlobals.RequestsTracer, this, "New device class is added to the existing org '{0}'.", organizationId); } } } else if (this.cache.Count >= GlobalSettings.ADCacheMaxOrgCount) { AirSyncDiagnostics.TraceDebug <OrganizationId, int>(ExTraceGlobals.RequestsTracer, this, "Device class set will not be added to the cache since it already reaches the cap:orgId={0}, count={1}.", organizationId, this.cache.Count); } else { deviceClassDataSet = new DeviceClassCache.DeviceClassDataSet(organizationId); deviceClassDataSet.Add(data); this.cache.Add(organizationId, deviceClassDataSet); AirSyncDiagnostics.TraceDebug <OrganizationId>(ExTraceGlobals.RequestsTracer, this, "New device class is added to the new org '{0}'.", organizationId); } } } finally { AirSyncDiagnostics.FaultInjectionTracer.TraceTest <bool>(2359700797U, ref this.realTimeRefresh); if (this.realTimeRefresh) { AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "Calling Refresh real time."); this.Refresh(null); this.realTimeRefresh = false; } } }