internal static PublicFolderMailboxDiagnosticsInfo Load(OrganizationId organizationId, Guid contentMailboxGuid, DiagnosticsLoadFlags loadFlags, Action <LocalizedString, LocalizedString, int> writeProgress)
        {
            PublicFolderMailboxDiagnosticsInfo result;

            using (PublicFolderSession publicFolderSession = PublicFolderSession.OpenAsAdmin(organizationId, null, contentMailboxGuid, null, CultureInfo.CurrentCulture, "Client=Management;Action=Get-PublicFolderMailboxDiagnostics", null))
            {
                result = PublicFolderMailboxDiagnosticsInfo.Load(publicFolderSession, loadFlags, writeProgress);
            }
            return(result);
        }
        internal static PublicFolderMailboxDiagnosticsInfo Load(PublicFolderSession session, DiagnosticsLoadFlags loadFlags, Action <LocalizedString, LocalizedString, int> writeProgress)
        {
            PublicFolderMailboxDiagnosticsInfo publicFolderMailboxDiagnosticsInfo = new PublicFolderMailboxDiagnosticsInfo("Public Folder Diagnostics Information");

            publicFolderMailboxDiagnosticsInfo.SyncInfo      = (PublicFolderMailboxDiagnosticsInfo.LoadMailboxInfo <PublicFolderMailboxSynchronizerInfo>(session, "PublicFolderSyncInfo", "PublicFolderLastSyncCylceLog") as PublicFolderMailboxSynchronizerInfo);
            publicFolderMailboxDiagnosticsInfo.AssistantInfo = (PublicFolderMailboxDiagnosticsInfo.LoadMailboxInfo <PublicFolderMailboxAssistantInfo>(session, "PublicFolderAssistantInfo", "PublicFolderLastAssistantCycleLog") as PublicFolderMailboxAssistantInfo);
            if ((loadFlags & DiagnosticsLoadFlags.DumpsterInfo) != DiagnosticsLoadFlags.Default)
            {
                publicFolderMailboxDiagnosticsInfo.DumpsterInfo = PublicFolderMailboxDumpsterInfo.LoadInfo(session, writeProgress);
            }
            if ((loadFlags & DiagnosticsLoadFlags.HierarchyInfo) != DiagnosticsLoadFlags.Default)
            {
                publicFolderMailboxDiagnosticsInfo.HierarchyInfo = PublicFolderMailboxHierarchyInfo.LoadInfo(session, writeProgress);
            }
            return(publicFolderMailboxDiagnosticsInfo);
        }
        private static PublicFolderMailboxMonitoringInfo LoadMailboxInfo <TValue>(PublicFolderSession session, string stateInfoConfigurationName, string logInfoConfigurationName) where TValue : PublicFolderMailboxMonitoringInfo, new()
        {
            TValue tvalue = Activator.CreateInstance <TValue>();

            using (Folder folder = Folder.Bind(session, session.GetTombstonesRootFolderId()))
            {
                using (UserConfiguration configuration = UserConfiguration.GetConfiguration(folder, new UserConfigurationName(stateInfoConfigurationName, ConfigurationNameKind.Name), UserConfigurationTypes.Dictionary))
                {
                    tvalue.LastAttemptedSyncTime               = (PublicFolderMailboxDiagnosticsInfo.GetMetadataValue(configuration, "LastAttemptedSyncTime") as ExDateTime?);
                    tvalue.LastFailedSyncTime                  = (PublicFolderMailboxDiagnosticsInfo.GetMetadataValue(configuration, "LastFailedSyncTime") as ExDateTime?);
                    tvalue.LastSuccessfulSyncTime              = (PublicFolderMailboxDiagnosticsInfo.GetMetadataValue(configuration, "LastSuccessfulSyncTime") as ExDateTime?);
                    tvalue.LastSyncFailure                     = (PublicFolderMailboxDiagnosticsInfo.GetMetadataValue(configuration, "LastSyncFailure") as string);
                    tvalue.NumberofAttemptsAfterLastSuccess    = (PublicFolderMailboxDiagnosticsInfo.GetMetadataValue(configuration, "NumberofAttemptsAfterLastSuccess") as int?);
                    tvalue.FirstFailedSyncTimeAfterLastSuccess = (PublicFolderMailboxDiagnosticsInfo.GetMetadataValue(configuration, "FirstFailedSyncTimeAfterLastSuccess") as ExDateTime?);
                    PublicFolderMailboxSynchronizerInfo publicFolderMailboxSynchronizerInfo = tvalue as PublicFolderMailboxSynchronizerInfo;
                    if (publicFolderMailboxSynchronizerInfo != null)
                    {
                        publicFolderMailboxSynchronizerInfo.NumberOfBatchesExecuted   = (PublicFolderMailboxDiagnosticsInfo.GetMetadataValue(configuration, "NumberOfBatchesExecuted") as int?);
                        publicFolderMailboxSynchronizerInfo.NumberOfFoldersToBeSynced = (PublicFolderMailboxDiagnosticsInfo.GetMetadataValue(configuration, "NumberOfFoldersToBeSynced") as int?);
                        publicFolderMailboxSynchronizerInfo.NumberOfFoldersSynced     = (PublicFolderMailboxDiagnosticsInfo.GetMetadataValue(configuration, "NumberOfFoldersSynced") as int?);
                        publicFolderMailboxSynchronizerInfo.BatchSize = (PublicFolderMailboxDiagnosticsInfo.GetMetadataValue(configuration, "BatchSize") as int?);
                    }
                }
                using (UserConfiguration configuration2 = UserConfiguration.GetConfiguration(folder, new UserConfigurationName(logInfoConfigurationName, ConfigurationNameKind.Name), UserConfigurationTypes.Stream))
                {
                    using (Stream stream = configuration2.GetStream())
                    {
                        using (GZipStream gzipStream = new GZipStream(stream, CompressionMode.Decompress, true))
                        {
                            using (MemoryStream memoryStream = new MemoryStream())
                            {
                                gzipStream.CopyTo(memoryStream);
                                tvalue.LastSyncCycleLog = Encoding.ASCII.GetString(memoryStream.ToArray());
                            }
                        }
                    }
                }
            }
            return(tvalue);
        }