次の方法で共有


Admin.UpdateTimeSheetSettings メソッド

名前空間:  WebSvcAdmin
アセンブリ:  ProjectServerServices (ProjectServerServices.dll 内)

構文

'宣言
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Admin/UpdateTimeSheetSettings", RequestNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Admin/",  _
    ResponseNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Admin/",  _
    Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Sub UpdateTimeSheetSettings ( _
    dsDelta As TimeSheetSettingsDataSet _
)
'使用
Dim instance As Admin
Dim dsDelta As TimeSheetSettingsDataSet

instance.UpdateTimeSheetSettings(dsDelta)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Admin/UpdateTimeSheetSettings", RequestNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Admin/", 
    ResponseNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Admin/", 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public void UpdateTimeSheetSettings(
    TimeSheetSettingsDataSet dsDelta
)

パラメーター

注釈

タイムシートの設定は、[タイムシートの設定および既定値ページProject Web App (http:///ServerName/ProjectServerName/_layouts/pwa/Admin/TSSettings.aspx) で設定できます。

TimeSheetSettingsDataSet.TimeSheetSettings[0 のプロパティ] の行にある制約です。それらは null にできません。ReadTimeSheetSettingsメソッドを使用して、現在の設定を取得し、変更を加えます。

プロジェクト サーバーのアクセス許可

権限

説明

ManageTimeTracking

リソースから送信されたタイムシートを管理することができます。グローバル アクセス権。

次の例では、タイムシートの現在の設定を読み取り、 WADMIN_TS_MAX_HR_PER_TSとで、 TimeSheetSettingsDataSet、 WADMIN_TS_MIN_HR_PER_TSの値を変更およびタイムシートの最小時間と最大時間を変更するには、 UpdateTimeSheetSettingsメソッドを使用しています。例では、ProjectServerServices.dll プロキシ アセンブリ内のSvcAdminの名前空間を使用します。またこの例では XML ファイルには、新しいTimeSheetSettingsDataSetでの更新。

注意

ConfigClientEndpointsメソッドは、WCF のバインディング、動作、およびエンドポイントの設定を app.config ファイルを使用します。PSI プロキシ アセンブリと app.config ファイルを作成する方法の詳細については、 Project 2013 での WCF ベースのコード サンプルの前提条件を参照してください。

using System;
using System.Text;
using System.ServiceModel;
using System.Xml;
using PSLibrary = Microsoft.Office.Project.Server.Library;

namespace Microsoft.SDK.Project.Samples.UpdateTimeSheetSettings
{
    class Program
    {
        private const string ENDPOINT = "basicHttp_Admin";
        private const string OUTPUT_FILES = @"C:\Project\Samples\Output\";

        private static SvcAdmin.AdminClient adminClient;
        private static string outFilePath;

        static void Main(string[] args)
        {
            outFilePath = OUTPUT_FILES + "TimesheetSettings.xml";
            ConfigClientEndpoints(ENDPOINT);

            Console.WriteLine("Retrieving the timesheet settings...");
            SvcAdmin.TimeSheetSettingsDataSet timesheetSettingsDS =
                new SvcAdmin.TimeSheetSettingsDataSet();

            // Get the current timesheet settings, and then make changes to 
            // two settings: maximum and minimum hours per timesheet. 
            try
            {
                timesheetSettingsDS = adminClient.ReadTimeSheetSettings();

               // Changes the timesheet settings to be 50 hours per week maximum
                // and 15 hours per week minimum.
                timesheetSettingsDS.TimeSheetSettings[0].WADMIN_TS_MAX_HR_PER_TS = 3000000;
                timesheetSettingsDS.TimeSheetSettings[0].WADMIN_TS_MIN_HR_PER_TS = 900000;


                // Write the changed dataset to an output file, for debugging purposes.
                timesheetSettingsDS.WriteXml(outFilePath);

                // Update the timesheet settings with the changes.
                adminClient.UpdateTimeSheetSettings(timesheetSettingsDS);
            }

            catch (FaultException fault)
            {
                // Use the WCF FaultException, because the ASMX SoapException does not 
                // exist in a WCF-based application.
                WriteFaultOutput(fault);
                Console.Write("\nThe attempt to update the timesheet settings has failed.");
            }

            Console.WriteLine("\nSee XML output of the updated TimeSheetSettingsDataSet at:\n\t{0}",
                outFilePath);
            Console.Write("\nPress any key to exit... ");
            Console.ReadKey(true);

        }

        // Extract a PSClientError object from the WCF FaultException object, and
        // then display the exception details and each error in the PSClientError stack.
        private static void WriteFaultOutput(FaultException fault)
        {
            string errAttributeName;
            string errAttribute;
            string errOut;
            string errMess = "".PadRight(30, '=') + "\r\n"
                + "Error details: " + "\r\n";

            PSLibrary.PSClientError error = Helpers.GetPSClientError(fault, out errOut);
            errMess += errOut;

            PSLibrary.PSErrorInfo[] errors = error.GetAllErrors();
            PSLibrary.PSErrorInfo thisError;

            for (int i = 0; i < errors.Length; i++)
            {
                thisError = errors[i];
                errMess += "\r\n".PadRight(30, '=') + "\r\nPSClientError output:\r\n";
                errMess += thisError.ErrId.ToString() + "\n";

                for (int j = 0; j < thisError.ErrorAttributes.Length; j++)
                {
                    errAttributeName = thisError.ErrorAttributeNames()[j];
                    errAttribute = thisError.ErrorAttributes[j];
                    errMess += "\r\n\t" + errAttributeName
                        + ": " + errAttribute;
                }
            }
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(errMess);
            Console.ResetColor();
        }

        // Use the endpoints that are defined in app.config to configure the client.
        public static void ConfigClientEndpoints(string endpt)
        {
            adminClient = new SvcAdmin.AdminClient(endpt);
        }
    }

    // Helper method: GetPSClientError.
    class Helpers
    {
   
        /// <summary>
        /// Extract a PSClientError object from the ServiceModel.FaultException,
        /// for use in output of the GetPSClientError stack of errors.
        /// </summary>
        /// <param name="e"></param>
        /// <param name="errOut">Shows that FaultException has more information 
        /// about the errors than PSClientError has. FaultException can also contain 
        /// other types of errors, such as failure to connect to the server.</param>
        /// <returns>PSClientError object, for enumerating errors.</returns>
        public static PSLibrary.PSClientError GetPSClientError(FaultException e,
                                                               out string errOut)
        {
            const string PREFIX = "GetPSClientError() returns null: ";
            errOut = string.Empty;
            PSLibrary.PSClientError psClientError = null;

            if (e == null)
            {
                errOut = PREFIX + "Null parameter (FaultException e) passed in.";
                psClientError = null;
            }
            else
            {
                // Get a ServiceModel.MessageFault object.
                var messageFault = e.CreateMessageFault();

                if (messageFault.HasDetail)
                {
                    using (var xmlReader = messageFault.GetReaderAtDetailContents())
                    {
                        var xml = new XmlDocument();
                        xml.Load(xmlReader);

                        var serverExecutionFault = xml["ServerExecutionFault"];
                        if (serverExecutionFault != null)
                        {
                            var exceptionDetails = serverExecutionFault["ExceptionDetails"];
                            if (exceptionDetails != null)
                            {
                                try
                                {
                                    errOut = exceptionDetails.InnerXml + "\r\n";
                                    psClientError =
                                        new PSLibrary.PSClientError(exceptionDetails.InnerXml);
                                }
                                catch (InvalidOperationException ex)
                                {
                                    errOut = PREFIX + "Unable to convert fault exception info ";
                                    errOut += "a valid Project Server error message. Message: \n\t";
                                    errOut += ex.Message;
                                    psClientError = null;
                                }
                            }
                            else
                            {
                                errOut = PREFIX + "The FaultException e is a ServerExecutionFault, "
                                    + "but does not have ExceptionDetails.";
                            }
                        }
                        else
                        {
                            errOut = PREFIX + "The FaultException e is not a ServerExecutionFault.";
                        }
                    }
                }
                else // No detail in the MessageFault.
                {
                    errOut = PREFIX + "The FaultException e does not have any detail.";
                }
            }
            errOut += "\r\n" + e.ToString() + "\r\n";
            return psClientError;
        }
    }
}

アプリケーションが保存されている UpdateTimesheetSettings.xml ファイルの例を次に示します。WADMIN_TS_MIN_HR_PER_TS要素とWADMIN_TS_MAX_HR_PER_TS要素が更新されます。

<?xml version="1.0" standalone="yes"?>
<TimeSheetSettingsDataSet xmlns="https://schemas.microsoft.com/office/project/server/webservices/TimeSheetSettingsDataSet/">
  <TimeSheetSettings>
    <WADMIN_UIDFAKE>446855fe-d085-4ba0-8006-9fce73e9c9fb</WADMIN_UIDFAKE>
    <WADMIN_TS_IS_UNVERS_TASK_ALLOWED>true</WADMIN_TS_IS_UNVERS_TASK_ALLOWED>
    <WADMIN_TS_PROJECT_MANAGER_COORDINATION>true</WADMIN_TS_PROJECT_MANAGER_COORDINATION>
    <WADMIN_TS_PROJECT_MANAGER_APPROVAL>false</WADMIN_TS_PROJECT_MANAGER_APPROVAL>
    <WADMIN_TS_IS_AUDIT_ENABLED>true</WADMIN_TS_IS_AUDIT_ENABLED>
    <WADMIN_TS_IS_FUTURE_REP_ALLOWED>true</WADMIN_TS_IS_FUTURE_REP_ALLOWED>
    <WADMIN_TS_FIXED_APPROVAL_ROUTING>false</WADMIN_TS_FIXED_APPROVAL_ROUTING>
    <WADMIN_TS_TIED_MODE>true</WADMIN_TS_TIED_MODE>
    <WADMIN_TS_MIN_HR_PER_TS>900000</WADMIN_TS_MIN_HR_PER_TS><WADMIN_TS_MAX_HR_PER_TS>3000000</WADMIN_TS_MAX_HR_PER_TS>
    <WADMIN_TS_MAX_HR_PER_DAY>600000.000000</WADMIN_TS_MAX_HR_PER_DAY>
    <WADMIN_TS_HOURS_PER_DAY>480000.000000</WADMIN_TS_HOURS_PER_DAY>
    <WADMIN_TS_HOURS_PER_WEEK>2400000.000000</WADMIN_TS_HOURS_PER_WEEK>
    <WADMIN_TS_DEF_DISPLAY_ENUM>7</WADMIN_TS_DEF_DISPLAY_ENUM>
    <WADMIN_TS_CREATE_MODE_ENUM>1</WADMIN_TS_CREATE_MODE_ENUM>
    <WADMIN_TS_REPORT_UNIT_ENUM>0</WADMIN_TS_REPORT_UNIT_ENUM>
    <WADMIN_TS_DEF_ENTRY_MODE_ENUM>0</WADMIN_TS_DEF_ENTRY_MODE_ENUM>
    <WADMIN_DEFAULT_TRACKING_METHOD>1</WADMIN_DEFAULT_TRACKING_METHOD>
    <WADMIN_IS_TRACKING_METHOD_LOCKED>true</WADMIN_IS_TRACKING_METHOD_LOCKED>
    <WADMIN_TS_ALLOW_PROJECT_LEVEL>true</WADMIN_TS_ALLOW_PROJECT_LEVEL>
  </TimeSheetSettings>
</TimeSheetSettingsDataSet>

関連項目

参照先

Admin クラス

Admin メンバー

WebSvcAdmin 名前空間