Hi,
We have a schedule with almost 2000 activities and we are unable to export to project.
It is very slow in resource assignments.
After 4 hours of execution the following error happens:
Exception in thread "main" class com.aspose.tasks.private_.Exceptions.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: Parameter name: index
com.aspose.tasks.private_.Collections.Generic.List.b(Unknown Source)
com.aspose.tasks.SplitPartCollection.a(Unknown Source)
com.aspose.tasks.dfg.h(Unknown Source)
com.aspose.tasks.bdk.b(Unknown Source)
com.aspose.tasks.xw.a(Unknown Source)
com.aspose.tasks.gm.a(Unknown Source)
com.aspose.tasks.gm.a(Unknown Source)
com.aspose.tasks.ResourceAssignment.a(Unknown Source)
com.aspose.tasks.ResourceAssignment.set(Unknown Source)
Below is the sample source code and csv file with the activities:
public class TestExportProject {
private static final DateFormat DF = new SimpleDateFormat("dd/MM/yyyy");
public static void main(String[] args) throws FileNotFoundException, IOException, ParseException {
long startTime = System.nanoTime();
List<List<String>> records = new ArrayList<>();
try (BufferedReader br = new BufferedReader(
new FileReader(TestExportProject.class.getResource("tasks.csv").getFile()))) {
String line;
while ((line = br.readLine()) != null) {
String[] values = line.split(";");
records.add(Arrays.asList(values));
}
}
records.remove(0);
AsposeTasksLicenseLoader.loadLicense();
Project project = new Project();
project.set(Prj.START_DATE, DF.parse(records.get(0).get(3)));
project.setCalculationMode(CalculationMode.None);
List<Task> tasks = new ArrayList<Task>();
Task rootTask = project.getRootTask();
for (List<String> csvTask : records) {
Task task = rootTask.getChildren().add(csvTask.get(1));
if (!csvTask.get(2).isEmpty()) {
task.set(Tsk.DURATION, project.getDuration(
Double.parseDouble(csvTask.get(2).replace(".", "").replace(",", ".")), TimeUnitType.Minute));
}
if (!csvTask.get(3).isEmpty()) {
Date start = DF.parse(csvTask.get(3));
task.set(Tsk.START, start);
task.set(Tsk.CONSTRAINT_TYPE, ConstraintType.StartNoEarlierThan);
task.set(Tsk.CONSTRAINT_DATE, start);
}
if (!csvTask.get(4).isEmpty()) {
task.set(Tsk.FINISH, DF.parse(csvTask.get(4)));
}
tasks.add(task);
}
project.setCalculationMode(CalculationMode.Automatic);
project.recalculate();
ChildTasksCollector collector = new ChildTasksCollector();
TaskUtils.apply(project.getRootTask(), collector, 0);
List<Task> tasksView = collector.getTasks();
for (Task task : tasksView) {
printTask(task);
}
long endTaskTime = System.nanoTime();
long timeTaskElapsed = endTaskTime - startTime;
System.out.println("Execution time to export tasks in milliseconds : " +
timeTaskElapsed / 1000000);
long startResourcesTime = System.nanoTime();
Map<String, Resource> mapResources = new HashMap<String, Resource>();
for (int i = 0; i < records.size(); i++) {
List<String> csvTask = records.get(i);
if (csvTask.size() < 6 || csvTask.get(5).isEmpty()) {
continue;
}
String[] taskResources = csvTask.get(5).split(",");
for (String csvResource : taskResources) {
Resource resource = mapResources.get(csvResource);
if (resource == null) {
resource = project.getResources().add(csvResource);
mapResources.put(csvResource, resource);
}
project.getResourceAssignments().add(tasks.get(i), resource).set(Asn.UNITS, 100d);
}
}
collector = new ChildTasksCollector();
TaskUtils.apply(project.getRootTask(), collector, 0);
tasksView = collector.getTasks();
for (Task task : tasksView) {
printTask(task);
}
long endResourcesTime = System.nanoTime();
long timeResourcesElapsed = endResourcesTime - startResourcesTime;
System.out.println("Execution time to export resources in milliseconds : " +
timeResourcesElapsed / 1000000);
long timeTotalElapsed = endResourcesTime - startTime;
System.out.println("Execution total time to export in milliseconds : " +
timeTotalElapsed / 1000000);
}
private static void printTask(Task task) {
System.out.println(task.get(Tsk.ID) + " | " + task.get(Tsk.NAME) + " | " + task.get(Tsk.START) + " | "
+ task.get(Tsk.FINISH) + " | " + task.get(Tsk.DURATION));
}
}
tasks.csv.zip (8.1 KB)
Using Aspose Tasks for Java.