Skip to content

Commit 8ed45b0

Browse files
Merge pull request #1 from nausherwan-aslam/master
Restructured Examples
2 parents 0046e52 + 8b02f48 commit 8ed45b0

File tree

289 files changed

+3920
-5315
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

289 files changed

+3920
-5315
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ Out*/
2727
*.lic
2828
Data/*Out*
2929
.idea/
30-
pom.xml
30+
.project
31+
.classpath

Examples/Examples.xml

Lines changed: 0 additions & 1529 deletions
This file was deleted.

Examples/pom.xml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.aspose</groupId>
5+
<artifactId>tasks-java-examples</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
<packaging>jar</packaging>
8+
<properties>
9+
<maven.compiler.source>1.7</maven.compiler.source>
10+
<maven.compiler.target>1.7</maven.compiler.target>
11+
</properties>
12+
<dependencies>
13+
<dependency>
14+
<groupId>com.aspose</groupId>
15+
<artifactId>aspose-tasks</artifactId>
16+
<version>8.5.0</version>
17+
<classifier>jdk16</classifier>
18+
</dependency>
19+
<dependency>
20+
<groupId>javax.media.jai</groupId>
21+
<artifactId>com.springsource.javax.media.jai.core</artifactId>
22+
<version>1.1.3</version>
23+
</dependency>
24+
</dependencies>
25+
<repositories>
26+
<repository>
27+
<id>aspose-maven-repository</id>
28+
<url>http://maven.aspose.com/repository/repo/</url>
29+
</repository>
30+
<repository>
31+
<id>com.springsource.repository.bundles.external</id>
32+
<name>SpringSource Enterprise Bundle Repository - External Bundle Releases</name>
33+
<url>http://repository.springsource.com/maven/bundles/external</url>
34+
</repository>
35+
</repositories>
36+
</project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.aspose.tasks.examples;
2+
3+
import com.aspose.tasks.License;
4+
5+
import java.io.File;
6+
7+
public class Utils {
8+
9+
public static String getDataDir(Class c) {
10+
File dir = new File(System.getProperty("user.dir"));
11+
dir = new File(dir, "src");
12+
dir = new File(dir, "main");
13+
dir = new File(dir, "resources");
14+
15+
for (String s : c.getName().split("\\.")) {
16+
dir = new File(dir, s);
17+
if (dir.isDirectory() == false)
18+
dir.mkdir();
19+
}
20+
21+
System.out.println("Using data directory: " + dir.toString());
22+
return dir.toString() + File.separator;
23+
}
24+
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66
* "as is", without warranty of any kind, either expressed or implied.
77
*/
88

9-
package programmersguide.workingwithcalendars.calendarproperties.java;
9+
package com.aspose.tasks.examples.calendars;
1010

1111
import com.aspose.tasks.*;
12+
import com.aspose.tasks.examples.Utils;
1213

1314
public class CalendarProperties
1415
{
1516
public static void main(String[] args) throws Exception
1617
{
1718
// The path to the documents directory.
18-
String dataDir = "src/programmersguide/workingwithcalendars/calendarproperties/data/";
19+
String dataDir = Utils.getDataDir(CalendarProperties.class);
1920

2021
long OneSec = 10000000;//microsecond * 10
2122
long OneMin = 60 * OneSec;
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,28 @@
66
* "as is", without warranty of any kind, either expressed or implied.
77
*/
88

9-
package programmersguide.workingwithcalendars.creatingacalendar.java;
9+
package com.aspose.tasks.examples.calendars;
1010

1111
import com.aspose.tasks.*;
12+
import com.aspose.tasks.examples.Utils;
1213

13-
public class CreatingACalendar
14+
public class CreateCalendar
1415
{
1516
public static void main(String[] args) throws Exception
1617
{
1718
// The path to the documents directory.
18-
String dataDir = "src/programmersguide/workingwithcalendars/creatingacalendar/data/";
19-
//Create a project instance
20-
Project prj = new Project();
19+
String dataDir = Utils.getDataDir(CreateCalendar.class);
2120

22-
//Define Calendar
23-
Calendar cal1 = prj.getCalendars().add("no info");
24-
Calendar cal2 = prj.getCalendars().add("no name");
25-
Calendar cal3 = prj.getCalendars().add("cal3");
21+
//Create a project instance
22+
Project prj = new Project();
2623

27-
//Save the Project
28-
prj.save("Project.Xml",SaveFileFormat.XML);
24+
//Define Calendar
25+
Calendar cal1 = prj.getCalendars().add("no info");
26+
Calendar cal2 = prj.getCalendars().add("no name");
27+
Calendar cal3 = prj.getCalendars().add("cal3");
28+
29+
//Save the Project
30+
prj.save(dataDir + "Project.Xml",SaveFileFormat.XML);
2931

3032
//Display result of conversion.
3133
System.out.println("Process completed Successfully");
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright 2001-2015 Aspose Pty Ltd. All Rights Reserved.
3+
*
4+
* This file is part of Aspose.Tasks. The source code in this file
5+
* is only intended as a supplement to the documentation, and is provided
6+
* "as is", without warranty of any kind, either expressed or implied.
7+
*/
8+
9+
package com.aspose.tasks.examples.calendars;
10+
11+
import com.aspose.tasks.*;
12+
import com.aspose.tasks.examples.Utils;
13+
14+
import java.util.Date;
15+
16+
public class DefineWeekdays
17+
{
18+
public static void main(String[] args) throws Exception
19+
{
20+
// The path to the documents directory.
21+
String dataDir = Utils.getDataDir(DefineWeekdays.class);
22+
23+
//Create a project instance
24+
Project prj = new Project();
25+
26+
//Define Calendar
27+
Calendar cal = prj.getCalendars().add("Calendar1");
28+
29+
//Add working days monday through thursday with default timings
30+
cal.getWeekDays().add(WeekDay.createDefaultWorkingDay(DayType.Monday));
31+
cal.getWeekDays().add(WeekDay.createDefaultWorkingDay(DayType.Tuesday));
32+
cal.getWeekDays().add(WeekDay.createDefaultWorkingDay(DayType.Wednesday));
33+
cal.getWeekDays().add(WeekDay.createDefaultWorkingDay(DayType.Thursday));
34+
cal.getWeekDays().add(new WeekDay(DayType.Saturday));
35+
cal.getWeekDays().add(new WeekDay(DayType.Sunday));
36+
37+
//Set friday as short working day
38+
WeekDay myWeekDay = new WeekDay(DayType.Friday);
39+
40+
//Sets working time. Only time part of DateTime is important
41+
WorkingTime wt1 = new WorkingTime();
42+
java.util.Calendar calTime = java.util.Calendar.getInstance();
43+
44+
calTime.set(1,1,1,9,0,0);
45+
Date date = calTime.getTime();
46+
wt1.setFromTime(date);
47+
48+
calTime.set(1,1,1,12,0,0);
49+
date = calTime.getTime();
50+
wt1.setToTime(date);
51+
52+
WorkingTime wt2 = new WorkingTime();
53+
54+
calTime.set(1,1,1,13,0,0);
55+
date = calTime.getTime();
56+
wt2.setFromTime(date);
57+
58+
calTime.set(1,1,1,16,0,0);
59+
date = calTime.getTime();
60+
wt2.setToTime(date);
61+
62+
myWeekDay.getWorkingTimes().add(wt1);
63+
myWeekDay.getWorkingTimes().add(wt2);
64+
myWeekDay.setDayWorking(true);
65+
cal.getWeekDays().add(myWeekDay);
66+
67+
68+
//Save the Project
69+
prj.save(dataDir + "Project.Xml", SaveFileFormat.XML);
70+
71+
//Display result of conversion.
72+
System.out.println("Process completed Successfully");
73+
74+
}
75+
}
76+
77+
78+
79+
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright 2001-2015 Aspose Pty Ltd. All Rights Reserved.
3+
*
4+
* This file is part of Aspose.Tasks. The source code in this file
5+
* is only intended as a supplement to the documentation, and is provided
6+
* "as is", without warranty of any kind, either expressed or implied.
7+
*/
8+
9+
package com.aspose.tasks.examples.calendars;
10+
11+
import com.aspose.tasks.*;
12+
import com.aspose.tasks.examples.Utils;
13+
14+
public class GetWorkingHours
15+
{
16+
public static void main(String[] args) throws Exception
17+
{
18+
// The path to the documents directory.
19+
String dataDir = Utils.getDataDir(GetWorkingHours.class);
20+
21+
long OneSec = 10000000;//microsecond * 10
22+
long OneMin = 60 * OneSec;
23+
long OneHour = 60 * OneMin;
24+
25+
Project project = new Project(dataDir + "BaselineTask.mpp");
26+
Task task = project.getRootTask().getChildren().getById(1);
27+
28+
Calendar taskCalendar = task.get(Tsk.CALENDAR);
29+
30+
java.util.Calendar calStartDate = java.util.Calendar.getInstance();
31+
calStartDate.setTime(task.get(Tsk.START));
32+
33+
java.util.Calendar calEndDate = java.util.Calendar.getInstance();
34+
calEndDate.setTime(task.get(Tsk.FINISH));
35+
36+
java.util.Calendar tempDate = java.util.Calendar.getInstance();
37+
tempDate = calStartDate;
38+
39+
Resource resource = project.getResources().getById(1);
40+
Calendar resourceCalendar = resource.get(Rsc.CALENDAR);
41+
42+
//TimeSpan timeSpan;
43+
long timeSpan = 0;
44+
45+
//Get Duration in Minutes
46+
double durationInMins = 0;
47+
48+
while (tempDate.before(calEndDate))
49+
{
50+
if (taskCalendar.isDayWorking(tempDate.getTime()) && resourceCalendar.isDayWorking(tempDate.getTime()))
51+
{
52+
timeSpan = (long) taskCalendar.getWorkingHours(tempDate.getTime());
53+
durationInMins = durationInMins + (timeSpan / OneMin);
54+
}
55+
tempDate.add(java.util.Calendar.DATE, 1);
56+
}
57+
tempDate.setTime(task.get(Tsk.START));
58+
59+
//Get Duration in Hours
60+
double durationInHours = 0;
61+
62+
while (tempDate.before(calEndDate))
63+
{
64+
if (taskCalendar.isDayWorking(tempDate.getTime()) && resourceCalendar.isDayWorking(tempDate.getTime()))
65+
{
66+
timeSpan = (long) taskCalendar.getWorkingHours(tempDate.getTime());
67+
durationInHours = durationInHours + (timeSpan / OneHour);
68+
}
69+
tempDate.add(java.util.Calendar.DATE, 1);
70+
}
71+
tempDate.setTime(task.get(Tsk.START));
72+
73+
//Get Duration in Days
74+
double durationInDays = 0;
75+
76+
while (tempDate.before(calEndDate))
77+
{
78+
if (taskCalendar.isDayWorking(tempDate.getTime()) && resourceCalendar.isDayWorking(tempDate.getTime()))
79+
{
80+
timeSpan = (long) taskCalendar.getWorkingHours(tempDate.getTime());
81+
if ((timeSpan / OneHour) > 0)
82+
durationInDays = durationInDays + (timeSpan/OneHour/8.0);
83+
}
84+
tempDate.add(java.util.Calendar.DATE, 1);
85+
}
86+
tempDate = calStartDate;
87+
88+
System.out.println("Duration in Minutes = " + durationInMins);
89+
System.out.println("Duration in Hours = " + durationInHours);
90+
System.out.println("Duration in Days = " + durationInDays);
91+
System.out.println();
92+
}
93+
}
94+
95+
96+
97+
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,28 @@
66
* "as is", without warranty of any kind, either expressed or implied.
77
*/
88

9-
package programmersguide.workingwithcalendars.makingastandardcalendar.java;
9+
package com.aspose.tasks.examples.calendars;
1010

1111
import com.aspose.tasks.*;
12+
import com.aspose.tasks.examples.Utils;
1213

13-
public class MakingAStandardCalendar
14+
public class MakeStandardCalendar
1415
{
1516
public static void main(String[] args) throws Exception
1617
{
1718
// The path to the documents directory.
18-
String dataDir = "src/programmersguide/workingwithcalendars/makingastandardcalendar/data/";
19+
String dataDir = Utils.getDataDir(MakeStandardCalendar.class);
1920

2021
//Create a project instance
21-
Project project = new Project();
22+
Project project = new Project();
2223

23-
//Define Calendar and make it standard
24-
Calendar cal1 = project.getCalendars().add("My Cal");
25-
Calendar.makeStandardCalendar(cal1);
24+
//Define Calendar and make it standard
25+
Calendar cal1 = project.getCalendars().add("My Cal");
26+
Calendar.makeStandardCalendar(cal1);
27+
28+
//Save the Project
29+
project.save(dataDir + "Project.Xml", SaveFileFormat.XML);
2630

27-
//Save the Project
28-
project.save("Project.Xml", SaveFileFormat.XML);
2931
//Display result of conversion.
3032
System.out.println("Process completed Successfully");
3133

0 commit comments

Comments
 (0)