Project Server または Project Online でのプロジェクトの読み取りと保存
Aspose.Tasks for .NET は、以下との連携に対して完全なサポートを提供します。 Project Server (オンプレミス)および Project Online (クラウドベース)で、Project Web Access (PWA) API を活用することで、開発者は企業のプロジェクト管理環境に格納されたプロジェクトをプログラムで作成、読み取り、更新できるようになります。
このような統合は、集中型のプロジェクトリポジトリに依存し、大量更新、定期レポート、プロジェクト同期などのプロセスを Microsoft Project や Project Web App での手動操作を必要とせずに自動化したい組織にとって有益です。
Project Server によるプロジェクト管理
Aspose.Tasks for .NET は、次のクラスを導入します
ProjectServerManager クラスは、Project Server または Project Online への接続に使用します。認証には、 ProjectServerCredentials クラスを使用します。このクラスでは、現在以下を直接指定できるようになっています。 SiteUrl
、 Username
、および Password
を直接指定できます。 Microsoft.SharePoint.Client.Runtime
以前は、開発者は AuthToken を取得するためにそのアセンブリを使用する必要がありましたが、この依存関係はもはや必要ありません。
注意:現在、Aspose.Tasks for .NET は Project Online のモダン認証をサポートしていません。
統合を成功させるには、Azure portal と Office 365 Admin Center でレガシー認証を有効にする必要があります。
Project Server からプロジェクトを読み取る
次の例は Project Server に接続して既存プロジェクトのデータを読み取る方法を示します:
1const string SharepointDomainAddress = "https://contoso.sharepoint.com";
2const string UserName = "admin@contoso.onmicrosoft.com";
3const string Password = "MyPassword";
4
5ProjectServerCredentials credentials = new ProjectServerCredentials(SharepointDomainAddress, UserName, Password);
6ProjectServerManager manager = new ProjectServerManager(credentials);
7IEnumerable<ProjectInfo> list = manager.GetProjectList();
8
9foreach (var info in list)
10{
11 Project project = manager.GetProject(info.Id);
12 Console.WriteLine("{0} - {1} - {2}", info.Name, info.CreatedDate, info.LastSavedDate);
13 Console.WriteLine("Resources count: {0}", project.Resources.Count);
14
15 // an user can read the project as raw data stream
16 var stream = manager.GetProjectRawData(info.Id);
17
18 // work with raw project data
19}
Project Server でのプロジェクト作成
この例は、Project Server にプログラムで新しいプロジェクトを作成する方法を示します:
1try
2{
3 const string SharepointDomainAddress = "https://contoso.sharepoint.com";
4 const string UserName = "admin@contoso.onmicrosoft.com";
5 const string Password = "MyPassword";
6
7 ProjectServerCredentials credentials = new ProjectServerCredentials(SharepointDomainAddress, UserName, Password);
8
9 Project project = new Project("New Project.mpp");
10
11 ProjectServerManager manager = new ProjectServerManager(credentials);
12 manager.CreateNewProject(project);
13}
14catch (ProjectOnlineException ex)
15{
16 Console.WriteLine(ex.Message);
17}
また、次の環境でもプロジェクトを作成できます: Project Online 事前定義された保存オプションを使用して:
1Project project = new Project("New Project.mpp");
2ProjectServerCredentials credentials = new ProjectServerCredentials("https://contoso.sharepoint.com", "admin@contoso.onmicrosoft.com", "MyPassword");
3ProjectServerManager manager = new ProjectServerManager(credentials);
4ProjectServerSaveOptions options = new ProjectServerSaveOptions
5{
6 Timeout = TimeSpan.FromSeconds(10)
7};
8manager.CreateNewProject(project, options);
Project Server でのプロジェクト更新
この例は、Project Server の既存プロジェクトを更新する方法を示します:
1const string URL = "https://contoso.sharepoint.com";
2const string Domain = "CONTOSO.COM";
3const string UserName = "Administrator";
4const string Password = "MyPassword";
5
6NetworkCredential windowsCredentials = new NetworkCredential(UserName, Password, Domain);
7ProjectServerCredentials projectServerCredentials = new ProjectServerCredentials(URL, windowsCredentials);
8try
9{
10 ProjectServerManager manager = new ProjectServerManager(projectServerCredentials);
11
12 var projectInfo = manager.GetProjectList().FirstOrDefault(p => p.Name == "My project");
13 if (projectInfo == null)
14 {
15 Console.WriteLine("Project 'My project' not found in working store of Project Online account.");
16 return;
17 }
18
19 Project project = manager.GetProject(projectInfo.Id);
20 project.Set(Prj.FinishDate, new DateTime(2020, 03, 01));
21
22 Task task = project.RootTask.Children.Add("New task");
23 task.Set(Tsk.Start, new DateTime(2020, 02, 26));
24 task.Set(Tsk.Duration, project.GetDuration(2, TimeUnitType.Day));
25
26 manager.UpdateProject(project);
27}
28catch (ProjectOnlineException ex)
29{
30 Console.WriteLine("Failed to update the project. Error: " + ex);
31}
Project Online でも保存オプションを使用してプロジェクトを更新でき、変更の適用方法をより細かく制御できます:
1const string SharepointDomainAddress = "https://contoso.sharepoint.com";
2const string UserName = "admin@contoso.onmicrosoft.com";
3const string Password = "MyPassword";
4
5ProjectServerCredentials credentials = new ProjectServerCredentials(SharepointDomainAddress, UserName, Password);
6
7try
8{
9 ProjectServerManager manager = new ProjectServerManager(credentials);
10
11 var projectInfo = manager.GetProjectList().FirstOrDefault(p => p.Name == "My project");
12 if (projectInfo == null)
13 {
14 Console.WriteLine("Project 'My project' not found in working store of Project Online account.");
15 return;
16 }
17
18 Project project = manager.GetProject(projectInfo.Id);
19 project.Set(Prj.FinishDate, new DateTime(2020, 03, 01));
20
21 Task task = project.RootTask.Children.Add("New task");
22 task.Set(Tsk.Start, new DateTime(2020, 02, 26));
23 task.Set(Tsk.Duration, project.GetDuration(2, TimeUnitType.Day));
24
25 ProjectServerSaveOptions options = new ProjectServerSaveOptions { Timeout = TimeSpan.FromMinutes(5) };
26
27 manager.UpdateProject(project, options);
28}
29catch (ProjectOnlineException ex)
30{
31 Console.WriteLine("Failed to update the project. Error: " + ex);
32}
Aspose.Tasks for .NET を使用することで、開発者は両方とシームレスに統合できます Project Server および Project Onlineこれにより、企業のプロジェクトをプログラムで作成、読み取り、更新できるようになり、一貫性の維持、ワークフローの自動化、プロジェクトデータの大規模な業務システムへの統合が容易になります。このような自動化は手作業を減らし、精度を高め、企業レベルのプロジェクト管理を同期され効率的に保つのに役立ちます。