We can access all the task filters from Project.TaskFilters collection where each Filter item contains FilterCriteria property. How can I apply a filter item to filter tasks?
I have seen that there is a method present which could serve my purpose is Aspose.Tasks.Util.TaskUtils.Filter(Task root, ICondition cond), but it takes ICondition.
I found no way to filter tasks using the Filter/Criteria object.
Is there any way to do this?
I have observed your inquiry and request you to please elaborate the requirements in the form of sample application and source file. We will be able to investigate further on our end on provision of requested information.
Hello,
We are working on implementing an application that exports a file from mpp file by following ISO standard (ILAP).
There we will give the user an option to filter out the tasks while exporting from the available task filters.
I have added a sample application to get a better understanding of what I am looking for. Let me know if you need further clarification.
var project = new Project(@"../../TestData/TestMsProject.mpp");
// All tasks
var allTasks = project.RootTask.SelectAllChildTasks();
var taskFilters = project.TaskFilters;
// User will get a dropdown list to select a filter item
var selectedFilter = taskFilters.SingleOrDefault(x => x.Name == "Active Tasks");
if (selectedFilter != null)
{
// TODO: Need to apply the selected filter, need a method something like TaskUtils.Filter()
//var filteredTasks = Aspose.Tasks.Util.TaskUtils.Filter(project.RootTask, selectedFilter);
}
SampleFilterTasks.zip (240.2 KB)
Thank you for your feedback.
We have logged this issue with ID “TASKSNET-3007” for further investigation, you will automatically be informed here once we have more information to share.
We have investigated the issue and found that unfortunately, there is no mechanism to apply filters of Filter classes to the tasks and/or resources.
Moreover, you may implement the interface Aspose.Tasks.Util.ICondition and use it with Aspose.Tasks.Util.TaskUtils.Filter method as follows:
/// <summary>
/// <summary>
/// Filters critical tasks.
/// </summary>
internal class CriticalTasksCollector : TaskCollector
{
public CriticalTasksCollector() : base(new CriticalTaskCondition())
{
}
private class CriticalTaskCondition : ICondition<Task>
{
public bool Check(Task el)
{
return el != null && el.Get(TskInternal.IsCritical).Value;
}
}
}
...
var allTasks = project.RootTask.SelectAllChildTasks();
var taskFilters = project.TaskFilters;
var selectedFilter = taskFilters.SingleOrDefault(x => x.Name == "Active Tasks");
if (selectedFilter != null)
{
var filteredTasks = Aspose.Tasks.Util.TaskUtils.Filter(project.RootTask, new CriticalTasksCollector<Task>());
}
Furthermore, please feel free to write back to us if you need additional information or if you have further queries.
Thanks for your feedback.
But I think this type of static implementation will not work for us since user also might create different kinds of filter using MS Project and we want to apply those filters as well.
Thank you for writing back to us.
Please feel free to share the complete scenario with us which is not fulfilling the requirements even with the provided code. We will definitely investigate it and it shall possibly be implemented in the API.