public static GetSyncStateResult GetData(MailboxSession session, ParsedCallData callData)
        {
            GetSyncStateResult getSyncStateResult = new GetSyncStateResult();

            getSyncStateResult.LoggingEnabled = SyncStateStorage.GetMailboxLoggingEnabled(session, null);
            using (SyncStateStorage.GetSyncFolderRoot(session, null))
            {
                UserSyncStateMetadata          userSyncStateMetadata = UserSyncStateMetadataCache.Singleton.Get(session, null);
                List <DeviceSyncStateMetadata> allDevices            = userSyncStateMetadata.GetAllDevices(session, true, null);
                getSyncStateResult.Devices = new List <DeviceData>(allDevices.Count);
                foreach (DeviceSyncStateMetadata deviceSyncStateMetadata in allDevices)
                {
                    if (SyncStateDiagnostics.ShouldAddDevice(callData, deviceSyncStateMetadata.Id))
                    {
                        DeviceData deviceData = new DeviceData
                        {
                            Name        = deviceSyncStateMetadata.Id.CompositeKey,
                            SyncFolders = new List <SyncStateFolderData>(),
                            FolderId    = deviceSyncStateMetadata.DeviceFolderId
                        };
                        getSyncStateResult.Devices.Add(deviceData);
                        foreach (KeyValuePair <string, SyncStateMetadata> keyValuePair in deviceSyncStateMetadata.SyncStates)
                        {
                            bool flag = string.Equals(keyValuePair.Key, callData.SyncStateName, StringComparison.OrdinalIgnoreCase);
                            if (callData.SyncStateName == null || flag)
                            {
                                SyncStateFolderData syncStateFolderData = new SyncStateFolderData
                                {
                                    Name        = keyValuePair.Key,
                                    StorageType = keyValuePair.Value.StorageType.ToString()
                                };
                                if (flag)
                                {
                                    SyncStateDiagnostics.GetSyncStateBlob(session, keyValuePair.Value, syncStateFolderData);
                                }
                                else
                                {
                                    syncStateFolderData.SyncStateSize = -1;
                                }
                                deviceData.SyncFolders.Add(syncStateFolderData);
                            }
                        }
                    }
                }
            }
            return(getSyncStateResult);
        }
 private static bool ShouldAddDevice(ParsedCallData callData, DeviceIdentity deviceIdentity)
 {
     return(callData.DeviceId == null || deviceIdentity.Equals(callData.DeviceId, callData.DeviceType));
 }