Freigeben über


Resource.ActivateResources-Methode

Aktiviert eine oder mehrere Project Server-Enterprise-Ressourcen.

Namespace:  WebSvcResource
Assembly:  ProjectServerServices (in ProjectServerServices.dll)

Syntax

'Declaration
<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 _
)
'Usage
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
)

Parameter

  • resourceGuids
    Typ: []

    Array von Guids der Ressourcen zu deaktivieren.

  • validateOnly
    Typ: System.Boolean

    Wenn true, nur die Daten überprüft und die neuen Ressourcen kann nicht aktiviert werden.

Hinweise

Project Server-Berechtigungen

Berechtigung

Beschreibung

ManageUsersAndGroups

Ermöglicht einem Benutzer das Verwalten von Ressourcen, Benutzern und Gruppen. Kategorieberechtigung.

Beispiele

In diesem Beispiel werden die Enterprise-Ressourcen, erstellen mehrere, wenn sie nicht vorhanden sind. Anschließend Deativates dieser Ressourcen und erneut aktiviert werden.

Please see Prerequisites for Reference Code Samples 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;
      }
   }
}

Siehe auch

Referenz

Resource Klasse

Resource-Member

WebSvcResource-Namespace