ObjectLinkProvider.ReadTaskLinkedWebObjects method
Obtém uma lista dos objetos da Web vinculados de uma tarefa especificada, filtrada por tipo de objeto.
Namespace: WebSvcObjectLinkProvider
Assembly: ProjectServerServices (in ProjectServerServices.dll)
Syntax
'Declaração
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/ObjectLinkProvider/ReadTaskLinkedWebObjects", RequestNamespace := "https://schemas.microsoft.com/office/project/server/webservices/ObjectLinkProvider/", _
ResponseNamespace := "https://schemas.microsoft.com/office/project/server/webservices/ObjectLinkProvider/", _
Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Function ReadTaskLinkedWebObjects ( _
taskUid As Guid, _
filterWebObjectTypes As Integer _
) As ObjectLinkProviderDataSet
'Uso
Dim instance As ObjectLinkProvider
Dim taskUid As Guid
Dim filterWebObjectTypes As Integer
Dim returnValue As ObjectLinkProviderDataSet
returnValue = instance.ReadTaskLinkedWebObjects(taskUid, _
filterWebObjectTypes)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/ObjectLinkProvider/ReadTaskLinkedWebObjects", RequestNamespace = "https://schemas.microsoft.com/office/project/server/webservices/ObjectLinkProvider/",
ResponseNamespace = "https://schemas.microsoft.com/office/project/server/webservices/ObjectLinkProvider/",
Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public ObjectLinkProviderDataSet ReadTaskLinkedWebObjects(
Guid taskUid,
int filterWebObjectTypes
)
Parâmetros
taskUid
Type: System.GuidContém a GUID da tarefa.
filterWebObjectTypes
Type: System.Int32Especifica o tipo de objeto da web.
Valor retornado
Type: WebSvcObjectLinkProvider.ObjectLinkProviderDataSet
Examples
O exemplo usa o namespace SvcObjectLinkProvider no assembly de proxy ProjectServerServices.dll. O método ConfigureClientEndPoints usa um arquivo App. config para definir a vinculação, comportamento e ponto de extremidade do WCF. Para obter informações sobre como criar um assembly de proxy PSI e um arquivo App. config, consulte Prerequisites for WCF-Based Code Samples.
Dica
Este exemplo é projetado para demonstrar o uso do método ReadTaskLinkedWebObjects ; não é uma solução completa.
Antes de executar o aplicativo de exemplo, execute as seguintes etapas:
Use o Project Professional 2013 para criar e publicar um projeto pelo menos uma tarefa.
Use Project Web App para abrir o site do projeto.
Crie pelo menos uma questão ou risco na lista da questão ou risco SharePoint do site do projeto.
Crie links de objeto da web. Para obter mais informações, consulte CreateWebObjectLinks
Altere os valores do construtor de acordo com seu exemplo.
Adicionar uma referência da web para https://localhost/pwa/_vti_bin/Lists.asmxe nomeie-o WebSvcLists.
Aqui está o que faz a este exemplo:
Verifica se o projeto e a tarefa existe e obtém as GUIDs correspondentes.
Obtenha os itens do SharePoint vinculados à tarefa especificada e grava o conteúdo de dsLinkedObjects conjunto de dados, o arquivo OLPDataset.xml.
O arquivo XML de exemplo é o seguinte:
<?xml version="1.0" standalone="yes"?>
<ObjectLinkProviderDataSet xmlns="https://schemas.microsoft.com/office/project/server/webservices/ObjectLinkProviderDataSet/">
<WebObjectLinks>
<WOBJLINK_UID>a17480e7-0d2b-4480-a465-5fe7064eb0df</WOBJLINK_UID>
<WOBJLINK_OBJECT1>7768c091-7956-4f3d-9c3f-078b9b038dda</WOBJLINK_OBJECT1>
<WOBJLINK_OBJECT2>46cc14c8-8a3d-4421-873f-ea7bc9de353d</WOBJLINK_OBJECT2>
<WOBJLINK_TYPE>1</WOBJLINK_TYPE>
<CREATED_DATE>2010-10-20T10:13:44.66-07:00</CREATED_DATE>
<MOD_DATE>2010-10-20T10:13:44.66-07:00</MOD_DATE>
</WebObjectLinks>
<WebObjects>
<WOBJ_UID>46cc14c8-8a3d-4421-873f-ea7bc9de353d</WOBJ_UID>
<WOBJ_TYPE>4</WOBJ_TYPE>
<WOBJ_PROJ_UID>4f4b5ffb-e143-4c84-9cf4-299d316c7d8e</WOBJ_PROJ_UID>
<WOBJ_TASK_UID>00000000-0000-0000-0000-000000000000</WOBJ_TASK_UID>
<WOBJ_TP_ID>1</WOBJ_TP_ID>
<WOBJ_LIST_NAME>8c6f74ee-3f64-4808-8e71-02d62c553374</WOBJ_LIST_NAME>
<WOBJ_DESC />
<WOBJ_DOC_REF_CNT>0</WOBJ_DOC_REF_CNT>
<WOBJ_ISSUE_REF_CNT>0</WOBJ_ISSUE_REF_CNT>
<WOBJ_OTHER_REF_CNT>2</WOBJ_OTHER_REF_CNT>
<WOBJ_RISK_REF_CNT>0</WOBJ_RISK_REF_CNT>
<WOBJ_SHARED_MILESTONE_REF_CNT>0</WOBJ_SHARED_MILESTONE_REF_CNT>
<WOBJ_COMMITMENT_REF_CNT>0</WOBJ_COMMITMENT_REF_CNT>
<CREATED_DATE>2010-10-18T10:41:27.777-07:00</CREATED_DATE>
<MOD_DATE>2010-10-18T10:41:27.777-07:00</MOD_DATE>
</WebObjects>
<WebObjects>
<WOBJ_UID>7768c091-7956-4f3d-9c3f-078b9b038dda</WOBJ_UID>
<WOBJ_TYPE>2</WOBJ_TYPE>
<WOBJ_PROJ_UID>4f4b5ffb-e143-4c84-9cf4-299d316c7d8e</WOBJ_PROJ_UID>
<WOBJ_TASK_UID>42b0aa16-4936-45f9-b094-2e4975d2b6fd</WOBJ_TASK_UID>
<WOBJ_TP_ID>-1</WOBJ_TP_ID>
<WOBJ_LIST_NAME>00000000-0000-0000-0000-000000000000</WOBJ_LIST_NAME>
<WOBJ_DESC />
<WOBJ_DOC_REF_CNT>0</WOBJ_DOC_REF_CNT>
<WOBJ_ISSUE_REF_CNT>1</WOBJ_ISSUE_REF_CNT>
<WOBJ_OTHER_REF_CNT>0</WOBJ_OTHER_REF_CNT>
<WOBJ_RISK_REF_CNT>0</WOBJ_RISK_REF_CNT>
<WOBJ_SHARED_MILESTONE_REF_CNT>1</WOBJ_SHARED_MILESTONE_REF_CNT>
<WOBJ_COMMITMENT_REF_CNT>0</WOBJ_COMMITMENT_REF_CNT>
<CREATED_DATE>2010-10-20T10:13:44.62-07:00</CREATED_DATE>
<MOD_DATE>2010-10-20T10:13:44.62-07:00</MOD_DATE>
</WebObjects>
</ObjectLinkProviderDataSet>
O código de exemplo é o seguinte:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.ServiceModel;
using System.Data;
using System.Xml;
using System.Web.Services;
using PSLibrary = Microsoft.Office.Project.Server.Library;
namespace Microsoft.SDK.Project.Samples.OLPRead
{
class OLPRead
{
private static SvcProject.ProjectClient projectClient;
private static SvcObjectLinkProvider.ObjectLinkProviderClient olpClient;
private static string outFilePathOLPDataSet;
private static string projectName; // Name of the project.
private static string taskName; // Name of the task.
private static string listName; // Name of the SharePoint list.
private static string linkedItems; // List of linked items to be displayed.
private static PSLibrary.WebObjectType webObjectType; // Type of web object (issue, risk, and so on.)
private const string OUTPUT_FILES = @"C:\Projects\Samples\Output\";
private const string ENDPOINT_P = "basicHttp_Project";
// private const string ENDPOINT_WSS = "basicHttp_WssInterop";
private const string ENDPOINT_OLP = "basicHttp_ObjectLinkProvider";
public OLPRead()
{
// Constructor to assign values to the variables.
// Change these for your example.
projectName = "My Swell Project2";
taskName = "T2";
listName = "Issues";
}
static void Main(string[] args)
{
// Configure the endpoints.
bool configResult = false;
configResult = ConfigClientEndpoints(ENDPOINT_P);
// configResult = ConfigClientEndpoints(ENDPOINT_WSS);
configResult = ConfigClientEndpoints(ENDPOINT_OLP);
OLPRead param = new OLPRead();
if (!configResult) throw new ApplicationException();
// If output directory does not exist,create it.
if (!Directory.Exists(OUTPUT_FILES))
{
Directory.CreateDirectory(OUTPUT_FILES);
}
// Set the output file path.
outFilePathOLPDataSet = OUTPUT_FILES + "OLPDataSet.xml";
Guid taskUid = new Guid();
Guid projectUid = new Guid();
String workspaceUrl = String.Empty;
#region Verify input values.
try
{
Console.WriteLine("Reading the list of projects...");
// Check whether the project exists and get the project GUID.
SvcProject.ProjectDataSet projectList = projectClient.ReadProjectList();
foreach (DataRow projectRow in projectList.Project)
{
if ((string)projectRow[projectList.Project.PROJ_NAMEColumn] == projectName)
{
projectUid = (Guid)projectRow[projectList.Project.PROJ_UIDColumn];
break;
}
}
if (projectUid == Guid.Empty)
{
Console.WriteLine("Project not found: " + projectName + "\n");
throw new ApplicationException();
}
// Get the task UID for the specified task.
Console.WriteLine("Reading the data for project: " + projectName);
SvcProject.ProjectDataSet dsProject =
projectClient.ReadProject(projectUid, SvcProject.DataStoreEnum.PublishedStore);
foreach (DataRow objRow in dsProject.Task)
{
if ((string)objRow[dsProject.Task.TASK_NAMEColumn] == taskName)
{
taskUid = (Guid)objRow[dsProject.Task.TASK_UIDColumn];
break;
}
}
if (taskUid == Guid.Empty)
{
Console.WriteLine("Task not found: " + taskName + "\n");
throw new ApplicationException();
}
}
catch (FaultException fault)
{
// Use the WCF FaultException, because the ASMX SoapException does not
// exist in a WCF-based application.
WriteFaultOutput(fault);
}
catch (CommunicationException e)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(
"\n***System.ServiceModel.CommunicationException:");
Console.WriteLine(e.ToString());
Console.ResetColor();
}
catch (ApplicationException)
{
ExitApp();
}
#endregion
#region Get the SharePoint items linked to the task
// Get the OLP DataSet for all SharePoint items of specified type
// that are linked to the task.
try
{
Console.WriteLine("\nGetting the list of SharePoint items linked to the task...");
SvcObjectLinkProvider.ObjectLinkProviderDataSet dsLinkedObjects =
new SvcObjectLinkProvider.ObjectLinkProviderDataSet();
// Set the WebObjectType, based on the listName.
switch (listName)
{
case "Issues":
webObjectType = PSLibrary.WebObjectType.Issue;
break;
case "Risks":
webObjectType = PSLibrary.WebObjectType.Risk;
break;
case "Documents":
webObjectType = PSLibrary.WebObjectType.Document;
break;
case "Commitments": // Commitments are now called Deliverables.
webObjectType = PSLibrary.WebObjectType.Commitment;
break;
default:
string errMess = listName +
" is not a default SharePoint list type for task links.";
throw new SystemException(errMess);
}
dsLinkedObjects = olpClient.ReadTaskLinkedWebObjects(taskUid,
(int)webObjectType);
int itemsFound = 0;
foreach (SvcObjectLinkProvider.ObjectLinkProviderDataSet.WebObjectsRow objRow
in dsLinkedObjects.WebObjects)
{
if (objRow.WOBJ_TASK_UID != taskUid)
{
// Add the internal OLP GUID, List GUID, and TP_ID.
linkedItems += string.Format(
"\n\n\tWebObjectUid:\t{0}\n\tList UID:\t{1}\n\tTP_ID:\t\t{2}",
objRow.WOBJ_UID.ToString(),
objRow.WOBJ_LIST_NAME,
objRow.WOBJ_TP_ID.ToString());
itemsFound++;
}
}
if (itemsFound == 0)
{
linkedItems = "No " + listName.ToLower() + " found, for task: " + taskName;
}
else
{
Console.WriteLine(linkedItems, listName);
}
// Write the OLP DataSet to an XML file.
Console.WriteLine("\nWriting the OLP DataSet to an XML file...");
dsLinkedObjects.WriteXml(outFilePathOLPDataSet);
Console.WriteLine("\nSee XML output of OLP Dataset at {0}",
outFilePathOLPDataSet);
Console.Write("\nPress any key to continue: ");
Console.ReadKey(true);
}
catch (FaultException fault)
{
// Use the WCF FaultException, because the ASMX SoapException does not
// exist in a WCF-based application.
WriteFaultOutput(fault);
}
catch (CommunicationException e)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(
"\n***System.ServiceModel.CommunicationException:");
Console.WriteLine(e.ToString());
Console.ResetColor();
}
#endregion
}
#region Private methods
// 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;
if (error != null)
{
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();
}
private static void ExitApp()
{
Console.Write("\nPress any key to exit: ");
Console.ReadKey(true);
Environment.Exit(0);
}
#endregion
// Configure the PSI client endpoints.
public static bool ConfigClientEndpoints(string endpt)
{
bool result = true;
switch (endpt)
{
case ENDPOINT_P:
projectClient = new SvcProject.ProjectClient(endpt);
break;
case ENDPOINT_OLP:
olpClient = new SvcObjectLinkProvider.ObjectLinkProviderClient(endpt);
break;
default:
result = false;
Console.WriteLine("Invalid endpoint: {0}", endpt);
break;
}
return result;
}
}
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;
}
}
}