Exposing

 

 

1)      Naming convention:  To expose only a “hostType” type name instead of “hostTypeEntryPoint” type name the following convention was used.  An alternative to this naming convention would be to move the original “hostType” class to a new namespace.       

 

  

Original Name

OriginalScope

Updated Name

UpdatedScope

Inheritance

Application

Public

Host Application

Internal

global::System.MarshalByRefObject

ApplicationEntryPoint

Public

Application

Public

global::Microsoft.VisualStudio.Tools.Applications.Runtime.IEntryPoint

hostTypeX

Public

Host        

hostTypeX

Internal

global::System.MarshalByRefObject

hostTypeXEntryPoint

Public

hostTypeX

Public

global::Microsoft.VisualStudio.Tools.Applications.Runtime.IEntryPoint

                                  

 

 

 

 

 

 

 

2)      IShape:   Because the IShape interface uses two methods which return an IShape (IShape.Clone and IShape.Load) which is not associated with an object traceable back to the host through the SerivceProvider, this type is still exposed to add-ins (as Host_IShape).  There may be a workaround for this. 

 

3)      Collections:  Collections such as the DrawingCollection and ShapeCollection are maintained by using collections both on the host side and on the proxy side.  When working with collections, some actions need to be carried out on both the host and proxy collections (Example:  Add, Remove) while other actions may be carried out on either (this[index], contains).  In this sample the proxy side collection hooks into host side events, such as itemAdded and itemRemoved, to keep the collections in sync, then uses the proxy collection for calls whenever possible.  However, you may want to resolve these calls through the host instead.

Example from the DrawingCollection (originally named DrawingCollectionEntryPoint) class:

public virtual void Add(global::Microsoft.VisualStudio.Tools.Applications.Samples.ShapeApp.Drawing drawing)

{

    //this.RemoteObject.Add(drawing);

   

    //add the drawing to the host collection

    this.Host_DrawingCollection.Add(drawing.Host_Drawing);

 

    //add the drawing to the proxy collection

    this.drawingEntryPointList.Add(drawing);           

}

public virtual bool Contains(global::Microsoft.VisualStudio.Tools.Applications.Samples.ShapeApp.Drawing value)

{

    //original code

    //return this.RemoteObject.Contains(value);

 

    //use the internal List<Drawing>- resolve the call using the proxy collectoin

    return this.drawingEntryPointList.Contains(value);

 

    //alternative- resolve the call using the host collection

    //return this.RemoteObject.Contains(value.Host_Drawing);

}

 

4)      Static methods:  Static methods originally implemented in the original “hostType” proxy code are in the current “hostType” (updated from “hostTypeEntryPoint”).  When moving statics, be sure to use the original “hostType” (updated to “Host_hostType”) type when going through the HTMP.

Example from the Application (originally named ApplicationEntryPoint) class:

        public static string Description

        {

            get

            {

                object[] _param = new object[0];

                string retVal_param;

                if ((global::Microsoft.VisualStudio.Tools.Applications.Samples.ShapeApp.Application.@__vstaCacheDescription5 == null))

                {

                    if ((global::Microsoft.VisualStudio.Tools.Applications.Samples.ShapeApp.Application.remoteType == null))

                    {

                        //NOTE- using original Application (Host_Application) type at end to go through HTMP

                        global::Microsoft.VisualStudio.Tools.Applications.Samples.ShapeApp.Application.remoteType = global::Microsoft.VisualStudio.Tools.Applications.ProxyServices.Helper.ProxyHelper.hostTypeProvider.GetHostType( typeof(global::Microsoft.VisualStudio.Tools.Applications.Samples.ShapeApp.Host_Application));

                    }

                    global::Microsoft.VisualStudio.Tools.Applications.Samples.ShapeApp.Application.@__vstaCacheDescription5 = global::Microsoft.VisualStudio.Tools.Applications.Samples.ShapeApp.Application.remoteType.GetProperty("Description", (((global::System.Reflection.BindingFlags.Static | global::System.Reflection.BindingFlags.Public)

                                    | global::System.Reflection.BindingFlags.GetProperty)

                                    | global::System.Reflection.BindingFlags.Default), null, typeof(string), new global::System.Type[0], null);

                }

 

                retVal_param = ((string)(((global::System.Reflection.PropertyInfo)(global::Microsoft.VisualStudio.Tools.Applications.Samples.ShapeApp.Application.@__vstaCacheDescription5)).GetValue(null, _param)));

                return retVal_param;

            }

        }

 

5)      Methods not intended for add-in use:  Any methods not intended for add-ins use contained in the “hostTypeEntryPoint” classes (updated to “hostType”) are marked internal or use the [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)] attribute to hide the method from add-ins.  This does not work with methods which are included in an implemented interface, such as:

Microsoft.VisualStudio.Tools.Applications.Runtime.IEntryPoint.FinishInitialization()

Microsoft.VisualStudio.Tools.Applications.Runtime.IEntryPoint.InitializeDataBindings()

Microsoft.VisualStudio.Tools.Applications.Runtime.IEntryPoint.OnShutdown()

Microsoft.VisualStudio.Tools.Applications.Runtime.IExtendedEntryPoint.GetEntryPointObject()

Note- the original implementation of the proxy has “hostTypes” inherit MBRO which includes and exposes several unwanted methods (such as GetHashCode, GetLifetimeService, MemberwiseClone, …) which are no longer exposed.

 

Any type which exposes a generic of any kind or which a generic can be referenced through must follow the classEntryPoint scheme.  Once you start making remoting calls through the MBRO types instead of the VSTA.Runtime.IEntryPoint types you lost the ability to catch and modify the remoting in the proxy.  Making these changes makes the proxy much more like a VSTA v 1 proxy where all calls go through the proxy instead of taking advantage of the VSTA v 2 runtime.  It’s a lot of changes. 

 

 

 

 


Posted May 22 2009, 02:23 PM by BillL
Filed under: ,
Copyright Summit Software Company, 2008. All rights reserved.