Project.QueueCreateProject 方法

与指定的实体、 创建一个项目并签入到草稿数据库表的项目。

命名空间:  WebSvcProject
程序集:  ProjectServerServices(位于 ProjectServerServices.dll 中)

语法

声明
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Project/QueueCreateProject", RequestNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Project/",  _
    ResponseNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Project/",  _
    Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Sub QueueCreateProject ( _
    jobUid As Guid, _
    dataset As ProjectDataSet, _
    validateOnly As Boolean _
)
用法
Dim instance As Project
Dim jobUid As Guid
Dim dataset As ProjectDataSet
Dim validateOnly As Boolean

instance.QueueCreateProject(jobUid, dataset, _
    validateOnly)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Project/QueueCreateProject", RequestNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Project/", 
    ResponseNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Project/", 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public void QueueCreateProject(
    Guid jobUid,
    ProjectDataSet dataset,
    bool validateOnly
)

参数

  • validateOnly
    类型:System.Boolean

    如果True,仅验证输入的数据并不会执行该操作。

备注

QueueCreateProject是将消息发送到项目服务器队列服务的异步方法。

备注

由于 PSI 不会不支持声明身份验证的QueueCreateProject方法不支持用于Windows Workflow Foundation 4 (WF4) 的工作流定义的企业项目类型 (EPT)。

PSI 可用于创建与 EPTs 有任何工作流或使用旧版的 WF3.5 定义的项目。若要创建与 EPT 的 WF4 定义的项目使用 CSOM。

如QueueCreateProject, Project类方法不能创建、 编辑或删除成本资源。如果ProjectDataSet在dataset参数中包括的成本资源方法返回ResourceCannotCreateCostResource错误 2076年。您可以使用CreateResources方法来创建成本资源但Resource类方法不能对其进行编辑。更多的信息请参阅PSI 可实现的操作和不可实现的操作

项目服务器接口 (PSI) 不能用于在项目中创建本地自定义域。但 PSI 不支持编辑在任务、 资源和工作分配的本地自定义域值。

在创建ProjectDataSet.TaskRow时必须指定TASK_DUR_FMT。否则以后的项目专家在此项目使用可能导致不可预知的行为包括可能的数据丢失。

ProjectDataSet.ProjectResourceRow中的企业资源属性所做的任何更改将会丢失项目专业刷新项目服务器中的数据在下一次。

当您将任务添加到ProjectDataSet时,不要设置TASK_WBS属性。TASK_WBS属性是只读、 尽管它被标记为读/写在 PSI。如果TASK_WBS属性设置为指定的值添加任务,项目专业人员会忽略从 PSI 设置的值并赋值根据任务大纲位置时打开的项目。若要查看项目专业导致,检查任务信息对话框中的高级选项卡上的WBS 代码值。

当您添加一个项目自定义字段到ProjectDataSet.ProjectCustomFields表未设置MD_PROP_ID属性的值。Project Server 自动将在创建项目时添加一个值。CreateProject4Department的代码示例显示了之前和之后对QueueCreateProject的调用ProjectDataSet中的数据。

Project Server 权限

权限

说明

NewProject

允许用户创建一个新项目。全局权限。

SaveProjectTemplate

允许用户创建并保存为企业项目模板的项目。

示例

为 WCF 的示例:  CreateProject4Department示例会执行下列各项:

  1. 建立基本的ProjectDataSetProjectCustomFields表中都有零个或多个任务、 再加上一行的一个新项目。项目通过项目部门自定义字段的Departments查阅表格中有一个值分配给指定部门。

  2. 在调用QueueCreateProject后, 等待完成和读取使用ReadProjectProjectDataSet备份到项目队列。

  3. 将ProjectDataSet保存到 XML 文件中创建该项目之前或之后调用ReadProject。项目服务器会自动创建Project Departments的自定义字段MD_PROP_ID字段所示。

  4. 演示如何使用 WCF FaultException,来显示错误堆栈。在PopulateData方法的注释显示如何在触发System.ServiceModel.FaultExceptionProjectDataSet中创建错误。例如异常处理程序的输出请参阅Project Server 2013 错误代码中的 WCF 节的代码示例。

在Microsoft Visual Studio 2010项目中使用的代码示例和创建 WCF 终结点配置了 app.config 文件有关的信息请参阅Project 2013 中基于 WCF 的代码示例的先决条件

using System;
using System.Text;
using System.ServiceModel;
using System.Xml;
using PSLibrary = Microsoft.Office.Project.Server.Library;

namespace Microsoft.SDK.Project.Samples.CreateProject4Department
{
    class Program
    {
        private const string ENDPOINT_PROJECT = "basicHttp_Project";
        private const string ENDPOINT_QUEUESYSTEM = "basicHttp_QueueSystem";
        // Change the output directory for your computer.
        private const string OUTPUT_FILES = @"C:\Project\Samples\Output\";

        // Change the following GUID to match a value in your Departments
        // lookup table. To find the GUID of a value in the Departments lookup table,
        // see the MSPLT_Department_UserView view in the Reporting database. 
        // For example, use the following query:
        //   SELECT TOP 20 [LookupMemberUID],[MemberValue],[MemberDescription]
        //     FROM [ProjectServer_Reporting].[dbo].[MSPLT_Department_UserView]
        //
        // Alternately, use the LookupTable.ReadLookupTablesByUids method and then 
        // get the GUID of the value you want. The GUID of the built-in Departments
        // lookup table is PSLibrary.LookupTables.DEPARTMENTS_LT_UID.
        private const string DEPARTMENT_TEST = "E78E047B-1F01-4882-8336-60DF5A727F6D";

        private static SvcProject.ProjectClient projectClient;
        private static SvcQueueSystem.QueueSystemClient queueSystemClient;

        private static string outFilePath1;
        private static string outFilePath2;
 
        static void Main(string[] args)
        {
            Guid sampleProjNameUid = Guid.NewGuid();
            string projName = "TestProjDept " + sampleProjNameUid;
            int numTasks = 0;

            if (args.Length > 0 && args.Length < 5)
            {
                if (args[0].ToLower() == "-name")
                {
                    projName = args[1];
                }

                if (args[2].ToLower() == "-tasks")
                    numTasks = Convert.ToInt32(args[3]);
            }
            outFilePath1 = OUTPUT_FILES + "ProjectDataSet4Department_before.xml";
            outFilePath2 = OUTPUT_FILES + "ProjectDataSet4Department_after.xml";
            ConfigClientEndpoints(ENDPOINT_PROJECT);
            ConfigClientEndpoints(ENDPOINT_QUEUESYSTEM);

            try
            {
                SvcProject.ProjectDataSet projectDs = new SvcProject.ProjectDataSet();

                projectDs = PopulateData(projectDs, projName.Trim(), numTasks);

                Console.WriteLine(
                    "\nXML output of the ProjectDataSet before QueueCreateProject:\n\t{0}",
                    outFilePath1);
                projectDs.WriteXml(outFilePath1);

                // Create the project.
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Creating project: {0}", projName);
                Console.ResetColor();

                Guid jobUid = Guid.NewGuid();
                DateTime startTime = DateTime.Now;
                projectClient.QueueCreateProject(jobUid, projectDs, false);

                // Wait for the Project Server Queuing System to create the project.
                if (Helpers.WaitForQueue(SvcQueueSystem.QueueMsgType.ProjectCreate,
                    queueSystemClient, startTime))
                {
                    Console.WriteLine(
                        "\nXML output of the ProjectDataSet after ReadProject:\n\t{0}",
                        outFilePath2);
                    Guid projUid = projectDs.Project[0].PROJ_UID;
                    projectDs = projectClient.ReadProject(projUid,
                        SvcProject.DataStoreEnum.WorkingStore);
                    projectDs.WriteXml(outFilePath2);
                }
                else
                {
                    Console.WriteLine("The project was not created: {0}.\n\tThe queue wait time exceeded 30 seconds.",
                        projName);
                }
            }
            catch(FaultException fault)
            {
                // Use the WCF FaultException, because the ASMX SoapException does not 
                // exist in a WCF-based application.
                WriteFaultOutput(fault);
            }
            Console.Write("\nPress any key to exit... ");
            Console.ReadKey(true);
        }

        // Populate the minimum data necessary for the ProjectDataSet, for the Project 
        // table and for the ProjectCustomFields table.
        private static SvcProject.ProjectDataSet PopulateData(
            SvcProject.ProjectDataSet projDs, string name, int numTasks)
        {
            SvcProject.ProjectDataSet.ProjectRow projRow = projDs.Project.NewProjectRow();
            SvcProject.ProjectDataSet.ProjectCustomFieldsRow projCF = 
                projDs.ProjectCustomFields.NewProjectCustomFieldsRow();

            projRow.PROJ_TYPE = (int)PSLibrary.Project.ProjectType.Project;
            projRow.PROJ_UID = Guid.NewGuid();
            projRow.PROJ_NAME = name;
            projDs.Project.AddProjectRow(projRow);

            projCF.CUSTOM_FIELD_UID = Guid.NewGuid();
            projCF.FIELD_TYPE_ENUM = (byte)PSLibrary.CustomField.Type.TEXT;
            projCF.PROJ_UID = projRow.PROJ_UID;

            // It is not strictly necessary to set unused values to null; 
            // however, doing so helps to emphasize that the custom field is not 
            // one of the following simple types.
            projCF.SetNUM_VALUENull();
            projCF.SetFLAG_VALUENull();
            projCF.SetDUR_VALUENull();
            projCF.SetDUR_FMTNull();
            projCF.SetDATE_VALUENull();
            projCF.SetTEXT_VALUENull();

            // To see the InvalidTypeColumnFilledIn exception when calling 
            // QueueCreateProject, uncomment the following line:
            // projCF.TEXT_VALUE = "Marketing";

            projCF.MD_PROP_UID = PSLibrary.CustomField.PROJECT_DEPARTMENT_MD_PROP_UID;
            Guid lookupTableMemberUid = new Guid(DEPARTMENT_TEST);

            // Comment-out the following line, to see an additional 
            // CustomFieldRequiredValueNotProvided exception.
            projCF.CODE_VALUE = lookupTableMemberUid;

            projDs.ProjectCustomFields.AddProjectCustomFieldsRow(projCF);

            // Add the specified number of tasks.
            if (numTasks > 0)
            {
                SvcProject.ProjectDataSet.TaskRow task = null;
                for (int i = 0; i < numTasks; i++)
                {
                    task = projDs.Task.NewTaskRow();
                    task.PROJ_UID = projRow.PROJ_UID;
                    task.TASK_UID = Guid.NewGuid();
                    task.TASK_DUR_FMT = (int)PSLibrary.Task.DurationFormat.Day;
                    task.TASK_DUR = 4800;  // The task duration is 8 hours.
                    task.TASK_NAME = "T" + (i + 1).ToString();
                    task.TASK_START_DATE = System.DateTime.Now.AddDays(i + 1);
                    projDs.Task.AddTaskRow(task);
                }
            }

            return projDs;
        }

        // Extract a PSClientError object from the WCF FaultException object, and
        // then display the exception details and each error in the PSClientError stack.
        private static void WriteFaultOutput(FaultException fault)
        {
            string errAttributeName;
            string errAttribute;
            string errOut;
            string errMess = "".PadRight(30, '=') + "\r\n"
                + "Error details: " + "\r\n";

            PSLibrary.PSClientError error = Helpers.GetPSClientError(fault, out errOut);
            errMess += errOut;

            PSLibrary.PSErrorInfo[] errors = error.GetAllErrors();
            PSLibrary.PSErrorInfo thisError;

            for (int i = 0; i < errors.Length; i++)
            {
                thisError = errors[i];
                errMess += "\r\n".PadRight(30, '=') + "\r\nPSClientError output:\r\n";
                errMess += thisError.ErrId.ToString() + "\n";

                for (int j = 0; j < thisError.ErrorAttributes.Length; j++)
                {
                    errAttributeName = thisError.ErrorAttributeNames()[j];
                    errAttribute = thisError.ErrorAttributes[j];
                    errMess += "\r\n\t" + errAttributeName
                        + ": " + errAttribute;
                }
            }
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(errMess);
            Console.ResetColor();
        }

        // Use the endpoints defined in app.config to configure the client.
        public static void ConfigClientEndpoints(string endpt)
        {
            if (endpt == ENDPOINT_PROJECT)
                projectClient = new SvcProject.ProjectClient(endpt);
            else if (endpt == ENDPOINT_QUEUESYSTEM)
                queueSystemClient = new SvcQueueSystem.QueueSystemClient(endpt);
        }            
    }

    // Helper methods: WaitForQueue and GetPSClientError.
    class Helpers
    {
        // Wait for the queue jobs to complete.
        public static bool WaitForQueue(SvcQueueSystem.QueueMsgType jobType,
            SvcQueueSystem.QueueSystemClient queueSystemClient,
            DateTime startTime)
        {
            const int MAX_WAIT = 30;    // Maximum wait time, in seconds.
            int numJobs = 1;            // Number of jobs in the queue.
            bool completed = false;     // Queue job completed.
            SvcQueueSystem.QueueStatusDataSet queueStatusDs = 
                new SvcQueueSystem.QueueStatusDataSet();

            int timeout = 0;            // Number of seconds waited.
            Console.Write("Waiting for job: {0} ", jobType.ToString());

            SvcQueueSystem.QueueMsgType[] messageTypes = { jobType };
            SvcQueueSystem.JobState[] jobStates = { SvcQueueSystem.JobState.Success };

            while (timeout < MAX_WAIT)
            {
                System.Threading.Thread.Sleep(1000);    // Sleep one second.

                queueStatusDs = queueSystemClient.ReadMyJobStatus(
                    messageTypes,
                    jobStates,
                    startTime,
                    DateTime.Now,
                    numJobs,
                    true,
                    SvcQueueSystem.SortColumn.QueuePosition,
                    SvcQueueSystem.SortOrder.LastOrder);

                timeout++;
                Console.Write(".");
            }
            Console.WriteLine();

            if (queueStatusDs.Status.Count == numJobs)
                completed = true;
            return completed;
        }

        /// <summary>
        /// Extract a PSClientError object from the ServiceModel.FaultException,
        /// for use in output of the GetPSClientError stack of errors.
        /// </summary>
        /// <param name="e"></param>
        /// <param name="errOut">Shows that FaultException has more information 
        /// about the errors than PSClientError has. FaultException can also contain 
        /// other types of errors, such as failure to connect to the server.</param>
        /// <returns>PSClientError object, for enumerating errors.</returns>
        public static PSLibrary.PSClientError GetPSClientError(FaultException e, 
                                                               out string errOut)
        {
            const string PREFIX = "GetPSClientError() returns null: ";
            errOut = string.Empty;
            PSLibrary.PSClientError psClientError = null;

            if (e == null)
            {
                errOut = PREFIX + "Null parameter (FaultException e) passed in.";
                psClientError = null;
            }
            else
            {
                // Get a ServiceModel.MessageFault object.
                var messageFault = e.CreateMessageFault();

                if (messageFault.HasDetail)
                {
                    using (var xmlReader = messageFault.GetReaderAtDetailContents())
                    {
                        var xml = new XmlDocument();
                        xml.Load(xmlReader);

                        var serverExecutionFault = xml["ServerExecutionFault"];
                        if (serverExecutionFault != null)
                        {
                            var exceptionDetails = serverExecutionFault["ExceptionDetails"];
                            if (exceptionDetails != null)
                            {
                                try
                                {
                                    errOut = exceptionDetails.InnerXml + "\r\n";
                                    psClientError = 
                                        new PSLibrary.PSClientError(exceptionDetails.InnerXml);
                                }
                                catch (InvalidOperationException ex)
                                {
                                    errOut = PREFIX + "Unable to convert fault exception info ";
                                    errOut += "a valid Project Server error message. Message: \n\t";
                                    errOut += ex.Message;
                                    psClientError = null;
                                }
                            }
                            else
                            {
                                errOut = PREFIX + "The FaultException e is a ServerExecutionFault, "
                                    + "but does not have ExceptionDetails.";
                            }
                        }
                        else
                        {
                            errOut = PREFIX + "The FaultException e is not a ServerExecutionFault.";
                        }
                    }
                }
                else // No detail in the MessageFault.
                {
                    errOut = PREFIX + "The FaultException e does not have any detail.";
                }
            }
            errOut += "\r\n" + e.ToString() + "\r\n";
            return psClientError;
        }
    }
}

下面的命令行运行CreateProject4Department应用程序创建的项目的任何任务。该部门 GUID (自定义字段的 CODE_VALUE 属性) 的值是硬编码在该应用程序。

CreateProject4Department -name "Proj Dept Test 2"

以下是CreateProject4Department应用程序在调用QueueCreateProject之前保存的 ProjectDataSet4Department_before.xml 文件的内容。

<?xml version="1.0" standalone="yes"?>
<ProjectDataSet xmlns="https://schemas.microsoft.com/office/project/server/webservices/ProjectDataSet/">
  <Project>
    <PROJ_UID>e1c2d38b-1529-4128-b707-42a94045e55b</PROJ_UID>
    <PROJ_NAME>Proj Dept Test 2</PROJ_NAME>
    <PROJ_TYPE>0</PROJ_TYPE>
  </Project>
  <ProjectCustomFields>
    <CUSTOM_FIELD_UID>4802a711-62a0-4f84-8e08-c7d22daadb5b</CUSTOM_FIELD_UID>
    <PROJ_UID>e1c2d38b-1529-4128-b707-42a94045e55b</PROJ_UID>
    <MD_PROP_UID>9d77d62a-a92e-4d40-adc8-446c90eb7456</MD_PROP_UID>
    <FIELD_TYPE_ENUM>21</FIELD_TYPE_ENUM>
    <CODE_VALUE>a47930d6-b89d-4f3a-b4e3-522015fe82a1</CODE_VALUE>
  </ProjectCustomFields>
</ProjectDataSet>

以下是CreateProject4Department应用程序保存在调用ReadProject的 ProjectDataSet4Department_after.xml 文件的内容。项目服务器填充用ProjectCustomFields表中包括MD_PROP_ID字段的默认值的附加字段。

<?xml version="1.0" standalone="yes"?>
<ProjectDataSet xmlns="https://schemas.microsoft.com/office/project/server/webservices/ProjectDataSet/">
  <Project>
    <PROJ_UID>e1c2d38b-1529-4128-b707-42a94045e55b</PROJ_UID>
    <PROJ_NAME>Proj Dept Test 2</PROJ_NAME>
    <PROJ_TYPE>0</PROJ_TYPE>
    <PROJ_PROP_AUTHOR>REDMOND\jcorbin</PROJ_PROP_AUTHOR>
    <CAL_UID>b6635b2e-e747-4771-a78b-24f7509629d0</CAL_UID>
    <CAL_NAME>Standard</CAL_NAME>
    <PROJ_PROP_TITLE>Proj Dept Test 2</PROJ_PROP_TITLE>
    <PROJ_OPT_CALC_ACT_COSTS>false</PROJ_OPT_CALC_ACT_COSTS>
    <PROJ_OPT_CRITICAL_SLACK_LIMIT>0</PROJ_OPT_CRITICAL_SLACK_LIMIT>
    <PROJ_OPT_CURRENCY_DIGITS>2</PROJ_OPT_CURRENCY_DIGITS>
    <PROJ_OPT_CURRENCY_POSITION>0</PROJ_OPT_CURRENCY_POSITION>
    <PROJ_OPT_CURRENCY_SYMBOL>$</PROJ_OPT_CURRENCY_SYMBOL>
    <PROJ_OPT_CURRENCY_CODE>USD</PROJ_OPT_CURRENCY_CODE>
    <PROJ_OPT_NEW_TASKS_ARE_EFFORT_DRIVEN>false</PROJ_OPT_NEW_TASKS_ARE_EFFORT_DRIVEN>
    <PROJ_INFO_CURRENT_DATE>2010-06-21T08:00:00-07:00</PROJ_INFO_CURRENT_DATE>
    <PROJ_OPT_DEF_FINISH_TIME>2010-06-21T17:00:00-07:00</PROJ_OPT_DEF_FINISH_TIME>
    <PROJ_OPT_DEF_FIX_COST_ACCRUAL>3</PROJ_OPT_DEF_FIX_COST_ACCRUAL>
    <PROJ_OPT_DEF_OVT_RATE>0</PROJ_OPT_DEF_OVT_RATE>
    <PROJ_OPT_DEF_STD_RATE>0</PROJ_OPT_DEF_STD_RATE>
    <PROJ_OPT_DEF_START_TIME>2010-06-21T08:00:00-07:00</PROJ_OPT_DEF_START_TIME>
    <PROJ_OPT_DEF_TASK_TYPE>0</PROJ_OPT_DEF_TASK_TYPE>
    <WPROJ_TRACKING_METHOD>0</WPROJ_TRACKING_METHOD>
    <PROJ_OPT_DUR_ENTRY_FMT>7</PROJ_OPT_DUR_ENTRY_FMT>
    <PROJ_INFO_FINISH_DATE>2010-06-21T08:00:00-07:00</PROJ_INFO_FINISH_DATE>
    <PROJ_OPT_HONOR_CONSTRAINTS>true</PROJ_OPT_HONOR_CONSTRAINTS>
    <PROJ_OPT_MULT_CRITICAL_PATHS>false</PROJ_OPT_MULT_CRITICAL_PATHS>
    <PROJ_INFO_SCHED_FROM>true</PROJ_INFO_SCHED_FROM>
    <PROJ_OPT_SPLIT_IN_PROGRESS>true</PROJ_OPT_SPLIT_IN_PROGRESS>
    <PROJ_OPT_SPREAD_ACT_COSTS>false</PROJ_OPT_SPREAD_ACT_COSTS>
    <PROJ_OPT_SPREAD_PCT_COMP>false</PROJ_OPT_SPREAD_PCT_COMP>
    <PROJ_INFO_START_DATE>2010-06-21T08:00:00-07:00</PROJ_INFO_START_DATE>
    <PROJ_INFO_STATUS_DATE>2010-06-21T08:00:00-07:00</PROJ_INFO_STATUS_DATE>
    <PROJ_OPT_TASK_UPDATES_RES>true</PROJ_OPT_TASK_UPDATES_RES>
    <PROJ_OPT_WORK_ENTRY_FMT>2</PROJ_OPT_WORK_ENTRY_FMT>
    <PROJ_OPT_NEW_TASK_EST>true</PROJ_OPT_NEW_TASK_EST>
    <PROJ_PROTECTED_ACTUALS_SYNCH>false</PROJ_PROTECTED_ACTUALS_SYNCH>
    <PROJ_OPT_FY_START_MONTH>1</PROJ_OPT_FY_START_MONTH>
    <PROJ_OPT_FY_USE_START_YR>false</PROJ_OPT_FY_USE_START_YR>
    <PROJ_OPT_MINUTES_PER_DAY>480</PROJ_OPT_MINUTES_PER_DAY>
    <PROJ_OPT_MINUTES_PER_WEEK>2400</PROJ_OPT_MINUTES_PER_WEEK>
    <PROJ_OPT_DAYS_PER_MONTH>20</PROJ_OPT_DAYS_PER_MONTH>
    <PROJ_OPT_MOVE_ACTUAL_IF_LATER>false</PROJ_OPT_MOVE_ACTUAL_IF_LATER>
    <PROJ_OPT_MOVE_ACTUAL_TO_STATUS>false</PROJ_OPT_MOVE_ACTUAL_TO_STATUS>
    <PROJ_OPT_MOVE_REMAINING_IF_EARLIER>false</PROJ_OPT_MOVE_REMAINING_IF_EARLIER>
    <PROJ_OPT_MOVE_REMAINING_TO_STATUS>false</PROJ_OPT_MOVE_REMAINING_TO_STATUS>
    <PROJ_OPT_SHOW_EST_DUR>true</PROJ_OPT_SHOW_EST_DUR>
    <PROJ_OPT_WEEK_START_DAY>0</PROJ_OPT_WEEK_START_DAY>
    <ProjectOwnerID>a91826f2-e125-4b85-b59e-0bebbca19208</ProjectOwnerID>
    <PROJ_STALE_FLAGS>3</PROJ_STALE_FLAGS>
    <PROJ_LAST_SAVED>2010-06-21T14:58:41.01-07:00</PROJ_LAST_SAVED>
    <CREATED_DATE>2010-06-21T14:58:39.89-07:00</CREATED_DATE>
    <ENTERPRISE_PROJECT_TYPE_UID>09fa52b4-059b-4527-926e-99f9be96437a</ENTERPRISE_PROJECT_TYPE_UID>
    <ENTERPRISE_PROJECT_TYPE_NAME>Basic Project Plan</ENTERPRISE_PROJECT_TYPE_NAME>
    <PROJ_NEW_TASKS_ARE_MANUAL>true</PROJ_NEW_TASKS_ARE_MANUAL>
    <PROJ_WINPROJ_VERSION_NUMBER>14.0000000000</PROJ_WINPROJ_VERSION_NUMBER>
  </Project>
  <Task>
    <PROJ_UID>e1c2d38b-1529-4128-b707-42a94045e55b</PROJ_UID>
    <TASK_UID>efcca348-2057-4ec7-9e21-13e073fade66</TASK_UID>
    <TASK_PARENT_UID>efcca348-2057-4ec7-9e21-13e073fade66</TASK_PARENT_UID>
    <TASK_NAME>Proj Dept Test 2</TASK_NAME>
    <TASK_ID>0</TASK_ID>
    <TASK_IS_MILESTONE>false</TASK_IS_MILESTONE>
    <TASK_IS_SUMMARY>true</TASK_IS_SUMMARY>
    <TASK_IS_MARKED>false</TASK_IS_MARKED>
    <TASK_IGNORES_RES_CAL>false</TASK_IGNORES_RES_CAL>
    <TASK_IS_EFFORT_DRIVEN>false</TASK_IS_EFFORT_DRIVEN>
    <TASK_IS_CRITICAL>true</TASK_IS_CRITICAL>
    <TASK_IS_EXTERNAL>false</TASK_IS_EXTERNAL>
    <TASK_IS_FROM_FINISH_SUBPROJ>false</TASK_IS_FROM_FINISH_SUBPROJ>
    <TASK_IS_OVERALLOCATED>false</TASK_IS_OVERALLOCATED>
    <TASK_IS_RECURRING>false</TASK_IS_RECURRING>
    <TASK_IS_RECURRING_SUMMARY>false</TASK_IS_RECURRING_SUMMARY>
    <TASK_IS_SUBPROJ>false</TASK_IS_SUBPROJ>
    <TASK_IS_READONLY_SUBPROJ>false</TASK_IS_READONLY_SUBPROJ>
    <TASK_LOCKDOWN_BY_MANAGER>false</TASK_LOCKDOWN_BY_MANAGER>
    <TASK_LEVELING_DELAY>0</TASK_LEVELING_DELAY>
    <TASK_LEVELING_DELAY_FMT>8</TASK_LEVELING_DELAY_FMT>
    <TASK_LEVELING_CAN_SPLIT>true</TASK_LEVELING_CAN_SPLIT>
    <TASK_LEVELING_ADJUSTS_ASSN>true</TASK_LEVELING_ADJUSTS_ASSN>
    <TASK_DUR_IS_EST>false</TASK_DUR_IS_EST>
    <TASK_DUR>0</TASK_DUR>
    <TASK_DUR_FMT>53</TASK_DUR_FMT>
    <TASK_DUR_VAR>0</TASK_DUR_VAR>
    <TASK_EAC>0</TASK_EAC>
    <TASK_VAC>0</TASK_VAC>
    <TASK_ACT_DUR>0</TASK_ACT_DUR>
    <TASK_REM_DUR>0</TASK_REM_DUR>
    <TASK_CONSTRAINT_TYPE>0</TASK_CONSTRAINT_TYPE>
    <TASK_PRIORITY>500</TASK_PRIORITY>
    <TASK_PCT_COMP>0</TASK_PCT_COMP>
    <TASK_PCT_WORK_COMP>0</TASK_PCT_WORK_COMP>
    <TASK_TYPE>1</TASK_TYPE>
    <TASK_FIXED_COST_ACCRUAL>3</TASK_FIXED_COST_ACCRUAL>
    <TASK_WORK>0</TASK_WORK>
    <TASK_OVT_WORK>0</TASK_OVT_WORK>
    <TASK_REG_WORK>0</TASK_REG_WORK>
    <TASK_ACT_WORK>0</TASK_ACT_WORK>
    <TASK_ACT_OVT_WORK>0</TASK_ACT_OVT_WORK>
    <TASK_REM_WORK>0</TASK_REM_WORK>
    <TASK_REM_OVT_WORK>0</TASK_REM_OVT_WORK>
    <TASK_COST>0</TASK_COST>
    <TASK_OVT_COST>0</TASK_OVT_COST>
    <TASK_FIXED_COST>0</TASK_FIXED_COST>
    <TASK_ACT_COST>0</TASK_ACT_COST>
    <TASK_ACT_OVT_COST>0</TASK_ACT_OVT_COST>
    <TASK_REM_COST>0</TASK_REM_COST>
    <TASK_REM_OVT_COST>0</TASK_REM_OVT_COST>
    <TASK_OUTLINE_LEVEL>0</TASK_OUTLINE_LEVEL>
    <TASK_OUTLINE_NUM />
    <TASK_START_DATE>2010-06-21T08:00:00-07:00</TASK_START_DATE>
    <TASK_START_VAR>0</TASK_START_VAR>
    <TASK_FINISH_DATE>2010-06-21T08:00:00-07:00</TASK_FINISH_DATE>
    <TASK_FINISH_VAR>0</TASK_FINISH_VAR>
    <TASK_EARLY_START>2010-06-21T08:00:00-07:00</TASK_EARLY_START>
    <TASK_EARLY_FINISH>2010-06-21T08:00:00-07:00</TASK_EARLY_FINISH>
    <TASK_LATE_START>2010-06-21T08:00:00-07:00</TASK_LATE_START>
    <TASK_LATE_FINISH>2010-06-21T08:00:00-07:00</TASK_LATE_FINISH>
    <TASK_BCWS>0</TASK_BCWS>
    <TASK_BCWP>0</TASK_BCWP>
    <TASK_ACWP>0</TASK_ACWP>
    <TASK_FREE_SLACK>0</TASK_FREE_SLACK>
    <TASK_TOTAL_SLACK>0</TASK_TOTAL_SLACK>
    <TASK_HAS_LINKED_FIELDS>false</TASK_HAS_LINKED_FIELDS>
    <CREATED_DATE>2010-06-21T14:58:39.987-07:00</CREATED_DATE>
    <MOD_DATE>2010-06-21T14:58:40.807-07:00</MOD_DATE>
    <TASK_BUDGET_COST>0</TASK_BUDGET_COST>
    <TASK_IS_NULL>false</TASK_IS_NULL>
    <TASK_BUDGET_WORK>0</TASK_BUDGET_WORK>
    <TASK_COST_VAR>0</TASK_COST_VAR>
    <TASK_CPI>0</TASK_CPI>
    <TASK_CV>0</TASK_CV>
    <TASK_START_SLACK>0</TASK_START_SLACK>
    <TASK_FINISH_SLACK>0</TASK_FINISH_SLACK>
    <TASK_IS_ROLLED_UP>false</TASK_IS_ROLLED_UP>
    <TASK_SV>0</TASK_SV>
    <TASK_TCPI>0</TASK_TCPI>
    <TASK_WORK_VAR>0</TASK_WORK_VAR>
    <TASK_COMPLETE_THROUGH>2010-06-21T08:00:00-07:00</TASK_COMPLETE_THROUGH>
    <TASK_IS_MANUAL>false</TASK_IS_MANUAL>
    <TASK_IS_ACTIVE>true</TASK_IS_ACTIVE>
    <TASK_IS_DISPSUMMARY>false</TASK_IS_DISPSUMMARY>
    <TASK_SCHED_START>2010-06-21T08:00:00-07:00</TASK_SCHED_START>
    <TASK_SCHED_FINISH>2010-06-21T08:00:00-07:00</TASK_SCHED_FINISH>
    <TASK_SCHED_DUR>0</TASK_SCHED_DUR>
    <TASK_SCHED_DUR_FMT>53</TASK_SCHED_DUR_FMT>
  </Task>
  <ProjectCustomFields>
    <CUSTOM_FIELD_UID>4802a711-62a0-4f84-8e08-c7d22daadb5b</CUSTOM_FIELD_UID>
    <PROJ_UID>e1c2d38b-1529-4128-b707-42a94045e55b</PROJ_UID>
    <MD_PROP_UID>9d77d62a-a92e-4d40-adc8-446c90eb7456</MD_PROP_UID>
    <MD_PROP_ID>190873600</MD_PROP_ID>
    <FIELD_TYPE_ENUM>21</FIELD_TYPE_ENUM>
    <CODE_VALUE>a47930d6-b89d-4f3a-b4e3-522015fe82a1</CODE_VALUE>
  </ProjectCustomFields>
  <ProjectResourceCustomFields>
    <CUSTOM_FIELD_UID>ba309fe8-2a23-440c-9e48-bce9dd001845</CUSTOM_FIELD_UID>
    <PROJ_UID>e1c2d38b-1529-4128-b707-42a94045e55b</PROJ_UID>
    <RES_UID>a0cb8b7e-2a8c-436d-0000-0000000000ff</RES_UID>
    <MD_PROP_UID>d5799183-1107-4ffa-95c1-26d5dfe2cd79</MD_PROP_UID>
    <MD_PROP_ID>205553667</MD_PROP_ID>
    <FIELD_TYPE_ENUM>21</FIELD_TYPE_ENUM>
    <TEXT_VALUE> calendar</TEXT_VALUE>
  </ProjectResourceCustomFields>
  <ProjectResourceCustomFields>
    <CUSTOM_FIELD_UID>45bf1b3d-a695-49c9-8481-8dc2e1220c34</CUSTOM_FIELD_UID>
    <PROJ_UID>e1c2d38b-1529-4128-b707-42a94045e55b</PROJ_UID>
    <RES_UID>a0cb8b7e-2a8c-436d-0000-0000000000ff</RES_UID>
    <MD_PROP_UID>09c05c93-c582-4dd9-8c44-ae9cd2471603</MD_PROP_UID>
    <MD_PROP_ID>205553668</MD_PROP_ID>
    <FIELD_TYPE_ENUM>21</FIELD_TYPE_ENUM>
    <TEXT_VALUE>Cost center: </TEXT_VALUE>
  </ProjectResourceCustomFields>
</ProjectDataSet>

用于 ASMX 的示例:  下面的示例将创建一个项目、 向其添加一些任务,然后将项目保存到服务器。

有关运行该代码示例请参阅Project 2013 中基于 ASMX 的代码示例的先决条件

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Web.Services.Protocols;
using System.Threading;
using PSLibrary = Microsoft.Office.Project.Server.Library;

namespace Microsoft.SDK.Project.Samples.QueueCreateProject
{
   class Program
   {
      [STAThread]
      static void Main(string[] args)
      {
         try
         {
            const string PROJECT_SERVER_URI = "https://ServerName/ProjectServerName/";
            const string PROJECT_SERVICE_PATH = "_vti_bin/psi/project.asmx";
            const string QUEUESYSTEM_SERVICE_PATH = "_vti_bin/psi/queuesystem.asmx";

            Guid jobId;

            // Set up the web service objects.
            SvcProject.Project projectSvc = new SvcProject.Project();

            SvcProject.ProjectDataSet projectDs = new SvcProject.ProjectDataSet();

            projectSvc.Url = PROJECT_SERVER_URI + PROJECT_SERVICE_PATH;
            projectSvc.Credentials = CredentialCache.DefaultCredentials;

            SvcQueueSystem.QueueSystem q = new SvcQueueSystem.QueueSystem();
            q.Url = PROJECT_SERVER_URI + QUEUESYSTEM_SERVICE_PATH;
            q.UseDefaultCredentials = true;

            // Create a sample project.
            Console.WriteLine("Creating project data");
            projectDs = new SvcProject.ProjectDataSet();
            
            // Create the project.
            SvcProject.ProjectDataSet.ProjectRow projectRow = projectDs.Project.NewProjectRow();
            projectRow.PROJ_UID = Guid.NewGuid();
         projectRow.PROJ_NAME = "Its a wonderful project at " + 
            DateTime.Now.ToShortDateString().Replace("/", "") + " " + 
            DateTime.Now.ToShortTimeString().Replace(":", "");
            projectRow.PROJ_TYPE = (int)PSLibrary.Project.ProjectType.Project;
            projectDs.Project.AddProjectRow(projectRow);

            // Add some tasks.
            SvcProject.ProjectDataSet.TaskRow taskOne = projectDs.Task.NewTaskRow();
            taskOne.PROJ_UID = projectRow.PROJ_UID;
            taskOne.TASK_UID = Guid.NewGuid();
            // The Task Duration format must be specified.
            taskOne.TASK_DUR_FMT = (int)PSLibrary.Task.DurationFormat.Day;
            taskOne.TASK_DUR = 4800;  // 8 hours in duration units (minute/10)taskOne.TASK_NAME = "Task One";
            taskOne.TASK_START_DATE = System.DateTime.Now.AddDays(1);
            projectDs.Task.AddTaskRow(taskOne);

            SvcProject.ProjectDataSet.TaskRow taskTwo = projectDs.Task.NewTaskRow();
            taskTwo.PROJ_UID = projectRow.PROJ_UID;
            taskTwo.TASK_UID = Guid.NewGuid();
            // The Task Duration format must be specified.
            taskTwo.TASK_DUR_FMT = (int)PSLibrary.Task.DurationFormat.Day;
            taskTwo.TASK_DUR = 4800;  // 8 hours in duration units (minute/10)
            taskTwo.TASK_NAME = "Task Two";
            taskTwo.TASK_START_DATE = System.DateTime.Now.AddDays(1);
            projectDs.Task.AddTaskRow(taskTwo);

            // Save the project to the database.
            Console.WriteLine("Saving project data to the server");
            jobId = Guid.NewGuid();
            projectSvc.QueueCreateProject(jobId, projectDs, false);
            WaitForQueue(q, jobId);

         }
         catch (SoapException ex)
         {
            PSLibrary.PSClientError error = new PSLibrary.PSClientError(ex);
            PSLibrary.PSErrorInfo[] errors = error.GetAllErrors();
            string errMess = "==============================\r\nError: \r\n";
            for (int i = 0; i < errors.Length; i++)
            {
               errMess += "\n" + ex.Message.ToString() + "\r\n";
               errMess += "".PadRight(30, '=') + "\r\nPSCLientError Output:\r\n \r\n";
               errMess += errors[i].ErrId.ToString() + "\n";

               for (int j = 0; j < errors[i].ErrorAttributes.Length; j++)
               {
                  errMess += "\r\n\t" + errors[i].ErrorAttributeNames()[j] + ": " + errors[i].ErrorAttributes[j];
               }
               errMess += "\r\n".PadRight(30, '=');
            }
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(errMess);
         }
         catch (WebException ex)
         {
            string errMess = ex.Message.ToString() +
               "\n\nLog on, or check the Project Server Queuing Service";
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Error: " + errMess);
         }
         catch (Exception ex)
         {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Error: " + ex.Message);
         }
         finally
         {
            Console.ResetColor();
            Console.WriteLine("\r\n\r\nPress any key...");
            Console.ReadKey();
         }
      }
      static private void WaitForQueue(SvcQueueSystem.QueueSystem q, Guid jobId)
      {
         SvcQueueSystem.JobState jobState;
         const int QUEUE_WAIT_TIME = 2; // two seconds
         bool jobDone = false;
         string xmlError = string.Empty;
         int wait = 0;

         // Wait for the project to get through the queue.
         // Get the estimated wait time in seconds.
         wait = q.GetJobWaitTime(jobId);

         // Wait for it.
         Thread.Sleep(wait * 1000);
         // Wait until it is finished.

         do
         {
            // Get the job state.
            jobState = q.GetJobCompletionState(jobId, out xmlError);

            if (jobState == SvcQueueSystem.JobState.Success)
            {
               jobDone = true;
            }
            else
            {
               if (jobState == SvcQueueSystem.JobState.Unknown
               || jobState == SvcQueueSystem.JobState.Failed
               || jobState == SvcQueueSystem.JobState.FailedNotBlocking
               || jobState == SvcQueueSystem.JobState.CorrelationBlocked
               || jobState == SvcQueueSystem.JobState.Canceled)
               {
                  // If the job failed, error out.
                  throw (new ApplicationException("Queue request failed \"" + jobState + "\" Job ID: " + jobId + ".\r\n" + xmlError));
               }
               else
               {
                  Console.WriteLine("Job State: " + jobState + " Job ID: " + jobId);
                  Thread.Sleep(QUEUE_WAIT_TIME * 1000);
               }
            }
         }
         while (!jobDone);
      }
   }
}

另请参阅

引用

Project 类

Project 成员

WebSvcProject 命名空间