Freigeben über


TimeSheet.QueueSubmitTimesheet-Methode

Den Status der angegebenen Arbeitszeittabelle von In Progress in Submitted über Arbeitszeittabellen-Warteschlange geändert.

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

Syntax

'Declaration
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/TimeSheet/QueueSubmitTimesheet", RequestNamespace := "https://schemas.microsoft.com/office/project/server/webservices/TimeSheet/",  _
    ResponseNamespace := "https://schemas.microsoft.com/office/project/server/webservices/TimeSheet/",  _
    Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Sub QueueSubmitTimesheet ( _
    jobUID As Guid, _
    tsUID As Guid, _
    approverUID As Guid, _
    comment As String _
)
'Usage
Dim instance As TimeSheet
Dim jobUID As Guid
Dim tsUID As Guid
Dim approverUID As Guid
Dim comment As String

instance.QueueSubmitTimesheet(jobUID, _
    tsUID, approverUID, comment)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/TimeSheet/QueueSubmitTimesheet", RequestNamespace = "https://schemas.microsoft.com/office/project/server/webservices/TimeSheet/", 
    ResponseNamespace = "https://schemas.microsoft.com/office/project/server/webservices/TimeSheet/", 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public void QueueSubmitTimesheet(
    Guid jobUID,
    Guid tsUID,
    Guid approverUID,
    string comment
)

Parameter

  • jobUID
    Typ: System.Guid

    Der eindeutige Bezeichner des Warteschlangenauftrags.

  • tsUID
    Typ: System.Guid

    Der eindeutige Bezeichner der Arbeitszeittabelle.

  • approverUID
    Typ: System.Guid

    Der eindeutige Bezeichner, der die genehmigende Person der Arbeitszeittabelle.

  • comment
    Typ: System.String

    Die Nachricht an die Aktion begleiten.

Hinweise

Die QueueSubmitTimesheet -Methode wird über die Project Server-Arbeitszeittabellen-Warteschlange asynchron verarbeitet.

Diese Methode sendet Aufträge auf das QueueSystem -Objekt. Die CorrelationGUID -Eigenschaft für den Auftrag ist gleich dem Wert der Eigenschaft TS_UID .

Project Server-Berechtigungen

Berechtigung

Beschreibung

Nicht standardmäßige

Der aktuelle Benutzer ist Besitzer der Arbeitszeittabelle.

Beispiele

Im folgenden Codebeispiel wird bestimmt, ob eine Arbeitszeittabelle für die erste offene Periode vorhanden ist. Wenn dies der Fall ist, liest die im Beispiel wird die Arbeitszeittabelle. Wenn die Arbeitszeittabelle nicht vorhanden ist, erstellt eine Arbeitszeittabelle mit den Standardeinstellungen Arbeitszeittabellen-Zeilen, die auf dem Server angegeben sind. Das Beispiel sendet die Arbeitszeittabelle und zeigt die Ergebnisse dann.

Am Ende im Beispiel zurückgerufen die Arbeitszeittabelle und gelöscht, damit es erneut erstellt werden kann. Wenn Sie die Genehmigung für Arbeitszeittabellen in Project Web App anzeigen möchten, kommentieren Sie den Abschnitt Rückruf und löschen.

Zeiträume in der Arbeitszeittabelle müssen in den Servereinstellungen für Arbeitszeittabellen funktioniert erstellt werden.

For critical information about running this code sample, see Prerequisites for Reference Code Samples.

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Data;
using System.Threading;
using System.Web.Services.Protocols;
using PSLibrary = Microsoft.Office.Project.Server.Library;

namespace Microsoft.SDK.Project.Samples.QueueSubmitTimesheet
{
   class Program
   {
      [STAThread]
      static void Main()
      {
         try{
            #region Setup
            const string PROJECT_SERVER_URI = "http:// ServerName/ProjectServerName/"; // <<--Change to be the name of your server running Project Server and the name of your directory.
            const string TIMESHEET_SERVICE_PATH = "_vti_bin/psi/timesheet.asmx";
            const string RESOURCE_SERVICE_PATH = "_vti_bin/psi/resource.asmx";
            const string ADMIN_SERVICE_PATH = "_vti_bin/psi/admin.asmx";
            const string QUEUESYSTEM_SERVICE_PATH = "_vti_bin/psi/queuesystem.asmx";
            TimeSheetWebSvc.TimesheetDataSet timeSheetDs;
            Guid jobUid;

            // Set up the services.
            TimeSheetWebSvc.TimeSheet timeSheetSvc = new TimeSheetWebSvc.TimeSheet();
            timeSheetSvc.UseDefaultCredentials = true;
            timeSheetSvc.Url = PROJECT_SERVER_URI + TIMESHEET_SERVICE_PATH;

            ResourceWebSvc.Resource resourceSvc = new ResourceWebSvc.Resource();
            resourceSvc.Url = PROJECT_SERVER_URI + RESOURCE_SERVICE_PATH;
            resourceSvc.UseDefaultCredentials = true;

            AdminWebSvc.Admin adminSvc = new AdminWebSvc.Admin();
            adminSvc.Url = PROJECT_SERVER_URI + ADMIN_SERVICE_PATH;
            adminSvc.UseDefaultCredentials = true;

            QueueSystemWebSvc.QueueSystem q = new QueueSystemWebSvc.QueueSystem();
            q.Url = PROJECT_SERVER_URI + QUEUESYSTEM_SERVICE_PATH;
            q.UseDefaultCredentials = true;

            Guid myUid = resourceSvc.GetCurrentUserUid();
            Guid tsUid;

            #endregion
            #region Read Timesheet
            // Time periods must be created by the admin to use timesheets.
            // We are just reading the first open period here.
            AdminWebSvc.TimePeriodDataSet timeperiodDs = adminSvc.ReadPeriods(AdminWebSvc.PeriodState.Open);
            Guid periodUid = timeperiodDs.TimePeriods[0].WPRD_UID;

            // If timesheet already exists, read it.
            // (To delete an existing unsubmitted timesheet,
            //   go to the My Timesheet area of the Project Web App site.)
            timeSheetDs = timeSheetSvc.ReadTimesheetByPeriod(myUid,periodUid,TimeSheetWebSvc.Navigation.Current);
            #endregion
            #region CreateTimesheet if it doesn't exist, then read it
            // If the timesheet does not exist, create it.
            if(timeSheetDs.Headers.Count<1)
            {
               timeSheetDs = new TimeSheetWebSvc.TimesheetDataSet();
               TimeSheetWebSvc.TimesheetDataSet.HeadersRow headersRow = timeSheetDs.Headers.NewHeadersRow();
               headersRow.RES_UID = myUid;
               headersRow.TS_UID = Guid.NewGuid();
               headersRow.WPRD_UID = periodUid;
               headersRow.TS_CREATOR_RES_UID = myUid;
               headersRow.TS_NAME = "Timesheet ";
               headersRow.TS_COMMENTS = "Random comment text here";
               headersRow.TS_ENTRY_MODE_ENUM = (byte)PSLibrary.TimesheetEnum.EntryMode.Weekly; 
               timeSheetDs.Headers.AddHeadersRow(headersRow);

               // Create the timesheet with the default line types that are specified by the admin.
               timeSheetSvc.CreateTimesheet(timeSheetDs, TimeSheetWebSvc.PreloadType.Default);
               timeSheetDs = timeSheetSvc.ReadTimesheet(headersRow.TS_UID);
            }
            CodeSampleUtilities.WriteTablesFormated("Timesheet after create:" ,timeSheetDs.Tables);
            tsUid=timeSheetDs.Headers[0].TS_UID;
            #endregion
            #region Submit timesheet, if the status is OK
            if ((timeSheetDs.Headers[0].TS_STATUS_ENUM != (byte)PSLibrary.TimesheetEnum.Status.Approved)
               && timeSheetDs.Headers[0].TS_STATUS_ENUM != (byte)PSLibrary.TimesheetEnum.Status.Submitted
               )
            {
               jobUid = Guid.NewGuid();
               timeSheetSvc.QueueSubmitTimesheet(jobUid,tsUid,myUid,"I created this timesheet and submitted it through my handy-dandy program.");
               CodeSampleUtilities.WaitForQueue(q, jobUid);
            }
            timeSheetDs = timeSheetSvc.ReadTimesheet(tsUid);
            CodeSampleUtilities.WriteTablesFormated("After submission:", timeSheetDs.Tables);
            #endregion
            #region Recall the timesheet and delete it
            // Recall the timesheet and delete it so that we can run the sample again.
            jobUid = Guid.NewGuid();
            timeSheetSvc.QueueRecallTimesheet(jobUid,tsUid);
            CodeSampleUtilities.WaitForQueue(q, jobUid);

            jobUid = Guid.NewGuid();
            timeSheetSvc.QueueDeleteTimesheet(jobUid, tsUid);
            CodeSampleUtilities.WaitForQueue(q, jobUid);
            #endregion
         }
         #region Exception Handlers
         catch (SoapException ex)
         {
            ExceptionHandlers.HandleSoapException(ex);
         }
         catch (WebException ex)
         {
            ExceptionHandlers.HandleWebException(ex);
         }
         catch (Exception ex)
         {
            ExceptionHandlers.HandleException(ex);
         }
         finally
         {
            ExceptionHandlers.ResetConsole();
         }
         #endregion
      }
      class ExceptionHandlers
      {

         public static void HandleSoapException(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);
         }

         public static void HandleWebException(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);
         }

         public static void HandleException(Exception ex)
         {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Error: " + ex.Message);
         }

         public static void ResetConsole()
         {
            Console.ResetColor();
            Console.WriteLine("\r\n\r\nPress any key...");
            Console.ReadKey();
         }
      }
      class CodeSampleUtilities
      {
         // Write all contents of a table collection to the console.
         public 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 that it will not 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();
         }
         // A helper function for WriteTablesToConsole.
         private static int GetColumnWidth(DataColumn column)
         {
            // Note: Might 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 maxlength.
            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);
         }
         public static void WriteTablesFormated(string Title, System.Data.DataTableCollection theTables)
         {
            WriteSeparator();

            Console.WriteLine(Title);

            CodeSampleUtilities.WriteTablesToConsole(theTables);

         }
         public static void WriteSeparator()
         {
            Console.ForegroundColor = ConsoleColor.DarkYellow;
            Console.WriteLine("".PadRight(Console.BufferWidth, '='));
            Console.ResetColor();

         }

         // Wait for the job to finish.
         // Outputs job status to the console.
         static public void WaitForQueue(QueueSystemWebSvc.QueueSystem q, Guid jobId)
         {
            QueueSystemWebSvc.JobState jobState;
            const int QUEUE_WAIT_TIME = 1; // One second
            bool jobDone = false;
            string xmlError = string.Empty;
            int wait = 0;

            //Wait for the project to get through the queue.
            // Get the estimated wait time in seconds.
            wait = q.GetJobWaitTime(jobId);

            // Wait for it.
            Console.Write("Waiting on queue. Estimate: {0} seconds.\r\n ", wait);

            // Wait until it is finished.

            do
            {
               // Get the job state.
               jobState = q.GetJobCompletionState(jobId, out xmlError);

               if (jobState == QueueSystemWebSvc.JobState.Success)
               {
                  jobDone = true;
               }
               else
               {
                  if (jobState == QueueSystemWebSvc.JobState.Unknown
                  || jobState == QueueSystemWebSvc.JobState.Failed
                  || jobState == QueueSystemWebSvc.JobState.FailedNotBlocking
                  || jobState == QueueSystemWebSvc.JobState.CorrelationBlocked
                  || jobState == QueueSystemWebSvc.JobState.Canceled)
                  {
                     // If the job failed, error out.
                     throw (new ApplicationException("Queue request " + jobState + " for Job ID " + jobId + ".\r\n" + xmlError));
                  }
                  else
                  {
                     //Console.WriteLine("Job State: " + jobState + " for Job ID: " + jobId);
                     Console.Write("~");
                     Thread.Sleep(QUEUE_WAIT_TIME * 1000);
                  }
               }
            }
            while (!jobDone);
            Console.Write("\r\n");
         }
      }
   }
}

Siehe auch

Referenz

TimeSheet Klasse

TimeSheet-Member

WebSvcTimeSheet-Namespace