ExtenderProvider.cs :  » Development » devAdvantage » AnticipatingMinds » DevAdvantageVSAddIn » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Development » devAdvantage 
devAdvantage » AnticipatingMinds » DevAdvantageVSAddIn » ExtenderProvider.cs
using System;
using System.Collections;
using System.Diagnostics;
using System.Runtime.InteropServices;
using EnvDTE;
using AnticipatingMinds.Genesis.KnowledgeManagement;

namespace AnticipatingMinds.DevAdvantageVSAddIn{
  /// <summary>
  /// Extender Provider object. This is the "class factory" for the Extender and is registered
  /// under the CATIDs of the solution objects (vsCATIDSolution and vsCATIDSolutionBrowseObject)
  /// it is extending. See SolutionExtender.reg for the registration entries.
  /// </summary>
  [ComVisibleAttribute(true)]
  [GuidAttribute("E480F8BD-8327-41EC-BBD4-637C21E57FE5")] 
  [ProgId("DevAdvantage.SolutionAndProjectExtenderProvider")]  
  public class ExtenderProvider : Object, IExtenderProvider
  {
    /// <summary>
    /// Constructor does nothing special.
    /// </summary>
    public ExtenderProvider(_DTE applicationObject,KnowledgeBase knowledgeBase)
    {
      this.knowledgeBase = knowledgeBase;
      this.applicationObject = applicationObject;
    }

    //IExtenderProvider implementation

    /// <summary>
    /// Implementation of IExtenderProvider::CanExtend.
    /// </summary>
    /// <param name="ExtenderCATID">CATID of the object being extended.</param>
    /// <param name="ExtenderName">Name of the Extension.</param>
    /// <param name="ExtendeeObject">Object being extended.</param>
    /// <returns>true if can provide an extender for Extendee Object, false otherwise.</returns>
    public bool CanExtend(string ExtenderCATID, string ExtenderName, object ExtendeeObject)
    {
      //Extends the solution automation and browseobject unconditionally. 
      //The extension name is given by SlnAutExtension ("SolutionMisc").
      if(ExtenderName.ToUpper() != SolutionExtenderName.ToUpper() && ExtenderName.ToUpper() != ProjectExtenderName.ToUpper())
        return false;

      if (ExtenderCATID.ToUpper() == EnvDTE.Constants.vsCATIDSolutionBrowseObject.ToUpper())
        return true;

      if (ExtenderCATID.ToUpper() == EnvDTE.Constants.vsCATIDSolution.ToUpper())
        return true;

      if (ExtenderCATID.ToUpper() == DevAdvantage.CSharpProjectCATID_GUID.ToUpper())
        return true;

      if (ExtenderCATID.ToUpper() == VSLangProj.PrjCATID.prjCATIDProject.ToUpper())
        return true;

      return false;
    }

    /// <summary>
    /// Implementation of IExtenderProvider::GetExtender.
    /// </summary>
    /// <param name="ExtenderCATID">CATID of the object being extended.</param>
    /// <param name="ExtenderName">Name of the Extension.</param>
    /// <param name="ExtendeeObject">Object being extended.</param>
    /// <param name="ExtenderSite">Site object for the Extender.</param>
    /// <param name="cookie">Cookie value that identifies the Extender to its Site.</param>
    /// <returns>A newly created Extender object.</returns>
    public object GetExtender(string ExtenderCATID, string ExtenderName, object ExtendeeObject, EnvDTE.IExtenderSite ExtenderSite, int Cookie)
    {
      object extender = null; //In case of failure.
      if(servicedExtenders.Contains(ExtendeeObject))
        return servicedExtenders[ExtendeeObject];

      if (CanExtend(ExtenderCATID, ExtenderName, ExtendeeObject))
      {
        if (((ExtenderCATID.ToUpper() == EnvDTE.Constants.vsCATIDSolutionBrowseObject.ToUpper()) ||
          (ExtenderCATID.ToUpper() == EnvDTE.Constants.vsCATIDSolution.ToUpper())) &&
          ExtenderName.ToUpper() == SolutionExtenderName.ToUpper())
        {
          Solution solution = ExtendeeObject as Solution;
          if (solution == null)
          {
            //Extending the Soltuion browse object (the object that's displayed
            //in the property browser when the Solution Node is selected in
            //the Solution Explorer). In this case, get the DTE.Solution object
            //directly from the object model.
            EnvDTE.DTE root = (EnvDTE.DTE) ExtenderSite.GetObject("");
            solution = root.Solution;
          }
            
          if (solution != null)
          {
            //Init our extender.
            extender = new SolutionExtender(solution,knowledgeBase,Cookie,ExtenderSite);
          }
        }
        else
        {
          //Extending the project
          VSLangProj.ProjectProperties projectProperties = ExtendeeObject as VSLangProj.ProjectProperties;
          foreach(Project project in applicationObject.Solution.Projects)
          {
            Project extendedProject = FindProject(project,projectProperties.__id);
            if(extendedProject != null)
            {
              extender = new ProjectExtender(extendedProject,knowledgeBase,Cookie,ExtenderSite);
              break;
            }
          }
        }
      }

      return extender;
    }

    private Project FindProject(Project rootProject,string targetedProjectId)
    {
      string projectId = string.Empty;
      //Some etp projects hate Name property and throw exception. 
      //just ignore it, we are more intrested in their sub projects than in them itself
      try
      {
        projectId = rootProject.Name;
      }
      catch(Exception)
      {
      }

      //Is it us?
      if(projectId == targetedProjectId)
        return rootProject;

      if(rootProject.ProjectItems != null)
      {
        foreach(ProjectItem projectItem in rootProject.ProjectItems)
        {
          Project subProject = projectItem.SubProject;
          if(subProject != null)
          {
            Project foundProject = FindProject(subProject,targetedProjectId);
            if(foundProject != null)
              return foundProject;
          }
        }
      }

      return null;
    }

    /// <summary>
    /// The Extension name for this Extender.
    /// </summary>
    internal static string SolutionExtenderName = "DevAdvantageSolutionExtenderProvider";
    internal static string ProjectExtenderName = "DevAdvantageProjectExtenderProvider";
    private KnowledgeBase knowledgeBase;
    private Hashtable servicedExtenders = new Hashtable();
    private _DTE applicationObject;
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.