ProjectCreationInformation クラス

プロジェクトの作成時に設定できるプロパティが含まれています。

継承階層

System.Object
  Microsoft.SharePoint.Client.ClientValueObject
    Microsoft.ProjectServer.Client.ProjectCreationInformation

名前空間:  Microsoft.ProjectServer.Client
アセンブリ:  Microsoft.ProjectServer.Client (Microsoft.ProjectServer.Client.dll 内)

構文

'宣言
<ScriptTypeAttribute("PS.ProjectCreationInformation", ValueObject := True,  _
    ServerTypeId := "{1e88d96b-47f5-44ca-b0d2-7e8309cd03a8}")> _
Public Class ProjectCreationInformation _
    Inherits ClientValueObject
'使用
Dim instance As ProjectCreationInformation
[ScriptTypeAttribute("PS.ProjectCreationInformation", ValueObject = true, 
    ServerTypeId = "{1e88d96b-47f5-44ca-b0d2-7e8309cd03a8}")]
public class ProjectCreationInformation : ClientValueObject

注釈

プロジェクトのコレクションを取得するには、 Project Web Appのインスタンスで、 ProjectServer.Projectsプロパティを使用します。

QueueCreateProjectという名前のコンソール アプリケーションの例は、次のジョブを行います。

  • 任意のキュー ジョブの待機時間、新しいプロジェクトの名前を取得するには、コマンド行を解析します。既定の待機時間は 10 秒です。たとえば、 Project Web Appでテスト プロジェクト 1という名前のプロジェクトが存在しない場合は、 QueueCreateProject -projName "Test proj 1"コマンドを使ってアプリケーションを実行できます。

  • 指定されたProject Web AppインスタンスのProjectContextオブジェクトを作成します。

  • エンタープライズ プロジェクトの種類 (EPT)「エンタープライズ プロジェクト」という名前の GUID を取得します。

  • CreateTestProjectメソッド、 ProjectCreationInformationオブジェクトのプロパティを設定すると、プロジェクトを作成します。

  • プロジェクト サーバー キュー サービスのProjectContext.WaitForQueueメソッドを使用して、新しいプロジェクトを発行するまで待機します。

  • 発行済みプロジェクトの一覧を表示します。QueueCreateProjectアプリケーションは、 WaitForQueueメソッドを呼び出しません場合、発行されたプロジェクトの新しいプロジェクトはまだ表示されません。

次の使用例の詳細については、 Project Server CSOM および .NET の概要を参照してください。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.ProjectServer.Client;

namespace QueueCreateProject
{
    class Program
    {
        private const string pwaPath = "https://ServerName/pwa/"; // Change the path to Project Web App.
        private static string basicEpt = "Enterprise Project";   // Basic enterprise project type.
        private static string projName = string.Empty;
        private static int timeoutSeconds = 10;  // The maximum wait time for a queue job, in seconds.

        private static ProjectContext projContext;

        static void Main(string[] args)
        {
            if (!ParseCommandLine(args))
            {
                Usage();
                ExitApp();
            }

            projContext = new ProjectContext(pwaPath);

            if (CreateTestProject())
                ListPublishedProjects();
            else
                Console.WriteLine("\nProject creation failed: {0}", projName);

            ExitApp();
        }

        // Create a project.
        private static bool CreateTestProject()
        {
            bool projCreated = false;

            try
            {
                Console.Write("\nCreating project: {0} ...", projName);
                ProjectCreationInformation newProj = new ProjectCreationInformation();

                newProj.Id = Guid.NewGuid();
                newProj.Name = projName;
                newProj.Description = "Test creating a project with CSOM";
                newProj.Start = DateTime.Today.Date;

                // Setting the EPT GUID is optional. If no EPT is specified, 
                // Project Server uses the default EPT. 
                newProj.EnterpriseProjectTypeId = GetEptUid(basicEpt);

                PublishedProject newPublishedProj = projContext.Projects.Add(newProj);
                QueueJob qJob = projContext.Projects.Update();

                // Calling Load and ExecuteQuery for the queue job is optional. If qJob is 
                // not initialized when you call WaitForQueue, Project Server initializes it.
                // projContext.Load(qJob);
                // projContext.ExecuteQuery();

                JobState jobState = projContext.WaitForQueue(qJob, timeoutSeconds);

                if (jobState == JobState.Success)
                {
                    projCreated = true;
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("\nThere is a problem in the queue. Timeout is {0} seconds.", 
                        timeoutSeconds);
                    Console.WriteLine("\tQueue JobState: {0}", jobState.ToString());
                    Console.ResetColor();
                }

                Console.WriteLine();
            }
            catch(Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("\nError: {0}", ex.Message);
                Console.ResetColor();
            }
            return projCreated;
        }

        // Get the GUID of the specified enterprise project type.
        private static Guid GetEptUid(string eptName)
        {
            Guid eptUid = Guid.Empty;

            try
            {
                // Get the list of EPTs that have the specified name. 
                // If the EPT name exists, the list will contain only one EPT.
                var eptList = projContext.LoadQuery(
                    projContext.EnterpriseProjectTypes.Where(
                        ept => ept.Name == eptName));
                projContext.ExecuteQuery();

                eptUid = eptList.First().Id;

                // Alternate routines to find the EPT GUID. Both (a) and (b) download the entire list of EPTs.
                // (a) Using a foreach block:
                //foreach (EnterpriseProjectType ept in projSvr.EnterpriseProjectTypes)
                //{
                //    if (ept.Name == eptName)
                //    {
                //        eptUid = ept.Id;
                //        break;
                //    }
                //}
                // (b) Querying for the EPT list, and then using a lambda expression to select the EPT:
                //var eptList = projContext.LoadQuery(projContext.EnterpriseProjectTypes);
                //projContext.ExecuteQuery();
                //eptUid = eptList.First(ept => ept.Name == eptName).Id;
            }
            catch (Exception ex)
            {
                string msg = string.Format("GetEptUid: eptName = \"{0}\"\n\n{1}",
                    eptName, ex.GetBaseException().ToString());
                throw new ArgumentException(msg);
            }
            return eptUid;
        }

        // List the published projects.
        private static void ListPublishedProjects()
        {
            // Get the list of projects on the server.
            projContext.Load(projContext.Projects);
            projContext.ExecuteQuery();

            Console.WriteLine("\nProject ID : Project name : Created date");

            foreach (PublishedProject pubProj in projContext.Projects)
            {
                Console.WriteLine("\n\t{0} :\n\t{1} : {2}", pubProj.Id.ToString(), pubProj.Name,
                    pubProj.CreatedDate.ToString());
            }
        }

        // Parse the command line. Return true if there are no errors.
        private static bool ParseCommandLine(string[] args)
        {
            bool error = false;
            int argsLen = args.Length;

            try
            {
                for (int i = 0; i < argsLen; i++)
                {
                    if (error) break;
                    if (args[i].StartsWith("-") || args[i].StartsWith("/"))
                        args[i] = "*" + args[i].Substring(1).ToLower();

                    switch (args[i])
                    {
                        case "*projname":
                        case "*n":
                            if (++i >= argsLen) return false;
                            projName = args[i];
                            break;
                        case "*timeout":
                        case "*t":
                            if (++i >= argsLen) return false;
                            timeoutSeconds = Convert.ToInt32(args[i]);
                            break;
                        case "*?":
                        default:
                            error = true;
                            break;
                    }
                }
            }
            catch (FormatException)
            {
                error = true;
            }
            if (string.IsNullOrEmpty(projName)) error = true;
            return !error;
        }

        private static void Usage()
        {
            string example = "Usage: QueueCreateProject -projName | -n \"New project name\" [-timeout | -t sec]";
            example += "\nExample: QueueCreateProject -n \"My new project\"";
            example += "\nDefault timeout seconds = " + timeoutSeconds.ToString();
            Console.WriteLine(example);
        }

        private static void ExitApp()
        {
            Console.Write("\nPress any key to exit... ");
            Console.ReadKey(true);
            Environment.Exit(0);
        }
    }
}

スレッド セーフ

この型のパブリック static (Visual Basic のShared ) メンバーはいずれもスレッド セーフです。インスタンス メンバーはスレッド セーフになるという保証はありません。

関連項目

参照先

ProjectCreationInformation メンバー

Microsoft.ProjectServer.Client 名前空間

Project

DraftProject

PublishedProject

ProjectCollection