internal static List <StoreIntegrityCheckJob> GetStoreIntegrityCheckJob(Database database, Guid mailboxGuid, Guid requestGuid, IntegrityCheckQueryFlags flags, bool details, Task.TaskErrorLoggingDelegate writeError, Task.TaskWarningLoggingDelegate writeWarning, Task.TaskVerboseLoggingDelegate writeVerbose)
        {
            List <StoreIntegrityCheckJob> jobs = new List <StoreIntegrityCheckJob>();

            try
            {
                StoreIntegrityCheckAdminRpc.ExecuteAdminRpc(database.Guid, delegate(ExRpcAdmin rpcAdmin, string serverFqdn)
                {
                    int num;
                    int num2;
                    rpcAdmin.GetAdminVersion(out num, out num2);
                    if (num < 7 || (num == 7 && num2 < 15))
                    {
                        throw new NotSupportedException();
                    }
                    PropValue[][] array = rpcAdmin.StoreIntegrityCheckEx(database.Guid, mailboxGuid, requestGuid, 2U, (uint)flags, null, StoreIntegrityCheckAdminRpc.JobPropTags);
                    foreach (PropValue[] propValues in array)
                    {
                        jobs.Add(new StoreIntegrityCheckJob(new DatabaseId(null, serverFqdn, database.Name, database.Guid), propValues));
                    }
                }, writeError, writeWarning, writeVerbose);
            }
            catch (MapiExceptionNetworkError innerException)
            {
                writeError(new OnlineIsIntegQueryJobException(database.Identity.ToString(), Strings.ServiceUnavaiable, innerException), ErrorCategory.ResourceUnavailable, database.Identity);
            }
            catch (MapiExceptionMdbOffline innerException2)
            {
                writeError(new OnlineIsIntegQueryJobException(database.Identity.ToString(), Strings.DatabaseOffline, innerException2), ErrorCategory.InvalidOperation, database.Identity);
            }
            catch (MapiPermanentException ex)
            {
                writeError(new OnlineIsIntegQueryJobException(database.Identity.ToString(), Strings.UnexpectedError(ex.ToString()), ex), ErrorCategory.InvalidOperation, database.Identity);
            }
            catch (MapiRetryableException ex2)
            {
                writeError(new OnlineIsIntegQueryJobException(database.Identity.ToString(), Strings.UnexpectedError(ex2.ToString()), ex2), ErrorCategory.InvalidOperation, database.Identity);
            }
            if (details)
            {
                return(jobs);
            }
            return(new List <StoreIntegrityCheckJob>
            {
                StoreIntegrityCheckJob.Aggregate(jobs)
            });
        }
        internal static StoreIntegrityCheckJob CreateStoreIntegrityCheckJob(Database database, Guid mailboxGuid, StoreIntegrityCheckRequestFlags flags, MailboxCorruptionType[] taskIds, Task.TaskErrorLoggingDelegate writeError, Task.TaskWarningLoggingDelegate writeWarning, Task.TaskVerboseLoggingDelegate writeVerbose)
        {
            List <StoreIntegrityCheckJob> result = null;

            try
            {
                StoreIntegrityCheckAdminRpc.ExecuteAdminRpc(database.Guid, delegate(ExRpcAdmin rpcAdmin, string serverFqdn)
                {
                    uint[] array = new uint[taskIds.Length];
                    for (int i = 0; i < taskIds.Length; i++)
                    {
                        array[i] = (uint)taskIds[i];
                    }
                    int num;
                    int num2;
                    rpcAdmin.GetAdminVersion(out num, out num2);
                    if (num < 7 || (num == 7 && num2 < 15))
                    {
                        string input;
                        rpcAdmin.ISIntegCheck(database.Guid, mailboxGuid, (uint)flags, array.Length, array, out input);
                        JobFlags jobFlags = JobFlags.None;
                        if ((flags & StoreIntegrityCheckRequestFlags.DetectOnly) == StoreIntegrityCheckRequestFlags.DetectOnly)
                        {
                            jobFlags |= JobFlags.DetectOnly;
                        }
                        if ((flags & (StoreIntegrityCheckRequestFlags)2147483648U) == (StoreIntegrityCheckRequestFlags)2147483648U)
                        {
                            jobFlags |= (JobFlags)2147483648U;
                        }
                        if ((flags & StoreIntegrityCheckRequestFlags.Force) == StoreIntegrityCheckRequestFlags.None)
                        {
                            jobFlags |= JobFlags.Background;
                        }
                        StoreIntegrityCheckJob item = new StoreIntegrityCheckJob(new DatabaseId(null, serverFqdn, database.Name, database.Guid), Guid.Parse(input), jobFlags, (from x in array
                                                                                                                                                                               select(MailboxCorruptionType) x).ToArray <MailboxCorruptionType>());
                        result = new List <StoreIntegrityCheckJob>();
                        result.Add(item);
                        return;
                    }
                    PropValue[][] array2 = rpcAdmin.StoreIntegrityCheckEx(database.Guid, mailboxGuid, Guid.Empty, 1U, (uint)flags, array, StoreIntegrityCheckAdminRpc.JobPropTags);
                    result = new List <StoreIntegrityCheckJob>(array2.Length);
                    foreach (PropValue[] propValues in array2)
                    {
                        StoreIntegrityCheckJob item2 = new StoreIntegrityCheckJob(new DatabaseId(null, serverFqdn, database.Name, database.Guid), propValues);
                        result.Add(item2);
                    }
                }, writeError, writeWarning, writeVerbose);
            }
            catch (MapiExceptionNetworkError innerException)
            {
                writeError(new OnlineIsIntegException(database.Identity.ToString(), Strings.ServiceUnavaiable, innerException), ErrorCategory.ResourceUnavailable, database.Identity);
            }
            catch (MapiExceptionMdbOffline innerException2)
            {
                writeError(new OnlineIsIntegException(database.Identity.ToString(), Strings.DatabaseOffline, innerException2), ErrorCategory.InvalidOperation, database.Identity);
            }
            catch (MapiExceptionISIntegMdbTaskExceeded innerException3)
            {
                writeError(new OnlineIsIntegException(database.Identity.ToString(), Strings.DatabaseWideTasksExceeded, innerException3), ErrorCategory.InvalidOperation, database.Identity);
            }
            catch (MapiExceptionISIntegQueueFull innerException4)
            {
                writeError(new OnlineIsIntegException(database.Identity.ToString(), Strings.IsIntegQueueFull, innerException4), ErrorCategory.InvalidOperation, database.Identity);
            }
            catch (MapiExceptionUnknownUser)
            {
                writeWarning(Strings.WarningMailboxNeverBeenLoggedOn(mailboxGuid.ToString(), database.Identity.ToString()));
            }
            catch (MapiPermanentException ex)
            {
                writeError(new OnlineIsIntegException(database.Identity.ToString(), Strings.UnexpectedError(ex.ToString()), ex), ErrorCategory.InvalidOperation, database.Identity);
            }
            catch (MapiRetryableException ex2)
            {
                writeError(new OnlineIsIntegException(database.Identity.ToString(), Strings.UnexpectedError(ex2.ToString()), ex2), ErrorCategory.InvalidOperation, database.Identity);
            }
            return(StoreIntegrityCheckJob.Aggregate(result));
        }
        internal static StoreIntegrityCheckJob Aggregate(IList <StoreIntegrityCheckJob> jobs)
        {
            if (jobs == null || jobs.Count == 0)
            {
                return(null);
            }
            if (jobs.Count == 1)
            {
                return(jobs[0]);
            }
            HashSet <MailboxCorruptionType> hashSet = new HashSet <MailboxCorruptionType>();
            TimeSpan timeSpan = default(TimeSpan);
            List <StoreIntegrityCheckJob.Corruption> list = new List <StoreIntegrityCheckJob.Corruption>();
            DatabaseId  databaseId  = jobs[0].databaseId;
            Guid        guid        = jobs[0].requestGuid;
            Guid        empty       = jobs[0].mailboxGuid;
            Guid        guid2       = jobs[0].jobGuid;
            JobFlags    jobFlags    = JobFlags.None;
            JobSource   jobSource   = jobs[0].source;
            JobPriority jobPriority = jobs[0].priority;
            JobState    jobState    = jobs[0].state;
            DateTime?   dateTime    = null;
            DateTime?   dateTime2   = null;
            int         num         = 0;
            int         num2        = 0;
            DateTime?   dateTime3   = jobs[0].finishTime;
            long        num3        = 0L;
            bool        flag        = false;

            for (int i = 0; i < jobs.Count; i++)
            {
                StoreIntegrityCheckJob storeIntegrityCheckJob = jobs[i];
                if (storeIntegrityCheckJob.mailboxGuid != empty)
                {
                    empty = Guid.Empty;
                }
                if (!hashSet.Contains(storeIntegrityCheckJob.Tasks[0]))
                {
                    hashSet.Add(storeIntegrityCheckJob.Tasks[0]);
                }
                if (dateTime == null)
                {
                    dateTime = storeIntegrityCheckJob.creationTime;
                }
                else if (dateTime != null && storeIntegrityCheckJob.creationTime != null && dateTime.Value > storeIntegrityCheckJob.creationTime.Value)
                {
                    dateTime = storeIntegrityCheckJob.creationTime;
                }
                if (dateTime2 == null)
                {
                    dateTime2 = storeIntegrityCheckJob.lastExecutionTime;
                }
                if (dateTime2 != null && storeIntegrityCheckJob.lastExecutionTime != null && dateTime2 < storeIntegrityCheckJob.lastExecutionTime.Value)
                {
                    dateTime2 = storeIntegrityCheckJob.lastExecutionTime;
                }
                if (dateTime3 != null && storeIntegrityCheckJob.finishTime != null)
                {
                    if (dateTime3.Value < storeIntegrityCheckJob.finishTime.Value)
                    {
                        dateTime3 = storeIntegrityCheckJob.finishTime;
                    }
                }
                else
                {
                    dateTime3 = null;
                }
                if (storeIntegrityCheckJob.TimeInServer != null)
                {
                    timeSpan += storeIntegrityCheckJob.TimeInServer.Value;
                }
                jobFlags |= storeIntegrityCheckJob.flags;
                if (storeIntegrityCheckJob.state != jobState)
                {
                    if ((storeIntegrityCheckJob.state == JobState.Succeeded || storeIntegrityCheckJob.state == JobState.Failed) && (jobState == JobState.Succeeded || jobState == JobState.Failed))
                    {
                        jobState = JobState.Failed;
                    }
                    else
                    {
                        jobState = JobState.Running;
                    }
                }
                num3 += (long)storeIntegrityCheckJob.progress;
                if (storeIntegrityCheckJob.corruptions != null)
                {
                    list.AddRange(storeIntegrityCheckJob.corruptions);
                }
                num  += storeIntegrityCheckJob.CorruptionsDetected;
                num2 += storeIntegrityCheckJob.CorruptionsFixed;
                if (storeIntegrityCheckJob.errorCode != null && storeIntegrityCheckJob.errorCode.Value != 0)
                {
                    flag = true;
                }
            }
            num3 /= (long)jobs.Count;
            int?num4 = null;

            if (flag)
            {
                num4 = new int?(-2147467259);
            }
            return(new StoreIntegrityCheckJob(databaseId, empty, guid, Guid.Empty, jobFlags, hashSet.ToArray <MailboxCorruptionType>(), jobState, jobSource, jobPriority, (short)num3, dateTime, dateTime2, dateTime3, new TimeSpan?(timeSpan), num4, num, num2, list.ToArray()));
        }