Partager via


Resource.CheckOutResources - Méthode

Extrait un ou plusieurs des ressources d'entreprise pour la modification.

Espace de noms :  WebSvcResource
Assembly :  ProjectServerServices (dans ProjectServerServices.dll)

Syntaxe

'Déclaration
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Resource/CheckOutResources", 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 CheckOutResources ( _
    array As Guid() _
)
'Utilisation
Dim instance As Resource
Dim array As Guid()

instance.CheckOutResources(array)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Resource/CheckOutResources", 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 CheckOutResources(
    Guid[] array
)

Paramètres

  • array
    Type : []

    Tableau de GUID des ressources d'entreprise à extraire.

Remarques

Si les ressources demandées sont déjà extraits, CheckOutResources échoue pour toutes les ressources spécifiées par le paramètre array . Si vous obtenez un objet PSClientError à l'aide de l'exception SOAP, il ne vous indique pas les ressources qui sont extraits. Par exemple, le fragment de code suivant utilise PSClientError pour obtenir des informations sur l'exception et l'écrire dans la console. L'objet resource est une instance de la classe Resource dans le service Web de la ressource.

using PSLibrary = Microsoft.Office.Project.Server.Library;
. . .
try
{
    resource.CheckOutResources(resourcesToTest);
    Console.WriteLine("Checkout succeeded.");
}
catch (SoapException ex)
{
    string errMess = string.Empty;
    // Pass the exception to the PSClientError constructor to 
    // get all error information.
    PSLibrary.PSClientError psiError = new PSLibrary.PSClientError(ex);
    PSLibrary.PSErrorInfo[] psiErrors = psiError.GetAllErrors();

    for (int j = 0; j < psiErrors.Length; j++)
    {
        errMess += psiErrors[j].ErrId.ToString() + "\n";
    }
    errMess += "\n" + ex.Message.ToString();
    Console.WriteLine(errMess + "\n");
}

Si deux des ressources sont déjà extraits, une pour l'utilisateur de l'application et l'autre vers un autre utilisateur, l'application écrit ce qui suit dans la console.

CICOAlreadyCheckedOutToYou
CICOCheckedOutToOtherUser

System.Web.Services.Protocols.SoapException: ProjectServerError(s) LastError=CICOCheckedOutToOtherUser Instructions: Pass this into PSClientError constructor to access all error information
   at Microsoft.Office.Project.Server.WebService.Resource.CheckOutResources(Guid[] array)

L'exemple d'application console suivant montre comment obtenir des informations sur les ressources sont extraits. Pour utiliser l'application, définissez une référence Web au service Web de ressources et nommez la référence ResourceWS. Si aucune des ressources spécifiées sont déjà extraits, TestResourceCheckOut.exe extrait les ressources, puis vérifie leur retour dans. Si les ressources sont déjà extraits, l'application écrit un message d'erreur dans la console avec le GUID de ressource et un motif. Pour exécuter l'application, spécifiez l'URL de Project Web App en tant qu'argument, par exemple, TestResourceCheckOut https://ServerName/ProjectServerName.

using System;
using System.Collections;
using System.Text;
using System.Net;
using System.Web.Services.Protocols;
using System.Xml;

namespace TestResourceCheckOut
{
    class Program
    {
        private const string RESOURCEWEBSERVICE = "/_vti_bin/PSI/Resource.asmx";
        static ResourceWS.Resource resource = new ResourceWS.Resource();

        // Test application to determine if resources are already checked out.
        static void Main(string[] args)
        { 
            ArrayList checkedOut = null;
            String pwaUrl = args[0];
            resource.Url = pwaUrl + RESOURCEWEBSERVICE;
            resource.Credentials = CredentialCache.DefaultCredentials;

            Guid[] resourcesToTest = new Guid[3];
            // Change the following GUIDs to match resources in your system.
            resourcesToTest[0] = new Guid("{09be4db3-129e-46b9-b47a-d66ff6f2cbd2}");
            resourcesToTest[1] = new Guid("{50752a44-4b31-4f4c-bbfc-a54c10ec871a}");
            resourcesToTest[2] = new Guid("{cfb5216c-1f43-49f7-85e4-e0bab57dcdef}");

            Console.WriteLine("Trying to check out resources ...");
            
            try
            {
                // If any resources are already checked out, 
                // CheckOutResources fails for all resources.
                resource.CheckOutResources(resourcesToTest);
                Console.WriteLine("Checkout succeeded.");
            }
            catch (SoapException ex)
            {
                String tempXml = ex.Detail.InnerXml;
                checkedOut = ExtractError(tempXml);
            }

            int numAlreadyCheckedOut = checkedOut != null ? checkedOut.Count : 0;
            int totalTested = resourcesToTest.Length;
            int num2CheckIn = totalTested - numAlreadyCheckedOut;

            // Check in the resources this application just checked out.
            if (numAlreadyCheckedOut == 0)
            {
                resource.CheckInResources(resourcesToTest, false);

                for (int i = 0; i < num2CheckIn; i++)
                    Console.WriteLine(string.Format("Checked back in: {0}",
                        resourcesToTest[i].ToString()));
            }
            Console.ReadLine();
        }

        // Write reason for resource checkout error to console.
        // Return a list of resources checked out.
        static ArrayList ExtractError(String xmlstr)
        {
            ArrayList checkedOut = new ArrayList();
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xmlstr);

            foreach (XmlNode node in doc.DocumentElement.FirstChild.ChildNodes)
            {
                String err = String.Empty;
                if (node.Name.Equals("item"))
                {
                    // The node is one error.
                    XmlNode n = node.Attributes.GetNamedItem("value");
                    err = "Error:  Resource - " + n.Value;
                    checkedOut.Add(new Guid(n.Value));

                    XmlNode childn = node.FirstChild;

                    if (childn.Name.Equals("error"))
                    {
                        XmlNode nodeItem = childn.Attributes.GetNamedItem("name");

                        switch (nodeItem.Value)
                        {
                            case "CICOAlreadyCheckedOutToYou":
                                err += "\n\t--already checked out to you.";
                                break;
                            case "CICOCheckedOutInOtherSession":
                                err += "\n\t--checked out in another session.";
                                break;
                            case "CICOCheckedOutToOtherUser":
                                err += "\n\t--checked out to another user.";
                                break;
                        }
                    }
                }
                Console.WriteLine(err);
            }
            return checkedOut;
        }
    }
}

Dans le cas précédent où les deux ressources sont extraits, TestResourceCheckOut.exe renvoie les résultats de l'erreur.

C:\Project\Test>testresourcecheckout https://servername/pwa
Trying to check out resources ...
Error:  Resource - 09be4db3-129e-46b9-b47a-d66ff6f2cbd2
        --already checked out to you.
Error:  Resource - 50752a44-4b31-4f4c-bbfc-a54c10ec871a
        --checked out to another user.

Si aucun des ressources sont extraits, l'application extrait correctement les ressources, puis vérifie leur retour dans.

C:\Project\Test>testresourcecheckout https://servername/pwa
Trying to check out resources ...
Checkout succeeded.
Checked back in: 09be4db3-129e-46b9-b47a-d66ff6f2cbd2
Checked back in: 2e956742-bca3-4445-8d3b-8640b9ec3b26
Checked back in: cfb5216c-1f43-49f7-85e4-e0bab57dcdef

Autorisations Project Server

Autorisation

Description

ManageUsersAndGroups

Permet à un utilisateur de gérer tous les utilisateurs de l'entreprise, les ressources et les groupes. Autorisation globale.

EditEnterpriseResourceData

Permet à un utilisateur d'afficher les données de ressources d'entreprise pour cette ressource. Autorisation de catégorie.

Exemples

L'exemple suivant récupère les ressources d'entreprise, la création de plusieurs si elles ne sont pas présentes, lit la ressource à l'aide d'un filtre de ressource, retire de chaque ressource si elle est disponible, met à jour la propriété RES_CODE des ressources disponibles et vérifie de nouveau les ressources. Il indique l'avant d'état, mises à jour et l'état d'après des ressources.

Please see Prerequisites for Reference Code Samples for critical information on running this code sample.

Vous pouvez accéder aux Admin/AddModifyUser.aspx sur votre site Project Web App pour vérifier que la ressource est extrait dans une autre session

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.CheckInResources
{
   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;
            string filterXml;

            // 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);

            // Read the resources so we can see what it looked like before.
            resourceFilter = GetResourceFilter(resources);
            filterXml = resourceFilter.GetXml();

            resourceDs = resourceSvc.ReadResources(filterXml, false);
            WriteTablesToConsole(resourceDs.Tables);

            // Check out resources so they can be modified
            Guid me = resourceSvc.GetCurrentUserUid();
            bool checkedOut =false;
            Random rand = new Random();
            // Modify the resources
            foreach(SvcResource.ResourceDataSet.ResourcesRow resourceRow in resourceDs.Resources)
            {
               Console.WriteLine("Check out " + resourceRow.RES_NAME);
               if (resourceRow.IsRES_CHECKOUTBYNull())
               {
                  resourceSvc.CheckOutResources(new Guid[] { resourceRow.RES_UID });
                  checkedOut=true;
               }
               else
               {
                  if (resourceRow.RES_CHECKOUTBY == me)
                  {
                     checkedOut = true;
                  }
                  else
                  {
                     checkedOut = false;
                     Console.WriteLine("\tCan't check out this resource, skip updating this one.");
                  }
               }
               if (checkedOut)
               {
                  SvcResource.ResourceDataSet updateDs = resourceSvc.ReadResource(resourceRow.RES_UID);
                  updateDs.Resources[0].RES_CODE = "A" + rand.Next(1000,9999) ;
                  Console.WriteLine("Update RES_CODE to " + updateDs.Resources[0].RES_CODE);
                  resourceSvc.UpdateResources(updateDs, false, false);
                  Console.WriteLine("Check in " + resourceRow.RES_NAME);
                  resourceSvc.CheckInResources(new Guid[] { resourceRow.RES_UID },false);
               }
               Console.ForegroundColor=ConsoleColor.Yellow;
               Console.WriteLine("".PadRight(30,'-'));
               Console.ResetColor();
            }

            // retrieve the data from the server for display
            resourceDs = resourceSvc.ReadResources(filterXml, false);
            WriteTablesToConsole(resourceDs.Tables);

         }
         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));
         resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_CODEColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));

         resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_ACCRUE_ATColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
         resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_BOOKING_TYPEColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));

         resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_CAN_LEVELColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
         resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_CHECKOUTBYColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
         resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_CHECKOUTDATEColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
         resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_COST_CENTERColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
         resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_DEF_ASSN_OWNERColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
         resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_EXTERNAL_IDColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
         resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_GROUPColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
         resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_HAS_NOTESColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
         resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_HIRE_DATEColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
         resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_HYPERLINK_ADDRESSColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
         resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_HYPERLINK_FRIENDLY_NAMEColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
         resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_HYPERLINK_SUB_ADDRESSColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));

         resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_IDColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
         resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_IS_TEAMColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
         resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_IS_WINDOWS_USERColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
         resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_MATERIAL_LABELColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
         //resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_NOTESColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));

         resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_PHONETICSColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
         resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_RTF_NOTESColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
         resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_TERMINATION_DATEColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));

         resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_TIMESHEET_MGR_UIDColumn.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;
      }
      // Write all contents of a table collection to the console
      private static void WriteTablesToConsole(System.Data.DataTableCollection theTables)
      {
         Console.ForegroundColor = ConsoleColor.DarkGreen;
         foreach (System.Data.DataTable table in theTables)
         {

            int[] columnWidths = new int[table.Columns.Count];
            int tableWidth = 0;
            string dataString;
            Console.WriteLine("Table: " + table.TableName);

            // Write out the column names and get their spacing
            StringBuilder tableRow = new StringBuilder();
            for (int i = 0; i < table.Columns.Count; i++)
            {
               columnWidths[i] = GetColumnWidth(table.Columns[i]);
               tableRow.Append(table.Columns[i].ColumnName.PadRight(columnWidths[i]));

               tableWidth += columnWidths[i];
            }
            // add a space so it won't wrap
            tableWidth += 1;
            // make the console as wide as the widest table
            Console.BufferWidth = (Console.BufferWidth > tableWidth ? Console.BufferWidth : tableWidth);
            tableRow.Append("\r\n");
            Console.Write(tableRow.ToString());

            // Write out the data
            foreach (DataRow row in table.Rows)
            {
               tableRow = new StringBuilder();
               for (int i = 0; i < table.Columns.Count; i++)
               {
                  dataString = row[i].ToString();
                  // truncate output if it is wider than 
                  // the desired column width
                  if (dataString.Length >= columnWidths[i])
                  {
                     dataString = dataString.Substring(0, columnWidths[i] - 1);
                  }
                  // add the output to the stringbuilder and pad right to fill
                  // up to the column width.
                  tableRow.Append(dataString.PadRight(columnWidths[i]));
               }
               tableRow.Append("\r\n");
               Console.Write(tableRow.ToString());
            }
            Console.Write("\r\n".PadLeft(tableWidth, '-'));
         }
         Console.ResetColor();
      }
      // Helper function for WriteTablesToConsole
      private static int GetColumnWidth(DataColumn column)
      {
         // Note: may not handle byte[]data types well
         const int MAX_COL_WIDTH = 40;
         int dataWidth = 0;

         //return 12 for numbers, 30 for dates, and string width for strings.
         switch (column.DataType.UnderlyingSystemType.ToString())
         {
            case "System.Boolean":
            case "System.Byte":
            case "System.Byte[]":
            case "System.Char":
            case "System.Decimal":
            case "System.Double":
            case "System.Int16":
            case "System.Int32":
            case "System.Int64":
            case "System.SByte":
            case "System.Single":
            case "System.UInt16":
            case "System.UInt32":
            case "System.UInt64":
               dataWidth = 12;
               break;
            case "System.DateTime":
            case "System.TimeSpan":
               dataWidth = 30;
               break;
            case "System.Guid":
               dataWidth = 37;
               break;
            case "System.String":
               // If it has a maxlength, use it
               if (column.MaxLength > 0)
               {
                  dataWidth = column.MaxLength;
               }
               else
               {
                  // Otherwise use the max col width
                  dataWidth = MAX_COL_WIDTH;
               }
               break;
            default:
               dataWidth = column.ColumnName.Length;
               break;
         }
         // truncate if over the max length
         if (dataWidth > MAX_COL_WIDTH)
         {
            dataWidth = MAX_COL_WIDTH;
         }
         // always be at least as wide as the colum name
         return (column.ColumnName.Length > (dataWidth) ? column.ColumnName.Length + 1 : dataWidth);
      }
   }
}

Voir aussi

Référence

Resource classe

Resource - Membres

WebSvcResource - Espace de noms