Метод Resource.ActivateResources
Активирует одного или нескольких корпоративных ресурсов Project Server.
Пространство имен: WebSvcResource
Сборка: ProjectServerServices (в ProjectServerServices.dll)
Синтаксис
'Декларация
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Resource/ActivateResources", RequestNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Resource/", _
ResponseNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Resource/", _
Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Sub ActivateResources ( _
resourceGuids As Guid(), _
validateOnly As Boolean _
)
'Применение
Dim instance As Resource
Dim resourceGuids As Guid()
Dim validateOnly As Boolean
instance.ActivateResources(resourceGuids, _
validateOnly)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Resource/ActivateResources", RequestNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Resource/",
ResponseNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Resource/",
Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public void ActivateResources(
Guid[] resourceGuids,
bool validateOnly
)
Параметры
resourceGuids
Тип: []Массив идентификаторов GUID ресурсов, чтобы отключить.
validateOnly
Тип: System.BooleanЕсли trueпроверяет данные, а не активируется новые ресурсы.
Замечания
Разрешения Project Server
Разрешение |
Описание |
---|---|
Позволяет пользователю управлять ресурсами, пользователи и группы. Разрешение категории. |
Примеры
В этом примере показано получение корпоративных ресурсов, создание несколько, если они не задан. Он затем deativates этих ресурсов и их повторной активации.
Please see Необходимые условия для образцов кода на основе ASMX в Project 2013 for critical information on running this code sample.
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Data;
using System.Web.Services.Protocols;
using System.Threading;
using PSLibrary = Microsoft.Office.Project.Server.Library;
namespace Microsoft.SDK.Project.Samples.ActivateResources
{
class Program
{
[STAThread]
static void Main()
{
try
{
const string PROJECT_SERVER_URI = "https://ServerName/ProjectServerName/";
const string RESOURCE_SERVICE_PATH = "_vti_bin/psi/resource.asmx";
SvcResource.ResourceDataSet resourceDs;
PSLibrary.Filter resourceFilter;
// Set up the Web service objects
SvcResource.Resource resourceSvc = new SvcResource.Resource();
resourceSvc.Url = PROJECT_SERVER_URI + RESOURCE_SERVICE_PATH;
resourceSvc.Credentials = CredentialCache.DefaultCredentials;
// Get the resources
Console.WriteLine("Getting/Creating resources");
Guid[] resources= EnsureEnterpriseResources(resourceSvc);
// Deactivate them so we can activate them.
Console.WriteLine("Deactivating resources");
resourceSvc.DeactivateResources(resources, false);
resourceFilter = GetResourceFilter(resources);
resourceDs = resourceSvc.ReadResources(resourceFilter.GetXml(), false);
WriteResourceState(resourceDs);
// Activate Resources
Console.WriteLine("Activating resources");
resourceSvc.ActivateResources(resources, false);
resourceDs = resourceSvc.ReadResources(resourceFilter.GetXml(), false);
WriteResourceState(resourceDs);
}
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();
}
}
private static void WriteResourceState(SvcResource.ResourceDataSet resourceDs)
{
foreach (SvcResource.ResourceDataSet.ResourcesRow row in resourceDs.Resources.Rows)
{
// If the resource type is greater than the inactive offset, it is inactive.
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write(row.RES_NAME);
Console.ForegroundColor = ConsoleColor.Gray;
Console.Write(" is ");
if (row.RES_TYPE > (int)PSLibrary.Resource.Type.INACTIVATED_OFFSET)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("Inactive\r\n");
}
else
{
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.Write("Active\r\n");
}
Console.ResetColor();
}
}
private static Guid[] EnsureEnterpriseResources(SvcResource.Resource resourceSvc)
{
string[] resourceNames = new string[] { "Lertchai Treetawatchaiwong",
"Bricks",
"Conference Room A",
"Rental"};
PSLibrary.Resource.Type[] resourceTypes = new PSLibrary.Resource.Type[] { PSLibrary.Resource.Type.WorkResource, PSLibrary.Resource.Type.MaterialResource, PSLibrary.Resource.Type.WorkResource,PSLibrary.Resource.Type.CostResources};
Guid[] resources = new Guid[resourceNames.Length];
for (int i=0; i < resourceNames.Length; i++)
{
resources[i] = EnsureEnterpriseResource(resourceSvc, resourceNames[i], resourceTypes[i]);
}
return resources;
}
private static Guid EnsureEnterpriseResource(SvcResource.Resource resourceSvc, string resourceName, PSLibrary.Resource.Type resourceType)
{
SvcResource.ResourceDataSet resourceDs = new SvcResource.ResourceDataSet();
PSLibrary.Filter resourceFilter = new Microsoft.Office.Project.Server.Library.Filter();
resourceFilter.FilterTableName = resourceDs.Resources.TableName;
resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_UIDColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_NAMEColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_INITIALSColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_TYPEColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
PSLibrary.Filter.FieldOperator existingResource = new PSLibrary.Filter.FieldOperator(PSLibrary.Filter.FieldOperationType.Equal, resourceDs.Resources.RES_NAMEColumn.ColumnName, resourceName);
resourceFilter.Criteria = existingResource;
string filterXml = resourceFilter.GetXml();
resourceDs = resourceSvc.ReadResources(filterXml, false);
if (resourceDs.Resources.Count >= 1)
{
return resourceDs.Resources[0].RES_UID;
}
else
{
resourceDs = new SvcResource.ResourceDataSet();
SvcResource.ResourceDataSet.ResourcesRow resourceRow = resourceDs.Resources.NewResourcesRow();
resourceRow.RES_UID = Guid.NewGuid();
resourceRow.RES_NAME = resourceName;
resourceRow.RES_INITIALS = resourceName.Substring(0,1) +
(resourceName.IndexOf(" ")>0?resourceName.Substring(resourceName.IndexOf(" ")+1,1):"");
resourceRow.RES_TYPE = (int)resourceType;
resourceDs.Resources.AddResourcesRow(resourceRow);
resourceSvc.CreateResources(resourceDs, false, true);
return resourceRow.RES_UID;
}
}
private static PSLibrary.Filter GetResourceFilter(Guid[] resources)
{
SvcResource.ResourceDataSet resourceDs = new SvcResource.ResourceDataSet();
PSLibrary.Filter resourceFilter = new PSLibrary.Filter();
resourceFilter.FilterTableName = resourceDs.Resources.TableName;
resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_UIDColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_NAMEColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_INITIALSColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_TYPEColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
//List<PSLibrary.Filter.FieldOperator> resourceFieldOps = new List<PSLibrary.Filter.FieldOperator>();
PSLibrary.Filter.IOperator[] fos = new PSLibrary.Filter.IOperator[resources.Length];
for (int i = 0; i < resources.Length; i++)
{
fos[i] = new PSLibrary.Filter.FieldOperator(PSLibrary.Filter.FieldOperationType.Equal, resourceDs.Resources.RES_UIDColumn.ColumnName, resources[i]);
}
PSLibrary.Filter.LogicalOperator lo = new Microsoft.Office.Project.Server.Library.Filter.LogicalOperator(PSLibrary.Filter.LogicalOperationType.Or,fos);
resourceFilter.Criteria = lo;
return resourceFilter;
}
}
}