Project.QueueDeleteProjects 方法

删除一个或多个项目。

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

语法

声明
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Project/QueueDeleteProjects", 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 QueueDeleteProjects ( _
    jobUid As Guid, _
    deleteWSS As Boolean, _
    projectUids As Guid(), _
    deleteBoth As Boolean _
)
用法
Dim instance As Project
Dim jobUid As Guid
Dim deleteWSS As Boolean
Dim projectUids As Guid()
Dim deleteBoth As Boolean

instance.QueueDeleteProjects(jobUid, _
    deleteWSS, projectUids, deleteBoth)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Project/QueueDeleteProjects", 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 QueueDeleteProjects(
    Guid jobUid,
    bool deleteWSS,
    Guid[] projectUids,
    bool deleteBoth
)

参数

  • deleteWSS
    类型:System.Boolean

    如果删除了与 SharePoint 网站true,每个指定的项目。

  • projectUids
    类型:[]

    项目的 Guid 的数组。

  • deleteBoth
    类型:System.Boolean

    如果True,删除工作数据库和发布的数据库中的项目。如果只将已发布的数据库中删除项目。

备注

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

Project Server 权限

权限

说明

CleanupProjectServerDatabase

允许用户删除或移动项目。全局权限。如果用户具有此权限,不需要任何其他权限。

全局权限

DeleteProject

允许用户删除指定的项目。类别的权限。

示例

下面的示例创建两个示例项目、 发布项目,然后将它们删除。

有关运行此代码示例的关键信息,请参阅Project 2013 中基于 ASMX 的代码示例的先决条件

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

namespace Microsoft.SDK.Project.Samples.QueueDeleteProjects
{
    class Program
    {
        private static int numProjects = 2;
        private const string ENDPOINT_PROJECT = "basicHttp_Project";
        private const string ENDPOINT_QUEUESYSTEM = "basicHttp_QueueSystem";
        private static SvcProject.ProjectClient projectClient;
        private static SvcQueueSystem.QueueSystemClient queueSystemClient;

        static void Main(string[] args)
        {
            int maxSeconds2Wait = 20;       // Maximum number of seconds to wait for the queue.
            string comment = string.Empty;
            string queueError = "\n\tThe {0} queue job did not complete within {1} seconds.";

            Console.WriteLine("\nStart Time: {0}", DateTime.Now.ToString());
            Stopwatch timer = new Stopwatch();
            timer.Start();

            ConfigClientEndpoints(ENDPOINT_PROJECT);
            ConfigClientEndpoints(ENDPOINT_QUEUESYSTEM);

            // Prepare data for the specified number of projects to create.
            Guid[] projectUids = new Guid[numProjects];
            Int32 projectType = Convert.ToInt32(PSLibrary.Project.ProjectType.Project);
            SvcProject.ProjectDataSet[] projDs = new SvcProject.ProjectDataSet[numProjects];

            for (int i = 0; i < numProjects; i++)
            {
                projectUids[i] = Guid.NewGuid();
                projDs[i] = new SvcProject.ProjectDataSet();
                SvcProject.ProjectDataSet.ProjectRow projRow = projDs[i].Project.NewProjectRow();
                projRow.PROJ_TYPE = projectType;
                projRow.PROJ_UID = projectUids[i];
                projRow.PROJ_NAME = "QDelProjTest_" + projectUids[i].ToString();
                projDs[i].Project.AddProjectRow(projRow);
            }

            // Create and publish the projects.

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("\nCreating {0} projects via WCF...", numProjects.ToString());
            Console.ResetColor();

            try
            {
                for (int i = 0; i < numProjects; i++)
                {
                    // Create the project and wait for the queue.
                    projectClient.QueueCreateProject(projectUids[i], projDs[i], false);

                    if (!Helpers.WaitForQueue(SvcQueueSystem.QueueMsgType.ProjectCreate,
                                         queueSystemClient, maxSeconds2Wait))
                    {
                        Console.WriteLine(queueError, "ProjectCreate", maxSeconds2Wait.ToString());
                    }

                    // Publish the project and wait for the queue.
                    projectClient.QueuePublish(projectUids[i], projectUids[i], true, string.Empty);

                    if (Helpers.WaitForQueue(SvcQueueSystem.QueueMsgType.ProjectPublish,
                                         queueSystemClient, maxSeconds2Wait))
                    {
                        comment = "\nProject created and published: " + projDs[i].Project[0].PROJ_NAME;
                    }
                    else
                    {
                        comment = string.Format(queueError, "ProjectPublish", maxSeconds2Wait.ToString());
                    }

                    DisplayTime(timer, comment);
                }

                // Delete the projects and wait for the queue.

                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.Write("\n\nDeleting {0} projects...\n", numProjects.ToString());
                Console.ResetColor();

                Guid deleteJobUid = Guid.NewGuid();
                projectClient.QueueDeleteProjects(deleteJobUid, true, projectUids, true);

                if (Helpers.WaitForQueue(SvcQueueSystem.QueueMsgType.ProjectDelete,
                                     queueSystemClient, maxSeconds2Wait))
                {
                    comment = "\nProjects Deleted.";
                }
                else
                {
                    comment = string.Format(queueError, "ProjectDelete", maxSeconds2Wait.ToString());
                }

                DisplayTime(timer, comment);
            }

            // Use the WCF FaultException, because the ASMX SoapException does not 
            // exist in a WCF-based application.

            catch (FaultException fault)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                WriteFaultOutput(fault);

                Console.ForegroundColor = ConsoleColor.Yellow;
                comment = "\nTotal RunTime: ";
                DisplayTime(timer, comment);
                Console.ResetColor();
            }
            finally
            {
                Console.Write("\nPress any key to exit... ");
                Console.ReadKey(true);
            }
        }

        public static void DisplayTime(Stopwatch timer, string comment)
        {
            // Pause the timer and display the current accumulated time in seconds.
            timer.Stop();
            TimeSpan ts = timer.Elapsed;
            string elapsedTime = String.Format("\n\tElapsed time: {0:F4} seconds ({1:F2} minutes) ", 
                ts.TotalSeconds, ts.TotalMinutes);
            Console.WriteLine(comment + elapsedTime);
            timer.Start();
        }

        // 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);
        }
        // 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: \n" + "\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\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.WriteLine(errMess);
        }
    }


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

        public static bool WaitForQueue(SvcQueueSystem.QueueMsgType jobType, 
                                        SvcQueueSystem.QueueSystemClient queueSystemClient,
                                        int maxSeconds)
        {
            int numJobs = 1;         // Number of jobs in the queue, of the same type; one in this example.
            bool completed = false;  // Queue job completed.
            DateTime startTime = DateTime.Now;
            SvcQueueSystem.QueueStatusDataSet queueStatusDs = new SvcQueueSystem.QueueStatusDataSet();

            int timeout = 0;         // Number of seconds waited.
            Console.Write("\nWaiting for job " + jobType.ToString());

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

            while ((timeout < maxSeconds) && (queueStatusDs.Status.Count < numJobs))
            {
                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("\n\tQueue Correlation GUID: {0}\n", 
            //    queueStatusDs.Status[0].CorrelationGUID.ToString());

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

下面是该程序的输出。它显示的两个项目已创建、 发布和删除在所用的时间。

Start Time: 5/12/2011 1:05:27 PM

Creating 2 projects via WCF...

Waiting for job ProjectCreate.
Waiting for job ProjectPublish.
Project created and published: QDelProjTest_057714bf-acf6-4d62-ab3d-d50f88704f5b

        Elapsed time: 4.0213 seconds (0.07 minutes)

Waiting for job ProjectCreate.
Waiting for job ProjectPublish.
Project created and published: QDelProjTest_3e92d726-59df-4cb7-943a-39970fc90ae9

        Elapsed time: 6.8441 seconds (0.11 minutes)


Deleting 2 projects...

Waiting for job ProjectDelete.
Projects Deleted.
        Elapsed time: 8.3478 seconds (0.14 minutes)

Press any key to exit...

另请参阅

引用

Project 类

Project 成员

WebSvcProject 命名空间