Project.QueueDeleteProjects method
Exclui um ou mais projetos.
Namespace: WebSvcProject
Assembly: ProjectServerServices (in ProjectServerServices.dll)
Syntax
'Declaração
<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 _
)
'Uso
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
)
Parâmetros
jobUid
Type: System.GuidO GUID do trabalho em fila.
deleteWSS
Type: System.BooleanSe true, exclui o site do SharePoint que é associado a cada especificado project.
projectUids
Type: []Uma matriz de GUIDs de projeto.
deleteBoth
Type: System.BooleanSe True, exclui os projetos no banco de dados de trabalho e o banco de dados publicado. Se False, exclui os projetos de apenas o banco de dados publicado.
Comentários
QueueDeleteProjects é um método assíncrono que envia uma mensagem para o serviço de enfileiramento do Project Server.
Permissões do Project Server
Permissão |
Descrição |
---|---|
Permite que um usuário exclua ou mova os projetos. Permissão global. Se um usuário tiver esta permissão, nenhuma outra permissão é necessárias. Permissão global |
|
Permite que um usuário exclua os projetos especificados. Permissão de categoria. |
Examples
O exemplo a seguir cria duas projetos de amostra, publica os projetos e, em seguida, exclui-los.
For critical information about running this code sample, see Prerequisites for Reference Code Samples.
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;
}
}
}
A seguir é a saída do programa. Ele mostra que dois projetos foram criados, publicados e excluídos no tempo decorrido.
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...