Connect.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 » Connect.cs
using System;
using System.Diagnostics;
using System.Reflection;
using Microsoft.Office.Core;
using Extensibility;
using System.Runtime.InteropServices;
using EnvDTE;
using AnticipatingMinds.PlatformServices.ErrorReporting;

namespace AnticipatingMinds.DevAdvantageVSAddIn{
  #region Read me for Add-in installation and setup information.
  // When run, the Add-in wizard prepared the registry for the Add-in.
  // At a later time, if the Add-in becomes unavailable for reasons such as:
  //   1) You moved this project to a computer other than which is was originally created on.
  //   2) You chose 'Yes' when presented with a message asking if you wish to remove the Add-in.
  //   3) Registry corruption.
  // you will need to re-register the Add-in by building the MyAddin21Setup project 
  // by right clicking the project in the Solution Explorer, then choosing install.
  #endregion
  
  /// <summary>
  ///   The object for implementing an Add-in.
  /// </summary>
  /// <seealso class='IDTExtensibility2' />
  [ComVisibleAttribute(true)]
  [GuidAttribute("73A2204F-62E5-4770-9F7F-DB3094C8B27B"), ProgId("DevAdvantageVSAddIn.Connect")]
  public class Connect : Object, Extensibility.IDTExtensibility2, IDTCommandTarget
  {
    /// <summary>
    ///    Implements the constructor for the Add-in object.
    ///    Place your initialization code within this method.
    /// </summary>
    public Connect()
    {
      AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
    }

    /// <summary>
    ///      Implements the OnConnection method of the IDTExtensibility2 interface.
    ///      Receives notification that the Add-in is being loaded.
    /// </summary>
    /// <param term='application'>
    ///      Root object of the host application.
    /// </param>
    /// <param term='connectMode'>
    ///      Describes how the Add-in is being loaded.
    /// </param>
    /// <param term='addInInst'>
    ///      Object representing this Add-in.
    /// </param>
    /// <seealso class='IDTExtensibility2' />
    public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
    {
      try
      {
        applicationObject = (_DTE)application;
        addInInstance = (AddIn)addInInst;

        //Check that KB exists
        if(connectMode == Extensibility.ext_ConnectMode.ext_cm_Startup || 
          connectMode == Extensibility.ext_ConnectMode.ext_cm_AfterStartup || 
          connectMode == Extensibility.ext_ConnectMode.ext_cm_Solution)
        {
          try
          {
            if(devAdvantage == null && AnticipatingMinds.Genesis.KnowledgeManagement.KnowledgeBase.OpenKnowledgeBase("DevAdvantage") == null)
            {
              System.Windows.Forms.MessageBox.Show(DevAdvantage.GetLocalizedString("KnowledgeBaseIsMissingMessage"),DevAdvantage.GetLocalizedString("KnowledgeBaseIsMissingTitle"));
              return;
            }
          }
          catch(System.Xml.XmlException)
          {
            System.Windows.Forms.MessageBox.Show(DevAdvantage.GetLocalizedString("KnowledgeBaseFileFormatIsInvalid"),DevAdvantage.GetLocalizedString("KnowledgeBaseIsMissingTitle"));
            return;
          }
        }


        if(devAdvantage == null)
          devAdvantage = new DevAdvantage(applicationObject,addInInstance);

        if(connectMode == Extensibility.ext_ConnectMode.ext_cm_Startup || 
          connectMode == Extensibility.ext_ConnectMode.ext_cm_AfterStartup || 
          connectMode == Extensibility.ext_ConnectMode.ext_cm_Solution)
        {
          devAdvantage.InitializeAssemblyResolution();
          devAdvantage.BuildMenus();
          //devAdvantage.BuildToolbar();
          devAdvantage.InitializeExtenders();
          devAdvantage.CreateRulesExplorer();
          devAdvantage.CreateAnalysisResults();
        }

      }
      catch(Exception e)
      {
        //TODO: Pass Serial Number of product here!
        ExceptionsManager.ReportUnhandledException(e,"devAdvantage"); //Get the srial Number here!
      }
    }

    /// <summary>
    ///     Implements the OnDisconnection method of the IDTExtensibility2 interface.
    ///     Receives notification that the Add-in is being unloaded.
    /// </summary>
    /// <param term='disconnectMode'>
    ///      Describes how the Add-in is being unloaded.
    /// </param>
    /// <param term='custom'>
    ///      Array of parameters that are host application specific.
    /// </param>
    /// <seealso class='IDTExtensibility2' />
    public void OnDisconnection(Extensibility.ext_DisconnectMode disconnectMode, ref System.Array custom)
    {
      if(devAdvantage == null)
        return;

      try
      {
        if(disconnectMode == Extensibility.ext_DisconnectMode.ext_dm_HostShutdown || 
          disconnectMode == Extensibility.ext_DisconnectMode.ext_dm_UserClosed || 
          disconnectMode == Extensibility.ext_DisconnectMode.ext_dm_SolutionClosed)
        {
          devAdvantage.DeinitializeExtenders();
          devAdvantage.SaveUserSettigs();
          devAdvantage.TearDownMenus();
          devAdvantage.DeInitializeAssemblyResolution();
        }
      }
      catch(Exception e)
      {
        //TODO: Pass Serial Number of product here!
        ExceptionsManager.ReportUnhandledException(e,"devAdvantage"); //Get the srial Number here!
      }

    }

    /// <summary>
    ///      Implements the OnAddInsUpdate method of the IDTExtensibility2 interface.
    ///      Receives notification that the collection of Add-ins has changed.
    /// </summary>
    /// <param term='custom'>
    ///      Array of parameters that are host application specific.
    /// </param>
    /// <seealso class='IDTExtensibility2' />
    public void OnAddInsUpdate(ref System.Array custom)
    {
    }

    /// <summary>
    ///      Implements the OnStartupComplete method of the IDTExtensibility2 interface.
    ///      Receives notification that the host application has completed loading.
    /// </summary>
    /// <param term='custom'>
    ///      Array of parameters that are host application specific.
    /// </param>
    /// <seealso class='IDTExtensibility2' />
    public void OnStartupComplete(ref System.Array custom)
    {
    }

    /// <summary>
    ///      Implements the OnBeginShutdown method of the IDTExtensibility2 interface.
    ///      Receives notification that the host application is being unloaded.
    /// </summary>
    /// <param term='custom'>
    ///      Array of parameters that are host application specific.
    /// </param>
    /// <seealso class='IDTExtensibility2' />
    public void OnBeginShutdown(ref System.Array custom)
    {
    }
    
    /// <summary>
    ///      Implements the QueryStatus method of the IDTCommandTarget interface.
    ///      This is called when the command's availability is updated
    /// </summary>
    /// <param term='commandName'>
    ///    The name of the command to determine state for.
    /// </param>
    /// <param term='neededText'>
    ///    Text that is needed for the command.
    /// </param>
    /// <param term='status'>
    ///    The state of the command in the user interface.
    /// </param>
    /// <param term='commandText'>
    ///    Text requested by the neededText parameter.
    /// </param>
    /// <seealso class='Exec' />
    public void QueryStatus(string commandName, EnvDTE.vsCommandStatusTextWanted neededText, ref EnvDTE.vsCommandStatus status, ref object commandText)
    {
      if(devAdvantage == null)
        return;

      try
      {
        if(neededText == EnvDTE.vsCommandStatusTextWanted.vsCommandStatusTextWantedNone)
        {
          if(commandName.StartsWith("DevAdvantageVSAddIn.Connect"))
            status = devAdvantage.OnCommandStatus(commandName.Substring("DevAdvantageVSAddIn.Connect.".Length));
        }
      }
      catch(Exception e)
      {
        //TODO: Pass Serial Number of product here!
        ExceptionsManager.ReportUnhandledException(e,"devAdvantage"); //Get the srial Number here!
      }
    }

    /// <summary>
    ///      Implements the Exec method of the IDTCommandTarget interface.
    ///      This is called when the command is invoked.
    /// </summary>
    /// <param term='commandName'>
    ///    The name of the command to execute.
    /// </param>
    /// <param term='executeOption'>
    ///    Describes how the command should be run.
    /// </param>
    /// <param term='varIn'>
    ///    Parameters passed from the caller to the command handler.
    /// </param>
    /// <param term='varOut'>
    ///    Parameters passed from the command handler to the caller.
    /// </param>
    /// <param term='handled'>
    ///    Informs the caller if the command was handled or not.
    /// </param>
    /// <seealso class='Exec' />
    public void Exec(string commandName, EnvDTE.vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
    {
      if(devAdvantage == null)
        return;

      try
      {
        handled = false;
        if(executeOption == EnvDTE.vsCommandExecOption.vsCommandExecOptionDoDefault)
        {
          if(commandName.StartsWith("DevAdvantageVSAddIn.Connect"))
          {
            if(devAdvantage.OnCommand(commandName.Substring("DevAdvantageVSAddIn.Connect.".Length)))
            {
              handled = true;
              return;
            }
          }
        }
      }
      catch(Exception e)
      {
        //TODO: Pass Serial Number of product here!
        ExceptionsManager.ReportUnhandledException(e,"devAdvantage"); //Get the srial Number here!
      }
    }
    private _DTE applicationObject;
    private AddIn addInInstance;
    DevAdvantage devAdvantage = null;

    private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
    {
      //Assemblies bellow contain types invoked dynamicly by properties grid designer
      //apparently in case of COM .NET component, these assemblies cannot be resolved
      //therefore do it manually here.
      if(args.Name == typeof(AnticipatingMinds.Genesis.KnowledgeManagement.KnowledgeBaseUI.ProfilesArrayUIEditor).Assembly.FullName)
        return typeof(AnticipatingMinds.Genesis.KnowledgeManagement.KnowledgeBaseUI.ProfilesArrayUIEditor).Assembly;

      if(args.Name == typeof(AnticipatingMinds.Genesis.KnowledgeManagement.ApplicabilityScopeTypeConverter).Assembly.FullName)
        return typeof(AnticipatingMinds.Genesis.KnowledgeManagement.ApplicabilityScopeTypeConverter).Assembly;

      return null;
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.