Project.ReadProjectStatus 方法

获取指定项目的状态。

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

语法

声明
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Project/ReadProjectStatus", 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 Function ReadProjectStatus ( _
    projGuid As Guid, _
    dataStore As DataStoreEnum, _
    projName As String, _
    projType As Integer _
) As ProjectDataSet
用法
Dim instance As Project
Dim projGuid As Guid
Dim dataStore As DataStoreEnum
Dim projName As String
Dim projType As Integer
Dim returnValue As ProjectDataSet

returnValue = instance.ReadProjectStatus(projGuid, _
    dataStore, projName, projType)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Project/ReadProjectStatus", 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 ProjectDataSet ReadProjectStatus(
    Guid projGuid,
    DataStoreEnum dataStore,
    string projName,
    int projType
)

参数

  • projGuid
    类型:System.Guid

    该项目的 GUID。默认值为Guid.Empty。

  • projName
    类型:System.String

    项目的名称。默认值是String.Empty,以获取对用户可见的所有项目。

返回值

类型:WebSvcProject.ProjectDataSet
状态和当前用户的权限确定可见的项目的列表。ProjectDataSet架构包含仅Project表与以下字段: PROJ_UID、 PROJ_NAME、 PROJ_TYPE、 PROJ_CHECKOUTDATE、 PROJ_SESSION_DESCRIPTION、 WPROJ_LAST_PUB、 PROJ_LAST_SAVED、 CREATED_DATE、 ENTERPRISE_PROJECT_TYPE_UID、 ENTERPRISE_PROJECT_TYPE_NAME和PROJ_WINPROJ_VERSION_NUMBER。

备注

由于它采用入帐户的用户权限的ReadProjectStatus方法是获取的项目的列表的首选的方法。此方法填充Project表中的某些字段。若要填充Project中的其他字段表、 Task的表或其他表、 使用ReadProject与所需项目的 GUID。

ReadProjectStatus方法使您能够获得一个项目使用的名称。您必须使用项目的完整名称。若要只按名称获取项目,将projGuid设置为Guid.Empty、 指定dataStore、 projName,在传递项目名称和指定的项目类型。CreateProjectFromTemplate中的示例使用ReadProjectStatus方法来检索该模板。

Project Server 权限

权限

说明

ViewProjectCenter

允许用户在Project Web App中查看项目中心。全局权限。

OpenProject

允许用户打开指定的项目。如果它们没有ViewProjectCenter只需要。类别的权限。

示例

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

  1. 获取当前用户的 GUID。

  2. 通过使用ReadProjectStatus来读取显示给用户的所有项目的列表。

  3. 通过使用ReadProject将读取每个项目在列表中。

  4. 如果项目所有者匹配当前用户:

    1. 将项目行复制到具有相同的架构创建的ReadProjectStatusProjectDataSet 。

    2. 将项目行复制到第二个ProjectDataSet具有完整的架构。

    3. 在项目中添加所选的任务的数据为TaskDataTable。

  5. 一个用于比较的架构的 XML 文件中写入每个输出ProjectDataSet 。

  6. 例如异常处理程序的输出请参阅Project Server 2013 错误代码中的 WCF 节的代码示例。

提示

如果存在大量的项目以阅读报告数据库的查询可以效率更高。也 PSI 扩展可以执行所有的ReadProjectStatus和ReadProject在服务器上调用并返回只是最终ProjectDataSet。

在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.ReadMyProjects
{
    class Program
    {
        private const string ENDPOINT_PROJECT = "basicHttp_Project";
        private const string ENDPOINT_RESOURCE = "basicHttp_Resource";

        // Change the output directory for your computer.
        private const string OUTPUT_FILES = @"C:\Project\Samples\Output\";
        private const string XML_FILE = "MyProjects.xml";
        private const string XML_FILE2 = "MyProjects2.xml";

        private static SvcProject.ProjectClient projectClient;
        private static SvcResource.ResourceClient resourceClient;
 
        static void Main(string[] args)
        {
            string outFilePath = OUTPUT_FILES + XML_FILE;
            string outFilePath2 = OUTPUT_FILES + XML_FILE2;

            try
            {
                ConfigClientEndpoints(ENDPOINT_PROJECT);
                ConfigClientEndpoints(ENDPOINT_RESOURCE);

                Guid myUid = resourceClient.GetCurrentUserUid();
                Console.WriteLine("My GUID: {0}", myUid.ToString());

                // Get the list of all projects visible to the user.
                SvcProject.ProjectDataSet projectDs = projectClient.ReadProjectStatus(
                    Guid.Empty, SvcProject.DataStoreEnum.WorkingStore,
                    string.Empty, (int)PSLibrary.Project.ProjectType.Project);

                SvcProject.ProjectDataSet tempProjDs = null;

                // Create an empty ProjectDataSet for projects the user owns.
                // By cloning the projectDs object, you get the same schema 
                // that is created by ReadProjectStatus.
                SvcProject.ProjectDataSet myProjectsDs = 
                    (SvcProject.ProjectDataSet)projectDs.Clone();

                // Create an empty ProjectDataSet that contains the complete schema.
                SvcProject.ProjectDataSet myProjectsDs2 = new SvcProject.ProjectDataSet();

                Console.WriteLine("Projects I own:");

                for (int i = 0; i < projectDs.Project.Count; i++)
                {
                    tempProjDs = projectClient.ReadProject(projectDs.Project[i].PROJ_UID,
                        SvcProject.DataStoreEnum.WorkingStore);

                    if (tempProjDs.Project[0].ProjectOwnerID == myUid)
                    {
                        Console.WriteLine("\t" + tempProjDs.Project[0].PROJ_NAME);
                        myProjectsDs.Project.ImportRow(
                            (SvcProject.ProjectDataSet.ProjectRow)tempProjDs.Project[0]);
                        myProjectsDs2.Project.ImportRow(
                            (SvcProject.ProjectDataSet.ProjectRow)tempProjDs.Project[0]);

                        // You can add task data to either ProjectDataSet. However,
                        // only myProjectsDs2 contains the complete Project table schema.
                        for (int t = 0; t < tempProjDs.Task.Count; t++)
                        {
                            // To get all of the task data, use the following statement
                            // instead of adding a new task row with specific fields.
                            //myProjectsDs2.Task.ImportRow(
                            //    (SvcProject.ProjectDataSet.TaskRow)tempProjDs.Task[t]);

                            // Add specific data in a new task row.
                            SvcProject.ProjectDataSet.TaskRow taskRow = 
                                myProjectsDs2.Task.NewTaskRow();

                            // If you comment-out the following line, you get a constraint error.
                            taskRow.PROJ_UID = tempProjDs.Task[t].PROJ_UID;

                            taskRow.TASK_UID = tempProjDs.Task[t].TASK_UID;
                            taskRow.TASK_NAME = tempProjDs.Task[t].TASK_NAME;
                            taskRow.TASK_IS_MANUAL = tempProjDs.Task[t].TASK_IS_MANUAL;
                            myProjectsDs2.Task.AddTaskRow(taskRow);
                        }
                    }
                }
                Console.WriteLine(
                    "\nXML output of myProjectsDs and myProjectDs2:\n\t{0}",
                    outFilePath);

                // Write both XML files for comparison of the ProjectDataSet schemas.
                myProjectsDs.WriteXml(outFilePath);
                myProjectsDs2.WriteXml(outFilePath2);
            }
            catch (FaultException fault)
            {
                // Use the WCF FaultException, because the ASMX SoapException does not 
                // exist in a WCF-based application.
                WriteFaultOutput(fault);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.Write("\nPress any key to exit... ");
            Console.ReadKey(true);
        }

        // 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_RESOURCE)
                resourceClient = new SvcResource.ResourceClient(endpt);
        }            
    }

    // Helper method: GetPSClientError.
    class Helpers
    {
        /// <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;
        }
    }
}

用于 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.ReadProjectStatus
{
   class Program
   {
      [STAThread]
      static void Main()
      {
         try
         {
            #region Setup
            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";

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

            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.Credentials = CredentialCache.DefaultCredentials;

            // Create a sample project.
            Console.WriteLine("Creating sample project");
            Guid projectId = CreateSampleProject(projectSvc, q);
            #endregion
            #region Read Project Status
            // Read all the projects.
            Console.WriteLine("Read the projects");
            SvcProject.ProjectDataSet readProjDs = projectSvc.ReadProjectStatus(Guid.Empty, SvcProject.DataStoreEnum.WorkingStore,string.Empty,(int) PSLibrary.Project.ProjectType.Project);
            #endregion
            #region Write out projects
            Console.ForegroundColor = ConsoleColor.DarkCyan;
            foreach (SvcProject.ProjectDataSet.ProjectRow project in readProjDs.Project)
            {
               Console.WriteLine(project.PROJ_NAME + " was last saved " + project.PROJ_LAST_SAVED);
            }
            Console.ResetColor();
            #endregion
         }
         #region Exception Handling and Final
         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();
         }
         #endregion
      }
      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 " + jobState + " for Job ID " + jobId + ".\r\n" + xmlError));
               }
               else
               {
                  Console.WriteLine("Job State: " + jobState + " for Job ID: " + jobId);
                  Thread.Sleep(QUEUE_WAIT_TIME * 1000);
               }
            }
         }
         while (!jobDone);
      }
      static private Guid CreateSampleProject(SvcProject.Project projectSvc,SvcQueueSystem.QueueSystem q)
      {
         SvcProject.ProjectDataSet projectDs = new SvcProject.ProjectDataSet();
         Guid jobId;
         // 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);

         //Add some resources.
         SvcProject.ProjectDataSet.ProjectResourceRow resourceOne = projectDs.ProjectResource.NewProjectResourceRow();
         resourceOne.PROJ_UID = projectRow.PROJ_UID;
         resourceOne.RES_UID = Guid.NewGuid();
         resourceOne.RES_NAME = "Brynja Sigrídur Blomsterberg";
         resourceOne.RES_INITIALS = "BSB";
         projectDs.ProjectResource.AddProjectResourceRow(resourceOne);
         CreateAssignment(projectDs, taskOne.TASK_UID, resourceOne.RES_UID);
         CreateAssignment(projectDs, taskTwo.TASK_UID, resourceOne.RES_UID);


         SvcProject.ProjectDataSet.ProjectResourceRow resourceTwo = projectDs.ProjectResource.NewProjectResourceRow();
         resourceTwo.PROJ_UID = projectRow.PROJ_UID;
         resourceTwo.RES_UID = Guid.NewGuid();
         resourceTwo.RES_NAME = "Ioannis Xylaras";
         resourceTwo.RES_INITIALS = "IX";
         projectDs.ProjectResource.AddProjectResourceRow(resourceTwo);
         CreateAssignment(projectDs, taskOne.TASK_UID, resourceTwo.RES_UID);
         CreateAssignment(projectDs, taskTwo.TASK_UID, resourceTwo.RES_UID);

         // Save the project to the database.
         jobId = Guid.NewGuid();
         projectSvc.QueueCreateProject(jobId, projectDs, false);
         WaitForQueue(q, jobId);
         return projectRow.PROJ_UID;
      }
      private static void CreateAssignment(SvcProject.ProjectDataSet projectDs, Guid taskGuid, Guid resourceGuid)
      {
         SvcProject.ProjectDataSet.AssignmentRow assnRow = projectDs.Assignment.NewAssignmentRow();
         assnRow.PROJ_UID = projectDs.Project[0].PROJ_UID;
         assnRow.ASSN_UID = Guid.NewGuid();
         assnRow.TASK_UID = taskGuid;
         assnRow.RES_UID = resourceGuid;
         projectDs.Assignment.AddAssignmentRow(assnRow);
      }
   }
}

另请参阅

引用

Project 类

Project 成员

WebSvcProject 命名空间