private static LdapOperationStatus ToLdapOperationStatus()
        {
            var operations = LDAPTasks.GetTasks().ToList();

            foreach (var o in operations)
            {
                if (!string.IsNullOrEmpty(o.InstanseId) &&
                    Process.GetProcesses().Any(p => p.Id == int.Parse(o.InstanseId)))
                {
                    continue;
                }

                o.SetProperty(LdapOperation.PROGRESS, 100);
                LDAPTasks.RemoveTask(o.Id);
            }

            var operation =
                operations
                .FirstOrDefault(t => t.GetProperty <int>(LdapOperation.OWNER) == TenantProvider.CurrentTenantID);

            if (operation == null)
            {
                return(null);
            }

            if (DistributedTaskStatus.Running < operation.Status)
            {
                operation.SetProperty(LdapOperation.PROGRESS, 100);
                LDAPTasks.RemoveTask(operation.Id);
            }

            var certificateConfirmRequest = operation.GetProperty <LdapCertificateConfirmRequest>(LdapOperation.CERT_REQUEST);

            var result = new LdapOperationStatus
            {
                Id        = operation.Id,
                Completed = operation.GetProperty <bool>(LdapOperation.FINISHED),
                Percents  = operation.GetProperty <int>(LdapOperation.PROGRESS),
                Status    = operation.GetProperty <string>(LdapOperation.RESULT),
                Error     = operation.GetProperty <string>(LdapOperation.ERROR),
                CertificateConfirmRequest = certificateConfirmRequest,
                Source        = operation.GetProperty <string>(LdapOperation.SOURCE),
                OperationType = Enum.GetName(typeof(LdapOperationType),
                                             (LdapOperationType)Convert.ToInt32(operation.GetProperty <string>(LdapOperation.OPERATION_TYPE))),
                Warning = operation.GetProperty <string>(LdapOperation.WARNING)
            };

            if (!(string.IsNullOrEmpty(result.Warning)))
            {
                operation.SetProperty(LdapOperation.WARNING, ""); // "mark" as read
            }

            return(result);
        }
        private LdapOperationStatus GetStartProcessError()
        {
            var result = new LdapOperationStatus
            {
                Id        = null,
                Completed = true,
                Percents  = 0,
                Status    = "",
                Error     = Resource.LdapSettingsTooManyOperations,
                CertificateConfirmRequest = null,
                Source = ""
            };

            return(result);
        }