Project.QueueDeleteFromProject 方法

删除指定的项目的实体。

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

语法

声明
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Project/QueueDeleteFromProject", 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 QueueDeleteFromProject ( _
    jobUid As Guid, _
    sessionUid As Guid, _
    projectUid As Guid, _
    projectEntityUids As Guid() _
)
用法
Dim instance As Project
Dim jobUid As Guid
Dim sessionUid As Guid
Dim projectUid As Guid
Dim projectEntityUids As Guid()

instance.QueueDeleteFromProject(jobUid, _
    sessionUid, projectUid, projectEntityUids)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Project/QueueDeleteFromProject", 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 QueueDeleteFromProject(
    Guid jobUid,
    Guid sessionUid,
    Guid projectUid,
    Guid[] projectEntityUids
)

参数

  • sessionUid
    类型:System.Guid

    队列作业提交的会话的 GUID。

  • projectEntityUids
    类型:[]

    若要删除项目实体的 Guid 的数组。

备注

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

备注

QueueDeleteFromProject不会删除自定义字段值。有关如何删除自定义字段的示例请参见QueueUpdateProject

Project Server 权限

权限

说明

SaveProject

允许用户保存指定的项目。类别的权限。

示例

下面的代码示例创建一个示例项目、 将项目保存到服务器但留检出,然后从项目中删除任务。

有关运行此代码示例的关键信息,请参阅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.QueueDeleteFromProject
{
   class Program
   {
      [STAThread]
      static void Main(string[] args)
      {
         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";
            const string SESSION_DESC = "Sample utility";

            Guid sessionId = Guid.NewGuid();
            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;
            #endregion
            #region Create Project
            // Create the project.
            Console.WriteLine("Creating project data");
            SvcProject.ProjectDataSet.ProjectRow projectRow = projectDs.Project.NewProjectRow();
            projectRow.PROJ_UID = Guid.NewGuid();
            projectRow.PROJ_NAME = "Its a wonderful project at " + 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 and checking out");
            jobId = Guid.NewGuid();
            projectSvc.QueueCreateProjectAndCheckOut(jobId, sessionId, SESSION_DESC, projectDs, false);
            WaitForQueue(q, jobId);
            #endregion
            #region Delete from project
            // Delete the last task on our project.
            Console.WriteLine("Deleting a task from the project");
            jobId = Guid.NewGuid();
            projectSvc.QueueDeleteFromProject(jobId, sessionId, projectRow.PROJ_UID,new Guid[] { taskTwo.TASK_UID});
            WaitForQueue(q, jobId);
            #endregion
            #region Check in project
            // Check in the project. 
            Console.WriteLine("Checking in the project");
            jobId = Guid.NewGuid();
            projectSvc.QueueCheckInProject(jobId, projectRow.PROJ_UID, false, sessionId, SESSION_DESC);
            WaitForQueue(q, jobId);
            #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 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 命名空间