Partager via


PortfolioAnalyses.QueueCreateOptimizerSolution Method

Enqueues a request to create a solution using the unique identifier of the specified analysis result, the dataset which contains analysis constraints, and the unique identifier for the solution.

Namespace:  [PortfolioAnalyses Web service]
Service reference: http://ServerName:32843/[Project Service Application GUID]/PSI/PortfolioAnalyses.svc
Web service reference: http://ServerName/ProjectServerName/_vti_bin/PSI/PortfolioAnalyses.asmx?wsdl

Syntax

'Declaration
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/PortfolioAnalyses/QueueCreateOptimizerSolution", RequestNamespace := "https://schemas.microsoft.com/office/project/server/webservices/PortfolioAnalyses/",  _
    ResponseNamespace := "https://schemas.microsoft.com/office/project/server/webservices/PortfolioAnalyses/",  _
    Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Sub QueueCreateOptimizerSolution ( _
    analysisUid As Guid, _
    solutionDS As OptimizerSolutionDataSet, _
    jobUid As Guid _
)
'Usage
Dim instance As PortfolioAnalyses
Dim analysisUid As Guid
Dim solutionDS As OptimizerSolutionDataSet
Dim jobUid As Guid

instance.QueueCreateOptimizerSolution(analysisUid, _
    solutionDS, jobUid)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/PortfolioAnalyses/QueueCreateOptimizerSolution", RequestNamespace = "https://schemas.microsoft.com/office/project/server/webservices/PortfolioAnalyses/", 
    ResponseNamespace = "https://schemas.microsoft.com/office/project/server/webservices/PortfolioAnalyses/", 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public void QueueCreateOptimizerSolution(
    Guid analysisUid,
    OptimizerSolutionDataSet solutionDS,
    Guid jobUid
)

Parameters

Remarks

Project Server Permissions

Permission

Description

ManagePortfolioAnalyses

Allows a user to create portfolio analyses. New in Project Server 2010. Global permission.

Examples

The example uses the SvcPortfolioAnalyses namespace in the ProjectServerServices.dll proxy assembly. The ConfigClientEndpoints and the SetClientEndPoints method use 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.

Note

The following example is designed to illustrate the use of various PortfolioAnalyses methods; it is not a full solution The GUIDs are hardcoded for the necessary local project, drivers, driver prioritization, and so forth. To use the example, change the GUID values to match those in you test installation of Project Server 2010

The CreateOptimizerSolution method adds a SolutionRow object, a SolutionProjectsRow object, a SolutionConstraintsRow object and a SolutionConstraintValuesRow object to the SolutionDataSet; the application writes the XML contents to the OptimizerSolutionDataSet.xml file, as follows:

<?xml version="1.0" standalone="yes"?>
<OptimizerSolutionDataSet xmlns="https://schemas.microsoft.com/office/project
/server/webservices/OptimizerSolutionDataSet/">
<Solution>
<ANALYSIS_UID>37b6529a-75d8-4ab8-a597-d2c07256f7be
</ANALYSIS_UID>
<SOLUTION_UID>df499264-3640-44fd-b8a1-92b3e74a4bb5
</SOLUTION_UID>
<SOLUTION_NAME>Baseline</SOLUTION_NAME>
<HARD_CONSTRAINT_CF_UID>dc68b96a-965e-4b25-ac8a-15a5df729831
</HARD_CONSTRAINT_CF_UID>
<HARD_CONSTRAINT_CF_NAME>Sample Proposal Cost
</HARD_CONSTRAINT_CF_NAME>
<FRONTIER_UID>11c19e14-fa13-49a6-932c-2a9e222ef64a
</FRONTIER_UID>
<OPT_USE_DEPENDENCIES>true</OPT_USE_DEPENDENCIES>
<CREATED_DATE>2010-04-07T10:28:09.007-07:00</CREATED_DATE>
<MOD_DATE>2010-04-07T10:28:09.007-07:00</MOD_DATE>
<LAST_UPDATED_BY_RES_UID>4cde51d4-d636-4c54-94c3-0b55b00aa111
</LAST_UPDATED_BY_RES_UID>
<LAST_UPDATED_BY_RES_NAME>Shana</LAST_UPDATED_BY_RES_NAME>
<CREATED_BY_RES_UID>4cde51d4-d636-4c54-94c3-0b55b00aa111
</CREATED_BY_RES_UID>
<CREATED_BY_RES_NAME>Shana</CREATED_BY_RES_NAME>
<ANALYSIS_NAME>Analysis8e805fcc-385e-4f9c-92e7-68ca1cdd9a2b
</ANALYSIS_NAME>
</Solution>
<SolutionConstraints>
<SOLUTION_UID>df499264-3640-44fd-b8a1-92b3e74a4bb5
</SOLUTION_UID>
<MD_PROP_UID>dc68b96a-965e-4b25-ac8a-15a5df729831
</MD_PROP_UID>
<MD_PROP_NAME>Sample Proposal Cost</MD_PROP_NAME>
<MD_PROP_POS>0</MD_PROP_POS>
<MAX_VALUE>0.000000</MAX_VALUE>
</SolutionConstraints>
<SolutionConstraintValues>
<SOLUTION_UID>df499264-3640-44fd-b8a1-92b3e74a4bb5
</SOLUTION_UID>
<MD_PROP_UID>dc68b96a-965e-4b25-ac8a-15a5df729831
</MD_PROP_UID>
<PROJ_UID>c13feaeb-8a19-4f43-becd-44f43b1a82d9
</PROJ_UID>
<NUM_VALUE>0.000000</NUM_VALUE>
</SolutionConstraintValues>
<SolutionProjects>
<SOLUTION_UID>df499264-3640-44fd-b8a1-92b3e74a4bb5
</SOLUTION_UID>
<PROJ_UID>c13feaeb-8a19-4f43-becd-44f43b1a82d9
</PROJ_UID>
<PROJ_NAME>Project1</PROJ_NAME>
<PRIORITY>1</PRIORITY>
<ABSOLUTE_PRIORITY>4.75</ABSOLUTE_PRIORITY>
<STATUS>1</STATUS>
<FORCE_STATUS>2</FORCE_STATUS>
</SolutionProjects>
<SolutionStrategicAlignment>
<SOLUTION_UID>df499264-3640-44fd-b8a1-92b3e74a4bb5
</SOLUTION_UID>
<DRIVER_UID>cb75b3e4-4f7a-44a3-bae1-59061b44b156
</DRIVER_UID>
<DRIVER_NAME>Driver1</DRIVER_NAME>
<DRIVER_PRIORITY>0.75</DRIVER_PRIORITY>
<REVERSE_VALUE>0.000000</REVERSE_VALUE>
</SolutionStrategicAlignment>
<SolutionStrategicAlignment>
<SOLUTION_UID>df499264-3640-44fd-b8a1-92b3e74a4bb5
</SOLUTION_UID>
<DRIVER_UID>bc858049-d638-480b-8071-e5eabe995fe8
</DRIVER_UID>
<DRIVER_NAME>Driver2</DRIVER_NAME>
<DRIVER_PRIORITY>0.25</DRIVER_PRIORITY>
<REVERSE_VALUE>0.000000</REVERSE_VALUE>
</SolutionStrategicAlignment>
<SolutionEfficientFrontier>
<FRONTIER_UID>11c19e14-fa13-49a6-932c-2a9e222ef64a
</FRONTIER_UID>
<ANALYSIS_UID>37b6529a-75d8-4ab8-a597-d2c07256f7be
</ANALYSIS_UID>
<POINT_UID>c443d627-2259-4ba6-acf0-b8139e8d5713
</POINT_UID>
<X_VALUE>0.000000</X_VALUE>
<Y_VALUE>1.000000</Y_VALUE>
</SolutionEfficientFrontier>
<SolutionEfficientFrontier>
<FRONTIER_UID>11c19e14-fa13-49a6-932c-2a9e222ef64a
</FRONTIER_UID>
<ANALYSIS_UID>37b6529a-75d8-4ab8-a597-d2c07256f7be
</ANALYSIS_UID>
<POINT_UID>6e3d8a42-cbaf-4e97-833a-2bcdb367cd94
</POINT_UID>
<X_VALUE>0.000000</X_VALUE>
<Y_VALUE>1.000000</Y_VALUE>
</SolutionEfficientFrontier>
<SolutionEfficientFrontier>
<FRONTIER_UID>11c19e14-fa13-49a6-932c-2a9e222ef64a
</FRONTIER_UID>
<ANALYSIS_UID>37b6529a-75d8-4ab8-a597-d2c07256f7be
</ANALYSIS_UID>
<POINT_UID>fd13f215-7436-4622-a0c6-54fdbda45f76
</POINT_UID>
<X_VALUE>0.000000</X_VALUE>
<Y_VALUE>1.000000</Y_VALUE>
</SolutionEfficientFrontier>
<SolutionEfficientFrontier>
<FRONTIER_UID>11c19e14-fa13-49a6-932c-2a9e222ef64a
</FRONTIER_UID>
<ANALYSIS_UID>37b6529a-75d8-4ab8-a597-d2c07256f7be
</ANALYSIS_UID>
<POINT_UID>40333069-0d35-4044-a813-7d76304320cd
</POINT_UID>
<X_VALUE>0.000000</X_VALUE>
<Y_VALUE>1.000000</Y_VALUE>
</SolutionEfficientFrontier>
<SolutionEfficientFrontier>
<FRONTIER_UID>11c19e14-fa13-49a6-932c-2a9e222ef64a
</FRONTIER_UID>
<ANALYSIS_UID>37b6529a-75d8-4ab8-a597-d2c07256f7be
</ANALYSIS_UID>
<POINT_UID>9018ffe8-8673-4d1e-b6d1-cba387116290
</POINT_UID>
<X_VALUE>0.000000</X_VALUE>
<Y_VALUE>1.000000</Y_VALUE>
</SolutionEfficientFrontier>
<SolutionEfficientFrontier>
<FRONTIER_UID>11c19e14-fa13-49a6-932c-2a9e222ef64a
</FRONTIER_UID>
<ANALYSIS_UID>37b6529a-75d8-4ab8-a597-d2c07256f7be
</ANALYSIS_UID>
<POINT_UID>11f01cd7-9c14-47b7-a62f-825d7f05b7a2
</POINT_UID>
<X_VALUE>0.000000</X_VALUE>
<Y_VALUE>1.000000</Y_VALUE>
</SolutionEfficientFrontier>
<SolutionEfficientFrontier>
<FRONTIER_UID>11c19e14-fa13-49a6-932c-2a9e222ef64a
</FRONTIER_UID>
<ANALYSIS_UID>37b6529a-75d8-4ab8-a597-d2c07256f7be
</ANALYSIS_UID>
<POINT_UID>afbe69c7-a142-4e25-8983-5bf8250b1342
</POINT_UID>
<X_VALUE>0.000000</X_VALUE>
<Y_VALUE>1.000000</Y_VALUE>
</SolutionEfficientFrontier>
<SolutionEfficientFrontier>
<FRONTIER_UID>11c19e14-fa13-49a6-932c-2a9e222ef64a
</FRONTIER_UID>
<ANALYSIS_UID>37b6529a-75d8-4ab8-a597-d2c07256f7be
</ANALYSIS_UID>
<POINT_UID>5d583716-bb47-46ee-ac8e-3d342bc38d46
</POINT_UID>
<X_VALUE>0.000000</X_VALUE>
<Y_VALUE>1.000000</Y_VALUE>
</SolutionEfficientFrontier>
<SolutionEfficientFrontier>
<FRONTIER_UID>11c19e14-fa13-49a6-932c-2a9e222ef64a
</FRONTIER_UID>
<ANALYSIS_UID>37b6529a-75d8-4ab8-a597-d2c07256f7be
</ANALYSIS_UID>
<POINT_UID>68c55a6e-2c46-470e-83d9-a57ccce35185
</POINT_UID>
<X_VALUE>0.000000</X_VALUE>
<Y_VALUE>1.000000</Y_VALUE>
</SolutionEfficientFrontier>
<SolutionEfficientFrontier>
<FRONTIER_UID>11c19e14-fa13-49a6-932c-2a9e222ef64a
</FRONTIER_UID>
<ANALYSIS_UID>37b6529a-75d8-4ab8-a597-d2c07256f7be
</ANALYSIS_UID>
<POINT_UID>288f4466-663c-45c0-94ed-666d91cc86f2
</POINT_UID>
<X_VALUE>0.000000</X_VALUE>
<Y_VALUE>1.000000</Y_VALUE>
</SolutionEfficientFrontier>
<SolutionEfficientFrontier>
<FRONTIER_UID>11c19e14-fa13-49a6-932c-2a9e222ef64a
</FRONTIER_UID>
<ANALYSIS_UID>37b6529a-75d8-4ab8-a597-d2c07256f7be
</ANALYSIS_UID>
<POINT_UID>ac25e7c9-95f7-4385-a739-60c2badb1064
</POINT_UID>
<X_VALUE>0.000000</X_VALUE>
<Y_VALUE>1.000000</Y_VALUE>
</SolutionEfficientFrontier>
</OptimizerSolutionDataSet>

The complete sample code is as follows:

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;

// The following code requires one project, two drivers and a driver 
// prioritization to exist in the database. Change the values of all hard-coded
// GUIDs to match values in your instance.
// You can make the same logic work for more than one project by 
// adding a FOR -EACH loop.
namespace Microsoft.SDK.Project.Samples.Portfolio
{
    class PortFolio
    {
        private const string PROJECT_GUID = 
            "C13FEAEB-8A19-4F43-BECD-44F43B1A82D9";
        private const string DRIVER0_GUID = 
            "CB75B3E4-4F7A-44A3-BAE1-59061B44B156";
        private const string DRIVER1_GUID = 
            "BC858049-D638-480B-8071-E5EABE995FE8";
        private const string DRIVER_PRIORITIZATION_GUID =
            "9ADF2C29-D409-41EB-BC6C-6B7BFCDC0CAA";
        private const string ALT_PROJECT_STARTDATE_CF_GUID =
             "5B21E11D-0B2F-4D93-8995-F4A6625EB3EB";
        private const string ALT_PROJECT_ENDDATE_CF_GUID =
            "5B21E11D-0B2F-4D93-8995-F4A6625EB3EB";
        private const string HARD_CONSTRAINT_CF_GUID = 
            "DC68B96A-965E-4B25-AC8A-15A5DF729831";
        private const string MD_PROP_GUID = 
            "DC68B96A-965E-4B25-AC8A-15A5DF729831";
        private const string BINARY_USING_CF_PRIORITY_GUID =
             "C834DF36-6712-4891-92B0-FA6BFB5775FD";
        private const string GREATER_THAN_LOOKUPTABLE_VALUE =
            "426F8D32-6961-4B4B-91AB-705F0200F45E";
        private const string LESS_THAN_LOOKUPTABLE_VALUE =
            "779271C4-894D-4385-9E33-1251A9E80541";

        private const string ENDPOINT_PA = "basicHttp_PortfolioAnalyses";
        private const string ENDPOINT_Q = "basicHttp_QueueSystem";
        private const string OUTPUT_FILES = @"C:\Projects\Samples\Output\";
        private static string outFilePathAnalysisDS;
        private static string outFilePathUpdatedAnalysisInfo;
        private static string outFilePathOptimizerDS;

        private static SvcPortfolioAnalyses.PortfolioAnalysesClient analysesClient;
        private static SvcQueueSystem.QueueSystemClient queueSystemClient;
        
        static void Main(string[] args)
        {
            DateTime startTime = DateTime.Now;

            // Configure the end points.
            ConfigClientEndpoints(ENDPOINT_PA);
            SetClientEndpoints(ENDPOINT_Q);

            // If output directory does not exist,create it.
            if (!Directory.Exists(OUTPUT_FILES))
            {
                Directory.CreateDirectory(OUTPUT_FILES);
            }
            outFilePathAnalysisDS = OUTPUT_FILES + "AnalysisDataSet.xml";
            outFilePathUpdatedAnalysisInfo = OUTPUT_FILES + "UpdatedAnalysisInfo.xml";
            outFilePathOptimizerDS = OUTPUT_FILES + "OptimizerSolutionDS.xml";

            // Create the Portfolio Analysis DataSet.
            SvcPortfolioAnalyses.AnalysisDataSet portfolioAnalysisDS =
                new SvcPortfolioAnalyses.AnalysisDataSet();
            Guid analysis_uid;
            Guid[] numDrivers;
            Guid jobGuid;

            // Create analysis.
            CreateAnalysis(portfolioAnalysisDS,
                out analysis_uid,
                out numDrivers,
                out jobGuid);

            // Read analysis.
            SvcPortfolioAnalyses.AnalysisDataSet analysisDSAfterAdd =
                analysesClient.ReadAnalysis(analysis_uid);

            // Write the DataSet contents to an XML file.
            analysisDSAfterAdd.WriteXml(outFilePathAnalysisDS);

            // Update the Portfolio Analysis.
            analysisDSAfterAdd = UpdateAnalysis(analysis_uid,
                numDrivers, jobGuid, analysisDSAfterAdd);

            // Create the Optimizer Solution.
            CreateOptimizerSolution(analysis_uid,
                analysisDSAfterAdd);

        }

        // Creates the Optimizer Solution.
        private static void CreateOptimizerSolution(Guid analysis_uid,
            SvcPortfolioAnalyses.AnalysisDataSet analysisDSAfterAdd)
        {
            // Create the Optimizer Solution DataSet.
            SvcPortfolioAnalyses.OptimizerSolutionDataSet solutionDS =
                new SvcPortfolioAnalyses.OptimizerSolutionDataSet();
            SvcPortfolioAnalyses.OptimizerSolutionDataSet.SolutionRow
                solutionRow =
                solutionDS.Solution.NewSolutionRow();
            Guid solutionGuid = Guid.NewGuid();
            string solutionName = "Baseline";
            solutionRow.ANALYSIS_UID = analysis_uid;
            solutionRow.SOLUTION_UID = solutionGuid;
            solutionRow.SOLUTION_NAME = solutionName;
            solutionRow.OPT_USE_DEPENDENCIES = true;  // The default is true.
            solutionDS.Solution.AddSolutionRow(solutionRow);

            // Populate DecisionsTable with projects and force-in/force-out status
            // and PrioritiesTable with projects and project priority.
            foreach (SvcPortfolioAnalyses.AnalysisDataSet.AnalysisProjectsRow
                projRow in
                analysisDSAfterAdd.AnalysisProjects.Rows)
            {
                SvcPortfolioAnalyses.OptimizerSolutionDataSet.SolutionProjectsRow
                     solutionsProjectsRow =
                     solutionDS.SolutionProjects.NewSolutionProjectsRow();

                solutionsProjectsRow.SOLUTION_UID =
                    solutionDS.Solution[0].SOLUTION_UID;
                solutionsProjectsRow.PROJ_UID = projRow.PROJ_UID;

                // Leave decision to the optimization (Auto = 2).
                solutionsProjectsRow.FORCE_STATUS = (byte)PSLibrary.Optimizer.ForceStatus.Auto;
                solutionDS.SolutionProjects.AddSolutionProjectsRow(
                    solutionsProjectsRow);
            }

            // Populate SolutionConstraintValuesDataTable with custom field 
            // Guid/Value pairs for each project.
            Decimal constraintTotal = 0;
            int num_value = 0;
                        
            SvcPortfolioAnalyses.OptimizerSolutionDataSet.SolutionConstraintsRow
                solutionConstraintsRow =
                solutionDS.SolutionConstraints.NewSolutionConstraintsRow();
            solutionConstraintsRow.SOLUTION_UID =
                solutionDS.Solution[0].SOLUTION_UID;
            solutionConstraintsRow.MD_PROP_UID = new Guid(MD_PROP_GUID);
            solutionConstraintsRow.MD_PROP_POS = 0;
            solutionConstraintsRow.MAX_VALUE = constraintTotal;
            solutionDS.SolutionConstraints.AddSolutionConstraintsRow(
                solutionConstraintsRow);

            foreach (SvcPortfolioAnalyses.AnalysisDataSet.AnalysisProjectsRow
                projRow in
                analysisDSAfterAdd.AnalysisProjects.Rows)
            {
                SvcPortfolioAnalyses.OptimizerSolutionDataSet.
                    SolutionConstraintValuesRow
                    solutionConstraintValuesRow =
                    solutionDS.SolutionConstraintValues.
                    NewSolutionConstraintValuesRow();
                solutionConstraintValuesRow.SOLUTION_UID =
                    solutionDS.Solution[0].SOLUTION_UID;
                solutionConstraintValuesRow.MD_PROP_UID = new Guid(MD_PROP_GUID);
                solutionConstraintValuesRow.PROJ_UID = projRow.PROJ_UID;

                constraintTotal += solutionConstraintValuesRow.NUM_VALUE =
                    Convert.ToDecimal(num_value);
                solutionDS.SolutionConstraintValues.
                    AddSolutionConstraintValuesRow(
                    solutionConstraintValuesRow);
            }
            Guid jobUid = Guid.NewGuid();
            try
            {
                // Create the Optimizer Solution.
                analysesClient.QueueCreateOptimizerSolution(
                    analysis_uid, solutionDS, jobUid);
                Helpers.WaitForQueue(SvcQueueSystem.QueueMsgType.
                    OptimizerSolutionCreate,
                    1, queueSystemClient, jobUid);
                Console.WriteLine("Optimizer solution created successfully.");
            }
            catch (CommunicationException e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(
                    "\n***System.ServiceModel.CommunicationException:");
                Console.WriteLine(e.ToString());
                Console.ResetColor();
            }

            // Read the contents of the Optimizer Solution DataSet.
            SvcPortfolioAnalyses.OptimizerSolutionDataSet
                optimizerSolutionDS =
                analysesClient.ReadOptimizerSolution(solutionGuid);
            optimizerSolutionDS.WriteXml(outFilePathOptimizerDS);

            // Commit Optimizer Solution.
            analysesClient.CommitOptimizerSolution(solutionGuid);
            Console.WriteLine("Optimizer solution committed.");
            Console.Read();
        }

        // Create the Portfolio Analysis.
        private static void CreateAnalysis(
            SvcPortfolioAnalyses.AnalysisDataSet portfolioAnalysisDS,
            out Guid analysis_uid,
            out Guid[] numDrivers,
            out Guid jobGuid)
        {
            string analysisName = "Analysis" + Guid.NewGuid();
            analysis_uid = Guid.NewGuid();
            Guid PROJECT_IMPACT_MD_PROP_UID = 
                PSLibrary.CustomField.PROJECT_IMPACT_MD_PROP_UID;
                
            Guid RoleCFGuid = 
                PSLibrary.CustomField.COST_TYPE_MD_PROP_UID;
            numDrivers = new Guid[2];
            numDrivers[0] = new Guid(DRIVER0_GUID);
            numDrivers[1] = new Guid(DRIVER1_GUID);

            int prioritizationType = (int)PSLibrary.Optimizer.PrioritizationType.BinaryUsingPrioritization;
            int analysisType = (int)PSLibrary.Optimizer.AnalysisType.Cost_and_Schedule;

            int binaryUsingPrioritizationPrioType =
                (int)PSLibrary.Optimizer.AnalysisType.Cost;

            // If the prioritization is not a driver prioritization, then impactGuid should be null.
            object impactGuid = null;

            if (prioritizationType == binaryUsingPrioritizationPrioType)
                impactGuid = PROJECT_IMPACT_MD_PROP_UID;

            SvcPortfolioAnalyses.AnalysisDataSet.AnalysisRow analysisRow =
                portfolioAnalysisDS.Analysis.NewAnalysisRow();
            analysisRow.ANALYSIS_NAME = analysisName;
            analysisRow.ANALYSIS_UID = analysis_uid;
            analysisRow.ANALYSIS_TYPE = analysisType;
            analysisRow.PRIORITIZATION_TYPE = prioritizationType;
            analysisRow.PRIORITIZATION_UID = new Guid(DRIVER_PRIORITIZATION_GUID);
            analysisRow.ROLE_CUSTOM_FIELD_UID = RoleCFGuid;
            analysisRow.PROJECT_IMPACT_CF_UID = new Guid(impactGuid.ToString());
            analysisRow.ALT_PROJ_START_DATE_CF_UID = new Guid(ALT_PROJECT_STARTDATE_CF_GUID);
            analysisRow.ALT_PROJ_END_DATE_CF_UID = new Guid(ALT_PROJECT_ENDDATE_CF_GUID);
            analysisRow.HORIZON_START_DATE = new DateTime(2010, 1, 1);
            analysisRow.HORIZON_END_DATE = new DateTime(2011, 1, 31);
            analysisRow.TIME_SCALE = (int)PSLibrary.TimeScaleClass.TimeScale.Months;
            analysisRow.BOOKING_TYPE = (int)PSLibrary.Resource.BookingType.Committed;
            analysisRow.HARD_CONSTRAINT_CF_UID = new Guid(HARD_CONSTRAINT_CF_GUID);

            portfolioAnalysisDS.Analysis.AddAnalysisRow(analysisRow);

            // Add a project to the Portfolio Analysis.
            SvcPortfolioAnalyses.AnalysisDataSet.AnalysisProjectsRow
                projectsRow =
                portfolioAnalysisDS.AnalysisProjects.NewAnalysisProjectsRow();

            projectsRow.ANALYSIS_UID = analysis_uid;
            projectsRow.PROJ_UID = new Guid(PROJECT_GUID);
            portfolioAnalysisDS.AnalysisProjects.AddAnalysisProjectsRow(
                projectsRow);

            Console.WriteLine("Creating analysis.....");
            jobGuid = Guid.NewGuid();

            try
            {
                analysesClient.QueueCreateAnalysis(portfolioAnalysisDS,
                    jobGuid);
                Helpers.WaitForQueue(SvcQueueSystem.QueueMsgType.AnalysisCreate,
                    1, queueSystemClient, jobGuid);
                Console.WriteLine("Analysis created successfully");
            }
            catch (CommunicationException e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(
                    "\n***System.ServiceModel.CommunicationException:");
                Console.WriteLine(e.ToString());
                Console.ResetColor();
            }
        }

        // Update the strategic impact data of a Portfolio Analysis.
        private static SvcPortfolioAnalyses.AnalysisDataSet UpdateAnalysis(
            Guid analysis_uid,
            Guid[] numDrivers,
            Guid jobGuid,
            SvcPortfolioAnalyses.AnalysisDataSet analysisDSAfterAdd)
        {
            // Update the impact values and update the analysis.

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

            // Represents the "greater than" relationship.
            lookUpTableValues[0] =
                new Guid(GREATER_THAN_LOOKUPTABLE_VALUE);
            // Represents the "less than" relationship.
            lookUpTableValues[1] =
                new Guid(LESS_THAN_LOOKUPTABLE_VALUE);  // is <
            SvcPortfolioAnalyses.AnalysisDataSet.AnalysisProjectImpactRow
                relationRow = null;

            // If there is more than one project, do the following for all the projects.
            for (int j = 0; j < numDrivers.Count(); j++)
            {
                relationRow =
                    analysisDSAfterAdd.AnalysisProjectImpact.
                    NewAnalysisProjectImpactRow();
                relationRow.ANALYSIS_UID = analysis_uid;
                relationRow.LT_STRUCT_UID = lookUpTableValues[j];
                relationRow.PROJ_UID = new Guid(PROJECT_GUID);
                relationRow.DRIVER_UID = numDrivers[j];
                analysisDSAfterAdd.AnalysisProjectImpact.
                    AddAnalysisProjectImpactRow(
                    relationRow);
            }
            try
            {
                Console.WriteLine("Updating the analysis....");
                analysesClient.QueueUpdateAnalysis(analysisDSAfterAdd,
                    false, updateJobGuid);
                Helpers.WaitForQueue(SvcQueueSystem.QueueMsgType.AnalysisUpdate,
                    1, queueSystemClient, updateJobGuid);
                Console.WriteLine("Analysis updated successfully...");
            }
            catch (CommunicationException e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(
                    "\n***System.ServiceModel.CommunicationException:");
                Console.WriteLine(e.ToString());
                Console.ResetColor();
            }
            // Read the updated Portfolio Analysis.
            SvcPortfolioAnalyses.AnalysisDataSet analysisDSAfterUpdate =
                analysesClient.ReadAnalysis(analysis_uid);
            analysisDSAfterUpdate.WriteXml(outFilePathUpdatedAnalysisInfo);
            return analysisDSAfterUpdate;
        }

        // Configure the custom field client end points.
        public static void ConfigClientEndpoints(string endpt)
        {
            analysesClient = new SvcPortfolioAnalyses.PortfolioAnalysesClient(endpt);
        }
        // Configure the client end points.
        public static void SetClientEndpoints(string qendpt)
        {
            queueSystemClient = new SvcQueueSystem.QueueSystemClient(qendpt);
        }
    }

    class Helpers
    {
        /// <summary>
        /// Public TimeOut property
        /// </summary>
        /// <value>Gets/sets the timeout for WaitForQueue calls</value>
        public static int TimeOut
        {
            get
            {
                return timeOut;
            }
            set
            {
                timeOut = value;
            }
        }
        // Default time out is 3 minutes.
        private static int timeOut = 3 * 60 * 1000;

        // Incremental sleep time is 2 seconds.
        private static int incrementalSleepTime = 2 * 1000;

        public static SvcQueueSystem.JobState WaitForQueue(SvcQueueSystem.QueueMsgType jobType, int numJobs,
            SvcQueueSystem.QueueSystemClient queueSystemClient, Guid jobId)
        {
            int timeSlept = 0;
            int sleepInterval = (TimeOut / 60 > incrementalSleepTime) ? TimeOut / 60 : incrementalSleepTime;

            SvcQueueSystem.QueueStatusDataSet queueStatusDs = new SvcQueueSystem.QueueStatusDataSet();
            String errorString = String.Empty;
            Console.WriteLine("Waiting for job" + jobType.ToString());
            while (true)
            {
                SvcQueueSystem.JobState jobState = queueSystemClient.GetJobCompletionState(out errorString, jobId);

                SvcQueueSystem.QueueStatusDataSet jobStatus = queueSystemClient.ReadJobStatusSimple(new Guid[] { jobId }, true);
                if (jobState == SvcQueueSystem.JobState.Unknown)
                {
                    string jobStatusInfo = "Job status is unknown.";
                    jobStatusInfo += "\n\tWas the job placed on the Queue?";
                    jobStatusInfo += "\n\t--returning from WaitForQueue.";
                    Console.WriteLine(jobStatusInfo);
                    return jobState;
                }
                if (jobState == SvcQueueSystem.JobState.Success ||
                    jobState == SvcQueueSystem.JobState.Failed ||
                    jobState == SvcQueueSystem.JobState.FailedNotBlocking ||
                    jobState == SvcQueueSystem.JobState.CorrelationBlocked ||
                    jobState == SvcQueueSystem.JobState.Canceled)
                {
                    Console.WriteLine("Job completed, returning from WaitForQueue");
                    return jobState;
                }
                System.Threading.Thread.CurrentThread.Join(sleepInterval);
                timeSlept += sleepInterval;

                if (timeSlept > TimeOut)
                {
                    return SvcQueueSystem.JobState.Unknown;
                }
            }

        }

    }
}

See Also

Reference

PortfolioAnalyses Class

PortfolioAnalyses Members

PortfolioAnalyses Web Service