Project Programmability

This blog focuses on customizations and programming for Project Web App, Project Server, Project Professional and Project Standard. Includes User Interface (UI) customizations, Project Server Interface (PSI) and Visual Basic for Applications (VBA) Programming. It also covers Business Intelligence.
 
 

July, 2007

  • Project Programmability and Business Intelligence

    VSTO Add-In Support for Project 2003 and Project 2007

    • 9 Comments

    I am very excited about the Visual Studio Beta 2 release, as it now has support for Project 2003 and Project 2007 add-ins! This makes coding and debugging managed code very easy in Project Client. It also makes it really simple to call into the PSI from Project Client to retrieve and update data on the server because you have the complete .Net framework at your disposal.

    You can download Visual Studio Beta 2 to try it out for yourself:

    http://msdn2.microsoft.com/en-us/vstudio/default.aspx

    I plan to do a few complex blog posts with regards to VSTO over the next couple of months, but to get started, here is a basic example:

    1. Download and install VS Beta 2 from: http://msdn2.microsoft.com/en-us/vstudio/default.aspx

    2. Open VS Beta 2 and Create a New Project selecting Project Add-in:

    image

    3. Give it a name and click OK

    4. Add a Windows Form called SimpleDemoForm to the project:

    image

    5. A label to the form called: lblProjectName

    6. In the ThisAddIn.cs class file add the following code in the startup method:

                SimpleDemoForm frmSimpleDemoForm = new SimpleDemoForm(Application);
                frmSimpleDemoForm.Show();

    This code will load and show the form we created in step 4. Note that we pass the Application into the form's constructor.

    7. View the code for the form and have it match the following:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using MSProject = Microsoft.Office.Interop.MSProject;
    
    namespace SimpleDemo
    {
        public partial class SimpleDemoForm : Form
        {
            private MSProject.Application Application;
    
            public SimpleDemoForm(MSProject.Application Application)
            {
                InitializeComponent();
                this.Application = Application;
            }
    
            private void SimpleDemoForm_Load(object sender, EventArgs e)
            {
                lblProjectName.Text = Application.ActiveProject.Name;
            }
        }
    }

    Couple of things to note with this code sample. We have referenced Microsoft.Office.Interop.MSProject and we have passed the Application variable to the form so that we can manipulate the project in the same way we can manipulate it in VBA. In the form load method, we read the project name and show it on the form.

    8. Build and run the application.

    This should launch Project automatically and load the add-in for you, with no configuration work involved. You can also add any debug breaks to troubleshoot your code.

    Here is what you should see when you build and run the add-in:

    image

    Chris Boyd

  • Project Programmability and Business Intelligence

    Checked Out Resources

    • 0 Comments

    Phil Smail has this great code snippet for providing better error handling with regards to checked out resources:

    While working with the PSI I wanted to check out a number of resources. Obviously the situation can arise where some of those resources are already checked out and I wanted to report that information to the client.

    Unfortunately the PSClientError object only gives you information that there were resources already checked out but not which ones were checked out. The data is contained with the XML for the Exception so I wrote a helper function to extract this information out

    The output from the code looks like the following:

    The code is as follows:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Net;
    using System.Web.Services.Protocols;
    using System.Xml;
    
    namespace GetError
    {
        class Program
        {
            private const string RESOURCESWEBSERVICE = "/_vti_bin/PSI/Resource.asmx";
            static GetError.ResourceWsc.Resource Resource = new GetError.ResourceWsc.Resource();
    
    
            static void Main(string[] args)
            {
                String PWAURL = args[0];
                Resource.Url = PWAURL + RESOURCESWEBSERVICE;
                Resource.Credentials = CredentialCache.DefaultCredentials;
                Guid[] restypeGuids = new Guid[2];
                //Change these GUIDS to res Guids in your system
                restypeGuids[0] = new Guid("{f461c3f7-e0c9-414f-ae1a-41abe862f709}");
                restypeGuids[1] = new Guid("{4e5d7702-7748-4a18-bc5d-7beef7004188}");
    
                Console.WriteLine("Trying to check out resources");
    
                try
                {
                    Resource.CheckOutResources(restypeGuids);
                }
                catch (SoapException ex)
                {
                    String tempxml = ex.Detail.InnerXml;
                    ExtractError(tempxml);
                }
                Console.ReadLine();
            }
    
            static void ExtractError(String xmlstr)
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xmlstr);
                foreach (XmlNode node in doc.DocumentElement.FirstChild.ChildNodes)
                {
                    String ErrString = "";
                    if(node.Name.Equals("item"))
                    {
                        //We know its one error
                        XmlNode n = node.Attributes.GetNamedItem("value");
                        ErrString = "Error: Resource - " + n.Value;
                        XmlNode childn = node.FirstChild;
                        if (childn.Name.Equals("error"))
                        {
                            XmlNode no = childn.Attributes.GetNamedItem("name");
    
                            switch (no.Value)
                            {
                            case "CICOAlreadyCheckedOutToYou":
                                ErrString += " Resource already checked out to you";
                                break;
                            case "CICOCheckedOutInOtherSession":
                                ErrString += " Resource checked out in another session";
                                break;
                            case "CICOCheckedOutToOtherUser":
                                ErrString += " Resource already checked out to another user";
                                break;
                            }      
                        }
                    }
                    Console.WriteLine(ErrString);
                }
            }
        }
    }
    
    
  • Project Programmability and Business Intelligence

    SDK Update

    • 0 Comments

    There is an updated version of the Project SDK:

     

    Project 2007 SDK online 

    Project 2007 SDK download

     

    New and updated topics since last April's release include:

    ·         Task Start and Finish Dates

    ·         Extending the Project Workspace Template

    ·         SetAssignmentWorkData Schema Reference

    ·         Changes for Custom Project Guides (additional information for deployment)

    ·         Using the Project.Open Event

     

    In addition, there is more information and examples for the Queue and the event receiver methods, along with several documentation bug fixes in other PSI reference topics.

     

    The download also includes an updated XML schema reference for Project Standard and Project Professional (mspdi_pj12.xsd), and a redistribution license for the Microsoft.Office.Project.Server.Library.dll assembly.

Page 1 of 1 (3 items)
Recent Posts