Resource.DeactivateResources 方法
停用一个或多个企业资源。
命名空间: WebSvcResource
程序集: ProjectServerServices(位于 ProjectServerServices.dll 中)
语法
声明
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Resource/DeactivateResources", 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 DeactivateResources ( _
resourceGuids As Guid(), _
validateOnly As Boolean _
)
用法
Dim instance As Resource
Dim resourceGuids As Guid()
Dim validateOnly As Boolean
instance.DeactivateResources(resourceGuids, _
validateOnly)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Resource/DeactivateResources", 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 DeactivateResources(
Guid[] resourceGuids,
bool validateOnly
)
参数
resourceGuids
类型:[]若要停用的企业资源的 Guid 的数组。
validateOnly
类型:System.Boolean如果true,仅验证数据,并不停用资源。
备注
Project Server 权限
权限 |
说明 |
---|---|
允许用户管理的资源、 用户和组。类别权限。 |
示例
此示例检索企业资源,创建几个,如果不存在。它然后 deativates 这些资源并将其重新激活。
Please see Project 2013 中基于 ASMX 的代码示例的先决条件 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.DeactivateResources
{
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 resources.
Console.WriteLine("Deactivating resources");
resourceSvc.DeactivateResources(resources, false);
resourceFilter = GetResourceFilter(resources);
resourceDs = resourceSvc.ReadResources(resourceFilter.GetXml(), false);
WriteResourceState(resourceDs);
// Activate Resources so we can use them later if we want
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;
}
}
}