Connect.cs
资源名称:DSWatch.zip [点击查看]
上传用户:jfy123
上传日期:2021-10-28
资源大小:14k
文件大小:9k
源码类别:
网络截获/分析
开发平台:
C++ Builder
- namespace DSWatch
- {
- using System;
- using Microsoft.Office.Core;
- using Extensibility;
- using System.Runtime.InteropServices;
- using EnvDTE;
- #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' />
- [GuidAttribute("56B77928-BB44-45F5-BC31-EFFAAF5D1386"), ProgId("DSWatch.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()
- {
- }
- /// <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)
- {
- applicationObject = (_DTE)application;
- addInInstance = (AddIn)addInInst;
- object []contextGUIDS = new object[] { };
- Commands commands = applicationObject.Commands;
- _CommandBars commandBars = applicationObject.CommandBars;
- // When run, the Add-in wizard prepared the registry for the Add-in.
- // At a later time, the Add-in or its commands may become 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) You add new commands or modify commands already defined.
- // You will need to re-register the Add-in by building the DSWatchSetup project,
- // right-clicking the project in the Solution Explorer, and then choosing install.
- // Alternatively, you could execute the ReCreateCommands.reg file the Add-in Wizard generated in
- // the project directory, or run 'devenv /setup' from a command prompt.
- try
- {
- // add the command to the right click context menu
- // note that when I insert the command it's inserted disabled "(int)vsCommandStatus.vsCommandStatusUnsupported +(int)vsCommandStatus.vsCommandStatusInvisible"
- Command command = commands.AddNamedCommand
- ( addInInstance, "DSWatchNode" , "DataSet Quick Watch",
- "DataSet Quick Watch", true, 60, ref contextGUIDS,
- (int)vsCommandStatus.vsCommandStatusUnsupported
- +(int)vsCommandStatus.vsCommandStatusInvisible
- );//too long :)
- CommandBar commandBar = (CommandBar)commandBars["Code Window"];
- CommandBarControl commandBarControl = command.AddControl(commandBar, 1);
- }
- catch(System.Exception /*e*/)
- {
- }
- }
- /// <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(commandName == "DSWatch.Connect.DSWatchNode"&&IsDebugging() )
- {
- status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported|vsCommandStatus.vsCommandStatusEnabled;
- }
- else
- {
- status = (vsCommandStatus)vsCommandStatus.vsCommandStatusUnsupported |vsCommandStatus.vsCommandStatusInvisible ;
- }
- }
- /// <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)
- {
- try
- {
- EnvDTE.Debugger debugger;
- debugger = applicationObject.Debugger;
- Expression expr ;
- string str;
- string isDataSetExpression=null ;
- string getXmlExpression=null;
- string fileExtintion ;
- TextSelection _TextSelection;
- _TextSelection=(TextSelection)applicationObject.ActiveDocument.Selection;
- str=_TextSelection.Text ;
- fileExtintion=applicationObject.ActiveDocument.FullName.Substring(applicationObject.ActiveDocument.FullName.Length-2 ) ;
- switch(fileExtintion.ToLower() )
- {
- case "cs":
- isDataSetExpression="(System.Data.DataSet)"+str+".Tables";
- getXmlExpression="((System.Data.DataSet)"+str+").GetXml()";
- break;
- case"vb":
- isDataSetExpression="ctype("+ str +",System.Data.DataSet).Tables";
- getXmlExpression="ctype("+ str +",System.Data.DataSet).GetXml()";
- break;
- }
- //cast the selcted text to dataset
- expr = debugger.GetExpression(isDataSetExpression,true,500);
- //System.Windows.Forms.MessageBox.Show(expr.Value );
- if (expr.Value.IndexOf("error:")>-1)
- {
- System.Windows.Forms.MessageBox.Show("This is not a DataSet!");
- return;
- }
- DatasetWatchFrm _DatasetWatchFrm;
- _DatasetWatchFrm =new DatasetWatchFrm();
- expr = debugger.GetExpression(getXmlExpression,true,500);
- _DatasetWatchFrm.getXml(expr.Value );
- _DatasetWatchFrm.Show();
- }
- catch(Exception e)
- {
- System.Windows.Forms.MessageBox.Show(e.Message );
- }
- }
- /// <summary>
- /// this function test the ide environment if it in debug mood or not
- /// i took this function from MSDN
- /// </summary>
- /// <returns>boolean</returns>
- private bool IsDebugging()
- {
- EnvDTE.Debugger debugger ;
- debugger = applicationObject.Debugger;
- if (debugger==null)
- return false;
- else
- {
- return(debugger.CurrentMode != dbgDebugMode.dbgDesignMode);
- }
- }
- /// <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)
- {
- }
- /// <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)
- {
- }
- private _DTE applicationObject;
- private AddIn addInInstance;
- }
- }