共用方式為


Driver.CreatePrioritization 方法

設定的優先順序層級 (None、 Low、 Moderate或Strong) 商業策略的驅動程式,專案的影響。

命名空間:  WebSvcDriver
組件:  ProjectServerServices (在 ProjectServerServices.dll 中)

語法

'宣告
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Driver/CreatePrioritization", RequestNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Driver/",  _
    ResponseNamespace := "https://schemas.microsoft.com/office/project/server/webservices/Driver/",  _
    Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Function CreatePrioritization ( _
    driverPrioritizationDataSet As DriverPrioritizationDataSet _
) As DriverPrioritizationDataSet
'用途
Dim instance As Driver
Dim driverPrioritizationDataSet As DriverPrioritizationDataSet
Dim returnValue As DriverPrioritizationDataSet

returnValue = instance.CreatePrioritization(driverPrioritizationDataSet)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Driver/CreatePrioritization", RequestNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Driver/", 
    ResponseNamespace = "https://schemas.microsoft.com/office/project/server/webservices/Driver/", 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public DriverPrioritizationDataSet CreatePrioritization(
    DriverPrioritizationDataSet driverPrioritizationDataSet
)

參數

傳回值

類型:WebSvcDriver.DriverPrioritizationDataSet
包含的優先處理順序資料。

備註

Project Server 權限

權限

描述

ManagePrioritizations

可讓使用者建立或編輯專案產品組合分析的優先順序。通用權限。

範例

The example uses the SvcDriver namespace in the ProjectServerServices.dll proxy assembly. The ConfigClientEndpoints method uses an app.config file for setting the WCF binding, behavior, and endpoint. For information about creating a PSI proxy assembly and an app.config file, see Prerequisites for WCF-Based Code Samples.

CreatePrioritization方法會driverPrioritizationDSPrioritizationRow物件。範例應用程式檔中寫入內容的資料集CreatePrioritization.xml ,,如下所示:

<?xml version="1.0" standalone="yes"?>
<DriverPrioritizationDataSet xmlns=
"https://schemas.microsoft.com/office/project/server/webservices/DriverPrioritizationDataSet/">
<Prioritization>
<PRIORITIZATION_UID>d8d908ce-6400-458f-9edd-554209d4efcf
</PRIORITIZATION_UID>
<PRIORITIZATION_NAME>Prioritization-d8d908ce-6400-458f-9edd-554209d4efcf
</PRIORITIZATION_NAME>
<PRIORITIZATION_DESCRIPTION>Test pri</PRIORITIZATION_DESCRIPTION>
<PRIORITIZATION_IS_MANUAL>false</PRIORITIZATION_IS_MANUAL>
<RELATIVE_IMPORTANCE_CF_UID>2cd29b66-4cca-4c3e-8421-1e54c6d06dca
</RELATIVE_IMPORTANCE_CF_UID>
<CONSISTENCY_RATIO>1</CONSISTENCY_RATIO>
</Prioritization>
</DriverPrioritizationDataSet>

以下是完成的範例程式碼。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.ServiceModel;
using PSLibrary = Microsoft.Office.Project.Server.Library;

namespace Microsoft.SDK.Project.Samples.Drivers
{
    class Driver
    {
        private static SvcDriver.DriverClient driverClient;
        private const string DRIVER_ENDPOINT = "basicHttp_Driver";
        private const string OUTPUT_FILES = @"C:\Projects\Samples\Output\";
        private static string outFilePathDriverImpactStmt;
        private static string outFilePathDriverList;
        private static string outFilePathPrioritizationInfo;
        private static string outFilePathPrioritizationRow;
        private static string OutFilePathDrivers;
        private Dictionary<Guid, SortedList<int, SortedList<Guid, object>>> 
            lookupTableValues = 
            new Dictionary<Guid, SortedList<int, SortedList<Guid, object>>>();

        static void Main(string[] args)
        {
            // Configure the endpoints.
            ConfigClientEndpoints(DRIVER_ENDPOINT);

            // If output directory does not exist, create it.
            if (!Directory.Exists(OUTPUT_FILES))
            {
                Directory.CreateDirectory(OUTPUT_FILES);
            }

            outFilePathDriverImpactStmt = OUTPUT_FILES 
                + "DriverImpactStatements.xml";
            outFilePathDriverList = OUTPUT_FILES 
                + "DriverList.xml";
            outFilePathPrioritizationInfo = OUTPUT_FILES 
                + "PrioritizationInfo.xml";
            outFilePathPrioritizationRow = OUTPUT_FILES 
                + "CreatePrioritization.xml";
            OutFilePathDrivers = OUTPUT_FILES + "Drivers.xml";

            // Create the Driver dataset.
            SvcDriver.DriverDataSet driverInfoDS = 
                new SvcDriver.DriverDataSet(); ;

            // Create the drivers.
            driverInfoDS = CreateDrivers();
            driverInfoDS.WriteXml(OutFilePathDrivers);

            // Get the first driver and update its impact statements.
            Guid DRV_UID = 
                new Guid(driverInfoDS.Driver.Rows[0][0].ToString());

            // Update driver impact statements.
            UpdateImpactStatement(DRV_UID);

            // Read the list of drivers.
            SvcDriver.DriverDataSet driverListDS = 
                driverClient.ReadDriverList();
            driverListDS.WriteXml(outFilePathDriverList);
            Console.WriteLine("\nSee XML output of the Updated DataSet at {0}",
            outFilePathDriverList);

            // Create prioritization.
            PrioritizationInfo priInfo = CreateNewPrioritization();
            
            // Create a guids list and add the prioritization GUID to it.
            List<Guid> guids = new List<Guid>();
            guids.Add(priInfo.UniqueId);

            // Read prioritization.
            SvcDriver.DriverPrioritizationDataSet prioritizationDS = 
                driverClient.ReadPrioritization(priInfo.UniqueId);

            // Look-up-table values for comparison (hard-coded here).
            Guid[] lookUpTableValues = new Guid[2];

            // The lookup table value is greater.
            lookUpTableValues[0] = new Guid("3E0D4FFF-52A6-4235-9B2D-8FB26D74A139");
            // The lookup table value is less.
            lookUpTableValues[1] = 
                new Guid("9CECF611-8F36-4CA2-89E4-640537848513");

            // Add drivers to prioritization.
            prioritizationDS = UpdatePrioritizationInfo(
                driverInfoDS, priInfo, prioritizationDS, lookUpTableValues);

            // Read updated prioritization information.
            SvcDriver.DriverPrioritizationDataSet updatedPrioritizationDS = 
                driverClient.ReadPrioritization(priInfo.UniqueId);
            updatedPrioritizationDS.WriteXml(outFilePathPrioritizationInfo);
            Console.WriteLine(
                "\nSee XML output of the Updated Prioritization at {0}",
                outFilePathPrioritizationInfo);

            // Delete prioritization.
            driverClient.DeletePrioritizations(guids.ToArray());
            Console.WriteLine(" Prioritization {0} deleted", priInfo.UniqueId);
            guids.Clear();

            // Delete drivers.
            foreach (SvcDriver.DriverDataSet.DriverRow drvRow in
                driverInfoDS.Driver.Rows)
            {
                guids.Add(drvRow.DRIVER_UID);
            }
            driverClient.DeleteDrivers(guids.ToArray());
            Console.WriteLine("Deleted drivers");
            Console.ReadKey();
        }

        // Update a prioritization.
        private static SvcDriver.DriverPrioritizationDataSet
            UpdatePrioritizationInfo(
            SvcDriver.DriverDataSet driverInfoDS,
            PrioritizationInfo priInfo,
            SvcDriver.DriverPrioritizationDataSet prioritizationDS,
            Guid[] lookUpTableValues)
        {
            // Add a prioritization row.
            foreach (SvcDriver.DriverDataSet.DriverRow dRow in
                driverInfoDS.Driver.Rows)
            {
                SvcDriver.DriverPrioritizationDataSet.PrioritizationEntriesDataTable
                    prioEntries = prioritizationDS.PrioritizationEntries;
                SvcDriver.DriverPrioritizationDataSet.PrioritizationEntriesRow
                    prioritizationEntriesRow =
                    prioEntries.NewPrioritizationEntriesRow();
                prioritizationEntriesRow.PRIORITIZATION_UID =
                    priInfo.UniqueId;
                prioritizationEntriesRow.DRIVER_UID = dRow.DRIVER_UID;
                prioritizationEntriesRow.DRIVER_DESCRIPTION =
                    dRow.DRIVER_DESCRIPTION;
                prioEntries.AddPrioritizationEntriesRow(
                    prioritizationEntriesRow);
            }

            // Add driver-to-driver relations.
            for (int i = 0; i < driverInfoDS.Driver.Rows.Count - 1; i++)
            {
                for (int j = i + 1; j < driverInfoDS.Driver.Rows.Count; j++)
                {
                    SvcDriver.DriverPrioritizationDataSet.DriverRelationsRow
                        driverRelationsRow =
                        prioritizationDS.DriverRelations.NewDriverRelationsRow();
                    driverRelationsRow.PRIORITIZATION_UID = priInfo.UniqueId;
                    driverRelationsRow.DRIVER1_UID =
                        new Guid(driverInfoDS.Driver.Rows[i][0].ToString());
                    driverRelationsRow.DRIVER2_UID =
                        new Guid(driverInfoDS.Driver.Rows[j][0].ToString());
                    driverRelationsRow.LT_STRUCT_UID = lookUpTableValues[i];

                    prioritizationDS.DriverRelations.AddDriverRelationsRow(
                        driverRelationsRow);

                    // Also save the complement values.
                    Guid complementCodeValue =
                        PSLibrary.LookupTables.GetRelativeImportanceComplement(
                        lookUpTableValues[i]);
                    if (complementCodeValue != Guid.Empty)
                    {
                        driverRelationsRow =
                            prioritizationDS.DriverRelations.NewDriverRelationsRow();
                        driverRelationsRow.PRIORITIZATION_UID = priInfo.UniqueId;
                        driverRelationsRow.DRIVER1_UID =
                            new Guid(driverInfoDS.Driver.Rows[j][0].ToString());
                        driverRelationsRow.DRIVER2_UID =
                            new Guid(driverInfoDS.Driver.Rows[i][0].ToString());
                        driverRelationsRow.LT_STRUCT_UID = complementCodeValue;
                        prioritizationDS.DriverRelations.AddDriverRelationsRow(
                            driverRelationsRow);
                    }
                }
            }

            try
            {
                Console.WriteLine("Updating the DataSet....");
                prioritizationDS =
                    driverClient.UpdatePrioritization(prioritizationDS);
                Console.WriteLine(" DataSet updated successfully!");
            }
            catch (CommunicationException e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(
                    "\n***System.ServiceModel.CommunicationException:");
                Console.WriteLine(e.ToString());
                Console.ResetColor();
            }
            return prioritizationDS;
        }
        
        // Create a new prioritization.
        private static PrioritizationInfo CreateNewPrioritization()
        {
                SvcDriver.DriverPrioritizationDataSet driverPrioritizationDS =
                    new SvcDriver.DriverPrioritizationDataSet();
                PrioritizationInfo priInfo = new PrioritizationInfo();
                priInfo.UniqueId = Guid.NewGuid();
                priInfo.Name = "Prioritization-" + priInfo.UniqueId;
                priInfo.Description = "Test pri";
            try
            {
                SvcDriver.DriverPrioritizationDataSet.PrioritizationRow 
                    prioritizationRow =
                    driverPrioritizationDS.Prioritization.NewPrioritizationRow();
                prioritizationRow.PRIORITIZATION_UID = priInfo.UniqueId;
                prioritizationRow.PRIORITIZATION_NAME = priInfo.Name;
                prioritizationRow.PRIORITIZATION_DESCRIPTION = 
                    priInfo.Description;
                prioritizationRow.RELATIVE_IMPORTANCE_CF_UID = 
                    PSLibrary.CustomField.RELATIVE_IMPORTANCE_MD_PROP_UID;
                prioritizationRow.PRIORITIZATION_IS_MANUAL = false;

                driverPrioritizationDS.Prioritization.AddPrioritizationRow(
                    prioritizationRow);
                Console.WriteLine("Prioritization: Adding driver prioritization"
                    + priInfo.Name);
                driverClient.CreatePrioritization(driverPrioritizationDS);
                Console.WriteLine("Prioritization: Creation done");
                driverPrioritizationDS.WriteXml(outFilePathPrioritizationRow);
            }
            catch (CommunicationException e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(
                    "\n System.ServiceModel.CommunicationException:");
                Console.WriteLine(e.ToString());
                Console.ResetColor();
            }
            return priInfo;
        }

        // Configure the custom field client endpoints.
        public static void ConfigClientEndpoints(string endpt)
        {
            driverClient = new SvcDriver.DriverClient(endpt);
        }

        // Create drivers with impact statements.
        private static SvcDriver.DriverDataSet CreateDrivers()
        {
            DriverInfo drvInfo = new DriverInfo();
            SvcDriver.DriverDataSet updatedDriverDS = 
                new SvcDriver.DriverDataSet();
            try
            {
                // Creates three drivers and the impact statements for each.
                for (int i = 0; i < 3; i++)
                {
                    SvcDriver.DriverDataSet drvDS =
                        new SvcDriver.DriverDataSet();
                    drvInfo.UniqueId = Guid.NewGuid();
                    drvInfo.Name = "Driver-" + drvInfo.UniqueId;
                    drvInfo.Description = "test" + drvInfo.Name;
                    drvInfo.StatementNone = "PROJECT_IMPACT_NONE_VALUE_TXT"
                        + "-" + drvInfo.UniqueId;
                    drvInfo.StatementLow = "PROJECT_IMPACT_LOW_VALUE_TXT"
                        + "-" + drvInfo.UniqueId;
                    drvInfo.StatementModerate = "PROJECT_IMPACT_MODERATE_VALUE_TXT"
                        + "-" + drvInfo.UniqueId;
                    drvInfo.StatementStrong = "PROJECT_IMPACT_STRONG_VALUE_TXT"
                        + "-" + drvInfo.UniqueId;
                    drvInfo.StatementExtreme = "PROJECT_IMPACT_EXTREME_VALUE_TXT"
                        + "-" + drvInfo.UniqueId;

                    SvcDriver.DriverDataSet.DriverRow drvRow = 
                        drvDS.Driver.NewDriverRow();
                    drvRow.DRIVER_UID = drvInfo.UniqueId;
                    drvRow.DRIVER_NAME = drvInfo.Name;
                    drvRow.DRIVER_DESCRIPTION = drvInfo.Description;
                    drvDS.Driver.AddDriverRow(drvRow);

                    SvcDriver.DriverDataSet.DriverImpactStatementsDataTable
                    drvImpStmts = drvDS.DriverImpactStatements;

                    SvcDriver.DriverDataSet.DriverImpactStatementsRow 
                        stmtRow = drvImpStmts.NewDriverImpactStatementsRow();
                    stmtRow.DRIVER_UID = drvInfo.UniqueId;
                    stmtRow.PROJECT_IMPACT_CF_UID = 
                        PSLibrary.CustomField.PROJECT_IMPACT_MD_PROP_UID;
                    stmtRow.LT_STRUCT_UID = 
                        PSLibrary.LookupTables.PROJECT_IMPACT_NONE_LT_STRUCT_UID;
                    stmtRow.DESCRIPTION = drvInfo.StatementNone;
                    drvImpStmts.AddDriverImpactStatementsRow(stmtRow);

                    stmtRow =
                        drvImpStmts.NewDriverImpactStatementsRow();
                    stmtRow.DRIVER_UID = drvInfo.UniqueId;
                    stmtRow.PROJECT_IMPACT_CF_UID = 
                        PSLibrary.CustomField.PROJECT_IMPACT_MD_PROP_UID;
                    stmtRow.LT_STRUCT_UID = 
                        PSLibrary.LookupTables.PROJECT_IMPACT_LOW_LT_STRUCT_UID;
                    stmtRow.DESCRIPTION = drvInfo.StatementLow;
                    drvImpStmts.AddDriverImpactStatementsRow(stmtRow);

                    stmtRow =
                        drvImpStmts.NewDriverImpactStatementsRow();
                    stmtRow.DRIVER_UID = drvInfo.UniqueId;
                    stmtRow.PROJECT_IMPACT_CF_UID = 
                        PSLibrary.CustomField.PROJECT_IMPACT_MD_PROP_UID;
                    stmtRow.LT_STRUCT_UID = 
                        PSLibrary.LookupTables.PROJECT_IMPACT_MODERATE_LT_STRUCT_UID;
                    stmtRow.DESCRIPTION = drvInfo.StatementModerate;
                    drvImpStmts.AddDriverImpactStatementsRow(stmtRow);

                    stmtRow =
                        drvImpStmts.NewDriverImpactStatementsRow();
                    stmtRow.DRIVER_UID = drvInfo.UniqueId;
                    stmtRow.PROJECT_IMPACT_CF_UID = 
                        PSLibrary.CustomField.PROJECT_IMPACT_MD_PROP_UID;
                    stmtRow.LT_STRUCT_UID = 
                        PSLibrary.LookupTables.PROJECT_IMPACT_STRONG_LT_STRUCT_UID;
                    stmtRow.DESCRIPTION = drvInfo.StatementStrong;
                    drvImpStmts.AddDriverImpactStatementsRow(stmtRow);

                    stmtRow =
                        drvImpStmts.NewDriverImpactStatementsRow();
                    stmtRow.DRIVER_UID = drvInfo.UniqueId;
                    stmtRow.PROJECT_IMPACT_CF_UID = 
                        PSLibrary.CustomField.PROJECT_IMPACT_MD_PROP_UID;
                    stmtRow.LT_STRUCT_UID = 
                        PSLibrary.LookupTables.PROJECT_IMPACT_EXTREME_LT_STRUCT_UID;
                    stmtRow.DESCRIPTION = drvInfo.StatementExtreme;
                    drvImpStmts.AddDriverImpactStatementsRow(stmtRow);

                    Console.WriteLine("Adding driver " + drvInfo.Name);
                    driverClient.CreateDriver(
                        (SvcDriver.DriverDataSet)drvDS);
                    Console.WriteLine("Drivers {0} created successfully!", i);
                    updatedDriverDS.Merge(drvDS);
                }
            }
            catch (CommunicationException e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(
                    "\n***System.ServiceModel.CommunicationException:");
                Console.WriteLine(e.ToString());
                Console.ResetColor();
            }
            return updatedDriverDS;
        }

        // Update the driver impact statements.
        private static void UpdateImpactStatement(Guid DriverGuid)
        {
            try
            {
                Guid LT_UID = 
                    new Guid("779271C4-894D-4385-9E33-1251A9E80541");
                Guid IMPACT_UID = 
                    new Guid("1728D080-BA74-4D86-A29A-27E4318001C4");
                SvcDriver.DriverDataSet drvInfoDS = 
                    driverClient.ReadDriver(DriverGuid);
                SvcDriver.DriverDataSet.DriverImpactStatementsRow impactRow;
                SvcDriver.DriverDataSet.DriverImpactStatementsDataTable 
                    drvImpactStmts = drvInfoDS.DriverImpactStatements;
                impactRow = 
                  drvImpactStmts.FindByDRIVER_UIDPROJECT_IMPACT_CF_UIDLT_STRUCT_UID(
                  DriverGuid, IMPACT_UID, LT_UID);
                impactRow.DESCRIPTION = "new desc";
                driverClient.UpdateDriver(drvInfoDS);
                drvInfoDS.DriverImpactStatements.WriteXml(
                    outFilePathDriverImpactStmt);
                Console.WriteLine(
                    "\nSee XML output of the Updated DataSet at {0}",
                outFilePathDriverImpactStmt);
            }
            catch (CommunicationException e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(
                    "\n***System.ServiceModel.CommunicationException:");
                Console.WriteLine(e.ToString());
                Console.ResetColor();
            }
        }
    }

    // This class contains the driver information.
    public class DriverInfo
    {
        private Guid driverGuid = new Guid();

        public Guid UniqueId
        {
            get { return this.driverGuid; }
            set { this.driverGuid = value; }
        }

        private string driverName = string.Empty;

        public string Name
        {
            get { return this.driverName; }
            set { this.driverName = value; }
        }

        private string driverDescription = string.Empty;

        public string Description
        {
            get { return this.driverDescription; }
            set { this.driverDescription = value; }
        }

        public static int DriverType
        {
            get { return (int)PSLibrary.Optimizer.OptimizerEntities.Driver; }
        }

        private string statementNone = string.Empty;

        public string StatementNone
        {
            get { return this.statementNone; }
            set { this.statementNone = value; }
        }

        private string statementLow = string.Empty;

        public string StatementLow
        {
            get { return this.statementLow; }
            set { this.statementLow = value; }
        }

        private string statementModerate = string.Empty;

        public string StatementModerate
        {
            get { return this.statementModerate; }
            set { this.statementModerate = value; }
        }

        private string statementStrong = string.Empty;

        public string StatementStrong
        {
            get { return this.statementStrong; }
            set { this.statementStrong = value; }
        }

        private string statementExtreme = string.Empty;

        public string StatementExtreme
        {
            get { return this.statementExtreme; }
            set { this.statementExtreme = value; }
        }
    }

    // This class contains the prioritization information.
    class PrioritizationInfo
    {
        private Guid prioritizationGuid = Guid.NewGuid();

        public Guid UniqueId
        {
            get { return this.prioritizationGuid; }
            set { this.prioritizationGuid = value; }
        }
        private string prioritizationName = string.Empty;

        public string Name
        {
            get { return this.prioritizationName; }
            set { this.prioritizationName = value; }
        }

        private string prioritizationDescription = string.Empty;

        public string Description
        {
            get { return this.prioritizationDescription; }
            set { this.prioritizationDescription = value; }
        }
    }
}

請參閱

參照

Driver 類別

Driver 成員

WebSvcDriver 命名空間