本文整理汇总了C#中Project.GetDuration方法的典型用法代码示例。如果您正苦于以下问题:C# Project.GetDuration方法的具体用法?C# Project.GetDuration怎么用?C# Project.GetDuration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Project
的用法示例。
在下文中一共展示了Project.GetDuration方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public static void Run()
{
// ExStart:CreateSplitTasks
// Create new project
Project splitTaskProject = new Project();
// Get a standard calendar
Calendar calendar = splitTaskProject.Get(Prj.Calendar);
// Set project's calendar settings
splitTaskProject.Set(Prj.StartDate, new DateTime(2000, 3, 15, 8, 0, 0));
splitTaskProject.Set(Prj.FinishDate, new DateTime(2000, 4, 21, 17, 0, 0));
// Add a new task to root task
Task rootTask = splitTaskProject.RootTask;
rootTask.Set(Tsk.Name, "Root");
Task taskToSplit = rootTask.Children.Add("Task1");
taskToSplit.Set(Tsk.Duration, splitTaskProject.GetDuration(3));
// Create a new resource assignment and generate timephased data
ResourceAssignment splitResourceAssignment = splitTaskProject.ResourceAssignments.Add(taskToSplit, null);
splitResourceAssignment.TimephasedDataFromTaskDuration(calendar);
// Split the task into 3 parts.
// Provide start date and finish date arguments to SplitTask method which will be used for split
splitResourceAssignment.SplitTask(new DateTime(2000, 3, 16, 8, 0, 0), new DateTime(2000, 3, 16, 17, 0, 0), calendar);
splitResourceAssignment.SplitTask(new DateTime(2000, 3, 18, 8, 0, 0), new DateTime(2000, 3, 18, 17, 0, 0), calendar);
splitResourceAssignment.Set(Asn.WorkContour, WorkContourType.Contoured);
// Save the Project
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
splitTaskProject.Save(dataDir + "CreateSplitTasks_out.xml", SaveFileFormat.XML);
// ExEnd:CreateSplitTasks
}
示例2: Run
public static void Run()
{
// ExStart:WriteTaskDuration
// Create a new project and add a new task
Project project = new Project();
Task task = project.RootTask.Children.Add("Task");
// Task duration in days (default time unit)
Duration duration = task.Get(Tsk.Duration);
Console.WriteLine("Duration equals 1 day: {0}", duration.ToString().Equals("1 day"));
// Convert to hours time unit
duration = duration.Convert(TimeUnitType.Hour);
Console.WriteLine("Duration equals 8 hrs: {0}", duration.ToString().Equals("8 hrs"));
// Get wrapped TimeSpan instance
Console.WriteLine("Duration TimeSpan equals to TimeSpan of 8 hrs: {0}", duration.TimeSpan.Equals(TimeSpan.FromHours(8)));
// Increase task duration to 1 week and display if duration is updated successfully
task.Set(Tsk.Duration, project.GetDuration(1, TimeUnitType.Week));
Console.WriteLine("Duration equals 1 wk: {0}", task.Get(Tsk.Duration).ToString().Equals("1 wk"));
// Decrease task duration and display if duration is updated successfully
task.Set(Tsk.Duration, task.Get(Tsk.Duration).Subtract(0.5));
Console.WriteLine("Duration equals 0.5 wks: {0}", task.Get(Tsk.Duration).ToString().Equals("0.5 wks"));
// ExEnd:WriteTaskDuration
// Save project as PDF
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
project.Save(dataDir + "WriteTaskDuration_out.pdf", SaveFileFormat.PDF);
}
示例3: Run
public static void Run()
{
try
{
// ExStart:UpdateTaskData
// Create project instance
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
string newProject = "UpdateTaskData.mpp";
Project project = new Project(dataDir + newProject);
// Set project start date
project.Set(Prj.StartDate, new DateTime(2012, 07, 29, 8, 0, 0));
// Add summary task and set its properties
Task summary = project.RootTask.Children.Add("Summary task");
Task task1 = summary.Children.Add("First task");
task1.Set(Tsk.Duration, project.GetDuration(3));
task1.Set(Tsk.Deadline, task1.Get(Tsk.Start).AddDays(10));
task1.Set(Tsk.NotesText, "The first task.");
task1.Set(Tsk.DurationFormat, TimeUnitType.MinuteEstimated);
task1.Set(Tsk.ConstraintType, ConstraintType.FinishNoLaterThan);
task1.Set(Tsk.ConstraintDate, task1.Get(Tsk.Deadline).AddDays(-1));
// Create 10 new sub tasks for summary task
for (int i = 0; i < 10; i++)
{
Task subTask = summary.Children.Add(string.Format("Task{0}", i + 2));
subTask.Set(Tsk.Duration, task1.Get(Tsk.Duration).Add(project.GetDuration(i + 1)));
subTask.Set(Tsk.DurationFormat, TimeUnitType.Day);
subTask.Set(Tsk.Deadline, task1.Get(Tsk.Deadline).AddDays(i + 1));
}
// Save the Project
project.Save(dataDir + "project_UpdateTaskData_updated_out.mpp", SaveFileFormat.MPP);
// ExEnd:UpdateTaskData
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
}
}
示例4: Run
public static void Run()
{
// ExStart:ChangeTaskProgress
Project project = new Project();
Console.WriteLine("Project Calculation mode is Automatic: {0}", project.CalculationMode.Equals(CalculationMode.Automatic));
Task task = project.RootTask.Children.Add("Task");
task.Set(Tsk.Duration, project.GetDuration(2));
task.Set(Tsk.PercentComplete, 50);
// ExEnd:ChangeTaskProgress
}
示例5: Run
public static void Run()
{
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// ExStart:AddNewTask
Project project = new Project(dataDir + "Project1.mpp");
Task task = project.RootTask.Children.Add("Task1");
task.Set(Tsk.ActualStart, DateTime.Parse("23-Aug-2012"));
// Set duration in hours
task.Set(Tsk.Duration, project.GetDuration(24, TimeUnitType.Hour));
task.Set(Tsk.DurationFormat, TimeUnitType.Day);
project.RootTask.Children.Add(task);
// Save the Project as XML
project.Save(dataDir + "AddNewTask_out.xml", SaveFileFormat.XML);
// ExEnd:AddNewTask
}
示例6: Run
public static void Run()
{
// ExStart:ReadWriteTimephasedData
// Create project instance
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Project project1 = new Project(dataDir + "ReadWriteTimephasedData.mpp");
// Set project properties
project1.Set(Prj.StartDate, new DateTime(2013, 10, 30, 9, 0, 0));
project1.Set(Prj.NewTasksAreManual, false);
// Add task and resources
Task task = project1.RootTask.Children.Add("Task");
Resource rsc = project1.Resources.Add("Rsc");
// Set resource rates and task duration
rsc.Set(Rsc.StandardRate, 10);
rsc.Set(Rsc.OvertimeRate, 15);
task.Set(Tsk.Duration, project1.GetDuration(6));
// Create resource assignment
ResourceAssignment assn = project1.ResourceAssignments.Add(task, rsc);
assn.Set(Asn.Stop, DateTime.MinValue);
assn.Set(Asn.Resume, DateTime.MinValue);
// Set Backloaded contour, it increases task duration from 6 to 10 days
assn.Set(Asn.WorkContour, WorkContourType.BackLoaded);
project1.SetBaseline(BaselineType.Baseline);
task.Set(Tsk.PercentComplete, 50);
// Read timephased data
List<TimephasedData> td = assn.GetTimephasedData(assn.Get(Asn.Start), assn.Get(Asn.Finish), TimephasedDataType.AssignmentRemainingWork).ToList();
Console.WriteLine(td.Count);
foreach(TimephasedData timePhasedValue in td)
{
Console.WriteLine(timePhasedValue.Value);
}
// ExEnd:ReadWriteTimephasedData
}
示例7: Run
public static void Run()
{
try
{
// ExStart:WriteMetadataToMPP
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Project project = new Project(dataDir + "Project1.mpp");
// Add working times to project calendar
WorkingTime wt = new WorkingTime();
wt.FromTime = new DateTime(2010, 1, 1, 19, 0, 0);
wt.ToTime = new DateTime(2010, 1, 1, 20, 0, 0);
WeekDay day = project.Get(Prj.Calendar).WeekDays.ToList()[1];
day.WorkingTimes.Add(wt);
// Change calendar name
project.Get(Prj.Calendar).Name = "CHANGED NAME!";
// Add tasks and set task meta data
Task task = project.RootTask.Children.Add("Task 1");
task.Set(Tsk.DurationFormat, TimeUnitType.Day);
task.Set(Tsk.Duration, project.GetDuration(3));
task.Set(Tsk.Contact, "Rsc 1");
task.Set(Tsk.IsMarked, true);
task.Set(Tsk.IgnoreWarnings, true);
Task task2 = project.RootTask.Children.Add("Task 2");
task2.Set(Tsk.DurationFormat, TimeUnitType.Day);
task2.Set(Tsk.Contact, "Rsc 2");
// Link tasks
project.TaskLinks.Add(task, task2, TaskLinkType.FinishToStart, project.GetDuration(-1, TimeUnitType.Day));
// Set project start date
project.Set(Prj.StartDate, new DateTime(2013, 8, 13, 9, 0, 0));
// Add resource and set resource meta data
Resource rsc1 = project.Resources.Add("Rsc 1");
rsc1.Set(Rsc.Type, ResourceType.Work);
rsc1.Set(Rsc.Initials, "WR");
rsc1.Set(Rsc.AccrueAt, CostAccrualType.Prorated);
rsc1.Set(Rsc.MaxUnits, 1);
rsc1.Set(Rsc.Code, "Code 1");
rsc1.Set(Rsc.Group, "Workers");
rsc1.Set(Rsc.EMailAddress, "[email protected]");
rsc1.Set(Rsc.WindowsUserAccount, "user_acc1");
rsc1.Set(Rsc.IsGeneric, new NullableBool(true));
rsc1.Set(Rsc.AccrueAt, CostAccrualType.End);
rsc1.Set(Rsc.StandardRate, 10);
rsc1.Set(Rsc.StandardRateFormat, RateFormatType.Day);
rsc1.Set(Rsc.OvertimeRate, 15);
rsc1.Set(Rsc.OvertimeRateFormat, RateFormatType.Hour);
rsc1.Set(Rsc.IsTeamAssignmentPool, true);
rsc1.Set(Rsc.CostCenter, "Cost Center 1");
// Create resource assignment and set resource assignment meta data
ResourceAssignment assn = project.ResourceAssignments.Add(task, rsc1);
assn.Set(Asn.Uid, 1);
assn.Set(Asn.Work, task.Get(Tsk.Duration));
assn.Set(Asn.RemainingWork, assn.Get(Asn.Work));
assn.Set(Asn.RegularWork, assn.Get(Asn.Work));
task.Set(Tsk.Work, assn.Get(Asn.Work));
rsc1.Set(Rsc.Work, task.Get(Tsk.Work));
assn.Set(Asn.Start, task.Get(Tsk.Start));
assn.Set(Asn.Finish, task.Get(Tsk.Finish));
// Add extended attribute for project and task
ExtendedAttributeDefinition attr = new ExtendedAttributeDefinition();
attr.FieldId = ((int)ExtendedAttributeTask.Flag1).ToString();
attr.Alias = "Labeled";
project.ExtendedAttributes.Add(attr);
ExtendedAttribute taskAttr = new ExtendedAttribute();
taskAttr.Value = "1";
taskAttr.FieldId = attr.FieldId;
task2.ExtendedAttributes.Add(taskAttr);
// Save project as MPP
project.Save(dataDir + "WriteMetaData_out.mpp", SaveFileFormat.MPP);
// ExEnd:WriteMetadataToMPP
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
}
}
示例8: Run
public static void Run()
{
try
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
// ExStart:AddTaskExtendedAttributes
// Create new project
Project project1 = new Project(dataDir + "Blank2010.mpp");
// Create the Extended Attribute Definition of Text Type
ExtendedAttributeDefinition taskExtendedAttributeText9Definition;
taskExtendedAttributeText9Definition = new ExtendedAttributeDefinition();
taskExtendedAttributeText9Definition.Alias = "Task City Name";
taskExtendedAttributeText9Definition.FieldName = "Text9";
taskExtendedAttributeText9Definition.ElementType = ElementType.Task;
taskExtendedAttributeText9Definition.CfType = CustomFieldType.Text;
taskExtendedAttributeText9Definition.FieldId = Convert.ToInt32(ExtendedAttributeTask.Text9).ToString(System.Globalization.CultureInfo.InvariantCulture);
// Create an Extended Attribute Definition of Flag Type
ExtendedAttributeDefinition taskExtendedAttributeFlag1Definition;
taskExtendedAttributeFlag1Definition = new ExtendedAttributeDefinition();
taskExtendedAttributeFlag1Definition.Alias = "Is Billable";
taskExtendedAttributeFlag1Definition.FieldName = "Flag1";
taskExtendedAttributeFlag1Definition.ElementType = ElementType.Task;
taskExtendedAttributeFlag1Definition.CfType = CustomFieldType.Flag;
taskExtendedAttributeFlag1Definition.FieldId = Convert.ToInt32(ExtendedAttributeTask.Flag1).ToString(System.Globalization.CultureInfo.InvariantCulture);
// Add the Extended Attribute Definitions to the Project's Extended Attribute Collection
project1.ExtendedAttributes.Add(taskExtendedAttributeText9Definition);
project1.ExtendedAttributes.Add(taskExtendedAttributeFlag1Definition);
// Add a task to project and set its properties
Task task = project1.RootTask.Children.Add("Task 1");
task.Set(Tsk.Start, new DateTime(2016, 7, 27, 8, 0, 0));
task.Set(Tsk.Duration, project1.GetDuration(8, TimeUnitType.Hour));
// Create Extended Attribute and set it's values
ExtendedAttribute taskExtendedAttributeText9 = new ExtendedAttribute();
taskExtendedAttributeText9.FieldId = taskExtendedAttributeText9Definition.FieldId;
taskExtendedAttributeText9.Value = "London";
// Create Extended Attribute of Flag type and set it's values
ExtendedAttribute taskExtendedAttributeFlag1 = new ExtendedAttribute();
taskExtendedAttributeFlag1.FieldId = taskExtendedAttributeFlag1Definition.FieldId;
taskExtendedAttributeFlag1.Value = "1";
// Add the Extended Attributes to Task
task.ExtendedAttributes.Add(taskExtendedAttributeText9);
task.ExtendedAttributes.Add(taskExtendedAttributeFlag1);
// Save the Project
project1.Save(dataDir + "AddTaskExtendedAttributes_out.mpp", SaveFileFormat.MPP);
// ExEnd:AddTaskExtendedAttributes
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
}
}