Driver.DeleteDrivers 方法

删除一个或多个业务策略驱动因素。

命名空间:  WebSvcDriver
程序集:  ProjectServerServices(位于 ProjectServerServices.dll 中)

语法

声明
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/Driver/DeleteDrivers", 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 Sub DeleteDrivers ( _
    driverUids As Guid() _
)
用法
Dim instance As Driver
Dim driverUids As Guid()

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

参数

  • driverUids
    类型:[]

    若要删除的驱动程序的 Guid。

备注

备注

如果驱动程序添加到优先顺序时,必须首先,将关联的优先顺序删除通过调用DeletePrioritizations([])

Project Server 权限

权限

说明

ManageDrivers

允许用户创建项目组合分析的项目驱动因素。全局权限。

示例

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 Project 2013 中基于 WCF 的代码示例的先决条件.

DeleteDrivers方法中删除指定的Driver对象数组。以下是完整的代码示例。

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

            // 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 命名空间