Keeping a DPM Add-in Project in Sync with its Associated Document

When working with a Dynamic Programming Model (DPM) style integration, it is important to keep the DPM add-in project in sync with the associated host document.  There are two items which must be kept in sync:  the DPM add-in project host item code files and the host's entry point list.  There are several times in which these items needs to be updated including when a host item is added, removed, or renamed.  In the SDK sample ShapeAppDynamicProgrammingModelCSharp the add-in project code files are updated; however, the list of entry points managed on the host side is not updated until a successful build of the add-in project.  This can cause the add-in project to become out of sync with the host document in some scenarios.  For example, if a host item is removed and the document is saved and closed without building the associated DPM add-in project, the result is an error when loading the DPM add-in project  when the document is re-opened.  Below is part a modified version of the VstaDesignTimeIntegration.cs file of the SDK DPM sample which demonstrates how to keep the entry point list in sync with the host document and add-in project.

Note, in the SDK sample ShapeAppDynamicProgrammingModelCSharp a host item is a Drawing and the entry point list is managed through an xml file (DocName.xml) included in the open xml ".msdx" file of a ShapeAppCSharp Document.

private void OnSuccessfulBuildDone()

   //UNCHANGED CODE REMOVED
   //moved to UpdateEntryPointList               
    //this.document.VstaRunTimeIntegration.EntryPointNameList.Clear(); 
   //this.document.VstaRunTimeIntegration.EntryPointNameToCookieMap.Clear(); 
   //// Need to execute the host operation from the main UI thread. 
   //AddEntryPointToDocument("ThisDocument"); 
   //foreach (Drawing drawing in this.document.Drawings) 
   //{ 
   //    AddEntryPointToDocument(drawing.Cookie); 
   //}

   //ADDED
   UpdateEntryPointList();   

   //UNCHANGED CODE REMOVED
}

//code taken from OnSuccessfulBuildDone
//needs to be run for any host item add/remove
private void UpdateEntryPointList()

    //clear the existing list of entry points 
    this.document.VstaRunTimeIntegration.EntryPointNameList.Clear(); 
    this.document.VstaRunTimeIntegration.EntryPointNameToCookieMap.Clear();     

    //Add the document then, each host item to the list of entry points 
    AddEntryPointToDocument("ThisDocument"); 
    foreach (Drawing drawing in this.document.Drawings) 
   
        AddEntryPointToDocument(drawing.Cookie); 
    }
 

//Entire method included for clarity
void Drawings_DrawingInserted(object sender, EventArgs e)

    Drawing drawing = (Drawing)sender; 
    AddDrawingProjectHostItem(drawing);

  //ADDED- Update the entry point list 
    UpdateEntryPointList();  
 

//Entire method included for clarity
void Drawings_DrawingRemoved(object sender, DrawingRemovedEventArgs e) 
 
     string cookie = e.RemovedDrawingCookie; 
     IVstaProjectHostItem item = this.hostAdapter.ProjectHostItems[cookie]; 
     if (item != null
         this.hostAdapter.ProjectHostItems.RemoveProjectHostItem(item);   

  //ADDED-  Update the entry point list 
     UpdateEntryPointList(); 
  

//Entire method included for clarity
private void AddEntryPointToDocument(string cookie)

    IVstaProjectHostItem projectHostItem = this.hostAdapter.ProjectHostItems[cookie]; 
    if (projectHostItem == null
   
        System.Diagnostics.Debug.Assert(false); 
        throw new InvalidOperationException("Cannot find the document ProjectHostItem"); 
   
    IVstaHostItem programmingModelHostItem = projectHostItem.ProgrammingModelHostItem; 

    string entryPointName = projectHostItem.FullyQualifiedNamespace + "." + programmingModelHostItem.Identifier;    
    this.document.VstaRunTimeIntegration.EntryPointNameList.Add(entryPointName); 
    this.document.VstaRunTimeIntegration.EntryPointNameToCookieMap.Add(entryPointName, cookie);
}

 


Posted Sep 20 2010, 10:24 AM by Melody
Copyright Summit Software Company, 2008. All rights reserved.