public static CleaningResult Clean(this IScriptRepository repository, ITaskRepository taskRepository, IComputerRepository computerRepository, ListFilter filter = null)
        {
            if (filter == null)
            {
                filter = new ListFilter
                {
                    SortDirection = SortDirection.Ascending
                };
            }

            var allScripts = repository.List(filter).Items;

            var unusedScripts = allScripts.Where(x =>
                {
                    var getOwnersFunctions = new Func<Script, object[]>[]
                        {
                            taskRepository.Get,
                            computerRepository.Get
                        };

                    foreach (var getOwnersFunction in getOwnersFunctions)
                    {
                        var owners = getOwnersFunction(x);

                        if (owners.Any())
                        {
                            return false;
                        }
                    }

                    return true;
                }).ToArray();

            foreach (var script in unusedScripts)
            {
                repository.Remove(script);
            }

            var result = new CleaningResult(filter, allScripts.Length, unusedScripts.Length);

            return result;
        }
        public static CleaningResult Clean(this ITaskRepository repository, User user, ListFilter filter = null)
        {
            if (filter == null)
            {
                filter = new ListFilter
                    {
                        SortDirection = SortDirection.Ascending
                    };
            }

            var allTasks = repository.List(user, filter).Items;

            var oldTasks = allTasks.Where(x => x.Received || x.Expired).ToArray();

            foreach (var task in allTasks)
            {
                repository.Remove(task);
            }

            var result = new CleaningResult(filter, allTasks.Length, oldTasks.Length);

            return result;
        }
        public static CleaningResult Clean(this ITaskRepository repository, User user, ListFilter filter = null, IRepositoryModelCache cache = null)
        {
            if (filter == null)
            {
                filter = new ListFilter
                {
                    SortDirection = SortDirection.Ascending
                };
            }

            var allTasks = repository.List(user, filter, cache).Items;

            var oldTasks = allTasks.Where(x => x.Received || x.Expired).ToArray();

            foreach (var task in allTasks)
            {
                repository.Remove(task);
            }

            var result = new CleaningResult(filter, allTasks.Length, oldTasks.Length);

            return(result);
        }