Пример #1
0
        public MailOperationStatus RecalculateFolders(Func <DistributedTask, string> translateMailOperationStatus = null)
        {
            var tenant = CoreContext.TenantManager.GetCurrentTenant();
            var user   = SecurityContext.CurrentAccount;

            var operations = MailOperations.GetTasks()
                             .Where(o =>
            {
                var oTenant = o.GetProperty <int>(MailOperation.TENANT);
                var oUser   = o.GetProperty <string>(MailOperation.OWNER);
                var oType   = o.GetProperty <MailOperationType>(MailOperation.OPERATION_TYPE);
                return(oTenant == tenant.TenantId &&
                       oUser == user.ID.ToString() &&
                       oType == MailOperationType.RecalculateFolders);
            });

            var runningOperation = operations.FirstOrDefault(o => o.Status <= DistributedTaskStatus.Running);

            if (runningOperation != null)
            {
                return(GetMailOperationStatus(runningOperation.Id, translateMailOperationStatus));
            }

            var op = new MailRecalculateFoldersOperation(tenant, user, this);

            return(QueueTask(op, translateMailOperationStatus));
        }
Пример #2
0
        public MailOperationStatus CheckDomainDns(string domainName, ServerDns dns,
                                                  Func <DistributedTask, string> translateMailOperationStatus = null)
        {
            var tenant = CoreContext.TenantManager.GetCurrentTenant();
            var user   = SecurityContext.CurrentAccount;

            var operations = MailOperations.GetTasks()
                             .Where(o =>
            {
                var oTenant = o.GetProperty <int>(MailOperation.TENANT);
                var oUser   = o.GetProperty <string>(MailOperation.OWNER);
                var oType   = o.GetProperty <MailOperationType>(MailOperation.OPERATION_TYPE);
                var oSource = o.GetProperty <string>(MailOperation.SOURCE);
                return(oTenant == tenant.TenantId &&
                       oUser == user.ID.ToString() &&
                       oType == MailOperationType.CheckDomainDns &&
                       oSource == domainName);
            });

            var runningOperation = operations.FirstOrDefault(o => o.Status <= DistributedTaskStatus.Running);

            if (runningOperation != null)
            {
                return(GetMailOperationStatus(runningOperation.Id, translateMailOperationStatus));
            }

            var op = new MailCheckMailserverDomainsDnsOperation(tenant, user, domainName, dns);

            return(QueueTask(op, translateMailOperationStatus));
        }
Пример #3
0
        public List <MailOperationStatus> GetMailOperations(Func <DistributedTask, string> translateMailOperationStatus = null)
        {
            var operations = MailOperations.GetTasks().Where(
                o =>
                o.GetProperty <int>(MailOperation.TENANT) == TenantProvider.CurrentTenantID &&
                o.GetProperty <string>(MailOperation.OWNER) == SecurityContext.CurrentAccount.ID.ToString());

            var list = new List <MailOperationStatus>();

            foreach (var o in operations)
            {
                if (string.IsNullOrEmpty(o.Id))
                {
                    continue;
                }

                list.Add(GetMailOperationStatus(o.Id, translateMailOperationStatus));
            }

            return(list);
        }
Пример #4
0
        public MailOperationStatus RemoveMailbox(MailBoxData mailbox,
                                                 Func <DistributedTask, string> translateMailOperationStatus = null)
        {
            var tenant = CoreContext.TenantManager.GetCurrentTenant();
            var user   = SecurityContext.CurrentAccount;

            var operations = MailOperations.GetTasks()
                             .Where(o =>
            {
                var oTenant = o.GetProperty <int>(MailOperation.TENANT);
                var oUser   = o.GetProperty <string>(MailOperation.OWNER);
                var oType   = o.GetProperty <MailOperationType>(MailOperation.OPERATION_TYPE);
                return(oTenant == tenant.TenantId &&
                       oUser == user.ID.ToString() &&
                       oType == MailOperationType.RemoveMailbox);
            })
                             .ToList();

            var sameOperation = operations.FirstOrDefault(o =>
            {
                var oSource = o.GetProperty <string>(MailOperation.SOURCE);
                return(oSource == mailbox.MailBoxId.ToString());
            });

            if (sameOperation != null)
            {
                return(GetMailOperationStatus(sameOperation.Id, translateMailOperationStatus));
            }

            var runningOperation = operations.FirstOrDefault(o => o.Status <= DistributedTaskStatus.Running);

            if (runningOperation != null)
            {
                throw new MailOperationAlreadyRunningException("Remove mailbox operation already running.");
            }

            var op = new MailRemoveMailboxOperation(tenant, user, mailbox);

            return(QueueTask(op, translateMailOperationStatus));
        }
Пример #5
0
        public MailOperationStatus GetMailOperationStatus(string operationId, Func <DistributedTask, string> translateMailOperationStatus = null)
        {
            var defaultResult = new MailOperationStatus
            {
                Id            = null,
                Completed     = true,
                Percents      = 100,
                Status        = "",
                Error         = "",
                Source        = "",
                OperationType = -1
            };

            if (string.IsNullOrEmpty(operationId))
            {
                return(defaultResult);
            }

            var operations = MailOperations.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(MailOperation.PROGRESS, 100);
                MailOperations.RemoveTask(o.Id);
            }

            var operation = operations
                            .FirstOrDefault(
                o =>
                o.GetProperty <int>(MailOperation.TENANT) == TenantProvider.CurrentTenantID &&
                o.GetProperty <string>(MailOperation.OWNER) == SecurityContext.CurrentAccount.ID.ToString() &&
                o.Id.Equals(operationId));

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

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

            var operationTypeIndex = (int)operation.GetProperty <MailOperationType>(MailOperation.OPERATION_TYPE);

            var result = new MailOperationStatus
            {
                Id        = operation.Id,
                Completed = operation.GetProperty <bool>(MailOperation.FINISHED),
                Percents  = operation.GetProperty <int>(MailOperation.PROGRESS),
                Status    = translateMailOperationStatus != null
                    ? translateMailOperationStatus(operation)
                    : operation.GetProperty <string>(MailOperation.STATUS),
                Error         = operation.GetProperty <string>(MailOperation.ERROR),
                Source        = operation.GetProperty <string>(MailOperation.SOURCE),
                OperationType = operationTypeIndex,
                Operation     = Enum.GetName(typeof(MailOperationType), operationTypeIndex)
            };

            return(result);
        }