Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active October 31, 2020 15:14
Show Gist options
  • Save aspose-com-gists/85d3cb818a62006b9ae8f8e3eaab6f80 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/85d3cb818a62006b9ae8f8e3eaab6f80 to your computer and use it in GitHub Desktop.
Aspose.Tasks for C++
Gists for Aspose.Tasks for C++.
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"Project2.mpp");
System::SharedPtr<SaveOptions> options = System::MakeObject<PdfSaveOptions>();
options->set_Timescale(Aspose::Tasks::Visualization::Timescale::Months);
options->set_View(ProjectView::GetDefaultGanttChartView());
System::SharedPtr<GanttChartColumn> column1 = System::DynamicCast_noexcept<Aspose::Tasks::Visualization::GanttChartColumn>(options->get_View()->get_Columns()->idx_get(2));
column1->set_StringAlignment(System::Drawing::StringAlignment::Center);
column1 = System::DynamicCast_noexcept<Aspose::Tasks::Visualization::GanttChartColumn>(options->get_View()->get_Columns()->idx_get(3));
column1->set_StringAlignment(System::Drawing::StringAlignment::Far);
column1 = System::DynamicCast_noexcept<Aspose::Tasks::Visualization::GanttChartColumn>(options->get_View()->get_Columns()->idx_get(4));
column1->set_StringAlignment(System::Drawing::StringAlignment::Far);
project->Save(dataDir + u"AlignCellContents_GanttChart_out.pdf", options);
options->set_PresentationFormat(Aspose::Tasks::Visualization::PresentationFormat::ResourceSheet);
options->set_View(ProjectView::GetDefaultResourceSheetView());
System::SharedPtr<ResourceViewColumn> column2 = System::DynamicCast_noexcept<Aspose::Tasks::Visualization::ResourceViewColumn>(options->get_View()->get_Columns()->idx_get(2));
column2->set_StringAlignment(System::Drawing::StringAlignment::Center);
column2 = System::DynamicCast_noexcept<Aspose::Tasks::Visualization::ResourceViewColumn>(options->get_View()->get_Columns()->idx_get(3));
column2->set_StringAlignment(System::Drawing::StringAlignment::Far);
column2 = System::DynamicCast_noexcept<Aspose::Tasks::Visualization::ResourceViewColumn>(options->get_View()->get_Columns()->idx_get(4));
column2->set_StringAlignment(System::Drawing::StringAlignment::Far);
project->Save(dataDir + u"AlignCellContents_ResourceSheet_out.pdf", options);
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"Project2.mpp");
System::SharedPtr<SaveOptions> options = System::MakeObject<XamlOptions>();
options->set_UseGradientBrush(false);
project->Save(dataDir + u"ChangeGanttBarsColorGradient_Solid_out.xaml", options);
options->set_UseGradientBrush(true);
project->Save(dataDir + u"ChangeGanttBarsColorGradient_Gradient_out.xaml", options);
System::SharedPtr<Project> project = System::MakeObject<Project>();
System::SharedPtr<Task> task1 = project->get_RootTask()->get_Children()->Add(u"Task 1");
System::SharedPtr<Task> task2 = project->get_RootTask()->get_Children()->Add(u"Task 2");
task1->Set<Duration>(Tsk::Duration(), project->GetDuration(1, Aspose::Tasks::TimeUnitType::Day));
task2->Set<Duration>(Tsk::Duration(), project->GetDuration(1, Aspose::Tasks::TimeUnitType::Day));
System::SharedPtr<TaskLink> link = project->get_TaskLinks()->Add(task1, task2, Aspose::Tasks::TaskLinkType::FinishToStart);
System::SharedPtr<Task> task3 = project->get_RootTask()->get_Children()->Add(u"Task 3");
System::SharedPtr<Resource> rsc1 = project->get_Resources()->Add(u"Resource 1");
System::SharedPtr<Resource> rsc2 = project->get_Resources()->Add(u"Resource 2");
System::SharedPtr<Resource> rsc3 = project->get_Resources()->Add(u"Resource 3");
System::SharedPtr<ResourceAssignment> assn1 = project->get_ResourceAssignments()->Add(task1, rsc1);
System::SharedPtr<ResourceAssignment> assn2 = project->get_ResourceAssignments()->Add(task2, rsc2);
System::SharedPtr<ResourceAssignment> assn3 = project->get_ResourceAssignments()->Add(task3, rsc3);
System::SharedPtr<SaveOptions> options = System::MakeObject<PdfSaveOptions>();
options->set_Timescale(Aspose::Tasks::Visualization::Timescale::ThirdsOfMonths);
System::SharedPtr<BarStyle> style = System::MakeObject<BarStyle>();
style->set_ItemType(Aspose::Tasks::Visualization::BarItemType::CriticalTask);
style->set_BarTextConverter(&CustomizeTextWithTaskBars::_anonymous_method_0);
System::SharedPtr<BarStyle> style2 = System::MakeObject<BarStyle>();
style2->set_BarColor(System::Drawing::Color::get_DarkOrchid());
style2->set_ItemType(Aspose::Tasks::Visualization::BarItemType::Task);
options->set_BarStyles(System::MakeObject<System::Collections::Generic::List<System::SharedPtr<BarStyle>>>());
options->get_BarStyles()->Add(style);
options->get_BarStyles()->Add(style2);
project->Save(dataDir + u"result2.pdf", options);
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CustomBarStyle.mpp");
System::SharedPtr<GanttChartView> view = System::DynamicCast_noexcept<Aspose::Tasks::GanttChartView>(project->get_DefaultView());
System::Console::WriteLine(u"Custom bar styles count: {0}", System::ObjectExt::Box<int32_t>(view->get_CustomBarStyles()->get_Count()));
System::SharedPtr<GanttBarStyle> style1 = view->get_CustomBarStyles()->idx_get(0);
System::Console::WriteLine(u"Style1.LeftField is TaskDurationText : {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(style1->get_LeftField(), Aspose::Tasks::Field::TaskDurationText)));
System::Console::WriteLine(u"Style1.RightField is TaskResourceNames : {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(style1->get_RightField(), Aspose::Tasks::Field::TaskResourceNames)));
System::Console::WriteLine(u"Style1.TopField is TaskACWP: {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(style1->get_TopField(), Aspose::Tasks::Field::TaskACWP)));
System::Console::WriteLine(u"Style1.BottomField is Undefined : {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(style1->get_BottomField(), Aspose::Tasks::Field::Undefined)));
System::Console::WriteLine(u"Style1.InsideField is Undefined : {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(style1->get_InsideField(), Aspose::Tasks::Field::Undefined)));
System::SharedPtr<GanttBarStyle> style2 = view->get_CustomBarStyles()->idx_get(1);
System::Console::WriteLine(u"Style2.LeftField is TaskActualWork : {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(style2->get_LeftField(), Aspose::Tasks::Field::TaskActualWork)));
System::Console::WriteLine(u"Style2.RightField is TaskActualCost : {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(style2->get_RightField(), Aspose::Tasks::Field::TaskActualCost)));
System::Console::WriteLine(u"Style2.TopField is Undefined : {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(style2->get_TopField(), Aspose::Tasks::Field::Undefined)));
System::Console::WriteLine(u"Style2.BottomField is Undefined : {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(style2->get_BottomField(), Aspose::Tasks::Field::Undefined)));
System::Console::WriteLine(u"Style2.InsideField is Undefined : {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(style2->get_InsideField(), Aspose::Tasks::Field::Undefined)));
System::SharedPtr<GanttBarStyle> style3 = view->get_CustomBarStyles()->idx_get(2);
System::Console::WriteLine(u"Style3.LeftField is TaskPercentComplete : {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(style3->get_LeftField(), Aspose::Tasks::Field::TaskPercentComplete)));
System::Console::WriteLine(u"Style3.RightField is TaskPercentWorkComplete : {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(style3->get_RightField(), Aspose::Tasks::Field::TaskPercentWorkComplete)));
System::Console::WriteLine(u"Style3.TopField is Field.TaskActive : {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(style3->get_TopField(), Aspose::Tasks::Field::TaskActive)));
System::Console::WriteLine(u"Style3.BottomField is TaskActualCost : {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(style3->get_BottomField(), Aspose::Tasks::Field::TaskActualCost)));
System::Console::WriteLine(u"Style3.InsideField is Field.TaskActualDuration : {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(style3->get_InsideField(), Aspose::Tasks::Field::TaskActualDuration)));
System::Console::WriteLine(u"Style3.StartShape is HouseDown : {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(style3->get_StartShape(), Aspose::Tasks::Visualization::GanttBarEndShape::HouseDown)));
System::Console::WriteLine(u"Style3.StartShapeType is Framed : {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(style3->get_StartShapeType(), Aspose::Tasks::Visualization::GanttBarType::Framed)));
System::Console::WriteLine(u"Style3.StartShapeColor is Red : {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(style3->get_StartShapeColor(), System::Drawing::Color::FromArgb(System::Drawing::Color::get_Red().ToArgb()))));
System::Console::WriteLine(u"Style3.EndShape is CircleDiamond : {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(style3->get_EndShape(), Aspose::Tasks::Visualization::GanttBarEndShape::CircleDiamond)));
System::Console::WriteLine(u"Style3.EndShapeType is Solid : {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(style3->get_EndShapeType(), Aspose::Tasks::Visualization::GanttBarType::Solid)));
System::Console::WriteLine(u"Style3.EndShapeColor is Yellow : {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(style3->get_EndShapeColor(), System::Drawing::Color::FromArgb(System::Drawing::Color::get_Yellow().ToArgb()))));
System::Console::WriteLine(u"Style3.MiddleShape is RectangleTop : {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(style3->get_MiddleShape(), Aspose::Tasks::Visualization::GanttBarMiddleShape::RectangleTop)));
System::Console::WriteLine(u"Style3.MiddleFillPattern is SolidFill : {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(style3->get_MiddleFillPattern(), Aspose::Tasks::Visualization::GanttBarFillPattern::SolidFill)));
System::Console::WriteLine(u"Style3.EndShapeColor is Red : {0}", System::ObjectExt::Box<bool>(System::ObjectExt::Equals(style3->get_MiddleShapeColor(), System::Drawing::Color::FromArgb(System::Drawing::Color::get_Red().ToArgb()))));
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"Project2.mpp");
PresentationFormat presentationFormat = Aspose::Tasks::Visualization::PresentationFormat::GanttChart;
System::String resultFile = System::String(u"RenderDifferentPresentationFormatsToXAML_") + System::ObjectExt::ToString(presentationFormat) + u"_out.xaml";
System::SharedPtr<SaveOptions> options = System::MakeObject<XamlOptions>();
options->set_PresentationFormat(presentationFormat);
project->Save(dataDir + resultFile, options);
System::SharedPtr<PdfSaveOptions> options = System::MakeObject<PdfSaveOptions>();
options->set_PresentationFormat(Aspose::Tasks::Visualization::PresentationFormat::GanttChart);
options->set_FitContent(true);
options->set_RollUpGanttBars(false);
options->set_DrawNonWorkingTime(false);
options->set_PageSize(Aspose::Tasks::Visualization::PageSize::A3);
System::String file = System::IO::Path::Combine(dataDir, fileName);
System::String resultFile = System::IO::Path::Combine(dataDir, u"RenderGanttChartWithBarsNotRolledUp_out.pdf");
System::SharedPtr<Project> project = System::MakeObject<Project>(file);
project->Save(resultFile, System::StaticCast<Aspose::Tasks::Saving::SaveOptions>(options));
System::SharedPtr<PdfSaveOptions> options = System::MakeObject<PdfSaveOptions>();
options->set_PresentationFormat(Aspose::Tasks::Visualization::PresentationFormat::GanttChart);
options->set_FitContent(true);
options->set_RollUpGanttBars(true);
options->set_DrawNonWorkingTime(true);
options->set_PageSize(Aspose::Tasks::Visualization::PageSize::A3);
System::String file = System::IO::Path::Combine(dataDir, fileName);
System::String resultFile = System::IO::Path::Combine(dataDir, u"RenderGanttChartWithBarsNotRolledUp_out.pdf");
System::SharedPtr<Project> project = System::MakeObject<Project>(file);
//for (int i = 14; i <= 23; i++)
// project.GetTaskById(i).HideBar = false;
project->Save(resultFile, System::StaticCast<Aspose::Tasks::Saving::SaveOptions>(options));
// Source file to be converted to TIFF
System::String file = u"Project2.mpp";
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + file);
// Save the project to TIFF
project->Save(dataDir + u"RenderMultipageTIFF_out.tif", Aspose::Tasks::Saving::SaveFileFormat::TIFF);
// Save the project with CCITT4 compression
System::SharedPtr<ImageSaveOptions> options = System::MakeObject<ImageSaveOptions>(Aspose::Tasks::Saving::SaveFileFormat::TIFF);
options->set_TiffCompression(Aspose::Tasks::Saving::TiffCompression::Ccitt4);
project->Save(dataDir + u"RenderMultipageTIFF_options_out.tif", System::StaticCast<Aspose::Tasks::Saving::SaveOptions>(options));
// Remove the compression
options->set_TiffCompression(Aspose::Tasks::Saving::TiffCompression::None);
project->Save(dataDir + u"RenderMultipageTIFF_comp_none_out.tif", System::StaticCast<Aspose::Tasks::Saving::SaveOptions>(options));
// Source File to Render
System::String fileName = u"Project2.mpp";
// Read the Project
System::SharedPtr<Project> project1 = System::MakeObject<Project>(dataDir + fileName);
// Select a Presentation format
PresentationFormat format = Aspose::Tasks::Visualization::PresentationFormat::GanttChart;
// Render the project to all Pre-Defined page sizes
{
for (PageSize pageSize : System::DynamicCast<System::Array<Aspose::Tasks::Visualization::PageSize>>(System::Enum<PageSize>::GetValues()))
{
System::SharedPtr<PdfSaveOptions> options = System::MakeObject<PdfSaveOptions>();
options->set_PresentationFormat(format);
options->set_FitContent(true);
options->set_PageSize(pageSize);
System::String resultFile = System::String(u"result_PredefinedPageSizes_") + System::ObjectExt::ToString(format) + u"_" + System::ObjectExt::ToString(pageSize) + u"_out.pdf";
project1->Save(dataDir + resultFile, System::StaticCast<Aspose::Tasks::Saving::SaveOptions>(options));
}
}
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"Project2.mpp");
System::String resultFile = u"RenderToXAML_out.xaml";
project->Save(dataDir + resultFile, Aspose::Tasks::Saving::SaveFileFormat::XAML);
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"Project2.mpp");
const System::String resultFile = u"RenderXAMLWithOptions_out.xaml";
System::SharedPtr<SaveOptions> options = System::MakeObject<XamlOptions>();
options->set_FitContent(true);
options->set_LegendOnEachPage(false);
options->set_Timescale(Aspose::Tasks::Visualization::Timescale::ThirdsOfMonths);
project->Save(dataDir + resultFile, options);
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"Project2.mpp");
project->Set(Prj::TimescaleStart(), System::DateTime(2012, 4, 30));
project->Save(dataDir + u"SetGanttChartViewStartDate_out.mpp", Aspose::Tasks::Saving::SaveFileFormat::MPP);
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"Project2.mpp");
// Save to one page image (Timescale.days by default)
project->Save(u"NewProductDevDays.jpeg", System::MakeObject<ImageSaveOptions>(Aspose::Tasks::Saving::SaveFileFormat::JPEG));
// Save to one page image (Timescale.ThirdsOfMonths)
System::SharedPtr<ImageSaveOptions> options = System::MakeObject<ImageSaveOptions>(Aspose::Tasks::Saving::SaveFileFormat::JPEG);
options->set_Timescale(Aspose::Tasks::Visualization::Timescale::ThirdsOfMonths);
project->Save(u"NewProductDevThirdsOfMonths.jpeg", options);
// Save to one page image (Timescale.Months)
options->set_Timescale(Aspose::Tasks::Visualization::Timescale::Months);
project->Save(u"NewProductDevMonths.jpeg", options);
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CreateProject2.mpp");
auto options = [&]{ auto tmp_0 = System::MakeObject<PdfSaveOptions>(); tmp_0->set_PresentationFormat(Aspose::Tasks::Visualization::PresentationFormat::GanttChart); tmp_0->set_FitContent(true); tmp_0->set_UseProjectDefaultFont(false); tmp_0->set_DefaultFontName(u"Segoe UI Black"); return tmp_0; }();
project->Save(dataDir + u"CreateProject2_out.pdf", System::StaticCast<Aspose::Tasks::Saving::SaveOptions>(options));
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CreateProject2.mpp");
System::SharedPtr<HtmlSaveOptions> options = [&]{ auto tmp_0 = System::MakeObject<HtmlSaveOptions>(); tmp_0->set_CssStylePrefix(u"test_prefix"); return tmp_0; }();
project->Save(dataDir + u"TestCssStylePrefix_out.html", options);
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CreateProject2.mpp");
System::SharedPtr<HtmlSaveOptions> htmlSaveOptions = System::MakeObject<HtmlSaveOptions>();
// Determines whether to include project name in HTML title (true by default)
htmlSaveOptions->set_IncludeProjectNameInTitle(false);
// Determines whether to include project name in HTML page header (true by default)
htmlSaveOptions->set_IncludeProjectNameInPageHeader(false);
htmlSaveOptions->set_Pages(System::MakeObject<System::Collections::Generic::List<int32_t>>());
htmlSaveOptions->get_Pages()->Add(1);
project->Save(dataDir + u"ControlHeaderNameDuringHTMLExport_out.html", htmlSaveOptions);
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CreateProject2.mpp");
project->Set(Prj::StartDate(), System::DateTime(2014, 9, 22));
// By default project.DateFormat == DateFormat.Date_ddd_mm_dd_yy (Mon 09/22/14) customize DateFormat (September 22, 2014)
project->Set<DateFormat>(Prj::DateFormat(), Aspose::Tasks::DateFormat::DateMmmmDdYyyy);
project->Save(dataDir + u"CustomizeDateFormats1_out.pdf", Aspose::Tasks::Saving::SaveFileFormat::PDF);
// Export to date format 19/07/2016
project->Set<DateFormat>(Prj::DateFormat(), Aspose::Tasks::DateFormat::DateDdMmYyyy);
project->Save(dataDir + u"CustomizeDateFormats2_out.pdf", Aspose::Tasks::Saving::SaveFileFormat::PDF);
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CreateProject2.mpp");
System::SharedPtr<SaveOptions> options = System::MakeObject<PdfSaveOptions>();
options->set_PresentationFormat(Aspose::Tasks::Visualization::PresentationFormat::ResourceSheet);
System::SharedPtr<TextStyle> style = System::MakeObject<TextStyle>();
style->set_Color(System::Drawing::Color::get_OrangeRed());
style->set_FontStyle(System::Drawing::FontStyle::Bold);
System::setter_or_wrap(style.GetPointer(), &TextStyle::get_FontStyle, &TextStyle::set_FontStyle, System::Drawing::FontStyle::Italic);
style->set_ItemType(Aspose::Tasks::Visualization::TextItemType::OverallocatedResources);
options->set_TextStyles(System::MakeObject<System::Collections::Generic::List<System::SharedPtr<TextStyle>>>());
options->get_TextStyles()->Add(style);
project->Save(dataDir + u"CustomizeTextStyle_out.pdf", options);
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CreateProject2.mpp");
System::SharedPtr<SaveOptions> saveOptions = System::MakeObject<PdfSaveOptions>();
// Set option fit content to true
saveOptions->set_FitContent(true);
saveOptions->set_Timescale(Aspose::Tasks::Visualization::Timescale::Months);
saveOptions->set_PresentationFormat(Aspose::Tasks::Visualization::PresentationFormat::TaskUsage);
project->Save(dataDir + u"FitContentsToCellSize_out.pdf", saveOptions);
System::SharedPtr<SaveOptions> saveOptions = System::MakeObject<PdfSaveOptions>();
// Set the LegendOnEachPage property to false to hide legends
saveOptions->set_LegendOnEachPage(false);
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CreateProject2.mpp");
System::SharedPtr<ImageSaveOptions> saveOptions = System::MakeObject<ImageSaveOptions>(Aspose::Tasks::Saving::SaveFileFormat::PNG);
saveOptions->set_StartDate(project->Get<System::DateTime>(Prj::StartDate()).AddDays(-3));
saveOptions->set_EndDate(project->Get<System::DateTime>(Prj::FinishDate()));
saveOptions->set_MarkCriticalTasks(true);
saveOptions->set_LegendOnEachPage(false);
saveOptions->set_Gridlines(System::MakeObject<System::Collections::Generic::List<System::SharedPtr<Gridline>>>());
System::SharedPtr<Gridline> gridline = System::MakeObject<Gridline>();
gridline->set_GridlineType(Aspose::Tasks::Visualization::GridlineType::GanttRow);
gridline->set_Color(System::Drawing::Color::get_CornflowerBlue());
gridline->set_Pattern(Aspose::Tasks::Visualization::LinePattern::Dashed);
saveOptions->get_Gridlines()->Add(gridline);
// Save the whole project layout to one file
project->Save(dataDir + u"PrintProjectPagesToSeparateFiles1_out.png", System::StaticCast<Aspose::Tasks::Saving::SaveOptions>(saveOptions));
// Save project layout to separate files
saveOptions->set_SaveToSeparateFiles(true);
project->Save(dataDir + u"PrintProjectPagesToSeparateFiles2_out.png", System::StaticCast<Aspose::Tasks::Saving::SaveOptions>(saveOptions));
// The path to the documents directory.
System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
//Read the MPP file.
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CreateProject2.mpp");
//Use ReduceFooterGap property to reduce the gap between list of tasks and Footer
auto imageSaveOptions = [&]{ auto tmp_0 = System::MakeObject<ImageSaveOptions>(Aspose::Tasks::Saving::SaveFileFormat::PNG); tmp_0->set_ReduceFooterGap(true); tmp_0->set_SaveToSeparateFiles(true); tmp_0->set_PageSize(Aspose::Tasks::Visualization::PageSize::A0); tmp_0->set_Timescale(Aspose::Tasks::Visualization::Timescale::Days); return tmp_0; }();
project->Save(dataDir + u"ReducingGapBetweenTasksListAndFooter_out.png", System::StaticCast<Aspose::Tasks::Saving::SaveOptions>(imageSaveOptions));
auto pdfSaveOptions = [&]{ auto tmp_1 = System::MakeObject<PdfSaveOptions>(); tmp_1->set_ReduceFooterGap(true); tmp_1->set_SaveToSeparateFiles(true); tmp_1->set_PageSize(Aspose::Tasks::Visualization::PageSize::A0); tmp_1->set_Timescale(Aspose::Tasks::Visualization::Timescale::Days); return tmp_1; }();
project->Save(dataDir + u"ReducingGapBetweenTasksListAndFooter_out.pdf", System::StaticCast<Aspose::Tasks::Saving::SaveOptions>(pdfSaveOptions));
auto htmlSaveOptions = [&]{ auto tmp_2 = System::MakeObject<HtmlSaveOptions>(); tmp_2->set_ReduceFooterGap(false); tmp_2->set_IncludeProjectNameInPageHeader(false); tmp_2->set_IncludeProjectNameInTitle(false); tmp_2->set_PageSize(Aspose::Tasks::Visualization::PageSize::A0); tmp_2->set_Timescale(Aspose::Tasks::Visualization::Timescale::Days); return tmp_2; }();
project->Save(dataDir + u"ReducingGapBetweenTasksListAndFooter_out.html", htmlSaveOptions);
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"Input.mpp");
project->get_DefaultView()->get_PageInfo()->get_PageViewSettings()->set_PrintNotes(true);
project->Save(dataDir + u"ProjectWithComments.pdf", Aspose::Tasks::Saving::SaveFileFormat::PDF);
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"TestProject1.mpp");
System::SharedPtr<ImageSaveOptions> options = System::MakeObject<ImageSaveOptions>(Aspose::Tasks::Saving::SaveFileFormat::TIFF);
options->set_HorizontalResolution(72.0f);
options->set_VerticalResolution(72.0f);
options->set_PixelFormat(System::Drawing::Imaging::PixelFormat::Format24bppRgb);
project->Save(dataDir + u"RenderProjectDataToFormat24bppRgb_out.tif", System::StaticCast<Aspose::Tasks::Saving::SaveOptions>(options));
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CreateProject1.mpp");
project->Save(dataDir + u"SaveProjectAsCSV_out.csv", Aspose::Tasks::Saving::SaveFileFormat::CSV);
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CreateProject2.mpp");
// in order to manipulate JPEG quality one can use ImageSaveOptions.JpegQuality property.
// The allowed value range is 0..100.
auto options = [&]{ auto tmp_0 = System::MakeObject<ImageSaveOptions>(Aspose::Tasks::Saving::SaveFileFormat::JPEG); tmp_0->set_JpegQuality(50); return tmp_0; }();
project->Save(dataDir + u"image_out.jpeg", System::StaticCast<Aspose::Tasks::Saving::SaveOptions>(options));
// Read the input Project file
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CreateProject2.mpp");
// Save the Project as PDF
project->Save(dataDir + u"SaveProjectAsPDF_out.pdf", Aspose::Tasks::Saving::SaveFileFormat::PDF);
// Read the input Project file
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CreateProject1.mpp");
// Save the Project as SVG
project->Save(dataDir + u"SaveProjectAsSVG_out.SVG", Aspose::Tasks::Saving::SaveFileFormat::SVG);
// Read the input Project file
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CreateProject2.mpp");
// Save the Project as text
project->Save(dataDir + u"SaveProjectAsText_out.txt", Aspose::Tasks::Saving::SaveFileFormat::TXT);
// Read the input Project file
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CreateProject2.mpp");
// Save the Project as XLSX
project->Save(dataDir + u"SaveProjectAsXLSX_out.xlsx", Aspose::Tasks::Saving::SaveFileFormat::XLSX);
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CreateProject2.mpp");
System::SharedPtr<HtmlSaveOptions> option = System::MakeObject<HtmlSaveOptions>();
project->Save(dataDir + u"SaveProjectDataAsHTML_out.html", option);
// OR
// Adding only one page (page number 2)
option = System::MakeObject<HtmlSaveOptions>();
option->get_Pages()->Add(2);
project->Save(dataDir + u"SaveProjectDataAsHTML2_out.html", option);
const System::String projectName = u"Project2.mpp";
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + projectName);
System::SharedPtr<ProjectFileInfo> projectFileInfo = Project::GetProjectFileInfo(dataDir + projectName);
if (Aspose::Tasks::FileFormat::MPP14 == projectFileInfo->get_ProjectFileFormat())
{
System::Console::WriteLine(u"Project file format is ok");
}
System::SharedPtr<SaveTemplateOptions> options = System::MakeObject<SaveTemplateOptions>();
options->set_RemoveActualValues(true);
options->set_RemoveBaselineValues(true);
const System::String templateName = u"SaveProjectDataAsTemplate_out.mpt";
project->SaveAsTemplate(dataDir + templateName);
System::SharedPtr<ProjectFileInfo> templateFileInfo = Project::GetProjectFileInfo(dataDir + templateName);
if (Aspose::Tasks::FileFormat::MPT14 == templateFileInfo->get_ProjectFileFormat())
{
System::Console::WriteLine(u"Template FileFormat is ok");
}
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CreateProject2.mpp");
project->Save(dataDir + u"SaveProjectDataToSpreadsheet2003XML_out.xml", Aspose::Tasks::Saving::SaveFileFormat::Spreadsheet2003);
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"Software Development Plan.mpp");
System::SharedPtr<PdfSaveOptions> saveOptions = System::MakeObject<PdfSaveOptions>();
saveOptions->set_SaveToSeparateFiles(true);
saveOptions->set_Pages(System::MakeObject<System::Collections::Generic::List<int32_t>>());
saveOptions->get_Pages()->Add(1);
saveOptions->get_Pages()->Add(4);
project->Save(dataDir + u"SaveToMultiplePDFFiles_out.pdf", System::StaticCast<Aspose::Tasks::Saving::SaveOptions>(saveOptions));
System::SharedPtr<Spreadsheet2003SaveOptions> options = System::MakeObject<Spreadsheet2003SaveOptions>();
System::SharedPtr<GanttChartColumn> col = System::MakeObject<GanttChartColumn>(u"WBS", 100, &UsingSpreadsheet2003SaveOptions::_anonymous_method_0);
options->get_View()->get_Columns()->Add(col);
System::SharedPtr<ResourceViewColumn> rscCol = System::MakeObject<ResourceViewColumn>(u"Cost center", 100, &UsingSpreadsheet2003SaveOptions::_anonymous_method_1);
options->get_ResourceView()->get_Columns()->Add(rscCol);
System::SharedPtr<AssignmentViewColumn> assnCol = System::MakeObject<AssignmentViewColumn>(u"Notes", 200, &UsingSpreadsheet2003SaveOptions::_anonymous_method_2);
options->get_AssignmentView()->get_Columns()->Add(assnCol);
project->Save(dataDir + u"UsingSpreadsheet2003SaveOptions_out.xml", options);
// Read the input Project file
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CreateProject2.mpp");
System::SharedPtr<SaveOptions> saveOptions = System::MakeObject<SvgOptions>();
saveOptions->set_FitContent(true);
saveOptions->set_Timescale(Aspose::Tasks::Visualization::Timescale::ThirdsOfMonths);
project->Save(dataDir + u"UseSvgOptions_out.svg", saveOptions);
// Read the input Project file
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CreateProject2.mpp");
System::SharedPtr<XlsxOptions> options = System::MakeObject<XlsxOptions>();
// Add desired Gantt Chart columns
System::SharedPtr<GanttChartColumn> col = System::MakeObject<GanttChartColumn>(u"WBS", 100, &UsingXlsxOptions::_anonymous_method_0);
options->get_View()->get_Columns()->Add(col);
// Add desired resource view columns
System::SharedPtr<ResourceViewColumn> rscCol = System::MakeObject<ResourceViewColumn>(u"Cost center", 100, &UsingXlsxOptions::_anonymous_method_1);
options->get_ResourceView()->get_Columns()->Add(rscCol);
// Add desired assignment view columns
System::SharedPtr<AssignmentViewColumn> assnCol = System::MakeObject<AssignmentViewColumn>(u"Notes", 200, &UsingXlsxOptions::_anonymous_method_2);
options->get_AssignmentView()->get_Columns()->Add(assnCol);
project->Save(dataDir + u"UsingXlsxOptions_out.xlsx", options);
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"Project1.mpp");
System::SharedPtr<Task> task = project->get_RootTask()->get_Children()->Add(u"Task1");
task->Set(Tsk::ActualStart(), System::DateTime::Parse(u"23-Aug-2012"));
// Set duration in hours
task->Set<Duration>(Tsk::Duration(), project->GetDuration(24, Aspose::Tasks::TimeUnitType::Hour));
task->Set<TimeUnitType>(Tsk::DurationFormat(), Aspose::Tasks::TimeUnitType::Day);
// Save the Project as XML
project->Save(dataDir + u"AddNewTask_out.xml", Aspose::Tasks::Saving::SaveFileFormat::XML);
System::SharedPtr<Project> project1 = System::MakeObject<Project>(dataDir + u"SampleProject.mpp");
// Declare ChildTasksCollector class object
System::SharedPtr<ChildTasksCollector> collector = System::MakeObject<ChildTasksCollector>();
// Use TaskUtils to get all children tasks in RootTask
TaskUtils::Apply(project1->get_RootTask(), collector, 0);
// Define Resources
for (int32_t i = 0; i <= 4; i++)
{
System::String devloper = System::String(u"Developer0") + i;
// Add resource to project
System::SharedPtr<Resource> newResource = project1->get_Resources()->Add(devloper);
newResource->Set<ResourceType>(Rsc::Type(), Aspose::Tasks::ResourceType::Work);
// Define assignment
System::SharedPtr<ResourceAssignment> newResourceAssignment = project1->get_ResourceAssignments()->Add(System::StaticCast<Aspose::Tasks::Task>(collector->get_Tasks()->idx_get(i)), newResource);
}
project1->Save(dataDir + u"CreateResourcesAndLinkToTasks_out.mpp", Aspose::Tasks::Saving::SaveFileFormat::MPP);
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"SampleProject.mpp");
System::SharedPtr<Task> task1 = project->get_RootTask()->get_Children()->GetById(1);
System::SharedPtr<Task> task2 = project->get_RootTask()->get_Children()->GetById(2);
System::SharedPtr<Task> task3 = project->get_RootTask()->get_Children()->GetById(3);
System::SharedPtr<Task> task4 = project->get_RootTask()->get_Children()->GetById(4);
System::SharedPtr<Task> task5 = project->get_RootTask()->get_Children()->GetById(5);
// Link the tasks
System::SharedPtr<TaskLink> tsklnk = project->get_TaskLinks()->Add(task1, task2, Aspose::Tasks::TaskLinkType::FinishToStart);
tsklnk = project->get_TaskLinks()->Add(task2, task3, Aspose::Tasks::TaskLinkType::FinishToStart);
tsklnk = project->get_TaskLinks()->Add(task3, task4, Aspose::Tasks::TaskLinkType::FinishToStart);
tsklnk = project->get_TaskLinks()->Add(task4, task5, Aspose::Tasks::TaskLinkType::FinishToStart);
tsklnk = project->get_TaskLinks()->Add(task2, task5, Aspose::Tasks::TaskLinkType::FinishToStart);
// Display links among the tasks
System::SharedPtr<TaskLinkCollection> allinks = project->get_TaskLinks();
{
auto tasklnk_enumerator = (allinks)->GetEnumerator();
decltype(tasklnk_enumerator->get_Current()) tasklnk;
while (tasklnk_enumerator->MoveNext() && (tasklnk = tasklnk_enumerator->get_Current(), true))
{
System::Console::WriteLine(System::String(u"From ID = ") + tasklnk->get_PredTask()->Get<int32_t>(Tsk::Id()) + u"=>To ID = " + tasklnk->get_SuccTask()->Get<int32_t>(Tsk::Id()));
System::Console::WriteLine(u"________________________________________");
}
}
// Save the project
project->Save(dataDir + u"LinkTasks_out.mpp", Aspose::Tasks::Saving::SaveFileFormat::MPP);
// Load MPP file
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"Project1.mpp");
// Get the critical path
System::SharedPtr<TaskCollection> criticalPath = project->get_CriticalPath();
// Enumerate the tasks in the critical path
{
auto task_enumerator = (criticalPath)->GetEnumerator();
decltype(task_enumerator->get_Current()) task;
while (task_enumerator->MoveNext() && (task = task_enumerator->get_Current(), true))
{
System::Console::WriteLine(System::Convert::ToString(task->Get<int32_t>(Tsk::Id())) + u" " + task->Get(Tsk::Name()));
System::Console::WriteLine(System::ObjectExt::Box<System::DateTime>(task->Get<System::DateTime>(Tsk::Start())));
System::Console::WriteLine(System::Convert::ToString(task->Get<System::DateTime>(Tsk::Finish())) + u"\n");
}
}
// Load MPP file
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"Project1.mpp");
// Load all tasks
System::SharedPtr<TaskCollection> allTasks = project->get_RootTask()->get_Children();
// Loop through each task and read information related to tasks
{
auto task_enumerator = (allTasks)->GetEnumerator();
decltype(task_enumerator->get_Current()) task;
while (task_enumerator->MoveNext() && (task = task_enumerator->get_Current(), true))
{
System::Console::WriteLine(System::String(u"Reading Task ") + task->Get(Tsk::Name()));
System::Console::WriteLine(System::String(u"\nID: ") + task->Get<int32_t>(Tsk::Id()));
System::Console::WriteLine(System::String(u"Start: ") + task->Get<System::DateTime>(Tsk::Start()));
System::Console::WriteLine(System::String(u"Finish: ") + task->Get<System::DateTime>(Tsk::Finish()));
System::Console::WriteLine(u"\n===========================\n");
}
}
// Loop through each resource and read information related to resources
{
auto resource_enumerator = (project->get_Resources())->GetEnumerator();
decltype(resource_enumerator->get_Current()) resource;
while (resource_enumerator->MoveNext() && (resource = resource_enumerator->get_Current(), true))
{
System::String resourceType;
switch (resource->Get<ResourceType>(Rsc::Type()))
{
case Aspose::Tasks::ResourceType::Material:
resourceType = u"Material";
break;
case Aspose::Tasks::ResourceType::Work:
resourceType = u"Work";
break;
default:
resourceType = u"Cost";
break;
}
System::Console::WriteLine(System::String(u"Reading Resource ") + resource->Get<System::String>(Rsc::Name()));
System::Console::WriteLine(System::String(u"\nID: ") + resource->Get<int32_t>(Rsc::Id()));
System::Console::WriteLine(System::String(u"Type: ") + resourceType);
System::Console::WriteLine(u"\n===========================\n");
}
}
System::SharedPtr<Aspose::Tasks::License> license = System::MakeObject<Aspose::Tasks::License>();
license->SetLicense(u"Aspose.Tasks.lic");
System::SharedPtr<Aspose::Tasks::License> license = System::MakeObject<Aspose::Tasks::License>();
System::SharedPtr<System::IO::FileStream> myStream = System::MakeObject<System::IO::FileStream>(u"Aspose.Tasks.lic", System::IO::FileMode::Open);
license->SetLicense(myStream);
// Create a prject instance
System::SharedPtr<Project> project1 = System::MakeObject<Project>();
// Define Tasks
System::SharedPtr<Task> task1 = project1->get_RootTask()->get_Children()->Add(u"Task1");
task1->Set(Tsk::ActualStart(), System::DateTime::Parse(u"06-Apr-2010"));
System::SharedPtr<Task> task2 = project1->get_RootTask()->get_Children()->Add(u"Task2");
task2->Set(Tsk::ActualStart(), System::DateTime::Parse(u"10-Apr-2010"));
// Save the Project as XML
project1->Save(u"EvalProject_out.xml", Aspose::Tasks::Saving::SaveFileFormat::XML);
System::SharedPtr<Project> project;
try
{
System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
project = System::MakeObject<Project>(dataDir + u"project.mpp");
}
catch (TasksReadingException& ex)
{
System::Console::WriteLine(u"Message:");
System::Console::WriteLine(ex->get_Message());
System::Console::WriteLine(u"Log:");
System::Console::WriteLine(ex->get_LogText());
if (ex->get_InnerException() != nullptr)
{
System::Console::WriteLine(u"Inner exception message:");
System::Console::WriteLine(ex->get_InnerException()->get_Message());
}
}
catch (System::Exception& ex)
{
System::Console::WriteLine(ex->get_Message());
}
// Analyze the project risks
System::SharedPtr<RiskAnalyzer> analyzer = System::MakeObject<RiskAnalyzer>(settings);
System::SharedPtr<RiskAnalysisResult> analysisResult = analyzer->Analyze(project);
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"Software Development Plan-1.mpp");
System::SharedPtr<Task> task = project->get_RootTask()->get_Children()->GetById(17);
// Initialize a risk pattern
System::SharedPtr<RiskPattern> pattern = System::MakeObject<RiskPattern>(task);
// Select a distribution type for the random number generator to generate possible values from (only two types currently supported, namely normal and uniform)
// For more details see here: https://en.wikipedia.org/wiki/Normal_distribution)
pattern->set_Distribution(Aspose::Tasks::RiskAnalysis::ProbabilityDistributionType::Normal);
// Set the percentage of the most likely task duration which can happen in the best possible project scenario
// The default value is 75, which means that if the estimated specified task duration is 4 days then the optimistic duration will be 3 days
pattern->set_Optimistic(70);
// Set the percentage of the most likely task duration which can happen in the worst possible project scenario
// The defaut value is 125, which means that if the estimated specified task duration is 4 days then the pessimistic duration will be 5 days.
pattern->set_Pessimistic(130);
// Set a confidence level that correspond to the percentage of the time the actual values will be within optimistic and pessimistic estimates.
// You can think of it as a value of standard deviation: the more uncertain about your estimates you are, the more the value of standard deviation used in random number generator is
pattern->set_ConfidenceLevel(Aspose::Tasks::RiskAnalysis::ConfidenceLevel::CL75);
settings->get_Patterns()->Add(pattern);
System::SharedPtr<RiskAnalysisSettings> settings = System::MakeObject<RiskAnalysisSettings>();
// Set number of iterations for Monte Carlo simulation (the default value is 100).
settings->set_IterationsCount(200);
// Select the desired output (here we get early finish of the root task)
System::SharedPtr<RiskItemStatistics> rootEarlyFinish = analysisResult->GetRiskItems(Aspose::Tasks::RiskAnalysis::RiskItemType::EarlyFinish)->Get(project->get_RootTask());
System::Console::WriteLine(u"Expected value: {0}", System::ObjectExt::Box<System::DateTime>(rootEarlyFinish->get_ExpectedValue()));
System::Console::WriteLine(u"StandardDeviation: {0}", System::ObjectExt::Box<Duration>(rootEarlyFinish->get_StandardDeviation()));
System::Console::WriteLine(u"10% Percentile: {0}", System::ObjectExt::Box<System::DateTime>(rootEarlyFinish->GetPercentile(10)));
System::Console::WriteLine(u"50% Percentile: {0}", System::ObjectExt::Box<System::DateTime>(rootEarlyFinish->GetPercentile(50)));
System::Console::WriteLine(u"90% Percentile: {0}", System::ObjectExt::Box<System::DateTime>(rootEarlyFinish->GetPercentile(90)));
System::Console::WriteLine(u"Minimum: {0}", System::ObjectExt::Box<System::DateTime>(rootEarlyFinish->get_Minimum()));
System::Console::WriteLine(u"Maximum: {0}", System::ObjectExt::Box<System::DateTime>(rootEarlyFinish->get_Maximum()));
// Save PDF report which is rendered for Project Root Task Finish date
analysisResult->SaveReport(dataDir + u"AnalysisReport_out.pdf");
System::SharedPtr<Project> project1 = System::MakeObject<Project>(dataDir + u"Cyclic stucture.mpp");
project1->SaveReport(dataDir + u"BestPracticeAnalyzer_out.pdf", Aspose::Tasks::Visualization::ReportType::BestPracticeAnalyzer);
System::SharedPtr<Project> project1 = System::MakeObject<Project>(dataDir + u"Homemoveplan.mpp");
project1->SaveReport(dataDir + u"Burndown_out.pdf", Aspose::Tasks::Visualization::ReportType::Burndown);
System::SharedPtr<Project> project1 = System::MakeObject<Project>(dataDir + u"OzBuild 16 Orig.mpp");
project1->SaveReport(dataDir + u"CashFlow_out.pdf", Aspose::Tasks::Visualization::ReportType::CashFlow);
System::SharedPtr<Project> project1 = System::MakeObject<Project>(dataDir + u"Software Development.mpp");
project1->SaveReport(dataDir + u"CostOverruns_out.pdf", Aspose::Tasks::Visualization::ReportType::CostOverruns);
System::SharedPtr<Project> project1 = System::MakeObject<Project>(dataDir + u"OzBuild 16 Orig.mpp");
project1->SaveReport(dataDir + u"CostOverview_out.pdf", Aspose::Tasks::Visualization::ReportType::CostOverview);
System::SharedPtr<Project> project1 = System::MakeObject<Project>(dataDir + u"Residential Construction.mpp");
project1->SaveReport(dataDir + u"CriticalTasks_out.pdf", Aspose::Tasks::Visualization::ReportType::CriticalTasks);
System::SharedPtr<Project> project1 = System::MakeObject<Project>(dataDir + u"Residential Construction.mpp");
project1->SaveReport(dataDir + u"LateTasks_out.pdf", Aspose::Tasks::Visualization::ReportType::LateTasks);
System::SharedPtr<Project> project1 = System::MakeObject<Project>(dataDir + u"Residential Construction.mpp");
project1->SaveReport(dataDir + u"Milestones_out.pdf", Aspose::Tasks::Visualization::ReportType::Milestones);
System::SharedPtr<Project> project1 = System::MakeObject<Project>(dataDir + u"Software Development Plan.mpp");
project1->SaveReport(dataDir + u"OverAllocatedResources_out.pdf", Aspose::Tasks::Visualization::ReportType::OverallocatedResources);
System::SharedPtr<Project> project1 = System::MakeObject<Project>(dataDir + u"Cyclic stucture.mpp");
project1->SaveReport(dataDir + u"ProjectOverView_out.pdf", Aspose::Tasks::Visualization::ReportType::ProjectOverview);
System::SharedPtr<Project> project1 = System::MakeObject<Project>(dataDir + u"OzBuild 16 Orig.mpp");
project1->SaveReport(dataDir + u"ResourceCostOverview_out.pdf", Aspose::Tasks::Visualization::ReportType::ResourceCostOverview);
System::SharedPtr<Project> project1 = System::MakeObject<Project>(dataDir + u"Software Development Plan.mpp");
project1->SaveReport(dataDir + u"ResourceOverview_out.pdf", Aspose::Tasks::Visualization::ReportType::ResourceOverview);
System::SharedPtr<Project> project1 = System::MakeObject<Project>(dataDir + u"Homemoveplan.mpp");
project1->SaveReport(dataDir + u"SlippingTasks_out.pdf", Aspose::Tasks::Visualization::ReportType::SlippingTasks);
System::SharedPtr<Project> project1 = System::MakeObject<Project>(dataDir + u"Software Development.mpp");
project1->SaveReport(dataDir + u"TaskCostOverview_out.pdf", Aspose::Tasks::Visualization::ReportType::TaskCostOverview);
System::SharedPtr<Project> project1 = System::MakeObject<Project>(dataDir + u"UpcomingTasks.mpp");
project1->SaveReport(dataDir + u"UpcomingTasks_out.pdf", Aspose::Tasks::Visualization::ReportType::UpcomingTask);
System::SharedPtr<Project> project1 = System::MakeObject<Project>(dataDir + u"Residential Construction.mpp");
project1->SaveReport(dataDir + u"WorkOverview_out.pdf", Aspose::Tasks::Visualization::ReportType::WorkOverview);
int32_t SortResourcesByName::RscNameComparer::Compare(System::SharedPtr<Resource> const &x, System::SharedPtr<Resource> const &y) ASPOSE_CONST
{
if (System::String::IsNullOrEmpty(x->Get<System::String>(Rsc::Name())))
{
return 1;
}
if (System::String::IsNullOrEmpty(y->Get<System::String>(Rsc::Name())))
{
return -1;
}
return x->Get<System::String>(Rsc::Name()).CompareTo(y->Get<System::String>(Rsc::Name()));
}
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"project-sort.mpp");
System::SharedPtr<System::Collections::Generic::List<System::SharedPtr<Resource>>> resources = project->get_Resources()->ToList();
resources->Sort(System::MakeObject<SortResourcesByName::RscNameComparer>());
{
auto rsc_enumerator = (resources)->GetEnumerator();
decltype(rsc_enumerator->get_Current()) rsc;
while (rsc_enumerator->MoveNext() && (rsc = rsc_enumerator->get_Current(), true))
{
System::Console::WriteLine(rsc);
}
}
int32_t SortTasksByName::TaskNameComparer::Compare(System::SharedPtr<Task> const &x, System::SharedPtr<Task> const &y) ASPOSE_CONST
{
if (System::String::IsNullOrEmpty(x->Get(Tsk::Name())))
{
return 1;
}
if (System::String::IsNullOrEmpty(y->Get(Tsk::Name())))
{
return -1;
}
return x->Get(Tsk::Name()).CompareTo(y->Get(Tsk::Name()));
}
System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"project-sort.mpp");
System::SharedPtr<ChildTasksCollector> coll = System::MakeObject<ChildTasksCollector>();
TaskUtils::Apply(project->get_RootTask(), coll, 0);
System::SharedPtr<System::Collections::Generic::List<System::SharedPtr<Task>>> tasks = coll->get_Tasks();
tasks->Sort(System::MakeObject<SortTasksByName::TaskNameComparer>());
{
auto task_enumerator = (tasks)->GetEnumerator();
decltype(task_enumerator->get_Current()) task;
while (task_enumerator->MoveNext() && (task = task_enumerator->get_Current(), true))
{
System::Console::WriteLine(task);
}
}
System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"project.mpp");
// Define outline code and its outline mask
System::SharedPtr<OutlineCodeDefinition> code1 = System::MakeObject<OutlineCodeDefinition>();
code1->set_Alias(u"New task outline code1");
code1->set_FieldId(System::Convert::ToString(((int32_t)Aspose::Tasks::ExtendedAttributeTask::OutlineCode1)));
code1->set_FieldName(u"Outline Code1");
System::SharedPtr<OutlineMask> mask = System::MakeObject<OutlineMask>();
mask->set_Separator(u"+");
mask->set_Level(1);
mask->set_Type(Aspose::Tasks::MaskType::Numbers);
code1->get_Masks()->Add(mask);
// Add outline value
System::SharedPtr<OutlineValue> value = System::MakeObject<OutlineValue>();
value->set_Description(u"Value description");
value->set_ValueId(1);
value->set_Value(u"123456");
value->set_Type(Aspose::Tasks::OutlineValueType::Number);
code1->get_Values()->Add(value);
// Add outline code to project
project->get_OutlineCodes()->Add(code1);
// Define outline code and its outline mask
System::SharedPtr<OutlineCodeDefinition> code2 = System::MakeObject<OutlineCodeDefinition>();
code2->set_Alias(u"New rsc outline code2");
code2->set_FieldId(System::Convert::ToString(((int32_t)Aspose::Tasks::ExtendedAttributeResource::OutlineCode2)));
code2->set_FieldName(u"Outline Code2");
System::SharedPtr<OutlineMask> mask2 = System::MakeObject<OutlineMask>();
mask2->set_Separator(u"/");
mask2->set_Level(1);
mask2->set_Type(Aspose::Tasks::MaskType::Numbers);
code2->get_Masks()->Add(mask2);
// Add outline value
System::SharedPtr<OutlineValue> value2 = System::MakeObject<OutlineValue>();
value2->set_Description(u"Value2 description");
value2->set_ValueId(2);
value2->set_Value(u"987654");
value2->set_Type(Aspose::Tasks::OutlineValueType::Number);
code2->get_Values()->Add(value2);
// Add outline code to project
project->get_OutlineCodes()->Add(code2);
// Save project as MPP
project->Save(dataDir + u"Updated_project_out.mpp", Aspose::Tasks::Saving::SaveFileFormat::MPP);
System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"Project1.mpp");
// Add working times to project calendar
System::SharedPtr<WorkingTime> wt = System::MakeObject<WorkingTime>();
wt->set_FromTime(System::DateTime(2010, 1, 1, 19, 0, 0));
wt->set_ToTime(System::DateTime(2010, 1, 1, 20, 0, 0));
System::SharedPtr<WeekDay> day = project->Get<System::SharedPtr<Calendar>>(Prj::Calendar())->get_WeekDays()->ToList()->idx_get(1);
day->get_WorkingTimes()->Add(wt);
// Change calendar name
project->Get<System::SharedPtr<Calendar>>(Prj::Calendar())->set_Name(u"CHANGED NAME!");
// Add tasks and set task meta data
System::SharedPtr<Task> task = project->get_RootTask()->get_Children()->Add(u"Task 1");
task->Set<TimeUnitType>(Tsk::DurationFormat(), Aspose::Tasks::TimeUnitType::Day);
task->Set<Duration>(Tsk::Duration(), project->GetDuration(3));
task->Set<System::String>(Tsk::Contact(), u"Rsc 1");
task->Set<bool>(Tsk::IsMarked(), true);
task->Set<bool>(Tsk::IgnoreWarnings(), true);
System::SharedPtr<Task> task2 = project->get_RootTask()->get_Children()->Add(u"Task 2");
task2->Set<TimeUnitType>(Tsk::DurationFormat(), Aspose::Tasks::TimeUnitType::Day);
task2->Set<System::String>(Tsk::Contact(), u"Rsc 2");
// Link tasks
project->get_TaskLinks()->Add(task, task2, Aspose::Tasks::TaskLinkType::FinishToStart, project->GetDuration(-1, Aspose::Tasks::TimeUnitType::Day));
// Set project start date
project->Set(Prj::StartDate(), System::DateTime(2013, 8, 13, 9, 0, 0));
// Add resource and set resource meta data
System::SharedPtr<Resource> rsc1 = project->get_Resources()->Add(u"Rsc 1");
rsc1->Set<ResourceType>(Rsc::Type(), Aspose::Tasks::ResourceType::Work);
rsc1->Set<System::String>(Rsc::Initials(), u"WR");
rsc1->Set<CostAccrualType>(Rsc::AccrueAt(), Aspose::Tasks::CostAccrualType::Prorated);
rsc1->Set<double>(Rsc::MaxUnits(), 1.0);
rsc1->Set<System::String>(Rsc::Code(), u"Code 1");
rsc1->Set<System::String>(Rsc::Group(), u"Workers");
rsc1->Set<System::String>(Rsc::EMailAddress(), u"1@gmail.com");
rsc1->Set<System::String>(Rsc::WindowsUserAccount(), u"user_acc1");
rsc1->Set<NullableBool>(Rsc::IsGeneric(), NullableBool(true));
rsc1->Set<CostAccrualType>(Rsc::AccrueAt(), Aspose::Tasks::CostAccrualType::End);
rsc1->Set<System::Decimal>(Rsc::StandardRate(), static_cast<System::Decimal>(10));
rsc1->Set<RateFormatType>(Rsc::StandardRateFormat(), Aspose::Tasks::RateFormatType::Day);
rsc1->Set<System::Decimal>(Rsc::OvertimeRate(), static_cast<System::Decimal>(15));
rsc1->Set<RateFormatType>(Rsc::OvertimeRateFormat(), Aspose::Tasks::RateFormatType::Hour);
rsc1->Set<bool>(Rsc::IsTeamAssignmentPool(), true);
rsc1->Set<System::String>(Rsc::CostCenter(), u"Cost Center 1");
// Create resource assignment and set resource assignment meta data
System::SharedPtr<ResourceAssignment> assn = project->get_ResourceAssignments()->Add(task, rsc1);
assn->Set<int32_t>(Asn::Uid(), 1);
assn->Set<Duration>(Asn::Work(), task->Get<Duration>(Tsk::Duration()));
assn->Set<Duration>(Asn::RemainingWork(), assn->Get<Duration>(Asn::Work()));
assn->Set<Duration>(Asn::RegularWork(), assn->Get<Duration>(Asn::Work()));
task->Set<Duration>(Tsk::Work(), assn->Get<Duration>(Asn::Work()));
rsc1->Set<Duration>(Rsc::Work(), task->Get<Duration>(Tsk::Work()));
assn->Set(Asn::Start(), task->Get<System::DateTime>(Tsk::Start()));
assn->Set(Asn::Finish(), task->Get<System::DateTime>(Tsk::Finish()));
// Add extended attribute for project and task
System::SharedPtr<ExtendedAttributeDefinition> attr = ExtendedAttributeDefinition::CreateTaskDefinition(Aspose::Tasks::CustomFieldType::Flag, Aspose::Tasks::ExtendedAttributeTask::Flag1, u"My Flag Field");
project->get_ExtendedAttributes()->Add(attr);
System::SharedPtr<ExtendedAttribute> taskAttr = attr->CreateExtendedAttribute();
taskAttr->set_FlagValue(true);
task2->get_ExtendedAttributes()->Add(taskAttr);
// Save project as MPP
project->Save(dataDir + u"WriteMetaData_out.mpp", Aspose::Tasks::Saving::SaveFileFormat::MPP);
System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
{
System::SharedPtr<System::IO::FileStream> fs = System::MakeObject<System::IO::FileStream>(dataDir + u"project_test.mpp", System::IO::FileMode::Open);
// Clearing resources under 'using' statement
System::Details::DisposeGuard<1> __dispose_guard_0({ fs});
// ------------------------------------------
try
{
// Create project instance
System::SharedPtr<Project> prj = System::MakeObject<Project>(fs);
// Remove an exception
System::SharedPtr<Aspose::Tasks::Calendar> cal = prj->get_Calendars()->ToList()->idx_get(0);
if (cal->get_Exceptions()->get_Count() > 1)
{
System::SharedPtr<CalendarException> exc = cal->get_Exceptions()->ToList()->idx_get(0);
cal->get_Exceptions()->Remove(exc);
}
// Add an exception
System::SharedPtr<CalendarException> calExc = System::MakeObject<CalendarException>();
calExc->set_FromDate(System::DateTime(2009, 1, 1));
calExc->set_ToDate(System::DateTime(2009, 1, 3));
cal->get_Exceptions()->Add(calExc);
// Display exceptions
{
auto calExc1_enumerator = (cal->get_Exceptions())->GetEnumerator();
decltype(calExc1_enumerator->get_Current()) calExc1;
while (calExc1_enumerator->MoveNext() && (calExc1 = calExc1_enumerator->get_Current(), true))
{
System::Console::WriteLine(System::String(u"From") + calExc1->get_FromDate().ToShortDateString());
System::Console::WriteLine(System::String(u"To") + calExc1->get_ToDate().ToShortDateString());
}
}
}
catch(...)
{
__dispose_guard_0.SetCurrentException(std::current_exception());
}
}
System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
// Create a project instance
System::SharedPtr<Project> prj = System::MakeObject<Project>();
// Define Calendar
System::SharedPtr<Aspose::Tasks::Calendar> cal = prj->get_Calendars()->Add(u"Calendar1");
// Define week days exception for a holiday
System::SharedPtr<CalendarException> except = System::MakeObject<CalendarException>();
except->set_EnteredByOccurrences(false);
except->set_FromDate(System::DateTime(2009, 12, 24, 0, 0, 0));
except->set_ToDate(System::DateTime(2009, 12, 31, 23, 59, 0));
except->set_Type(Aspose::Tasks::CalendarExceptionType::Daily);
except->set_DayWorking(false);
cal->get_Exceptions()->Add(except);
// Save the Project
prj->Save(dataDir + u"Project_DefineWeekDayException_out.xml", Aspose::Tasks::Saving::SaveFileFormat::XML);
// Define exception and specify occurences
System::SharedPtr<CalendarException> except = System::MakeObject<CalendarException>();
except->set_EnteredByOccurrences(true);
except->set_Occurrences(5);
except->set_Type(Aspose::Tasks::CalendarExceptionType::YearlyByDay);
System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
// Create project instance
System::SharedPtr<Project> project1 = System::MakeObject<Project>(dataDir + u"project_RetrieveExceptions_test.mpp");
// Access calendars
{
auto cal_enumerator = (project1->get_Calendars())->GetEnumerator();
decltype(cal_enumerator->get_Current()) cal;
while (cal_enumerator->MoveNext() && (cal = cal_enumerator->get_Current(), true))
{
// Access calendar exceptions
auto calExc_enumerator = (cal->get_Exceptions())->GetEnumerator();
decltype(calExc_enumerator->get_Current()) calExc;
while (calExc_enumerator->MoveNext() && (calExc = calExc_enumerator->get_Current(), true))
{
System::Console::WriteLine(System::String(u"From: ") + calExc->get_FromDate().ToShortDateString());
System::Console::WriteLine(System::String(u"To: ") + calExc->get_ToDate().ToShortDateString());
}
}
}
// Load an existing project
System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CalculateWorkHours.mpp");
// Access Task By Id
System::SharedPtr<Task> task = project->get_RootTask()->get_Children()->GetById(1);
// Access Calendar and it's start and end dates
System::SharedPtr<Aspose::Tasks::Calendar> taskCalendar = task->Get<System::SharedPtr<Calendar>>(Tsk::Calendar());
System::DateTime startDate = task->Get<System::DateTime>(Tsk::Start());
System::DateTime endDate = task->Get<System::DateTime>(Tsk::Finish());
System::DateTime tempDate = startDate;
// Access resource and their calendar
System::SharedPtr<Resource> resource = project->get_Resources()->GetByUid(1);
System::SharedPtr<Aspose::Tasks::Calendar> resourceCalendar = resource->Get<System::SharedPtr<Calendar>>(Rsc::Calendar());
System::TimeSpan timeSpan;
// Get Duration in Minutes
double durationInMins = 0;
while (tempDate < endDate)
{
if (taskCalendar->IsDayWorking(tempDate) && resourceCalendar->IsDayWorking(tempDate))
{
timeSpan = taskCalendar->GetWorkingHours(tempDate);
durationInMins = durationInMins + timeSpan.get_TotalMinutes();
}
tempDate = tempDate.AddDays(1);
}
tempDate = startDate;
// Get Duration in Hours
double durationInHours = 0;
while (tempDate < endDate)
{
if (taskCalendar->IsDayWorking(tempDate) && resourceCalendar->IsDayWorking(tempDate))
{
timeSpan = taskCalendar->GetWorkingHours(tempDate);
durationInHours = durationInHours + timeSpan.get_TotalHours();
}
tempDate = tempDate.AddDays(1);
}
tempDate = startDate;
// Get Duration in Days
double durationInDays = 0;
while (tempDate < endDate)
{
if (taskCalendar->IsDayWorking(tempDate) && resourceCalendar->IsDayWorking(tempDate))
{
timeSpan = taskCalendar->GetWorkingHours(tempDate);
if (timeSpan.get_TotalHours() > 0)
{
durationInDays = durationInDays + timeSpan.get_TotalDays() * (24 / (timeSpan.get_TotalHours()));
}
}
tempDate = tempDate.AddDays(1);
}
System::Console::WriteLine(System::String(u"Duration in Minutes = ") + durationInMins);
System::Console::WriteLine(System::String(u"Duration in Hours = ") + durationInHours);
System::Console::WriteLine(System::String(u"Duration in Days = ") + durationInDays);
// Create a project instance
System::SharedPtr<Project> project = System::MakeObject<Project>();
// New calendar can be added to a project's calendar collection using the collection's Add method.
System::SharedPtr<Aspose::Tasks::Calendar> cal1 = project->get_Calendars()->Add(u"New Info");
System::SharedPtr<Aspose::Tasks::Calendar> cal2 = project->get_Calendars()->Add(u"no name");
System::SharedPtr<Aspose::Tasks::Calendar> cal3 = project->get_Calendars()->Add(u"cal3");
// Save the Project
System::String dataDir = Examples::CPP::RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
project->Save(dataDir + u"CreatingCalendar_out.Xml", Aspose::Tasks::Saving::SaveFileFormat::XML);
// This example shows how Aspose.Tasks API can be used to define a new Calendar, add week days to it and define working times for days
// Create a project instance
System::SharedPtr<Project> project = System::MakeObject<Project>();
// Define Calendar
System::SharedPtr<Aspose::Tasks::Calendar> cal = project->get_Calendars()->Add(u"Calendar1");
// Add working days monday through thursday with default timings
cal->get_WeekDays()->Add(WeekDay::CreateDefaultWorkingDay(Aspose::Tasks::DayType::Monday));
cal->get_WeekDays()->Add(WeekDay::CreateDefaultWorkingDay(Aspose::Tasks::DayType::Tuesday));
cal->get_WeekDays()->Add(WeekDay::CreateDefaultWorkingDay(Aspose::Tasks::DayType::Wednesday));
cal->get_WeekDays()->Add(WeekDay::CreateDefaultWorkingDay(Aspose::Tasks::DayType::Thursday));
cal->get_WeekDays()->Add(System::MakeObject<WeekDay>(Aspose::Tasks::DayType::Saturday));
cal->get_WeekDays()->Add(System::MakeObject<WeekDay>(Aspose::Tasks::DayType::Sunday));
// Set friday as short working day
System::SharedPtr<WeekDay> myWeekDay = System::MakeObject<WeekDay>(Aspose::Tasks::DayType::Friday);
// Sets working time. Only time part of DateTime is important
System::SharedPtr<WorkingTime> wt1 = System::MakeObject<WorkingTime>();
wt1->set_FromTime(System::DateTime(1, 1, 1, 9, 0, 0, 0));
wt1->set_ToTime(System::DateTime(1, 1, 1, 12, 0, 0, 0));
System::SharedPtr<WorkingTime> wt2 = System::MakeObject<WorkingTime>();
wt2->set_FromTime(System::DateTime(1, 1, 1, 13, 0, 0, 0));
wt2->set_ToTime(System::DateTime(1, 1, 1, 16, 0, 0, 0));
myWeekDay->get_WorkingTimes()->Add(wt1);
myWeekDay->get_WorkingTimes()->Add(wt2);
myWeekDay->set_DayWorking(true);
cal->get_WeekDays()->Add(myWeekDay);
// Save the Project
System::String dataDir = Examples::CPP::RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
project->Save(u"Project_DefineCalendarWeekdays_out.xml", Aspose::Tasks::Saving::SaveFileFormat::XML);
// Create a project instance
System::SharedPtr<Project> project = System::MakeObject<Project>();
// Define Calendar and make it standard
System::SharedPtr<Aspose::Tasks::Calendar> cal1 = project->get_Calendars()->Add(u"My Cal");
Aspose::Tasks::Calendar::MakeStandardCalendar(cal1);
// Save the Project
System::String dataDir = Examples::CPP::RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
project->Save(dataDir + u"Project_MakeStandardCalendar_out.xml", Aspose::Tasks::Saving::SaveFileFormat::XML);
// The path to the documents directory.
System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"ReplaceCalendar.mpp");
// Add a new calendar to the project's calendars collection
project->get_Calendars()->Add(u"New cal1", project->Get<System::SharedPtr<Calendar>>(Prj::Calendar()));
// Now traverse through project calendars and replace the already added calendar with a new one
System::SharedPtr<CalendarCollection> calColl = project->get_Calendars();
{
auto c_enumerator = (calColl)->GetEnumerator();
decltype(c_enumerator->get_Current()) c;
while (c_enumerator->MoveNext() && (c = c_enumerator->get_Current(), true))
{
if (c->get_Name() == u"New cal1")
{
calColl->Remove(c);
calColl->Add(u"New cal2", project->Get<System::SharedPtr<Calendar>>(Prj::Calendar()));
break;
}
}
}
// Create project
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"Project5.mpp");
// Access project calendars
System::SharedPtr<CalendarCollection> calColl = project->get_Calendars();
calColl->Remove(calColl->GetByName(u"TestCalendar"));
// Add new calendar
System::SharedPtr<Calendar> newCalendar = calColl->Add(u"TestCalendar");
project->Save(dataDir + u"ReplaceCalendar_out.mpp", Aspose::Tasks::Saving::SaveFileFormat::MPP);
System::String resultFile = u"result_WriteUpdatedCalendarDataToMPP_out.mpp";
System::String newFile = u"project_update_test.mpp";
System::String dataDir = Examples::CPP::RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
try
{
// Create project instance and access calendar
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + newFile);
System::SharedPtr<Calendar> cal = project->get_Calendars()->GetByUid(3);
// Update the calendar information
Calendar::MakeStandardCalendar(cal);
cal->set_Name(u"Test calendar");
System::SharedPtr<CalendarException> exc = System::MakeObject<CalendarException>();
exc->set_FromDate(System::DateTime::get_Now());
exc->set_ToDate(System::DateTime::get_Now().AddDays(2));
exc->set_DayWorking(true);
System::SharedPtr<WorkingTime> wt1 = System::MakeObject<WorkingTime>();
wt1->set_FromTime(System::DateTime(10, 1, 1, 9, 0, 0));
wt1->set_ToTime(System::DateTime(10, 1, 1, 13, 0, 0));
System::SharedPtr<WorkingTime> wt2 = System::MakeObject<WorkingTime>();
wt2->set_FromTime(System::DateTime(10, 1, 1, 14, 0, 0));
wt2->set_ToTime(System::DateTime(10, 1, 1, 19, 0, 0));
System::SharedPtr<WorkingTime> wt3 = System::MakeObject<WorkingTime>();
wt3->set_FromTime(System::DateTime(10, 1, 1, 20, 0, 0));
wt3->set_ToTime(System::DateTime(10, 1, 1, 21, 0, 0));
exc->get_WorkingTimes()->Add(wt1);
exc->get_WorkingTimes()->Add(wt2);
exc->get_WorkingTimes()->Add(wt3);
cal->get_Exceptions()->Add(exc);
System::SharedPtr<CalendarException> exc2 = System::MakeObject<CalendarException>();
exc2->set_FromDate(System::DateTime::get_Now().AddDays(7));
exc2->set_ToDate(exc2->get_FromDate());
exc2->set_DayWorking(false);
cal->get_Exceptions()->Add(exc2);
project->Set<System::SharedPtr<Calendar>>(Prj::Calendar(), cal);
// Save project
project->Save(dataDir + resultFile, Aspose::Tasks::Saving::SaveFileFormat::MPP);
}
catch (System::Exception& ex)
{
System::Console::WriteLine(ex->get_Message() + u"\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.");
}
// Load an existing project
System::String dataDir = Examples::CPP::RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"Project_GeneralCalendarProperties.xml");
{
auto cal_enumerator = (project->get_Calendars())->GetEnumerator();
decltype(cal_enumerator->get_Current()) cal;
while (cal_enumerator->MoveNext() && (cal = cal_enumerator->get_Current(), true))
{
if (cal->get_Name() != nullptr)
{
System::Console::WriteLine(System::String(u"UID : ") + System::Convert::ToString(cal->get_Uid()) + u" Name: " + cal->get_Name());
// Show if it is has a base calendar
System::Console::Write(u"Base Calendar : ");
if (cal->get_IsBaseCalendar())
{
System::Console::WriteLine(u"Self");
}
else
{
System::Console::WriteLine(cal->get_BaseCalendar()->get_Name());
}
// Get Time in hours on each working day
{
auto wd_enumerator = (cal->get_WeekDays())->GetEnumerator();
decltype(wd_enumerator->get_Current()) wd;
while (wd_enumerator->MoveNext() && (wd = wd_enumerator->get_Current(), true))
{
System::TimeSpan ts = wd->GetWorkingTime();
System::Console::WriteLine(System::String(u"Day Type: ") + System::ObjectExt::ToString(wd->get_DayType()) + u" Hours: " + System::ObjectExt::ToString(ts));
}
}
}
}
}
System::String dataDir = Examples::CPP::RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
// Create project instance and access calendar and work weeks collection
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"ReadWorkWeeksInformation.mpp");
System::SharedPtr<Calendar> calendar = project->get_Calendars()->GetByUid(3);
System::SharedPtr<WorkWeekCollection> collection = calendar->get_WorkWeeks();
{
auto workWeek_enumerator = (collection)->GetEnumerator();
decltype(workWeek_enumerator->get_Current()) workWeek;
while (workWeek_enumerator->MoveNext() && (workWeek = workWeek_enumerator->get_Current(), true))
{
// Display work week name, from and to dates
System::String Name = workWeek->get_Name();
System::DateTime fromDate = workWeek->get_FromDate();
System::DateTime toDate = workWeek->get_ToDate();
// This data is all about "Details." button you can set special working times for special WeekDay or even make it nonworking
System::SharedPtr<WeekDayCollection> weekDays = workWeek->get_WeekDays();
{
auto day_enumerator = (weekDays)->GetEnumerator();
decltype(day_enumerator->get_Current()) day;
while (day_enumerator->MoveNext() && (day = day_enumerator->get_Current(), true))
{
// You can further traverse through working times and display these
System::SharedPtr<WorkingTimeCollection> workingTimes = day->get_WorkingTimes();
}
}
}
}
// The path to the documents directory.
System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
// Create a project instance
System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"RetrieveCalendarInfo.mpp");
// Retrieve Calendars Information
System::SharedPtr<CalendarCollection> alCals = project->get_Calendars();
{
auto cal_enumerator = (alCals)->GetEnumerator();
decltype(cal_enumerator->get_Current()) cal;
while (cal_enumerator->MoveNext() && (cal = cal_enumerator->get_Current(), true))
{
if (cal->get_Name() != nullptr)
{
System::Console::WriteLine(System::String(u"Calendar UID : ") + cal->get_Uid());
System::Console::WriteLine(System::String(u"Calendar Name : ") + cal->get_Name());
System::SharedPtr<WeekDayCollection> alDays = cal->get_WeekDays();
{
auto wd_enumerator = (alDays)->GetEnumerator();
decltype(wd_enumerator->get_Current()) wd;
while (wd_enumerator->MoveNext() && (wd = wd_enumerator->get_Current(), true))
{
System::TimeSpan ts = wd->GetWorkingTime();
if (wd->get_DayWorking())
{
System::Console::WriteLine(System::ObjectExt::ToString(wd->get_DayType()) + u":");
System::Console::WriteLine(System::ObjectExt::ToString(ts));
}
}
}
}
}
}
System::SharedPtr<Project> project1 = System::MakeObject<Project>(dataDir + u"project.mpp");
System::Console::WriteLine(project1->Get<System::String>(Prj::CurrencyCode()));
System::SharedPtr<Project> project1 = System::MakeObject<Project>(dataDir + u"project.mpp");
System::Console::WriteLine(project1->Get<int32_t>(Prj::CurrencyDigits()));
System::SharedPtr<Project> project1 = System::MakeObject<Project>(dataDir + u"project.mpp");
System::Console::WriteLine(project1->Get<System::String>(Prj::CurrencySymbol()));
// Create new project and set currency code
System::SharedPtr<Project> project1 = System::MakeObject<Project>();
project1->Set<System::String>(Prj::CurrencyCode(), u"USD");