旧版本插件代码备份

2015-11-12 17:06:43  访问(1639) 赞(0) 踩(0)

using System;
using System.Data;
using System.Collections;
// using System.Diagnostics;
using Extensibility;
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio.CommandBars;
using System.Resources;
using System.Reflection;
using System.Globalization;

using System.IO;
using System.Text;
using System.Windows.Forms;

using CT.BA.Classes.Classes;
using CT.BA.Classes.Common;
using CT.BA.Classes.Loger;
using CT.BA.Classes.Functions;

using SlowXLib.Classes;

namespace SlowXLib.Functions
{
    /// <summary>
    /// 插件相关的方法
    /// </summary>
    public class AddinFunctions
    {
        ///// <summary>
        ///// ftp更新
        ///// </summary>
        //private static WinForms.FtpForm ftpForm = null; // new SlowXLib.WinForms.FtpForm();

        /// <summary>
        /// ftp更新
        /// </summary>
        /// <returns></returns>
        public static bool ViewWebSite
            (
                DTE2 _applicationObject,
                AddIn _addInInstance
            )
        {
            SlowXLib.WinForms.ViewWebSite ftpForm = null;

            if (ftpForm == null)
                ftpForm = new SlowXLib.WinForms.ViewWebSite(_applicationObject, _addInInstance, null);

            ftpForm.Show();

            return true;
        }



        #region FTP 相关

        /// <summary>
        /// ftp更新
        /// </summary>
        /// <returns></returns>
        public static bool FtpUpdateAdvance
            (
                DTE2 _applicationObject,
                AddIn _addInInstance
            )
        {
            SlowXLib.WinForms.FtpForm ftpForm = null;

            if (ftpForm == null)
                ftpForm = new SlowXLib.WinForms.FtpForm(_applicationObject, _addInInstance, null);

            ftpForm.Show();

            return true;
        }

        public static string GetXmlUrlConfigFileName
            (
                DTE2 _applicationObject,
                AddIn _addInInstance            
            )
        {
            if (_applicationObject == null)
                return null;

            return FileFunctions.Add(
                Functions.AddinFunctions.GetProjFullPath(_applicationObject),
                "config\\url.config", false);
        }

        /// <summary>
        /// 高级窗口
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <param name="_addInInstance"></param>
        /// <returns></returns>
        public static bool AdvDialog
            (
                DTE2 _applicationObject,
                AddIn _addInInstance
            )
        {
            try
            {
                SlowXLib.WinForms.AdvDialog ftpForm = null;

                if (ftpForm == null)
                    ftpForm = new SlowXLib.WinForms.AdvDialog
                        (_applicationObject, _addInInstance, null);

                ftpForm.Show();

                return true;
            }
            catch (Exception err)
            {
                Recorder.Record(err.Message);
                return false;
            }
        }

        /// <summary>
        /// 高级窗口
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <param name="_addInInstance"></param>
        /// <returns></returns>
        public static bool myTest
            (
                DTE2 _applicationObject,
                AddIn _addInInstance
            )
        {
            try
            {
                //// Commands2 commands = (Commands2)_applicationObject.Commands;

                //// 
                //CommandBars cmdBars = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars);

                ////cmdBars.
                //// CommandBar bar = null;

                //// bar.Controls[0].Control
                //// cmdBars.Con
                //// cmdBars[

                //CommandBar bar = cmdBars[0];

                //MessageBox.Show(
                //    bar.Name);

                // 无效的代码 //
                // MessageBox.Show(
                //    "canoe" + System.Configuration.ConfigurationManager.AppSettings["canoe"]);

                // 这里可以获得配置文件 //

            //    System.Configuration.Configuration c = GetAddinAppConfig
            //(_applicationObject,
            //    _addInInstance
            //);

            //    if (c == null)
            //        MessageBox.Show("DD");
            //    else
            //    {
            //        // MessageBox.Show(c.AppSettings.v
            //        MessageBox.Show(
            //          "canoe" + ConfigurationFunctions.GetAppConfigString(c, "canoe", true, "") + "DSS");
  
            //    }

                // MessageBox.Show(CT.BA.Classes.Config.SysConfig.instance.GetConfig("DB_HELPER_TYPE_Test"));

                return true;
            }
            catch (Exception err)
            {
                Recorder.Record(err.Message);
                return false;
            }
        }


        /// <summary>
        /// ftp更新
        /// </summary>
        /// <returns></returns>
        public static bool URLView
            (
                DTE2 _applicationObject,
                AddIn _addInInstance
            )
        {
            try
            {
                // 打开URL //

                //SlowXLib.WinForms.ViewUrl ftpForm = null;

                //if (ftpForm == null)
                //    ftpForm = new SlowXLib.WinForms.ViewUrl(_applicationObject, _addInInstance, null);

                //ftpForm.Show();

                DataTable dt
                               = CT.BA.Classes.Functions.XmlFunctions.GetXmlToDataTable
                               ("", GetXmlUrlConfigFileName(_applicationObject, _addInInstance), true, true, true);

                if (dt == null || dt.Rows.Count == 0)
                    return false;

                string strUrl = "";

                foreach (DataRow dr in dt.Rows)
                {
                    string strId = DataSetFunctions.GetDataRowStr(dr, CommonConfig.Id);

                    if (strId != "0")
                        continue;

                    strUrl = DataSetFunctions.GetDataRowStr(dr, "url");

                    if (StringFunctions.IsNullOrEmptyAndBlank(strUrl))
                        continue;

                    break;

                }

                string strTmpUrl = Functions.AddinFunctions.GetProjFileSubFileName(_applicationObject);


                if (strTmpUrl.EndsWith(".cs", StringComparison.CurrentCultureIgnoreCase))
                    strTmpUrl = strTmpUrl.Substring(0, strTmpUrl.Length - 3);

                if (StringFunctions.IsNullOrEmptyAndBlank(strUrl))
                    return false;

                strUrl = FileFunctions.Add(strUrl, strTmpUrl, true);


                System.Diagnostics.Process.Start(strUrl);

                return true;
            }
            catch (Exception err)
            {
                Recorder.Record(err.Message);
                return false;
            }
        }


        /// <summary>
        /// ftp更新
        /// </summary>
        /// <returns></returns>
        public static bool FtpUpdate
            (
                DTE2 _applicationObject,
                AddIn _addInInstance
            )
        {
            WinForms.FtpForm ftpForm = null;

            if (ftpForm == null)
                ftpForm = new SlowXLib.WinForms.FtpForm(_applicationObject, _addInInstance, null);


            ftpForm.Show();
            return true;
        }

        // public static 

        /// <summary>
        /// ftp测试
        /// </summary>
        /// <returns></returns>
        public static bool Ftp()
        {
            // CT
            //Uri uri = new Uri("ftp://219.137.167.139/");
            Uri uri = new Uri("ftp://219.137.167.139/wwwroot/");
            string u = "canoe";
            string p = "canoe5626@21";

            CT.BA.Common.FtpHelper ftp = new CT.BA.Common.FtpHelper(uri, u, p);

            try
            {
                bool b = ftp.UploadFile("D:\\test.sql");
                // CT.BA.Common.FileStruct[] s = ftp.ListFiles();

                MessageBox.Show(b.ToString());
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }

            return true;
        }

        /// <summary>
        /// ftp更新
        /// </summary>
        /// <returns></returns>
        public static bool FtpUpload()
        {
            // CT
            Uri uri = new Uri("ftp://219.137.167.139/wwwroot/");
            string u = "canoe";
            string p = "canoe5626@21";

            CT.BA.Common.FtpHelper ftp = new CT.BA.Common.FtpHelper(uri, u, p);

            try
            {
                CT.BA.Common.FileStruct[] s = ftp.ListFiles();

                MessageBox.Show(s.Length.ToString());
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }

            return true;
        }

        #endregion

        /* 

        /// <summary>
        /// Add a command bar to the VS2005 interface.
        /// </summary>
        /// <param name="name">The name of the command bar</param>
        /// <param name="position">Initial command bar positioning</param>
        /// <returns></returns>
        private CommandBar AddCommandBar(string name, MsoBarPosition position)
        {
            // Get the command bars collection
            CommandBars cmdBars = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars);
            CommandBar bar = null;

            try
            {
                try
                {
                    // Create the new CommandBar
                    
                    bar = cmdBars.Add(name, position, false, false);
                    // cmdBars.Add(
                }
                catch (ArgumentException)
                {
                    // Try to find an existing CommandBar
                    bar = cmdBars[name];
                }
            }
            catch
            {
            }

            return bar;
        }

        /// <summary>
        /// Add a menu to the VS2005 interface.
        /// </summary>
        /// <param name="name">The name of the menu</param>
        /// <returns></returns>
        private CommandBar AddCommandMenu(string name)
        {
            // Get the command bars collection
            CommandBars cmdBars = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars);
            CommandBar menu = null;

            try
            {
                try
                {
                    // Create the new CommandBar
                    menu = cmdBars.Add(name, MsoBarPosition.msoBarPopup, false, false);
                }
                catch (ArgumentException)
                {
                    // Try to find an existing CommandBar
                    menu = cmdBars[name];
                }
            }
            catch
            {
            }

            return menu;
        }

        /// <summary>
        /// Add a command to a popup menu in VS2005.
        /// </summary>
        /// <param name="popup">The popup menu to add the command to.</param>
        /// <param name="name">The name of the new command.</param>
        /// <param name="label">The text label of the command.</param>
        /// <param name="ttip">The tooltip for the command.</param>
        /// <param name="iconIdx">The icon index, which should match the resource ID in the add-ins resource assembly.</param>
        private void AddPopupCommand(CommandBarPopup popup, string name, string label, string ttip, int iconIdx)
        {
            // Do not try to add commands to a null menu
            if (popup == null)
                return;

            // Get commands collection
            Commands2 commands = (Commands2)_applicationObject.Commands;
            object[] contextGUIDS = new object[] { };

            try
            {
                // Add command
                Command command = commands.AddNamedCommand2(_addInInstance, name, label, ttip, true, iconIdx, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                if ((command != null) && (popup != null))
                {
                    command.AddControl(popup.CommandBar, 1);
                }
            }
            catch (ArgumentException)
            {
                // Command already exists, so ignore
            }
        }

        /// <summary>
        /// Add a command to a toolbar in VS2005.
        /// </summary>
        /// <param name="bar">The bar to add the command to.</param>
        /// <param name="name">The name of the new command.</param>
        /// <param name="label">The text label of the command.</param>
        /// <param name="ttip">The tooltip for the command.</param>
        /// <param name="iconIdx">The icon index, which should match the resource ID in the add-ins resource assembly.</param>
        private void AddToolbarCommand(CommandBar bar, string name, string label, string ttip, int iconIdx)
        {
            // Do not try to add commands to a null bar
            if (bar == null)
                return;

            // Get commands collection
            Commands2 commands = (Commands2)_applicationObject.Commands;
            object[] contextGUIDS = new object[] { };

            try
            {
                // Add command
                Command command = commands.AddNamedCommand2(_addInInstance, name, label, ttip, false, iconIdx, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePict, vsCommandControlType.vsCommandControlTypeButton);
                if (command != null && bar != null)
                {
                    command.AddControl(bar, 1);
                }
            }
            catch (ArgumentException)
            {
                // Command already exists, so ignore
            }
        }
           
           
         
         */

        #region 添加菜单

        /// <summary>
        /// 获得菜单栏的MenuBar
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <param name="_addInInstance"></param>
        /// <returns></returns>
        public static CommandBar GetMenuBar
            (
                DTE2 _applicationObject,
                AddIn _addInInstance
            )
        {
            return ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["MenuBar"];
        }

        /// <summary>
        /// 获得Easy MDI Document Window的MenuBar
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <param name="_addInInstance"></param>
        /// <returns></returns>
        public static CommandBar GetEasyMDIDocumentWindowBar
            (
                DTE2 _applicationObject,
                AddIn _addInInstance
            )
        {
            return ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["Easy MDI Document Window"];
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <param name="_addInInstance"></param>
        /// <param name="strToolName"></param>
        /// <returns></returns>
        public static CommandBar CreateDefaultCommandBar
            (
                DTE2 _applicationObject,
                AddIn _addInInstance,
                string strToolName
            )
        {
            return CreateCommandBar(_applicationObject, _addInInstance, GetMenuBar(_applicationObject, _addInInstance), strToolName);
        }

        /// <summary>
        /// 创建菜单
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <param name="_addInInstance"></param>
        /// <param name="bar"></param>
        /// <param name="strToolName"></param>
        /// <returns></returns>
        public static CommandBar CreateCommandBar
            (
                DTE2 _applicationObject,
                AddIn _addInInstance,
                Microsoft.VisualStudio.CommandBars.CommandBar bar,
                string strToolName
            )
        {
            if (_applicationObject == null || _addInInstance == null || bar == null)
                return null;

            Commands2 commands = (Commands2)_applicationObject.Commands;

            

            try
            {
                CommandBar owner = (CommandBar)commands.AddCommandBar
                    (strToolName, vsCommandBarType.vsCommandBarTypeMenu, bar, bar.Controls.Count + 1);

                return owner;
            }
            catch (Exception err)
            {
                System.Diagnostics.Debug.WriteLine(err.Message);
                return null;
            }
        }

        public static CommandBar CreateCommandBarByObjectCtrl
                    (
                        DTE2 _applicationObject,
                        AddIn _addInInstance,
                        object bar,
                        string strToolName
                    )
        {
            return CreateCommandBarByObjectCtrl(_applicationObject, _addInInstance, bar, strToolName, -1);
        }

        public static CommandBar CreateCommandBarByObjectCtrl
                    (
                        DTE2 _applicationObject,
                        AddIn _addInInstance,
                        object bar,
                        string strToolName,
                        int iPosition
                    )
        {
            if (_applicationObject == null || _addInInstance == null || bar == null)
                return null;

            Commands2 commands = (Commands2)_applicationObject.Commands;

            try
            {
                if (iPosition == -1)
                {
                    if (bar is CommandBar)
                    {
                        iPosition = (bar as CommandBar).Controls.Count + 1;
                    }
                    else if (bar is CommandBarPopup)
                    {
                        iPosition = (bar as CommandBarPopup).Controls.Count + 1;
                    }
                    else iPosition = 1;
                }
                CommandBar owner = (CommandBar)commands.AddCommandBar
                    (strToolName, vsCommandBarType.vsCommandBarTypeMenu, bar, iPosition);

                return owner;
            }
            catch (Exception err)
            {
                System.Diagnostics.Debug.WriteLine(err.Message);
                return null;
            }
        }

        public static Command CreateCommand
                    (
                        DTE2 _applicationObject,
                        AddIn _addInInstance,
                        Microsoft.VisualStudio.CommandBars.CommandBar bar,
                        string strToolCode,
                        string strToolName,
                        string strToolDesc
                    )
        {
            if (_applicationObject == null || _addInInstance == null || bar == null)
                return null;

            object[] contextGUIDS = new object[] { };
            Commands2 commands = (Commands2)_applicationObject.Commands;

            try
            {
                //commands.AddNamedCommand2(_addInInstance,"","-","",false,null,ref contextGUIDS,vsCommandStatus.
                // vsCommandStyle., vsCommandControlType.vsCommandControlTypeButton);
                //vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                // vsCommandControlType.
                Command command = commands.AddNamedCommand2(_addInInstance, strToolCode, strToolName, strToolDesc, true, 60, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                // BindCommandKey 
                // command.Bind
                command.AddControl(bar, bar.Controls.Count + 1);
                // command.AddControl(

                return command;
            }
            catch (Exception err)
            {
                System.Diagnostics.Debug.WriteLine(err.Message);
                return null;
            }
        }


        #endregion

        #region 移除菜单

        /// <summary>
        /// 移除菜单
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <param name="_addInInstance"></param>
        /// <param name="bar"></param>
        /// <param name="strToolName"></param>
        /// <returns></returns>
        public static bool RemoveCommandByCommandBar
                            (
                                DTE2 _applicationObject,
                                AddIn _addInInstance,
                                Microsoft.VisualStudio.CommandBars.CommandBar bar,
                                string strToolName
                            )
        {

            if (bar == null || StringFunctions.IsNullOrEmptyAndBlank(strToolName))
                return false;

            try
            {
                CommandBarControl c = bar.Controls[strToolName];

                if (c == null)
                    return false;
                else
                    c.Delete(null);
            }
            catch (Exception err)
            {
                System.Diagnostics.Debug.WriteLine(err.Message);
                return false;
            }

            return true;

        }

        public static bool RemoveAllCommandByCommandBar
                                    (
                                        DTE2 _applicationObject,
                                        AddIn _addInInstance,
                                        Microsoft.VisualStudio.CommandBars.CommandBar bar
                                    )
        {

            if (bar == null)
                return false;

            try
            {
                int iLen = bar.Controls.Count;
                ArrayList arrayList = new ArrayList();
                foreach (CommandBarControl c in bar.Controls)
                {
                    arrayList.Add(c);
                }

                foreach (object o in arrayList)
                {
                    CommandBarControl c = o as CommandBarControl;
                    if (c != null)
                        c.Delete(null);
                }
                //for (int i = 0; i < iLen; ++i)
                //{
                //    CommandBarControl c = bar.Controls[i];

                //    if (c == null)
                //        continue;

                //    c.Delete(null);
                //}
            }
            catch (Exception err)
            {
                System.Diagnostics.Debug.WriteLine(err.Message);
                return false;
            }

            return true;

        }

        public static bool ClearAllCommandBar2
                            (
                                DTE2 _applicationObject,
                                AddIn _addInInstance,
                                string strToolName
                            )
        {

            while (true)
            {
                Microsoft.VisualStudio.CommandBars.CommandBar bar = GetCommandBar(_applicationObject, _addInInstance, strToolName);
                if (bar == null)
                    break;

                if (!RemoveAllCommandByCommandBar(_applicationObject, _addInInstance, bar))
                    return false;

                if (!RemoveCommandBar2(_applicationObject, _addInInstance, strToolName))
                    return false;
            }

            return true;
        }

        public static bool RemoveAllCommandBar2
                            (
                                DTE2 _applicationObject,
                                AddIn _addInInstance,
                                string strToolName
                            )
        {

            while (true)
            {
                if (!RemoveCommandBar2(_applicationObject, _addInInstance, strToolName))
                    return false;
            }

            return true;
        }


        public static bool RemoveCommandBar2
                    (
                        DTE2 _applicationObject,
                        AddIn _addInInstance,
                        string strToolName
                    )
        {

            try
            {
                Microsoft.VisualStudio.CommandBars.CommandBar bar = GetCommandBar(_applicationObject, _addInInstance, strToolName);

                if (bar == null)
                    return false;
                else
                    bar.Delete();
            }
            catch (Exception err)
            {
                System.Diagnostics.Debug.WriteLine(err.Message);
                return false;
            }

            return true;

        }


        public static Microsoft.VisualStudio.CommandBars.CommandBar GetCommandBar
            (
                DTE2 _applicationObject,
                AddIn _addInInstance,
                string strToolName
            )
        {
            if (_applicationObject == null || _addInInstance == null || StringFunctions.IsNullOrEmptyAndBlank(strToolName))
                return null;

            // "MenuBar"
            return ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)[strToolName];
        }

        //public static Microsoft.VisualStudio.CommandBars.CommandBar GetCommandBar
        //            (
        //                DTE2 _applicationObject,
        //                AddIn _addInInstance,
        //                string strToolName
        //            )
        //{
        //    if (_applicationObject == null || _addInInstance == null || StringFunctions.IsNullOrEmptyAndBlank(strToolName))
        //        return null;

        //    // "MenuBar"
        //    return ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)[strToolName];
        //}

        /// <summary>
        /// 移除菜单
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <param name="_addInInstance"></param>
        /// <returns></returns>
        public static bool RemoveCommandBar
            (
                DTE2 _applicationObject,
                AddIn _addInInstance,
                string strToolName
            )
        {
            return RemoveCommandBarByCommandBar(
                _applicationObject, _addInInstance, GetCommandBar(_applicationObject, _addInInstance, "MenuBar"), strToolName);

        }

        public static bool RemoveCommandBarByCommandBar
                    (
                        DTE2 _applicationObject,
                        AddIn _addInInstance,
                        Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar,
                        string strToolName
                    )
        {
            if (_applicationObject == null || _addInInstance == null || StringFunctions.IsNullOrEmptyAndBlank(strToolName) || menuBarCommandBar == null)
                return false;

            try
            {
                string toolsMenuName = GetMenuName(_applicationObject, _addInInstance, strToolName);

                CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName];

                toolsControl.Delete(null);
            }
            catch (Exception err)
            {
                System.Diagnostics.Debug.WriteLine(err.Message);

                // MessageBox.Show(err.Message);

                return false;
            }

            // MessageBox.Show("OL");

            return true;
        }
        public static bool RemoveCommand
                    (
                        DTE2 _applicationObject,
                        AddIn _addInInstance,
                        string strToolName
                    )
        {
            if (_applicationObject == null || _addInInstance == null || StringFunctions.IsNullOrEmptyAndBlank(strToolName))
                return false;

            try
            {
                Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["MenuBar"];

                string toolsMenuName = GetMenuName(_applicationObject, _addInInstance, strToolName);

                CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName];

                toolsControl.Delete(null);
            }
            catch (Exception err)
            {
                System.Diagnostics.Debug.WriteLine(err.Message);

                // MessageBox.Show(err.Message);

                return false;
            }

            // MessageBox.Show("OL");

            return true;
        }

        #endregion

        #region 创建菜单

        /// <summary>
        /// 获得菜单名
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <param name="_addInInstance"></param>
        /// <returns></returns>
        public static string GetMenuName
            (
                DTE2 _applicationObject,
                AddIn _addInInstance,
                string strMenuName
            )
        {
            string toolsMenuName = "";
            try
            {
                //If you would like to move the command to a different menu, change the word "Tools" to the 
                //  English version of the menu. This code will take the culture, append on the name of the menu
                //  then add the command to that menu. You can find a list of all the top-level menus in the file
                //  CommandBar.resx.
                string resourceName;
                ResourceManager resourceManager = new ResourceManager("SlowX.CommandBar", Assembly.GetExecutingAssembly());
                CultureInfo cultureInfo = new CultureInfo(_applicationObject.LocaleID);

                if (cultureInfo.TwoLetterISOLanguageName == "zh")
                {
                    System.Globalization.CultureInfo parentCultureInfo = cultureInfo.Parent;
                    resourceName = String.Concat(parentCultureInfo.Name, strMenuName);
                }
                else
                {
                    resourceName = String.Concat(cultureInfo.TwoLetterISOLanguageName, strMenuName);
                }
                toolsMenuName = resourceManager.GetString(resourceName);
            }
            catch
            {
                //We tried to find a localized version of the word Tools, but one was not found.
                //  Default to the en-US word, which may work for the current culture.
                toolsMenuName = strMenuName;
            }

            return toolsMenuName;
        }

        public static bool CreateOnlyOneSlowXMenu
            (
                DTE2 _applicationObject,
                AddIn _addInInstance
            )
        {
            CommandBar SlowXBar = GetCommandBarByName(_applicationObject, _addInInstance, "SlowX");

            if (SlowXBar == null)
                return CreateSlowXMenu(_applicationObject, _addInInstance);
            else
                return true;

        }

        public static bool CreateSlowXMenu
            (
                DTE2 _applicationObject,
                AddIn _addInInstance
            )
        {

            //CommandBar SlowXBar = GetCommandBarByName(_applicationObject, _addInInstance, "SlowX");

            //if (SlowXBar != null)
            //{
            //    if (IsDebugging(_applicationObject))
            //        RemoveSlowXMenu(_applicationObject, _addInInstance);
            //    else
            //        return true;
            //}

            try
            {
                //CommandBar bar = CreateDefaultCommandBar(_applicationObject, _addInInstance, "SlowX");

                //if (bar != null)
                //{
                //    CommandBar barSon = CreateCommandBar(_applicationObject, _addInInstance, bar, "SlowX_Code");

                //    if (barSon != null)
                //    {
                //        CreateCommand(_applicationObject, _addInInstance, barSon, "SlowX_Code_AddUsing", "添加using", "添加using");
                //        CreateCommand(_applicationObject, _addInInstance, barSon, "SlowX_Code_OpCtrl", "添加opCtrl", "添加opCtrl");
                //        CreateCommand(_applicationObject, _addInInstance, barSon, "SlowX_Code_GetSet", "添加GetSet", "添加GetSet");

                //        CreateCommand(_applicationObject, _addInInstance, barSon, "SlowX_Code_RemoveVarDefine", "去除变量定义", "去除变量定义");
                //        CreateCommand(_applicationObject, _addInInstance, barSon, "SlowX_Code_RemoveVarDefine2", "去除变量定义2", "去除变量定义2");
                        

                //        CreateCommand(_applicationObject, _addInInstance, barSon, "SlowX_Code_CS", "转成CS", "转成CS");

                //        // CreateCommand(_applicationObject, _addInInstance, barSon, "SlowX_Code_FormatVar", "格式化变量", "格式化变量");
                //        // CreateCommand(_applicationObject, _addInInstance, barSon, "SlowX_Code_SetVar", "定义变量", "格式化变量");
                //    }

                //    // CreateCommand(_applicationObject, _addInInstance, bar, "", "", "");

                //    CreateCommand(_applicationObject, _addInInstance, bar, "SlowX_Code_Dialog", "高级", "高级");
                //}

                //#region 复制一份菜单到Tools下面

                //CommandBar toolsPopup = GetToolsCommandBar(_applicationObject, _addInInstance);

                //if (toolsPopup != null)
                //{
                //    CommandBar barOne = CreateCommandBarByObjectCtrl(_applicationObject, _addInInstance, toolsPopup, "SlowX_One", 1);

                //    if (barOne != null)
                //    {
                //        CommandBar barSon = CreateCommandBar(_applicationObject, _addInInstance, barOne, "SlowX_Code_One");

                //        if (barSon != null)
                //        {
                //            CreateCommand(_applicationObject, _addInInstance, barSon, "SlowX_Code_AddUsing_One", "添加using", "添加using");
                //            CreateCommand(_applicationObject, _addInInstance, barSon, "SlowX_Code_OpCtrl_One", "添加opCtrl", "添加opCtrl");
                //            CreateCommand(_applicationObject, _addInInstance, barSon, "SlowX_Code_GetSet_One", "添加GetSet", "添加GetSet");

                //            CreateCommand(_applicationObject, _addInInstance, barSon, "SlowX_Code_RemoveVarDefine_One", "去除变量定义", "去除变量定义");
                //            CreateCommand(_applicationObject, _addInInstance, barSon, "SlowX_Code_RemoveVarDefine2_One", "去除变量定义2", "去除变量定义2");

                //            CreateCommand(_applicationObject, _addInInstance, barSon, "SlowX_Code_CS_One", "转成CS", "转成CS");

                //        }


                //        CreateCommand(_applicationObject, _addInInstance, barOne, "SlowX_Code_Dialog_One", "高级", "高级");
                //    }
                //}


                //#endregion

                #region Add CloseAllDocuments command

                // Get "Easy MDI Document Window" command bar

                CommandBar mdiDocCommandBar = GetCommandBarByName(_applicationObject, _addInInstance, "Easy MDI Document Window");

                // Place the command below "Close All But This" menu item
                CommandBarControl closeAllButThisCmd = mdiDocCommandBar.Controls["Close All But This"];

                int closeAllCmdIndex = (closeAllButThisCmd == null) ? 1 : (closeAllButThisCmd.Index + 1);

                int theIdx = 0;

                // Add a new command
                AddNamedCommand2(_applicationObject, _addInInstance, mdiDocCommandBar, "SlowX_KEYS_CloseAllDocuments",
                    "Close All Documents", "Close All Documents", false, 0, closeAllCmdIndex + theIdx++);

                AddNamedCommand2(_applicationObject, _addInInstance, mdiDocCommandBar, "SlowX_KEYS_CopyFile",
                    "Copy File", "Copy File", false, 0, closeAllCmdIndex + theIdx++);

                AddNamedCommand2(_applicationObject, _addInInstance, mdiDocCommandBar, "SlowX_KEYS_CopyTwoFile",
                    "Copy TwoFile", "Copy TwoFile", false, 0, closeAllCmdIndex +  theIdx++);

                AddNamedCommand2(_applicationObject, _addInInstance, mdiDocCommandBar, "SlowX_KEYS_CopyBin",
                                   "Copy Bin", "Copy Bin", false, 0, closeAllCmdIndex + theIdx++);

                AddNamedCommand2
                    (
                        _applicationObject, 
                        _addInInstance, 
                        mdiDocCommandBar, 
                        AddinMenu.CopyBinAndXmlAddinMenu.SortCode,
                        AddinMenu.CopyBinAndXmlAddinMenu.TheName, 
                        AddinMenu.CopyBinAndXmlAddinMenu.TheName, 
                        false, 
                        0, 
                        closeAllCmdIndex + theIdx++);

                AddNamedCommand2
                    (
                        _applicationObject,
                        _addInInstance,
                        mdiDocCommandBar,
                        AddinMenu.OpenBinDirAddinMenu.SortCode,
                        AddinMenu.OpenBinDirAddinMenu.TheName,
                        AddinMenu.OpenBinDirAddinMenu.TheName,
                        false,
                        0,
                        closeAllCmdIndex + theIdx++);

                AddNamedCommand2(_applicationObject, _addInInstance, mdiDocCommandBar, "SlowX_KEYS_TestFun",
                    "测试方法", "测试方法", false, 0, closeAllCmdIndex + theIdx++);

                AddNamedCommand2(_applicationObject, _addInInstance, mdiDocCommandBar, "SlowX_KEYS_CopyFileName",
                    "Copy FileName", "Copy FileName", false, 0, closeAllCmdIndex + theIdx++);

                AddNamedCommand2(_applicationObject, _addInInstance, mdiDocCommandBar, "SlowX_KEYS_FtpUpdate",
                    "FTP 更新", "FTP 更新", false, 0, closeAllCmdIndex +  theIdx++);

                // 访问地址
                AddNamedCommand2(_applicationObject, _addInInstance, mdiDocCommandBar, "SlowX_KEYS_FtpUpdateAdvance",
                    "访问地址", "访问地址", false, 0, closeAllCmdIndex + theIdx++);

                AddNamedCommand2(_applicationObject, _addInInstance, mdiDocCommandBar, "SlowX_KEYS_FtpUpdateViews",
                    "URL浏览", "URL浏览", false, 0, closeAllCmdIndex + theIdx++);

                
                // 
                AddNamedCommand2(_applicationObject, _addInInstance, mdiDocCommandBar, "SlowX_KEYS_AdvDialog",
                    "高级", "高级", false, 0, closeAllCmdIndex + theIdx++);


                AddNamedCommand2(_applicationObject, _addInInstance, mdiDocCommandBar, "SlowX_KEYS_myTest",
                    "测试", "测试", false, 0, closeAllCmdIndex + theIdx++);

                #endregion

            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);

                return false;
            }

            return true;
        }

 

        public static bool RemoveSlowXMenu
                   (
                       DTE2 _applicationObject,
                       AddIn _addInInstance
                   )
        {
            bool bFlag = ClearAllCommandBar2(_applicationObject, _addInInstance, "SlowX");

            if (bFlag)
                return ClearAllCommandBar2(_applicationObject, _addInInstance, "SlowX_One");

            return bFlag;
            // return RemoveAllCommandBar2(_applicationObject, _addInInstance, "SlowX");
        }

        public static CommandBarPopup GetToolsCommandBarPopup
            (
                DTE2 _applicationObject,
                AddIn _addInInstance
            )
        {
            string toolsMenuName = GetMenuName(_applicationObject, _addInInstance, "Tools");

            //Place the command on the tools menu.
            //Find the MenuBar command bar, which is the top-level command bar holding all the main menu items:
            Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["MenuBar"];

            //Find the Tools command bar on the MenuBar command bar:
            CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName];
            CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl;

            return toolsPopup;

        }

        public static Microsoft.VisualStudio.CommandBars.CommandBar GetToolsCommandBar
                    (
                        DTE2 _applicationObject,
                        AddIn _addInInstance
                    )
        {
            string toolsMenuName = GetMenuName(_applicationObject, _addInInstance, "Tools");

            //Place the command on the tools menu.
            //Find the MenuBar command bar, which is the top-level command bar holding all the main menu items:
            // Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["MenuBar"];

            Microsoft.VisualStudio.CommandBars.CommandBar toolsBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)[toolsMenuName];


            return toolsBar;

        }

        /// <summary>
        /// 创建菜单
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <param name="_addInInstance"></param>
        /// <param name="strMsg"></param>
        /// <returns></returns>
        public static bool CreateMenu
            (
                DTE2 _applicationObject,
                AddIn _addInInstance,
                out string strMsg
            )
        {

            strMsg = "";

            //object[] contextGUIDS = new object[] { };
            //Commands2 commands = (Commands2)_applicationObject.Commands;

            //CommandBarPopup toolsPopup = GetToolsCommandBarPopup(_applicationObject, _addInInstance);

            ////This try/catch block can be duplicated if you wish to add multiple commands to be handled by your Add-in,
            ////  just make sure you also update the QueryStatus/Exec method to include the new command names.
            //try
            //{
            //    //Add a command to the Commands collection:
            //    Command command =
            //        commands.AddNamedCommand2(_addInInstance, "SlowXTest", "SlowXTest", "Executes the command for SlowXTest",
            //        true, 59, ref contextGUIDS,
            //        (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

            //    //Add a control for the command to the tools menu:
            //    if ((command != null) && (toolsPopup != null))
            //    {
            //        command.AddControl(toolsPopup.CommandBar, 1);
            //    }
            //}
            //catch (System.ArgumentException)
            //{
            //    //If we are here, then the exception is probably because a command with that name
            //    //  already exists. If so there is no need to recreate the command and we can 
            //    //  safely ignore the exception.
            //}

            // CreateCommandBar(_applicationObject, _addInInstance, menuBarCommandBar,"SlowX");
            CreateSlowXMenu(_applicationObject, _addInInstance);

            return true;


        }

        public static void QueryStatus
            (
            DTE2 _applicationObject,
                AddIn _addInInstance,
                string commandName, vsCommandStatusTextWanted neededText, ref vsCommandStatus status, ref object commandText)
        {
            if (neededText == vsCommandStatusTextWanted.vsCommandStatusTextWantedNone)
            {
                if (commandName == "SlowX.Connect.SlowX"
                    || commandName == "SlowX.Connect.SlowX_Code"
                    || commandName == "SlowX.Connect.SlowX_Code_AddUsing"
                    || commandName == "SlowX.Connect.SlowX_Code_OpCtrl"
                    || commandName == "SlowX.Connect.SlowX_Code_GetSet"
                    || commandName == "SlowX.Connect.SlowX_Code_CS"
                    || commandName == "SlowX.Connect.SlowX_Code_Dialog"
                    || commandName == "SlowX.Connect.SlowX_KEYS_CloseAllDocuments"
                    || commandName == "SlowX.Connect.SlowX_KEYS_CopyFile"
                    || commandName == "SlowX.Connect.SlowX_KEYS_CopyTwoFile"
                    || commandName == "SlowX.Connect.SlowX_KEYS_CopyBin"
                    || commandName == SlowXLib.Classes.AddinMenu.CopyBinAndXmlAddinMenu.TheCode
                    || commandName == SlowXLib.Classes.AddinMenu.OpenBinDirAddinMenu.TheCode
                    || commandName == "SlowX.Connect.SlowX_KEYS_TestFun"
                    || commandName == "SlowX.Connect.SlowX_KEYS_CopyFileName"
                    || commandName == "SlowX.Connect.SlowX_KEYS_FtpUpdate"
                    || commandName == "SlowX.Connect.SlowX_KEYS_FtpUpdateAdvance"
                    || commandName == "SlowX.Connect.SlowX_KEYS_FtpUpdateViews"
                    || commandName == "SlowX.Connect.SlowX_KEYS_AdvDialog"
                    || commandName == "SlowX.Connect.SlowX_KEYS_myTest"
                    || commandName == "SlowX.Connect.SlowX_Code_RemoveVarDefine"
                    || commandName == "SlowX.Connect.SlowX_Code_RemoveVarDefine2"
                    )
                {
                    status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
                    return;
                }
                else if (commandName == "SlowX.Connect.SlowX_One"
                    || commandName == "SlowX.Connect.SlowX_Code_One"
                    || commandName == "SlowX.Connect.SlowX_Code_AddUsing_One"
                    || commandName == "SlowX.Connect.SlowX_Code_OpCtrl_One"
                    || commandName == "SlowX.Connect.SlowX_Code_GetSet_One"
                    || commandName == "SlowX.Connect.SlowX_Code_CS_One"
                    || commandName == "SlowX.Connect.SlowX_Code_Dialog_One"
                    || commandName == "SlowX.Connect.SlowX_Code_RemoveVarDefine_One"
                    || commandName == "SlowX.Connect.SlowX_Code_RemoveVarDefine2_One"
                    )
                {
                    status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
                    return;
                }


            }
        }

        public static void Exec(DTE2 _applicationObject,
                AddIn _addInInstance, string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
        {
            handled = false;
            if (executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
            {
                Do(_applicationObject, _addInInstance, commandName, executeOption, ref varIn, ref varOut, ref handled);
            }
        }

        public static void Do(DTE2 _applicationObject,
                AddIn _addInInstance, string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
        {
            if (commandName == "SlowX.Connect.SlowX_Code_AddUsing")
            {
                AddinFunctions.AddUsing(_applicationObject, _addInInstance);

                handled = true;
                return;
            }
            else if (commandName == "SlowX.Connect.SlowX_Code_OpCtrl")
            {
                AddinFunctions.CreateOpCtrlCode(_applicationObject, _addInInstance);

                handled = true;
                return;
            }
            else if (commandName == "SlowX.Connect.SlowX_Code_GetSet")
            {
                AddinFunctions.FormatToProperty(_applicationObject, _addInInstance);

                handled = true;
                return;
            }
            else if (commandName == "SlowX.Connect.SlowX_Code_GetSet")
            {
                AddinFunctions.FormatToProperty(_applicationObject, _addInInstance);

                handled = true;
                return;
            }
            else if (commandName == "SlowX.Connect.SlowX_Code_CS")
            {
                AddinFunctions.ToCS(_applicationObject, _addInInstance);

                handled = true;
                return;
            }
            else if (commandName == "SlowX.Connect.SlowX_Code_Dialog")
            {
                WinForms.SelectClass f = new SlowXLib.WinForms.SelectClass();
                f.ShowDialog();

                if (StringFunctions.IsNotNullOrEmptyAndBlank(f.CommandName))
                    Do(_applicationObject, _addInInstance, f.CommandName, executeOption, ref varIn, ref varOut, ref handled);
            }
            else if (commandName == "SlowX.Connect.SlowX_KEYS_CopyFile")
            {
                CopyFile(_applicationObject);
                handled = true;
                return;
            }
            else if (commandName == "SlowX.Connect.SlowX_KEYS_CopyTwoFile")
            {
                CopyTwoFile(_applicationObject);
                handled = true;
                return;
            }
            else if (commandName == "SlowX.Connect.SlowX_KEYS_CopyBin")
            {
                CopyBin(_applicationObject);
                handled = true;
                return;
            }
            else if (commandName == AddinMenu.CopyBinAndXmlAddinMenu.TheCode)
            {
                CopyBinAndXML(_applicationObject);
                handled = true;
                return;
            }
            else if (commandName == AddinMenu.OpenBinDirAddinMenu.TheCode)
            {
                OpenBinDir(_applicationObject);
                handled = true;
                return;
            }
            else if (commandName == "SlowX.Connect.SlowX_KEYS_TestFun")
            {
                TestFun(_applicationObject, _addInInstance);
                handled = true;
                return;
            }
            else if (commandName == "SlowX.Connect.SlowX_KEYS_CopyFileName")
            {
                CopyFileName(_applicationObject);
                handled = true;
                return;
            }
            else if (commandName == "SlowX.Connect.SlowX_KEYS_CloseAllDocuments")
            {
                CloseAllDocuments(_applicationObject);
                handled = true;
                return;
            }
            else if (commandName == "SlowX.Connect.SlowX_Code_RemoveVarDefine")
            {
                RemoveVarDefine(_applicationObject, _addInInstance);
                handled = true;
                return;
            }
            else if (commandName == "SlowX.Connect.SlowX_Code_RemoveVarDefine2")
            {
                RemoveVarDefine2(_applicationObject, _addInInstance);
                handled = true;
                return;
            }
            else if (commandName == "SlowX.Connect.SlowX_KEYS_FtpUpdate")
            {
                // RemoveVarDefine2(_applicationObject, _addInInstance);
                FtpUpdate(_applicationObject, _addInInstance);
                handled = true;
                return;
            }
            else if (commandName == "SlowX.Connect.SlowX_KEYS_FtpUpdateAdvance")
            {
                // 查看网址 //
                ViewWebSite(_applicationObject, _addInInstance);
                handled = true;
                return;
            }
            else if (commandName == "SlowX.Connect.SlowX_KEYS_FtpUpdateViews")
            {
                // RemoveVarDefine2(_applicationObject, _addInInstance);
                URLView(_applicationObject, _addInInstance);
                handled = true;
                return;
            }
            else if (commandName == "SlowX.Connect.SlowX_KEYS_AdvDialog")
            {
                // RemoveVarDefine2(_applicationObject, _addInInstance);
                AdvDialog(_applicationObject, _addInInstance);
                handled = true;
                return;
            }
            else if (commandName == "SlowX.Connect.SlowX_KEYS_myTest")
            {
                // RemoveVarDefine2(_applicationObject, _addInInstance);
                myTest(_applicationObject, _addInInstance);
                handled = true;
                return;
            }
            else
            {
                if (commandName.EndsWith("_One"))
                {
                    commandName = commandName.Substring(0, commandName.Length - ("_One").Length);
                    Do(_applicationObject, _addInInstance, commandName, executeOption, ref varIn, ref varOut, ref handled);
                    return;
                }
            }

        }
        #endregion

        /// <summary>
        /// 格式化变量
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <param name="_addInInstance"></param>
        /// <returns></returns>
        public static bool FormatVar
                    (
                        DTE2 _applicationObject,
                        AddIn _addInInstance
                    )
        {
            string strText = GetSelectionText(_applicationObject);

            if (StringFunctions.IsNullOrEmptyAndBlank(strText))
                return true;

            return true;

        }

        public static bool FormatString
                    (
                        DTE2 _applicationObject,
                        AddIn _addInInstance
                    )
        {
            string strText = GetSelectionText(_applicationObject);

            if (StringFunctions.IsNullOrEmptyAndBlank(strText))
                return true;

            return true;

        }

        public static bool RemoveVarDefine
                    (
                        DTE2 _applicationObject,
                        AddIn _addInInstance
                    )
        {
            string strText = GetSelectionText(_applicationObject);

            if (StringFunctions.IsNullOrEmptyAndBlank(strText))
                return true;

            string[] strArray = strText.Split('\n');

            string strResult = "";
            string strTmp = "";
            string strItem = "";

            int iLen = 0;
            int i = 0;
            int iFindIdx = 0;

            foreach (string s in strArray)
            {
                if (StringFunctions.IsNullOrEmptyAndBlank(s))
                    continue;

                strItem = s.Trim();

                iLen = strItem.Length;
                i = 0;
                iFindIdx = 0;

                for (i = 0; i < iLen; ++i)
                {
                    if (strItem[i] == ' ')
                    {
                        if (strTmp == "")
                            continue;
                        else
                        {
                            if (strTmp == "readonly"
                                || strTmp == "const"
                                || strTmp == "public"
                                || strTmp == "private"
                                || strTmp == "protected"
                                || strTmp == "static"
                                )
                            {
                                strTmp = "";
                                continue;
                            }
                            else
                                break;
                        }
                    }
                    else
                    {
                        if (strTmp == "")
                            iFindIdx = i;

                        strTmp += strItem[i].ToString();
                    }
                }

                if (iFindIdx < strItem.Length && iFindIdx >= 0)
                    strResult += strItem.Substring(iFindIdx) + StringFunctions.STR_CRLF;

                iFindIdx = 0;
                strTmp = "";
                strItem = "";

                iLen = 0;
                i = 0;
                iFindIdx = 0;
            }

            return SetSelectionText(_applicationObject, strResult);
        }

        public static bool RemoveVarDefine2
                            (
                                DTE2 _applicationObject,
                                AddIn _addInInstance
                            )
        {
            string strText = GetSelectionText(_applicationObject);

            if (StringFunctions.IsNullOrEmptyAndBlank(strText))
                return true;

            string[] strArray = strText.Split('\n');

            string strResult = "";
            string strTmp = "";
            string strItem = "";

            int iLen = 0;
            int i = 0;
            int iFindIdx = 0;

            foreach (string s in strArray)
            {
                if (StringFunctions.IsNullOrEmptyAndBlank(s))
                    continue;

                strItem = s.Trim();

                iLen = strItem.Length;
                i = 0;
                iFindIdx = 0;

                for (i = 0; i < iLen; ++i)
                {
                    if (strItem[i] == ' ')
                    {
                        if (strTmp == "")
                            continue;
                        else
                        {
                            if (strTmp == "readonly"
                                || strTmp == "const"
                                || strTmp == "public"
                                || strTmp == "private"
                                || strTmp == "protected"
                                || strTmp == "static"
                                || strTmp == "string"
                                || strTmp == "int"
                                || strTmp == "DateTime"
                                || strTmp == "long"
                                || strTmp == "double"
                                || strTmp == "float"
                                || strTmp == "bool"
                                || strTmp == "char"
                                )
                            {
                                strTmp = "";
                                continue;
                            }
                            else
                                break;
                        }
                    }
                    else
                    {
                        if (strTmp == "")
                            iFindIdx = i;

                        strTmp += strItem[i].ToString();
                    }
                }

                if (iFindIdx < strItem.Length && iFindIdx >= 0)
                    strResult += strItem.Substring(iFindIdx) + StringFunctions.STR_CRLF;

                iFindIdx = 0;
                strTmp = "";
                strItem = "";

                iLen = 0;
                i = 0;
                iFindIdx = 0;
            }

            return SetSelectionText(_applicationObject, strResult);
        }

        //bool IsPublic = false;
        //bool IsStatic = false;
        //bool IsReadonly = false;



        /// <summary>
        /// 有BUG,没写完
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string GetFormatString
                    (
                        string str
                    )
        {
            if (str == null || str == "")
                return "";
            else
            {
                if (StringFunctions.IsNullOrEmptyAndBlank(str))
                {
                    if (StringFunctions.Contains(str, StringFunctions.STR_N, false))

                        return StringFunctions.STR_CRLF;
                    else
                        return " ";
                }
                else
                {
                    //StringBuilder sb = new StringBuilder();

                    //int iLen = str.Length;

                    ////bool Is = false;
                    ////bool IsZhuanYi = false;
                    ////bool Is2 = false;

                    //for (int i = 0; i < iLen; ++i)
                    //{
                    //    char c = str[i];

                        
                    //}
                    // StringBu
                    //str = str.Replace('\n', ' ');
                    //string[] strArray = str.Split(' ');

                    //if (strArray == null || strArray.Length == 0)
                    //    return "";

                    //string strResult
                    //    = "";
                    //string strItem = "";
                    //string strTmp = "";

                    //bool IsPublic = false;
                    //bool IsStatic = false;
                    //bool IsReadonly = false;

                    //foreach (string s in strArray)
                    //{
                    //    if (StringFunctions.IsNullOrEmptyAndBlank(s))
                    //        continue;

                    //    strTmp = s.Trim();

                    //    if (strTmp == "public" || strTmp == "private" || strTmp == "protected")
                    //    {
                    //        if (!IsPublic)
                    //        {
                    //            strItem = StringFunctions.AddChar(str, strTmp, " ");
                    //            IsPublic = true;
                    //        }
                    //    }
                    //    else if (strTmp == "static")
                    //    {
                    //        if (!IsStatic)
                    //        {
                    //            strItem = StringFunctions.AddChar(str, strTmp, " ");
                    //            IsStatic = true;
                    //        }
                    //    }
                    //    else if (strTmp == "readonly" || strTmp == "const")
                    //    {
                    //        if (!IsReadonly)
                    //        {
                    //            strItem = StringFunctions.AddChar(str, strTmp, " ");
                    //            IsReadonly = true;
                    //        }
                    //    }
                    //    else if (strTmp == "," || strTmp == ";")
                    //    {
                    //        IsPublic = false;
                    //        IsStatic = false;
                    //        IsReadonly = false;

                    //        strItem = "";
                    //    }

                    //}

                }

                return "";

            }




        }

        /// <summary>
        /// 添加using
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <param name="_addInInstance"></param>
        /// <returns></returns>
        public static bool AddUsing
            (
                DTE2 _applicationObject,
                AddIn _addInInstance
            )
        {
            string strText
                 = "";

            strText = @"

using AjaxPro;

using CT.BA.Classes.Ajax;

using CT.BA.Classes.Entity;
using CT.BA.Classes.Business;

using CT.BA.Classes.Common;
using CT.BA.Classes.Pages;
using CT.BA.Classes.Functions;

using CT.BA.Classes.Loger;

";

            return SetSelectionText(_applicationObject, strText);

        }



        #region 生成CS文件

        /// <summary>
        /// 生成CS文件
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <param name="_addInInstance"></param>
        /// <returns></returns>
        public static bool ToCS
            (
                DTE2 _applicationObject,
                AddIn _addInInstance
            )
        {
            TextSelection objSel = GetTextSelection(_applicationObject);

            if (objSel == null)
                return false;

            string strText = objSel.Text;

            if (strText == null)
                return false;


            objSel.SelectAll();

            string str = @"
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using System.IO;
using System.Text;

using CT.BA.Controls.Web.UI.WebControls;

using CT.BA.Classes.Classes;
using CT.BA.Classes.Common;
using CT.BA.Classes.Functions;
using CT.BA.Classes.Pages;
using CT.BA.Classes.Utility;
using CT.BA.Classes.Entity;
using CT.BA.Classes.Business;

using CT.Lib.Classes.Pages;

public partial class {$ClassName} : FCAPageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {

        }
    }
}


";

            str = str.Replace("{$ClassName}", strText);

            objSel.Text = str;

            return true;

        }

        #endregion


        #region 格式化成get/set模式
        /// <summary>
        /// 格式化成get/set模式
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <param name="_addInInstance"></param>
        /// <returns></returns>
        public static bool FormatToProperty
            (
                DTE2 _applicationObject,
                AddIn _addInInstance
            )
        {
            TextSelection objSel = GetTextSelection(_applicationObject);

            if (objSel == null)
                return false;

            string strText = objSel.Text;

            if (strText == null)
                return false;

            strText = strText.Trim();

            if (strText == "")
                return false;

            if (strText.EndsWith(";"))
                strText = strText.Substring(0, strText.Length - 1);

            if (strText == "")
                return false;

            string[] strArray = strText.Split(' ');

            string strOne = null;
            string strTwo = null;
            string strThree = null;

            if (strArray == null || strArray.Length == 0)
                return false;

            foreach (string s in strArray)
            {
                if (s == null || s.Trim() == "")
                    continue;

                string str = s.Trim();

                if (str == "public" || str == "protected" || str == "private")
                    continue;

                if (strOne == null)
                    strOne = s.Trim();
                else if (strTwo == null)
                {
                    strTwo = s.Trim();
                    break;
                }
                else
                    break;
            }

            if (strTwo == null)
            {
                strTwo = strOne;
                strOne = "string";
            }

            strThree = strTwo;

            if (strThree.StartsWith("m_"))
                strThree = strThree.Substring(2);
            else if (strThree.StartsWith("_"))
                strThree = strThree.Substring(1);

            string strResult = "";

            strResult += "public " + strOne + " " + strThree + StringFunctions.STR_CRLF;

            strResult += "{" + StringFunctions.STR_CRLF;

            strResult += StringFunctions.STR_TAB + "get" + StringFunctions.STR_CRLF;
            strResult += StringFunctions.STR_TAB + "{" + StringFunctions.STR_CRLF;
            strResult += StringFunctions.STR_TAB + StringFunctions.STR_TAB + " return " + strTwo + ";" + StringFunctions.STR_CRLF;
            strResult += StringFunctions.STR_TAB + "}" + StringFunctions.STR_CRLF;

            strResult += StringFunctions.STR_TAB + "set" + StringFunctions.STR_CRLF;
            strResult += StringFunctions.STR_TAB + "{" + StringFunctions.STR_CRLF;
            strResult += StringFunctions.STR_TAB + StringFunctions.STR_TAB + strTwo + " = value;" + StringFunctions.STR_CRLF;
            strResult += StringFunctions.STR_TAB + "}" + StringFunctions.STR_CRLF;

            strResult += "}" + StringFunctions.STR_CRLF;

            strResult = StringFunctions.STR_CRLF + StringFunctions.STR_CRLF + strResult;


            objSel.Insert(strResult, System.Convert.ToInt32(
             vsInsertFlags.vsInsertFlagsInsertAtEnd));
            //TextDocument txtDoc = GetTextDocument(_applicationObject);

            //if (txtDoc == null)
            //    return false;

            //EditPoint p = (EditPoint)txtDoc.EndPoint.CreateEditPoint();
            //// EditPoint p1 = (EditPoint)txtDoc.Selection.End

            //if (p == null)
            //    return false;

            //p.Insert("cano");


            //string strSelectText = GetSelectionText(_applicationObject);



            // TextDocument objTextDoc = GetActiveDocument(_applicationObject) as TextDocument;

            //
            //d.Ins

            //if (objTextDoc == null)
            //    return false;

            //EditPoint p = (EditPoint)objTextDoc.EndPoint.CreateEditPoint();

            //p.Insert("cano");

            // ActivePointExample(_applicationObject);

            // AnchorPointExample(_applicationObject);

            // InsertExample(_applicationObject);

            // FindPatternExample(_applicationObject);

            // OutlineSectionExample(_applicationObject);

            // CommandNamesCollapseExample(_applicationObject);

            return true;

            //                    EditPoint objEditPoint = (EditPoint)objTextDoc.StartPoint.CreateEditPoint();//.CreateEditPoint;

            //                    objEditPoint.Insert(strRemark);

            //                    String strFileName = p.get_FileNames(0);

            //                    p.SaveAs(strFileName);

        }

        #endregion

        /// <summary>
        /// 创建实体操作的方法
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <param name="_addInInstance"></param>
        /// <returns></returns>
        public static bool CreateOpCtrlCode
            (
                DTE2 _applicationObject,
                AddIn _addInInstance
            )
        {
            // 加载Lib //

            Assembly assembly = GetLibAssembly(_applicationObject, null);

            if (assembly == null)
                return true;

            Type[] t = assembly.GetTypes();

            if (t == null)
                return true;

            string strSelectText = GetSelectionText(_applicationObject);
            string strClassFullName = "";
            foreach (Type type in t)
            {
                if (!StringFunctions.Contains(type.FullName, ".Classes.Business.", false))
                    continue;

                if (!StringFunctions.StringCompare(type.Name, strSelectText, true, true))
                    continue;

                strClassFullName = type.FullName;
                break;
            }

            if (strClassFullName == "")
                return true;

            strClassFullName = GetCode(strClassFullName);

            SetSelectionText(_applicationObject, strClassFullName);

            return true;
        }

        /// <summary>
        /// 测试
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <param name="_addInInstance"></param>
        /// <returns></returns>
        public static bool DoTest
            (
                DTE2 _applicationObject,
                AddIn _addInInstance
            )
        {

            //WinForms.ViewCommandForm f = new SlowXLib.WinForms.ViewCommandForm();
            //f.ShowDialog();

            //Do(
            //    _ap
            return true;

        }

        #region 获得类转义代码

        public static string GetEntityCode(string strName, string strFullName)
        {
            // string str = @"{$Name} = {$bll}.Entity as ";// +strFullName;

            string strResult = strName + " = " + strName.Replace("entity", "bll") + ".Entity as " + strFullName;

            return strResult;
        }

        public static string GetCode(string strClassFullName)
        {
            if (StringFunctions.IsNullOrEmptyAndBlank(strClassFullName))
                return "";

            string str = @"

        bool bIsCreate =
            CT.BA.Classes.OpCtrl.BaseOpCtrl.StaticNewOpCtrl(ref opCtrl);

        try
        {

            CT.BA.Classes.OpCtrl.BaseOpCtrl.StaticOpenOpCtrl(opCtrl, bIsCreate, false);


            {$Business} bll = new {$Business}(opCtrl.dbHelper);
            {$Entity} entity = bll.Entity as {$Entity};

            CT.BA.Classes.OpCtrl.BaseOpCtrl.StaticEndOpCtrl(opCtrl, bIsCreate);

        }
        catch (Exception err)
        {
            CT.BA.Classes.OpCtrl.BaseOpCtrl.StaticTranOpCtrl(opCtrl, bIsCreate, err);

            return false;
        }

        return true;

";
            string strEntity = strClassFullName.Replace(".Classes.Business.", ".Classes.Entity.");

            str = str.Replace("{$Business}", strClassFullName).Replace("{$Entity}", strEntity);

            return str;
        }

        #endregion


        #region 我自定义的方法


        /// <summary>
        /// 添加文本在光标后面
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <param name="strText"></param>
        /// <returns></returns>
        public static bool InsertTextAfterTextSelection(DTE2 _applicationObject, string strText)
        {
            if (strText == null || strText == "")
                return true;

            TextSelection objSel = GetTextSelection(_applicationObject);

            if (objSel == null)
                return false;

            objSel.Insert(strText, System.Convert.ToInt32(
                vsInsertFlags.vsInsertFlagsInsertAtEnd));

            return true;
        }

        /// <summary>
        /// 获得项目的类型
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <returns></returns>
        public static CT.BA.Classes.Enums.Common.ProjType.EmProjType
            GetEmProjType(DTE2 _applicationObject)
        {
            return GetEmProjType(null, _applicationObject);
        }

        /// <summary>
        /// 获得项目的类型
        /// </summary>
        /// <param name="proj"></param>
        /// <returns></returns>
        public static CT.BA.Classes.Enums.Common.ProjType.EmProjType
            GetEmProjType(EnvDTE.Project proj)
        {
            return GetEmProjType(proj, null);
        }

        /// <summary>
        /// 获得项目的类型
        /// </summary>
        /// <param name="proj"></param>
        /// <param name="_applicationObject"></param>
        /// <returns></returns>
        public static CT.BA.Classes.Enums.Common.ProjType.EmProjType
            GetEmProjType(EnvDTE.Project proj, DTE2 _applicationObject)
        {
            string strOutputFileName = GetProjOutputFileName(proj, _applicationObject);

            if (StringFunctions.IsNullOrEmptyAndBlank(strOutputFileName))
                return CT.BA.Classes.Enums.Common.ProjType.EmProjType.Web;

            if (StringFunctions.IsWith(strOutputFileName, ".exe", false, true))
                return CT.BA.Classes.Enums.Common.ProjType.EmProjType.Exe;
            else if (StringFunctions.IsWith(strOutputFileName, ".dll", false, true))
                return CT.BA.Classes.Enums.Common.ProjType.EmProjType.DLL;
            else
                return CT.BA.Classes.Enums.Common.ProjType.EmProjType.Web;
        }

        #region 获得项目的输出

        /// <summary>
        /// 获得项目的输出
        /// GetProjFullOutput
        /// E:\Projects\HomePage\Witch\SRC\Addin\SlowX\SlowXLib\bin\Debug\ 
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <returns></returns>
        public static string GetProjBinDir(DTE2 _applicationObject)
        {
            return GetProjBinDir(null, _applicationObject);
        }

        /// <summary>
        /// 获得项目的输出
        /// GetProjFullOutput
        /// E:\Projects\HomePage\Witch\SRC\Addin\SlowX\SlowXLib\bin\Debug\ 
        /// </summary>
        /// <param name="proj"></param>
        /// <returns></returns>
        public static string GetProjBinDir(EnvDTE.Project proj)
        {
            return GetProjBinDir(proj, null);
        }

        /// <summary>
        /// 获得项目的输出
        /// GetProjFullOutput
        /// E:\Projects\HomePage\Witch\SRC\Addin\SlowX\SlowXLib\bin\Debug\ 
        /// </summary>
        /// <param name="proj"></param>
        /// <param name="_applicationObject"></param>
        /// <returns></returns>
        public static string GetProjBinDir(EnvDTE.Project proj, DTE2 _applicationObject)
        {
            return FileFunctions.Add
                (GetProjFullPath(proj, _applicationObject), GetProjOutputPath(proj, _applicationObject), false);
        }

        /// <summary>
        /// 获得项目的输出
        /// GetProjFullOutput
        /// E:\Projects\HomePage\Witch\SRC\Addin\SlowX\SlowXLib\bin\Debug\SlowXLib.dll
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <returns></returns>
        public static string GetProjFullOutput(DTE2 _applicationObject)
        {
            return GetProjFullOutput(null, _applicationObject);
        }

        /// <summary>
        /// 获得项目的输出
        /// GetProjFullOutput
        /// E:\Projects\HomePage\Witch\SRC\Addin\SlowX\SlowXLib\bin\Debug\SlowXLib.dll
        /// </summary>
        /// <param name="proj"></param>
        /// <returns></returns>
        public static string GetProjFullOutput(EnvDTE.Project proj)
        {
            return GetProjFullOutput(proj, null);
        }

        /// <summary>
        /// 获得项目的输出
        /// GetProjFullOutput
        /// E:\Projects\HomePage\Witch\SRC\Addin\SlowX\SlowXLib\bin\Debug\SlowXLib.dll
        /// </summary>
        /// <param name="proj"></param>
        /// <param name="_applicationObject"></param>
        /// <returns></returns>
        public static string GetProjFullOutput(EnvDTE.Project proj, DTE2 _applicationObject)
        {
            if (proj == null)
                proj = GetCurProject(_applicationObject);

            if (proj == null)
                return null;

            CT.BA.Classes.Enums.Common.ProjType.EmProjType emProjType = GetEmProjType(proj, _applicationObject);

            try
            {
                string strResult = "";

                if (emProjType == CT.BA.Classes.Enums.Common.ProjType.EmProjType.Exe
                    || emProjType == CT.BA.Classes.Enums.Common.ProjType.EmProjType.DLL)
                {

                    strResult += GetProjFullPath(proj, _applicationObject);

                    if (!(strResult.EndsWith("\\") || strResult.EndsWith("/")))
                        strResult += "\\";

                    strResult += GetProjOutputPath(proj, _applicationObject);

                    if (!(strResult.EndsWith("\\") || strResult.EndsWith("/")))
                        strResult += "\\";

                    strResult += GetProjOutputFileName(proj, _applicationObject);
                }
                else if (emProjType == CT.BA.Classes.Enums.Common.ProjType.EmProjType.Web)
                {
                    strResult += GetProjFullPath(proj, _applicationObject);
                }

                return strResult;
            }
            catch
            {
                return null;
            }

        }

        /// <summary>
        /// 获得项目的输出
        /// GetProjFileSubDir
        /// E:\Projects\HomePage\Witch\SRC\Addin\SlowX\SlowXLib\bin\Debug\SlowXLib.dll
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <returns></returns>
        public static string GetProjFileSubDir(DTE2 _applicationObject)
        {
            return GetProjFileSubDir(null, _applicationObject);
        }

        /// <summary>
        /// 获得项目的输出
        /// GetProjFileSubDir
        /// E:\Projects\HomePage\Witch\SRC\Addin\SlowX\SlowXLib\bin\Debug\SlowXLib.dll
        /// </summary>
        /// <param name="proj"></param>
        /// <returns></returns>
        public static string GetProjFileSubDir(EnvDTE.Project proj)
        {
            return GetProjFileSubDir(proj, null);
        }

        /// <summary>
        /// 获得项目的输出
        /// GetProjFileSubDir
        /// E:\Projects\HomePage\Witch\SRC\Addin\SlowX\SlowXLib\bin\Debug\SlowXLib.dll
        /// </summary>
        /// <param name="proj"></param>
        /// <param name="_applicationObject"></param>
        /// <returns></returns>
        public static string GetProjFileSubDir(EnvDTE.Project proj, DTE2 _applicationObject)
        {
            string strProjFileSubFileName =
                GetProjFileSubFileName(proj, _applicationObject);

            if (StringFunctions.IsNullOrEmptyAndBlank(strProjFileSubFileName))
                return null;
            
            strProjFileSubFileName = strProjFileSubFileName.Trim();

            int idx = strProjFileSubFileName.LastIndexOf("\\");

            if (idx != -1)
                return strProjFileSubFileName.Substring(0, idx);
            else
            {
                //return strProjFileSubFileName;
                return "";
            }
        }


        /// <summary>
        /// 获得项目的输出
        /// GetProjFileSubFileName
        /// E:\Projects\HomePage\Witch\SRC\Addin\SlowX\SlowXLib\bin\Debug\SlowXLib.dll
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <returns></returns>
        public static string GetProjFileSubFileName(DTE2 _applicationObject)
        {
            return GetProjFileSubFileName(null, _applicationObject);
        }

        /// <summary>
        /// 获得项目的输出
        /// GetProjFileSubFileName
        /// E:\Projects\HomePage\Witch\SRC\Addin\SlowX\SlowXLib\bin\Debug\SlowXLib.dll
        /// </summary>
        /// <param name="proj"></param>
        /// <returns></returns>
        public static string GetProjFileSubFileName(EnvDTE.Project proj)
        {
            return GetProjFileSubFileName(proj, null);
        }

        /// <summary>
        /// 获得项目的输出
        /// GetProjFileSubFileName
        /// E:\Projects\HomePage\Witch\SRC\Addin\SlowX\SlowXLib\bin\Debug\SlowXLib.dll
        /// </summary>
        /// <param name="proj"></param>
        /// <param name="_applicationObject"></param>
        /// <returns></returns>
        public static string GetProjFileSubFileName(EnvDTE.Project proj, DTE2 _applicationObject)
        {
            if (proj == null)
                proj = GetCurProject(_applicationObject);

            if (proj == null)
                return null;

            CT.BA.Classes.Enums.Common.ProjType.EmProjType emProjType = GetEmProjType(proj, _applicationObject);

            try
            {
                string strResult = "";

                string strProjFullPath = GetProjFullPath(proj, _applicationObject);
                string strFileName = GetDocumentFullName(_applicationObject);

                if (StringFunctions.IsNullOrEmptyAndBlank(strFileName)
                    || StringFunctions.IsNullOrEmptyAndBlank(strProjFullPath))
                    return null;

                strProjFullPath = FileFunctions.ToName(strProjFullPath, false);
                strFileName = FileFunctions.ToName(strFileName, false);

                if (strFileName.StartsWith(strProjFullPath, true, null))
                    strResult = strFileName.Substring(strProjFullPath.Length);

                return strResult;
            }
            catch
            {
                return null;
            }

        }

        /// <summary>
        /// 获得项目的输出
        /// SlowXLib.dll
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <returns></returns>
        public static string GetProjOutputFileName(DTE2 _applicationObject)
        {
            return GetProjOutputFileName(null, _applicationObject);
        }

        /// <summary>
        /// 获得项目的输出
        /// SlowXLib.dll
        /// </summary>
        /// <param name="proj"></param>
        /// <returns></returns>
        public static string GetProjOutputFileName(EnvDTE.Project proj)
        {
            return GetProjOutputFileName(proj, null);
        }

        /// <summary>
        /// 获得项目的输出
        /// SlowXLib.dll
        /// </summary>
        /// <param name="proj"></param>
        /// <param name="_applicationObject"></param>
        /// <returns></returns>
        public static string GetProjOutputFileName(EnvDTE.Project proj, DTE2 _applicationObject)
        {
            if (proj == null)
                proj = GetCurProject(_applicationObject);

            if (proj == null)
                return null;

            try
            {
                return StringFunctions.GetObjNullToDefault(proj.Properties.Item("OutputFileName").Value, false, "", false);
            }
            catch
            {
                return null;
            }

        }

        #endregion

        #region 获得网站项目虚拟路径


        /// <summary>
        /// 获得网站项目虚拟路径
        /// 
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <returns></returns>
        public static string GetProjVsWebServerVPath(DTE2 _applicationObject)
        {
            return GetProjVsWebServerVPath(null, _applicationObject);
        }

        /// <summary>
        /// 获得网站项目虚拟路径
        /// </summary>
        /// <param name="proj"></param>
        /// <returns></returns>
        public static string GetProjVsWebServerVPath(EnvDTE.Project proj)
        {
            return GetProjVsWebServerVPath(proj, null);
        }

        /// <summary>
        /// 获得网站项目虚拟路径
        /// </summary>
        /// <param name="proj"></param>
        /// <param name="_applicationObject"></param>
        /// <returns></returns>
        public static string GetProjVsWebServerVPath(EnvDTE.Project proj, DTE2 _applicationObject)
        {
            if (proj == null)
                proj = GetCurProject(_applicationObject);

            if (proj == null)
                return null;

            try
            {
                return StringFunctions.GetObjNullToDefault(proj.Properties.Item("VsWebServerVPath").Value, false, "", false);
            }
            catch
            {
                return null;
            }

        }

        #endregion

        #region 获得项目根路径


        /// <summary>
        /// 获得项目根路径
        /// E:\Projects\HomePage\Witch\SRC\Addin\SlowX\SlowXLib\
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <returns></returns>
        public static string GetProjFullPath(DTE2 _applicationObject)
        {
            return GetProjFullPath(null, _applicationObject);
        }

        /// <summary>
        /// 获得项目根路径
        /// E:\Projects\HomePage\Witch\SRC\Addin\SlowX\SlowXLib\
        /// </summary>
        /// <param name="proj"></param>
        /// <returns></returns>
        public static string GetProjFullPath(EnvDTE.Project proj)
        {
            return GetProjFullPath(proj, null);
        }

        /// <summary>
        /// 获得项目根路径
        /// E:\Projects\HomePage\Witch\SRC\Addin\SlowX\SlowXLib\
        /// </summary>
        /// <param name="proj"></param>
        /// <param name="_applicationObject"></param>
        /// <returns></returns>
        public static string GetProjFullPath(EnvDTE.Project proj, DTE2 _applicationObject)
        {
            if (proj == null)
                proj = GetCurProject(_applicationObject);

            if (proj == null)
                return null;

            try
            {
                return StringFunctions.GetObjNullToDefault(proj.Properties.Item("FullPath").Value, false, "", false);
            }
            catch
            {
                return null;
            }

        }

        #endregion

        #region 获得项目输出路径
        /// <summary>
        /// 获得项目输出路径
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <returns></returns>
        public static string GetProjOutputPath(DTE2 _applicationObject)
        {
            return GetProjOutputPath(null, _applicationObject);
        }

        /// <summary>
        /// 获得项目输出路径
        /// </summary>
        /// <param name="proj"></param>
        /// <returns></returns>
        public static string GetProjOutputPath(EnvDTE.Project proj)
        {
            return GetProjOutputPath(proj, null);
        }

        /// <summary>
        /// 获得项目输出路径
        /// </summary>
        /// <param name="proj"></param>
        /// <param name="_applicationObject"></param>
        /// <returns></returns>
        public static string GetProjOutputPath(EnvDTE.Project proj, DTE2 _applicationObject)
        {
            if (proj == null)
                proj = GetCurProject(_applicationObject);

            if (proj == null)
                return null;

            // CT.BA.Classes.Enums.Common.ProjType.EmProjType em = GetEmProjType(proj, _applicationObject);

            try
            {
                if (proj.ConfigurationManager == null || proj.ConfigurationManager.ActiveConfiguration == null
                    || proj.ConfigurationManager.ActiveConfiguration.Properties == null)
                    return "bin\\";
                else
                {
                    string strTmp = StringFunctions.GetObjNullToDefault(proj.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath").Value, false, "", false);

                    return strTmp;
                }
            }
            catch
            {
                return null;
            }

        }

        #endregion

        #region 获得DLL的路径
        /// <summary>
        /// 获得DLL的路径
        /// </summary>
        /// <returns></returns>
        public static string GetLibFileName(DTE2 _applicationObject)
        {
            return GetLibFileName(_applicationObject, null);
        }

        /// <summary>
        /// 获得DLL的路径
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <param name="ddlName"></param>
        /// <returns></returns>
        public static string GetLibFileName(DTE2 _applicationObject, string ddlName)
        {
            if (StringFunctions.IsNullOrEmptyAndBlank(ddlName))
                ddlName = "ct.lib.dll";
            else
                ddlName = ddlName.Trim();

            string strFullPath = GetProjFullPath(_applicationObject);
            string strOutputPath = GetProjOutputPath(_applicationObject);

            if (strFullPath == null || strOutputPath == null)
                return null;
            else
            {
                if (strFullPath != "")
                {
                    if (!(strFullPath.EndsWith("\\") || strFullPath.EndsWith("/")))
                        strFullPath += "\\";
                }


                if (strOutputPath != "")
                {
                    if (!(strOutputPath.EndsWith("\\") || strOutputPath.EndsWith("/")))
                        strOutputPath += "\\";
                }
                return strFullPath + strOutputPath + ddlName;
            }
        }

        #endregion

        public static Assembly GetLibAssembly(DTE2 _applicationObject)
        {
            return GetLibAssembly(_applicationObject, null);
        }

        public static Assembly GetLibAssembly(DTE2 _applicationObject, string ddlName)
        {
            string strLib = GetLibFileName(_applicationObject, ddlName);

            if (strLib == null)
                return null;
            else
                return CommonFunctions.GetAssemblyByFullLibName(strLib);
        }

        /// <summary>
        /// 获得调试
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <returns></returns>
        public static Debugger GetDebugger(DTE2 _applicationObject)
        {
            if (_applicationObject == null)
                return null;

            EnvDTE.Debugger
            debugger = _applicationObject.Debugger;

            return debugger;
        }

        /// <summary>
        /// 是否调试(待确认的方法)
        /// </summary>
        /// <returns></returns>
        public static bool IsDebugging(DTE2 _applicationObject)
        {
            EnvDTE.Debugger debugger = GetDebugger(_applicationObject);

            if (debugger == null)
                return false;
            else
            {
                return (debugger.CurrentMode != dbgDebugMode.dbgDesignMode);
            }
        }

        /// <summary>
        /// 获得文本文档
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <returns></returns>
        public static EnvDTE.TextDocument GetTextDocument(DTE2 _applicationObject)
        {
            Document doc = GetActiveDocument(_applicationObject);
            if (doc == null)
                return null;

            TextDocument txtDoc = (EnvDTE.TextDocument)(doc.Object("TextDocument"));

            return txtDoc;
        }

        /// <summary>
        /// 获得当前文档
        /// </summary>
        /// <returns></returns>
        public static Document GetActiveDocument
            (
                DTE2 _applicationObject
            )
        {
            if (_applicationObject == null)
                return null;

            Document activeDocument = _applicationObject.ActiveDocument;

            return activeDocument;
        }

        /// <summary>
        /// 获得选中的文本的TextSelection
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <returns></returns>
        public static TextSelection GetTextSelection
            (
                DTE2 _applicationObject
            )
        {
            Document activeDocument = GetActiveDocument(_applicationObject);

            if (activeDocument == null)
                return null;

            TextSelection txtSelect = (TextSelection)activeDocument.Selection;

            return txtSelect;
        }

        /// <summary>
        /// 获得选中的文本
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <returns></returns>
        public static string GetSelectionText
            (
                DTE2 _applicationObject
            )
        {

            TextSelection txtSelect = GetTextSelection(_applicationObject);

            if (txtSelect == null)
                return null;

            return txtSelect.Text;
        }

        /// <summary>
        /// 设置选中的内容
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <param name="strText"></param>
        /// <returns></returns>
        public static bool SetSelectionText
                    (
                        DTE2 _applicationObject,
                        string strText
                    )
        {

            TextSelection txtSelect = GetTextSelection(_applicationObject);

            if (txtSelect == null)
                return false;

            if (strText == null)
                strText = "";

            txtSelect.Text = strText;

            return true;
        }

        /// <summary>
        /// 获得当前项目
        /// </summary>
        /// <returns></returns>
        public static EnvDTE.Project GetCurProject
            (DTE2 _applicationObject)
        {
            if (_applicationObject == null)
                return null;

            Array projects = (Array)_applicationObject.ActiveSolutionProjects;// .ActiveSolutionProjects ; //’开发环境下打开的所有项目

            if (projects == null || projects.Length == 0)
                return null;
            else
                return (EnvDTE.Project)projects.GetValue(0);
        }

        public static string GetSatelliteDllPath
            (
                DTE2 _applicationObject,
                AddIn _addInInstance
            )
        {
            if(_addInInstance == null)
                return "";

            return _addInInstance.SatelliteDllPath;
        }

        public static string GetSatelliteDllDirPath
            (
                DTE2 _applicationObject,
                AddIn _addInInstance
            )
        {
            string str = GetSatelliteDllPath(_applicationObject, _addInInstance);

            if (str == "")
                return "";
            else
            {
                int idx = str.LastIndexOf(FileFunctions.GetChar(false));
                if (idx != -1)
                    return str.Substring(0, idx);
                else
                    return str;
            }

        }

        /// <summary>
        /// 获得项目的配置文件
        /// </summary>
        /// <returns></returns>
        public static System.Configuration.Configuration GetAppConfig()
        {
            return GetAppConfig(null);
        }

        public static System.Configuration.Configuration GetAddinAppConfig
            (
                DTE2 _applicationObject,
                AddIn _addInInstance
            )
        {
            if (_addInInstance == null)
                return null;

            return GetAppConfig(GetSatelliteDllPath(_applicationObject, _addInInstance));
        }

        public static System.Configuration.Configuration GetProjAppConfig
            (
                DTE2 _applicationObject,
                AddIn _addInInstance
            )
        {
            if (_applicationObject == null || _addInInstance == null)
                return null;

            CT.BA.Classes.Enums.Common.ProjType.EmProjType em = GetEmProjType(_applicationObject);

            if (em == CT.BA.Classes.Enums.Common.ProjType.EmProjType.Web)
            {
                return GetWebAppConfig(GetProjVsWebServerVPath(_applicationObject));
            }
            else
            {
                return GetExecAppConfig(GetProjFullOutput(_applicationObject));
            }

        }

        public static System.Configuration.Configuration GetExecAppConfig
                    (
                        string strFileName
                    )
        {
            return GetAppConfig(strFileName);
        }

        public static System.Configuration.Configuration GetWebAppConfig
                    (
                        string strFileName
                    )
        {
            try
            {
                return System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(strFileName);
            }
            catch (Exception err)
            {
                System.Diagnostics.Debug.WriteLine(err.Message);
                return null;
            }
        }

        /// <summary>
        /// 获得项目的配置文件
        /// </summary>
        /// <param name="strConfigPath"></param>
        /// <returns></returns>
        public static System.Configuration.Configuration GetAppConfig(string strConfigPath)
        {
            if (StringFunctions.IsNullOrEmptyAndBlank(strConfigPath))
                strConfigPath = Assembly.GetExecutingAssembly().Location;


            System.Configuration.Configuration appConfig = System.Configuration.ConfigurationManager.OpenExeConfiguration(strConfigPath);

            return appConfig;
        }



        ///// <summary>
        ///// 创建巫霜代码
        ///// </summary>
        ///// <returns></returns>
        //private bool CreateSlowXCode()
        //{
        //    EnvDTE.Project proj = GetCurProject();

        //    // proj.ConfigurationManager.ActiveConfiguration.

        //    if (proj != null)
        //    {
        //        // proj.ConfigurationManager
        //    }
        //    //Document activeDocument = _applicationObject.ActiveDocument;

        //    //if (activeDocument != null)
        //    //{
        //    //    // CommonFunction.MessageBoxShow(activeDocument.Selection.ToString());


        //    //    // activeDocument.ReplaceText(activeDocument.Selection.ToString(), activeDocument.Name, 0);
        //    //    // activeDocument.ReplaceText("sss", s, 0);


        //    //    //return activeDocument.FullName.EndsWith(".cs", StringComparison.CurrentCultureIgnoreCase);
        //    //}
        //    return true;
        //}

        //private FileCodeModel ObtainCurrentFileCodeModel()
        //{

        //    //获取当前正活动的文档 

        //    Document activeDocument = _applicationObject.ActiveDocument;

        //    if (activeDocument != null)
        //    {

        //        ProjectItem projectItem = activeDocument.ProjectItem;

        //        if (projectItem != null)
        //        {

        //            return projectItem.FileCodeModel;

        //        }

        //    }



        //    return null;

        //}
        //private bool RemoveCommandBar(Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar)
        //{
        //    if (menuBarCommandBar == null)
        //        return false;

        //    try
        //    {

        //        foreach (CommandBarControl control in menuBarCommandBar.Controls)
        //        {
        //            if (control.Caption == "CanoeTools"
        //                || control.Caption == "CanoeTools2"
        //                || control.Caption == "SlowX")
        //            {
        //                RemoveCommand((CommandBar)control);
        //                ((CommandBarPopup)control).Delete(true);
        //            }

        //        }
        //    }
        //    catch
        //    {
        //        return false;
        //    }


        //    return true;
        //}

        ///// <summary>
        ///// 移除自定义的菜单
        ///// </summary>
        ///// <returns></returns>
        //private bool RemoveCommand(CommandBar control)
        //{
        //    if (control == null)
        //        return false;
        //    try
        //    {
        //        foreach (Command command2 in control.Controls)
        //        {
        //            if (command2.Name == "")
        //            {
        //                // command2.Delete();
        //            }
        //            //if ((command2.Name != null) && command2.Name.EndsWith("Foo"))
        //            //{
        //            //    command = command2;
        //            //}
        //        }
        //    }
        //    catch
        //    {
        //        return false;
        //    }

        //    return true;


        //}

        ///// <summary>
        ///// 添加版权所有的注释
        ///// </summary>
        //private void CreateCopyRightFileForAllCSharpfiles()
        //{
        //    string strRemark = "";

        //    strRemark = "// 巫霜代码插件v0.1 " + '\r' + '\n';

        //    try
        //    {
        //        Array projects = (Array)_applicationObject.ActiveSolutionProjects;// .ActiveSolutionProjects ; //’开发环境下打开的所有项目

        //        //    Env
        //        //Dim  As     ‘定一个Project,指示当前Project

        //        EnvDTE.Project theProject = null;



        //        if (projects.Length > 0)  //      ‘如过当前没有打开project,Pass什么也不错。
        //        {
        //            theProject = (EnvDTE.Project)projects.GetValue(0);//   ‘ 获得当前Project


        //            foreach (ProjectItem p in theProject.ProjectItems) //  ‘ 对改project下面的所有.vb文件添加注释
        //            {
        //                if (p.Name.Substring(p.Name.Length - 3, 3) == ".cs")
        //                {

        //                    EnvDTE.Window theWindow = null;

        //                    theWindow = p.Open(Constants.vsViewKindCode);

        //                    TextDocument objTextDoc = (TextDocument)theWindow.Document.Object("TextDocument");

        //                    EditPoint objEditPoint = (EditPoint)objTextDoc.StartPoint.CreateEditPoint();//.CreateEditPoint;

        //                    objEditPoint.Insert(strRemark);

        //                    String strFileName = p.get_FileNames(0);

        //                    p.SaveAs(strFileName);

        //                }

        //            }


        //        }
        //    }

        //    catch (Exception err)
        //    {
        //        CommonFunction.MessageBoxShow(err.Message);

        //        // MessageBox.Show(ee.ToString());
        //    }



        //}


        //public void Canoe()
        //{
        //    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);
        //    }
        //}

        #endregion

        #region Example

        public static void ActivePointExample(DTE2 dte)
        {
            // Before running this example, open a text document.
            TextSelection objSel = (TextSelection)(dte.ActiveDocument.Selection);

            VirtualPoint objActive = objSel.ActivePoint;

            // Collapse the selection to the beginning of the line.

            objSel.StartOfLine((EnvDTE.vsStartOfLineOptions)(0), false);

            // objActive is "live", tied to the position of the actual 
            // selection, so it reflects the new position.

            long iCol = objActive.DisplayColumn;

            // Move the selection to the end of the line.

            objSel.EndOfLine(false);

            MessageBox.Show("The length of the insertion point line is " +
                (objActive.DisplayColumn - iCol) + " display characters.");

        }

        public static void AnchorPointExample(DTE2 dte)
        {
            // Before running this example, open a text document.
            TextSelection objSel = (EnvDTE.TextSelection)(
                    dte.ActiveDocument.Selection);

            VirtualPoint objAnchor = objSel.AnchorPoint;

            // objAnchor is "live", tied to the position of the actual 
            // selection, so it reflects changes. iCol and iRow are 
            // created here to save a "snapshot" of the anchor point's 
            // position at this time.

            long iCol = objAnchor.DisplayColumn;

            long iRow = objAnchor.Line;

            // As the selection is extended, the active point moves but the 
            // anchor point remains in place.

            objSel.StartOfDocument(true);
            objSel.EndOfDocument(true);

            if ((iCol == objAnchor.DisplayColumn & iRow == objAnchor.Line))
            {
                MessageBox.Show
                ("The anchor point has remained in place at row "
                    + iRow + ", display column " + iCol);
            }
        }

        public static void InsertExample(DTE2 dte)
        {
            // Before running this example, open a code file.
            TextSelection objSel = (EnvDTE.TextSelection)(
         dte.ActiveDocument.Selection);
            if (objSel.IsEmpty)
            {
                // If there is no text selected, swap the words before and after 
                // the insertion point. Begin by selecting the word before 
                // the insertion point.
                objSel.WordLeft(true, 1);
                if (!(objSel.IsEmpty))
                {
                    // The example can continue only if the selection was not 
                    // already at the beginning of the document.
                    string strBefore = objSel.Text;

                    // The text is saved in strBefore; now delete it and move 
                    // past the following word.
                    objSel.Delete(1);
                    objSel.WordRight(true, 1);
                    if (objSel.Text.StartsWith(" "))
                    {
                        // The previous call to WordRight may have skipped 
                        // some white space instead of an actual word. In that 
                        // case, we should call it again.
                        objSel.WordRight(true, 1);
                    }

                    // Insert the new text at the end of the selection.
                    objSel.Insert(strBefore, System.Convert.ToInt32(
             vsInsertFlags.vsInsertFlagsInsertAtEnd));
                }
            }
            else
            {
                // If some text is selected, replace the following word with the 
                // selected text.
                string strSelected = objSel.Text;

                objSel.MoveToPoint(objSel.BottomPoint, false);
                objSel.WordRight(true, 1);
                if (objSel.Text.StartsWith(" "))
                {
                    // The previous call to WordRight may have skipped some 
                    // white space instead of an actual word. In that case, 
                    // we should call it again.
                    objSel.WordRight(true, 1);
                }

                // Insert the text, overwriting the existing text and leaving 
                // the selection containing the inserted text.
                objSel.Insert(strSelected, System.Convert.ToInt32(vsInsertFlags.vsInsertFlagsContainNewText));
            }
        }

        public static void FindPatternExample(DTE2 dte)
        {
            // Before running this example, open a text document
            // with the text " Sub ".
            TextSelection objSel = (EnvDTE.TextSelection)(dte.ActiveDocument.Selection);

            string srchPattern1 = " Sub ";
            EnvDTE.TextRanges textRanges = null;

            // Advance to the next Visual Basic function beginning or end by 
            // searching for  "Sub" with white space before and after it.
            objSel.FindPattern(srchPattern1, 0, ref textRanges);
            {
                //  Select the entire line.
                objSel.SelectLine();
            }
        }

        public static void OutlineSectionExample(DTE2 dte)
        {
            // Before running this example, open a code document
            // containing a #if _DEBUG…#endif block.
            TextSelection objSel = (EnvDTE.TextSelection)(
         dte.ActiveDocument.Selection);
            string srchPattern1 = "#if _DEBUG";
            string srchPattern2 = "#endif";
            EnvDTE.TextRanges textRanges = null;

            //Move to the beginning of the document so we can iterate 
            // over the whole thing.
            objSel.StartOfDocument(false);

            while (objSel.FindPattern(srchPattern1, 0, ref textRanges))
            {
                //  If it's the beginning of a debug-only section, 
                // save the position.
                long lStartLine = objSel.TopPoint.Line;
                long lStartColumn = objSel.TopPoint.LineCharOffset;

                //  Look for the end.
                if (objSel.FindPattern(srchPattern2, 0, ref textRanges))
                {
                    //  Select the entire section and outline it.
                    objSel.SwapAnchor();
                    objSel.MoveToLineAndOffset(System.Convert.ToInt32
        (lStartLine), System.Convert.ToInt32(lStartColumn), true);
                    objSel.OutlineSection();
                    objSel.LineDown(false, 1);
                }
            }
        }


        public static void CommandNamesCollapseExample(DTE2 dte)
        {
            Command Cmd = null;
            Commands Commands = dte.Commands;
            ProjectItem PrjItem = null;
            Document Doc = null;
            TextDocument TxtDoc = null;
            dte.ItemOperations.NewFile(@"General\Text File", "",
        "{00000000-0000-0000-0000-000000000000}");
            Doc = dte.ActiveDocument;
            TxtDoc = (EnvDTE.TextDocument)(Doc.Object("TextDocument"));
            foreach (EnvDTE.Command tempCmd in Commands)
            {
                Cmd = tempCmd;
                if ((Cmd.Name != ""))
                {
                    TxtDoc.Selection.Text = Cmd.Name + "\n";
                    TxtDoc.Selection.Collapse();
                }
            }
        }

        #endregion


        #region 外面接入的代码

        #region Helper Methods

        public static string GetCulturedMenuName(DTE2 _applicationObject, string englishName)
        {
            string result = englishName;

            try
            {
                string resourceName;
                ResourceManager resourceManager = new ResourceManager("SlowX.CommandBar", Assembly.GetExecutingAssembly());
                CultureInfo cultureInfo = new CultureInfo(_applicationObject.LocaleID);

                if (cultureInfo.TwoLetterISOLanguageName == "zh")
                {
                    System.Globalization.CultureInfo parentCultureInfo = cultureInfo.Parent;
                    resourceName = String.Concat(parentCultureInfo.Name, englishName);
                }
                else
                {
                    resourceName = String.Concat(cultureInfo.TwoLetterISOLanguageName, englishName);
                }

                result = resourceManager.GetString(resourceName);
            }
            catch
            {
                result = englishName;
            }

            return result;
        }

        public static string GetCommandFullName(string cmdName)
        {
            return "SlowX.Connect." + cmdName;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <param name="_addInInstance"></param>
        /// <param name="cmdBarName"></param>
        /// <returns></returns>
        public static CommandBar GetCommandBarByName
            (
                DTE2 _applicationObject,
                AddIn _addInInstance,
                string cmdBarName
            )
        {
            if (_applicationObject == null)
                return null;

            try
            {
                // (CommandBars)_applicationObject.CommandBars)
                // _applicationObject.AddIns.Add()
                return ((CommandBars)_applicationObject.CommandBars)[cmdBarName];
            }
            catch (Exception err)
            {
                System.Diagnostics.Debug.WriteLine(err.Message);
                return null;
            }
        }

        public static bool AddNamedCommand2
            (
                DTE2 _applicationObject,
                AddIn _addInInstance,
                CommandBar cmdBar,
                string cmdName,
                string buttonText,
                string toolTip,
                bool useMsoButton,
                int iconIndex,
                int position
            )
        {
            if (_applicationObject == null)
                return false;

            // Do not try to add commands to a null bar
            if (cmdBar == null) { return false; }

            // Get commands collection
            Commands2 commands = (Commands2)_applicationObject.Commands;

            object[] contextGUIDS = new object[] { };

            try
            {
                // Add command
                Command command = commands.AddNamedCommand2(_addInInstance, cmdName, buttonText, toolTip,
                    useMsoButton, iconIndex, ref contextGUIDS,
                    (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
                    (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                if (command != null && cmdBar != null)
                {
                    if (position >= 0)
                        command.AddControl(cmdBar, position);
                    else
                        command.AddControl(cmdBar, cmdBar.Controls.Count + 1);
                }
            }
            catch (ArgumentException)
            {
                // Command already exists, so ignore the exception.

                return false;
            }
            catch (Exception err)
            {

                return false;
            }

            return true;
        }

        #endregion

        #region Command Handler


        public static bool CloseAllDocuments(DTE2 _applicationObject)
        {
            if (_applicationObject == null)
                return false;

            // System.IO.FileInfo f = new System.IO.FileInfo("D:\\canoe.log"); 

            //System.Collections.Specialized.StringCollection d = new System.Collections.Specialized.StringCollection();
            //d.Add("D:\\canoe.log");

            //Clipboard.SetFileDropList(d);
            // Clipboard.SetDataObject(richTextBox.SelectedText);

            _applicationObject.ExecuteCommand("Window.CloseAllDocuments", string.Empty);

            // _applicationObject.ExecuteCommand("Window.CloseAllDocuments", string.Empty);

            return true;
        }


        public static string GetDocumentFullName(DTE2 _applicationObject)
        {
            if (_applicationObject == null)
                return "";

            Document doc = GetActiveDocument(_applicationObject);

            if (doc == null)
                return "";

            return doc.FullName;

        }

        /// <summary>
        /// 复制文件
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <returns></returns>
        public static bool CopyFile(DTE2 _applicationObject)
        {
            if (_applicationObject == null)
                return false;

            Document doc = GetActiveDocument(_applicationObject);

            if (doc == null)
                return false;

            System.Collections.Specialized.StringCollection d = new System.Collections.Specialized.StringCollection();
            d.Add(doc.FullName);

            Clipboard.SetFileDropList(d);

            return true;
        }

        public static string[] CopyTwoFileName(DTE2 _applicationObject)
        {

            if (_applicationObject == null)
                return null;

            Document doc = GetActiveDocument(_applicationObject);

            if (doc == null)
                return null;


            ArrayList arrayList = new ArrayList();

            arrayList.Add(doc.FullName);

            string strFullName = doc.FullName;

            int iLen = strFullName.Length;

            if (strFullName.ToLower().EndsWith(".aspx"))
            {
                if (File.Exists(strFullName + ".cs"))
                    arrayList.Add(strFullName + ".cs");
            }
            else if (strFullName.ToLower().EndsWith(".cs"))
            {
                string strFileName = strFullName.Substring(0, iLen - (".cs").Length);
                if (File.Exists(strFileName))
                    arrayList.Add(strFileName);
            }

            return ArrayFunctions.StaticGetStringArrayByObj(arrayList);
        }

        public static bool CopyTwoFile(DTE2 _applicationObject)
        {
            if (_applicationObject == null)
                return false;

            Document doc = GetActiveDocument(_applicationObject);

            if (doc == null)
                return false;

            System.Collections.Specialized.StringCollection d = new System.Collections.Specialized.StringCollection();
            d.Add(doc.FullName);

            string strFullName = doc.FullName;

            int iLen = strFullName.Length;

            if (strFullName.ToLower().EndsWith(".aspx"))
            {
                if (File.Exists(strFullName + ".cs"))
                    d.Add(strFullName + ".cs");
            }
            else if (strFullName.ToLower().EndsWith(".cs"))
            {
                string strFileName = strFullName.Substring(0, iLen - (".cs").Length);
                if (File.Exists(strFileName))
                    d.Add(strFileName);
            }


            Clipboard.SetFileDropList(d);

            return true;
        }

        public static FileInfo[] CopyBinFileInfo(DTE2 _applicationObject)
        {
            if (_applicationObject == null)
                return null;

            string strDir = GetProjBinDir(_applicationObject);

            string strExtension = "/.dll/";

             

            FileInfo[] fInfo =
                FileFunctions.GetFileInfoByBinDir(strDir,strExtension);

            return fInfo;
        }

        public static FileInfo[] CopyBinAndXmlFileInfo(DTE2 _applicationObject)
        {
            if (_applicationObject == null)
                return null;

            string strDir = GetProjBinDir(_applicationObject);

            string strExtension = "/.dll/.xml/";



            FileInfo[] fInfo =
                FileFunctions.GetFileInfoByBinDir(strDir, strExtension);


            return fInfo;
        }

        public static ArrayList FileInfoArrayToArrayList(FileInfo[] info)
        {
            if (info == null)
                return null;

            ArrayList arrayList = new ArrayList();

            int iLen = info.Length;

            for (int i = 0; i < iLen; ++i)
            {
                arrayList.Add(info[i]);
            }

            return arrayList;
        }

        /// <summary>
        /// ArrayList 变成FileInfo
        /// </summary>
        /// <param name="arrayList"></param>
        /// <returns></returns>
        public static FileInfo[] ArrayListToFileInfoArray(ArrayList arrayList)
        {
            return ArrayListToFileInfoArray(arrayList, true);
        }

        /// <summary>
        /// ArrayList 变成FileInfo 
        /// </summary>
        /// <param name="arrayList"></param>
        /// <param name="checkNull"></param>
        /// <returns></returns>
        public static FileInfo[] ArrayListToFileInfoArray(ArrayList arrayList, bool checkNull)
        {
            if (arrayList == null)
                return null;

            int iCount = 0;

            if (checkNull)
                iCount = ArrayListToFileInfoArrayCount(arrayList);
            else
                iCount = arrayList.Count;

            if (iCount == 0)
                return null;

            FileInfo[] theResult = new FileInfo[iCount];

            int idx = 0;

            if (checkNull)
            {
                foreach (object o in arrayList)
                {
                    if (o is FileInfo)
                        theResult[idx++] = o as FileInfo;
                }
            }
            else
            {
                foreach (object o in arrayList)
                {
                    theResult[idx++] = o as FileInfo;
                }
            }

            return theResult;
        }

        /// <summary>
        /// 统计FileInfo的个数
        /// </summary>
        /// <param name="arrayList"></param>
        /// <returns></returns>
        public static int ArrayListToFileInfoArrayCount(ArrayList arrayList)
        {
            if (arrayList == null)
                return 0;

            int theResult = 0;

            foreach (object o in arrayList)
            {
                if (o == null)
                    continue;

                if (o is FileInfo)
                    ++theResult;
            }

            return theResult;
        }

        public static string[] CopyBinFileName(DTE2 _applicationObject)
        {
            FileInfo[] fInfo = CopyBinFileInfo(_applicationObject);

            if (fInfo == null || fInfo.Length == 0)
                return null;

            int iLen = fInfo.Length;

            string[] strArray = new string[iLen];

            for (int i = 0; i < iLen; ++i)
            {
                FileInfo info = fInfo[i];

                if (info == null)
                    continue;

                strArray[i] = info.FullName;
            }

            return strArray;
        }

        /// <summary>
        /// 复制BIN
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <returns></returns>
        public static bool CopyBin(DTE2 _applicationObject)
        {
            FileInfo[] fInfo = CopyBinFileInfo(_applicationObject);

            if (fInfo == null || fInfo.Length == 0)
                return false;


            System.Collections.Specialized.StringCollection d = new System.Collections.Specialized.StringCollection();

            foreach (FileInfo info in fInfo)
            {
                if (info == null)
                    continue;

                d.Add(info.FullName);
            }

            Clipboard.SetFileDropList(d);

            return true;
        }

        /// <summary>
        /// 复制BIN
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <returns></returns>
        public static bool CopyBinAndXML(DTE2 _applicationObject)
        {
            FileInfo[] fInfo = CopyBinAndXmlFileInfo(_applicationObject);

            if (fInfo == null || fInfo.Length == 0)
                return false;


            System.Collections.Specialized.StringCollection d = new System.Collections.Specialized.StringCollection();

            foreach (FileInfo info in fInfo)
            {
                if (info == null)
                    continue;

                d.Add(info.FullName);
            }

            Clipboard.SetFileDropList(d);

            return true;
        }

        /// <summary>
        /// 复制BIN
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <returns></returns>
        public static bool OpenBinDir(DTE2 _applicationObject)
        {
            string strDir = GetProjBinDir(_applicationObject);

            if (StringFunctions.IsNotNullOrEmptyAndBlank(strDir))
                System.Diagnostics.Process.Start("explorer.exe", strDir);

            return true;
        }

        /// <summary>
        /// Copy两个文件
        /// </summary>
        /// <param name="_applicationObject"></param>
        /// <returns></returns>
        public static bool TestFun(DTE2 _applicationObject, AddIn _addInInstance)
        {
            if (_applicationObject == null || _addInInstance == null)
                return false;

            SlowXLib.WinForms.ReflectionForm
                form = new SlowXLib.WinForms.ReflectionForm();

            form._addInInstance = _addInInstance;
            form._applicationObject = _applicationObject;
            form.proj = GetCurProject(_applicationObject);

            form.Show();
 

            return true;
        }

        public static bool CopyFileName(DTE2 _applicationObject)
        {
            if (_applicationObject == null)
                return false;

            Document doc = GetActiveDocument(_applicationObject);

            if (doc == null)
                return false;

            string strFullName = doc.FullName;

            strFullName = strFullName.Replace("/", "\\");


            int idx = strFullName.LastIndexOf("\\");

            if (idx != -1)
                strFullName = strFullName.Substring(idx + 1);

            Clipboard.SetText(strFullName);

            return true;
        }

        #endregion

        #endregion
    }


}

/*


public void ActivePointExample( DTE2 dte ) 
{ 
    // Before running this example, open a text document.
    TextSelection objSel = (TextSelection )
(dte.ActiveDocument.Selection ); 
    VirtualPoint objActive = objSel.ActivePoint; 
    // Collapse the selection to the beginning of the line.
    objSel.StartOfLine( (EnvDTE.vsStartOfLineOptions)(0), false ); 
    // objActive is "live", tied to the position of the actual 
    // selection, so it reflects the new position.
    long iCol = objActive.DisplayColumn; 
    // Move the selection to the end of the line.
    objSel.EndOfLine( false );
            
    MessageBox.Show( "The length of the insertion point line is " + 
( objActive.DisplayColumn - iCol ) + " display characters."); 
}

public void AnchorPointExample( DTE2 dte ) 
{ 
// Before running this example, open a text document.
    TextSelection objSel = ( EnvDTE.TextSelection )(
 dte.ActiveDocument.Selection ); 
    VirtualPoint objAnchor = objSel.AnchorPoint; 
    // objAnchor is "live", tied to the position of the actual 
    // selection, so it reflects changes. iCol and iRow are 
    // created here to save a "snapshot" of the anchor point's 
    // position at this time.
    long iCol = objAnchor.DisplayColumn; 
    long iRow = objAnchor.Line; 
    // As the selection is extended, the active point moves but the 
    // anchor point remains in place.
    objSel.StartOfDocument( true ); 
    objSel.EndOfDocument( true ); 

    if ( ( iCol == objAnchor.DisplayColumn & iRow == objAnchor.Line ) ) 
        { 
           MessageBox.Show
( "The anchor point has remained in place at row "
 + iRow + ", display column " + iCol); 
        } 
}
// Add-in example.
using System.Windows.Forms;
public void OnConnection(object application, ext_ConnectMode
 connectMode, object addInInst, ref Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;

// Pass the applicationObject member variable to the code example.
    InsertExample (_applicationObject); 
}
public void InsertExample( DTE2 dte ) 
{ 
// Before running this example, open a code file.
    TextSelection objSel = ( EnvDTE.TextSelection )(
 dte.ActiveDocument.Selection ); 
    if ( objSel.IsEmpty ) 
    { 
    // If there is no text selected, swap the words before and after 
    // the insertion point. Begin by selecting the word before 
    // the insertion point.
        objSel.WordLeft( true, 1 ); 
        if ( !( objSel.IsEmpty ) ) 
        { 
        // The example can continue only if the selection was not 
        // already at the beginning of the document.
            string strBefore = objSel.Text; 
                    
            // The text is saved in strBefore; now delete it and move 
            // past the following word.
            objSel.Delete( 1 ); 
            objSel.WordRight( true, 1 ); 
            if ( objSel.Text.StartsWith( " " )) 
                { 
                // The previous call to WordRight may have skipped 
                // some white space instead of an actual word. In that 
                // case, we should call it again.
                objSel.WordRight( true, 1 ); 
            } 

        // Insert the new text at the end of the selection.
        objSel.Insert( strBefore, System.Convert.ToInt32(
 vsInsertFlags.vsInsertFlagsInsertAtEnd ) ); 
        } 
    } 
    else 
    { 
    // If some text is selected, replace the following word with the 
    // selected text.
    string strSelected = objSel.Text; 

        objSel.MoveToPoint( objSel.BottomPoint, false ); 
        objSel.WordRight( true, 1 ); 
        if ( objSel.Text.StartsWith( " " )) 
        { 
             // The previous call to WordRight may have skipped some 
             // white space instead of an actual word. In that case, 
            // we should call it again.
            objSel.WordRight( true, 1 ); 
        } 

        // Insert the text, overwriting the existing text and leaving 
        // the selection containing the inserted text.
    objSel.Insert( strSelected, System.Convert.ToInt32( vsInsertFlags.vsInsertFlagsContainNewText ) ); 
    }
}
// Add-in example.
using System.Windows.Forms;
public void OnConnection(object application, ext_ConnectMode
 connectMode, object addInInst, ref Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;

// Pass the applicationObject member variable to the code example.
    FindPatternExample (_applicationObject); 
}

public void FindPatternExample( DTE2 dte ) 
{ 
// Before running this example, open a text document
// with the text " Sub ".
    TextSelection objSel = (EnvDTE.TextSelection)(dte.ActiveDocument.Selection ); 

    string srchPattern1 = " Sub ";
    EnvDTE.TextRanges textRanges = null;

    // Advance to the next Visual Basic function beginning or end by 
    // searching for  "Sub" with white space before and after it.
    objSel.FindPattern( srchPattern1, 0, ref textRanges );
    { 
        //  Select the entire line.
        objSel.SelectLine(); 
    } 
}
// Add-in example for.
public void OnConnection(object application,
 Extensibility.ext_ConnectMode connectMode, object addInInst,
 ref System.Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    //  Pass the applicationObject member variable to the code example.
    OutlineSectionExample(_applicationObject ); 
}

public void OutlineSectionExample( DTE2 dte ) 
{ 
    // Before running this example, open a code document
    // containing a #if _DEBUG…#endif block.
    TextSelection objSel = ( EnvDTE.TextSelection )(
 dte.ActiveDocument.Selection ); 
    string srchPattern1 = "#if _DEBUG";
    string srchPattern2 = "#endif";
    EnvDTE.TextRanges textRanges = null;

    //Move to the beginning of the document so we can iterate 
    // over the whole thing.
    objSel.StartOfDocument( false ); 
 
    while ( objSel.FindPattern( srchPattern1, 0, ref textRanges) ) 
    { 
        //  If it's the beginning of a debug-only section, 
        // save the position.
        long lStartLine = objSel.TopPoint.Line; 
        long lStartColumn = objSel.TopPoint.LineCharOffset; 

        //  Look for the end.
        if ( objSel.FindPattern(srchPattern2 , 0,ref textRanges) ) 
        { 
            //  Select the entire section and outline it.
            objSel.SwapAnchor(); 
            objSel.MoveToLineAndOffset( System.Convert.ToInt32
( lStartLine ), System.Convert.ToInt32( lStartColumn ), true ); 
            objSel.OutlineSection(); 
            objSel.LineDown( false, 1 ); 
        } 
    } 
}
// Add-in example.
// This generates a text document listing all available command names.

public void OnConnection(object application,
 Extensibility.ext_ConnectMode connectMode, object addInInst,
 ref System.Array custom)
{
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
//  Pass the applicationObject member variable to the code example.
CommandNamesCollapseExample(_applicationObject ); 
}
public void CommandNamesCollapseExample( DTE2 dte ) 
{ 
    Command Cmd = null; 
    Commands Commands = dte.Commands; 
    ProjectItem PrjItem = null; 
    Document Doc = null; 
    TextDocument TxtDoc = null; 
    dte.ItemOperations.NewFile( @"General\Text File", "", 
"{00000000-0000-0000-0000-000000000000}" ); 
    Doc = dte.ActiveDocument; 
    TxtDoc = (EnvDTE.TextDocument )(Doc.Object( "TextDocument" )); 
    foreach ( EnvDTE.Command tempCmd in Commands ) 
    { 
        Cmd = tempCmd; 
        if ( ( Cmd.Name != "" ) ) 
        { 
            TxtDoc.Selection.Text = Cmd.Name +"\n"; 
            TxtDoc.Selection.Collapse(); 
        } 
    }
}


*/

/*

 * //Test.ThreadForm f = new SlowXLib.Test.ThreadForm();
            // f.Show();

            // Ftp();
            // GetProjFullOutput(_applicationObject);
            // System.Configuration.Configuration c = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/","http://www.gstt.org.cn");

            //MessageBox.Show((c == null).ToString());
            // MessageBox.Show(c.FilePath);
            //System.Configuration.Configuration c = GetAddinAppConfig(_applicationObject, _addInInstance);

            //MessageBox.Show(c.AppSettings.Settings["canoe"].Value);

            // MessageBox.Show(_addInInstance.Name);
            // System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration
            // MessageBox.Show(_addInInstance.SatelliteDllPath);
            // MessageBox.Show((GetCommandBar(_applicationObject, _addInInstance, "CanoeTools") == null).ToString());
            // MessageBox.Show(RemoveCommandBar2(_applicationObject, _addInInstance, "CanoeTools").ToString());

            // 获得配置文件,成功!

            //System.Configuration.Configuration appConfig = GetAppConfig();

            //try
            //{
            //    MessageBox.Show(appConfig.AppSettings.Settings["canoe"].Value);
            //}
            //catch (Exception err)
            //{
            //    MessageBox.Show(err.Message);
            //}

            // 失败
            //try
            //{
            //    MessageBox.Show(System.Configuration.ConfigurationSettings.AppSettings["canoe"]);
            //}
            //catch (Exception err)
            //{
            //    MessageBox.Show(err.Message);
            //}

            // 获得项目相关的属性 //
            //EnvDTE.Project proj = GetCurProject(_applicationObject);

            //if (proj == null)
            //    return true;

            #region 项目相关的属性


            //CT.BA.Classes.Loger.Loger.Record(CT.BA.Classes.Classes.RecordData.StaticGetRecordData("proj.Properties.Item"), "D:\\canoe.log");

            //if (proj.Properties == null)
            //{
            //    CT.BA.Classes.Loger.Loger.Record(CT.BA.Classes.Classes.RecordData.StaticGetRecordData("proj.Properties.Item is null"), "D:\\canoe.log");
            //}
            //else
            //{
            //    foreach (Property p in proj.Properties)
            //    {
            //        try
            //        {

            //            CT.BA.Classes.Loger.Loger.Record(CT.BA.Classes.Classes.RecordData.StaticGetRecordData(p.Name + " ~ " + p.Value), "D:\\canoe.log");
            //        }
            //        catch (Exception er)
            //        {
            //            CT.BA.Classes.Loger.Loger.Record(CT.BA.Classes.Classes.RecordData.StaticGetRecordData(er.Message), "D:\\canoe.log");
            //        }
            //    }
            //}

            //CT.BA.Classes.Loger.Loger.Record(CT.BA.Classes.Classes.RecordData.StaticGetRecordData("proj.ConfigurationManager.ActiveConfiguration.Properties"), "D:\\canoe.log");

            //if (proj.ConfigurationManager.ActiveConfiguration.Properties == null)
            //{
            //    CT.BA.Classes.Loger.Loger.Record(CT.BA.Classes.Classes.RecordData.StaticGetRecordData(" proj.ConfigurationManager.ActiveConfiguration.Properties is null"), "D:\\canoe.log");
            //}
            //else
            //{
            //    foreach (Property p in proj.ConfigurationManager.ActiveConfiguration.Properties)
            //    {
            //        try
            //        {
            //            CT.BA.Classes.Loger.Loger.Record(CT.BA.Classes.Classes.RecordData.StaticGetRecordData(p.Name + " ~ " + p.Value), "D:\\canoe.log");
            //        }
            //        catch (Exception er)
            //        {
            //            CT.BA.Classes.Loger.Loger.Record(CT.BA.Classes.Classes.RecordData.StaticGetRecordData(er.Message), "D:\\canoe.log");
            //        }
            //    }
            //}

            // 输出结果集合 //
            //【时间:2009-3-22 16:19:00】proj.Properties.Item
            //【时间:2009-3-22 16:19:00】ComVisible ~ False
            //【时间:2009-3-22 16:19:00】EnableSecurityDebugging ~ True
            //【时间:2009-3-22 16:19:00】OptionCompare ~ 0
            //【时间:2009-3-22 16:19:00】StartupObject ~ 
            //【时间:2009-3-22 16:19:00】ManifestCertificateThumbprint ~ 
            //【时间:2009-3-22 16:19:00】Trademark ~ 
            //【时间:2009-3-22 16:19:00】Title ~ WindowsFormsApplication1
            //【时间:2009-3-22 16:19:00】AssemblyOriginatorKeyFileType ~ 1
            //【时间:2009-3-22 16:19:00】FileName ~ WindowsFormsApplication1.csproj
            //【时间:2009-3-22 16:19:00】发生意外。 (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))
            //【时间:2009-3-22 16:19:00】AssemblyOriginatorKeyMode ~ 0
            //【时间:2009-3-22 16:19:00】AssemblyKeyContainerName ~ 
            //【时间:2009-3-22 16:19:00】ProjectType ~ 0
            //【时间:2009-3-22 16:19:00】ReferencePath ~ 
            //【时间:2009-3-22 16:19:00】PreBuildEvent ~ 
            //【时间:2009-3-22 16:19:00】Copyright ~ Copyright ? CCS 2009
            //【时间:2009-3-22 16:19:00】ApplicationIcon ~ 
            //【时间:2009-3-22 16:19:00】ExcludedPermissions ~ 
            //【时间:2009-3-22 16:19:00】RunPostBuildEvent ~ 1
            //【时间:2009-3-22 16:19:00】DefaultTargetSchema ~ 1
            //【时间:2009-3-22 16:19:00】RootNamespace ~ WindowsFormsApplication1
            //【时间:2009-3-22 16:19:00】ManifestTimestampUrl ~ 
            //【时间:2009-3-22 16:19:00】ManifestKeyFile ~ 
            //【时间:2009-3-22 16:19:00】DebugSecurityZoneURL ~ 
            //【时间:2009-3-22 16:19:00】Product ~ WindowsFormsApplication1
            //【时间:2009-3-22 16:19:00】PostBuildEvent ~ 
            //【时间:2009-3-22 16:19:00】OptionStrict ~ 0
            //【时间:2009-3-22 16:19:00】DefaultHTMLPageLayout ~ 1
            //【时间:2009-3-22 16:19:00】DelaySign ~ False
            //【时间:2009-3-22 16:19:00】OutputType ~ 0
            //【时间:2009-3-22 16:19:00】NeutralResourcesLanguage ~ 
            //【时间:2009-3-22 16:19:00】OptionExplicit ~ 1
            //【时间:2009-3-22 16:19:00】OutputFileName ~ WindowsFormsApplication1.exe
            //【时间:2009-3-22 16:19:00】发生意外。 (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))
            //【时间:2009-3-22 16:19:00】AssemblyGuid ~ ad9df11e-ee8c-43b5-8a68-7290602fd21e
            //【时间:2009-3-22 16:19:00】GenerateManifests ~ False
            //【时间:2009-3-22 16:19:00】AssemblyVersion ~ 1.0.0.0
            //【时间:2009-3-22 16:19:00】Win32ResourceFile ~ 
            //【时间:2009-3-22 16:19:00】Description ~ 
            //【时间:2009-3-22 16:19:00】URL ~ file:///E:\Projects\HomePage\Witch\SRC\WindowsFormsApplication1\WindowsFormsApplication1\
            //【时间:2009-3-22 16:19:00】DefaultClientScript ~ 0
            //【时间:2009-3-22 16:19:00】TargetFramework ~ 131072
            //【时间:2009-3-22 16:19:00】SignManifests ~ False
            //【时间:2009-3-22 16:19:00】发生意外。 (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))
            //【时间:2009-3-22 16:19:00】发生意外。 (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))
            //【时间:2009-3-22 16:19:00】Publish ~ System.__ComObject
            //【时间:2009-3-22 16:19:00】AssemblyType ~ 0
            //【时间:2009-3-22 16:19:00】FullPath ~ E:\Projects\HomePage\Witch\SRC\WindowsFormsApplication1\WindowsFormsApplication1\
            //【时间:2009-3-22 16:19:00】发生意外。 (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))
            //【时间:2009-3-22 16:19:00】AssemblyKeyProviderName ~ 
            //【时间:2009-3-22 16:19:00】TypeComplianceDiagnostics ~ False
            //【时间:2009-3-22 16:19:00】Company ~ CCS
            //【时间:2009-3-22 16:19:01】发生意外。 (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))
            //【时间:2009-3-22 16:19:01】AssemblyOriginatorKeyFile ~ 
            //【时间:2009-3-22 16:19:01】ApplicationManifest ~ DefaultManifest
            //【时间:2009-3-22 16:19:01】AssemblyFileVersion ~ 1.0.0.0
            //【时间:2009-3-22 16:19:01】发生意外。 (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))
            //【时间:2009-3-22 16:19:01】发生意外。 (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))
            //【时间:2009-3-22 16:19:01】AssemblyName ~ WindowsFormsApplication1
            //【时间:2009-3-22 16:19:01】LocalPath ~ E:\Projects\HomePage\Witch\SRC\WindowsFormsApplication1\WindowsFormsApplication1\
            //【时间:2009-3-22 16:19:01】DefaultNamespace ~ WindowsFormsApplication1
            //【时间:2009-3-22 16:19:01】LinkRepair ~ False
            //【时间:2009-3-22 16:19:01】TargetZone ~ 
            //【时间:2009-3-22 16:19:01】SignAssembly ~ False

            //【时间:2009-3-22 16:19:01】proj.ConfigurationManager.ActiveConfiguration.Properties

            //【时间:2009-3-22 16:19:01】LanguageVersion ~ 
            //【时间:2009-3-22 16:19:01】RunCodeAnalysis ~ False
            //【时间:2009-3-22 16:19:01】NoStdLib ~ False
            //【时间:2009-3-22 16:19:01】ErrorReport ~ prompt
            //【时间:2009-3-22 16:19:01】CodeAnalysisUseTypeNameInSuppression ~ True
            //【时间:2009-3-22 16:19:01】CodeAnalysisInputAssembly ~ 
            //【时间:2009-3-22 16:19:01】CodeAnalysisDictionaries ~ 
            //【时间:2009-3-22 16:19:01】GenerateSerializationAssemblies ~ 2
            //【时间:2009-3-22 16:19:01】CodeAnalysisModuleSuppressionsFile ~ GlobalSuppressions.cs
            //【时间:2009-3-22 16:19:01】StartWorkingDirectory ~ 
            //【时间:2009-3-22 16:19:01】Optimize ~ False
            //【时间:2009-3-22 16:19:01】DocumentationFile ~ 
            //【时间:2009-3-22 16:19:01】StartPage ~ 
            //【时间:2009-3-22 16:19:01】OutputPath ~ bin\Debug\
            //【时间:2009-3-22 16:19:01】TreatWarningsAsErrors ~ False
            //【时间:2009-3-22 16:19:01】EnableASPDebugging ~ False
            //【时间:2009-3-22 16:19:01】IncrementalBuild ~ True
            //【时间:2009-3-22 16:19:01】CodeAnalysisLogFile ~ 
            //【时间:2009-3-22 16:19:01】DefineConstants ~ DEBUG;TRACE
            //【时间:2009-3-22 16:19:01】UseVSHostingProcess ~ True
            //【时间:2009-3-22 16:19:01】StartProgram ~ 
            //【时间:2009-3-22 16:19:01】DefineDebug ~ False
            //【时间:2009-3-22 16:19:01】CodeAnalysisCulture ~ 
            //【时间:2009-3-22 16:19:01】CodeAnalysisOverrideRuleVisibilities ~ False
            //【时间:2009-3-22 16:19:01】CodeAnalysisRuleAssemblies ~ 
            //【时间:2009-3-22 16:19:01】DefineTrace ~ False
            //【时间:2009-3-22 16:19:01】DebugSymbols ~ True
            //【时间:2009-3-22 16:19:01】NoWarn ~ 
            //【时间:2009-3-22 16:19:01】CodeAnalysisIgnoreGeneratedCode ~ True
            //【时间:2009-3-22 16:19:01】EnableSQLServerDebugging ~ False
            //【时间:2009-3-22 16:19:01】BaseAddress ~ 4194304
            //【时间:2009-3-22 16:19:01】RemoteDebugEnabled ~ False
            //【时间:2009-3-22 16:19:01】StartURL ~ 
            //【时间:2009-3-22 16:19:01】AllowUnsafeBlocks ~ False
            //【时间:2009-3-22 16:19:01】TreatSpecificWarningsAsErrors ~ 
            //【时间:2009-3-22 16:19:01】PlatformTarget ~ AnyCPU
            //【时间:2009-3-22 16:19:01】EnableUnmanagedDebugging ~ False
            //【时间:2009-3-22 16:19:01】StartWithIE ~ False
            //【时间:2009-3-22 16:19:01】StartArguments ~ 
            //【时间:2009-3-22 16:19:01】IntermediatePath ~ obj\Debug\
            //【时间:2009-3-22 16:19:01】DebugInfo ~ full
            //【时间:2009-3-22 16:19:01】CheckForOverflowUnderflow ~ False
            //【时间:2009-3-22 16:19:01】RemoteDebugMachine ~ 
            //【时间:2009-3-22 16:19:01】CodeAnalysisSpellCheckLanguages ~ 
            //【时间:2009-3-22 16:19:01】CodeAnalysisRules ~ 
            //【时间:2009-3-22 16:19:01】RegisterForComInterop ~ False
            //【时间:2009-3-22 16:19:01】FileAlignment ~ 512
            //【时间:2009-3-22 16:19:01】StartAction ~ 0
            //【时间:2009-3-22 16:19:01】EnableASPXDebugging ~ False
            //【时间:2009-3-22 16:19:01】ConfigurationOverrideFile ~ 
            //【时间:2009-3-22 16:19:01】WarningLevel ~ 4
            //【时间:2009-3-22 16:19:01】RemoveIntegerChecks ~ False

            // Web相关
            //【时间:2009-3-22 16:40:48】proj.Properties.Item
            //【时间:2009-3-22 16:40:48】EnableFxCop ~ False
            //【时间:2009-3-22 16:40:48】CurrentWebsiteLanguage ~ Visual C#
            //【时间:2009-3-22 16:40:48】EnableNTLMAuthentication ~ False
            //【时间:2009-3-22 16:40:48】StartWorkingDirectory ~ 
            //【时间:2009-3-22 16:40:48】StartPage ~ 
            //【时间:2009-3-22 16:40:48】WebSiteType ~ 0
            //【时间:2009-3-22 16:40:48】FxCopRuleAssemblies ~ $(FxCopDir)\Rules
            //【时间:2009-3-22 16:40:48】StartProgram ~ 
            //【时间:2009-3-22 16:40:48】StartWebServerOnDebug ~ True
            //【时间:2009-3-22 16:40:48】VsWebServerPort ~ 3845
            //【时间:2009-3-22 16:40:48】EnableSQLServerDebugging ~ False
            //【时间:2009-3-22 16:40:49】TargetFramework ~ 131072
            //【时间:2009-3-22 16:40:49】StartURL ~ 
            //【时间:2009-3-22 16:40:49】EnableUnmanagedDebugging ~ False
            //【时间:2009-3-22 16:40:49】FullPath ~ E:\Projects\HomePage\Witch\SRC\SlowXWebSite
            //【时间:2009-3-22 16:40:49】ProjectDirty ~ False
            //【时间:2009-3-22 16:40:49】StartArguments ~ 
            //【时间:2009-3-22 16:40:49】BrowseURL ~ http://localhost:3845/SlowXWebSite
            //【时间:2009-3-22 16:40:49】OpenedURL ~ file:///E:/Projects/HomePage/Witch/SRC/SlowXWebSite/
            //【时间:2009-3-22 16:40:49】EnableVsWebServerDynamicPort ~ True
            //【时间:2009-3-22 16:40:49】FxCopRules ~ 
            //【时间:2009-3-22 16:40:49】EnableVsWebServer ~ True
            //【时间:2009-3-22 16:40:49】StartAction ~ 0
            //【时间:2009-3-22 16:40:49】EnableASPXDebugging ~ True
            //【时间:2009-3-22 16:40:49】VsWebServerVPath ~ /SlowXWebSite
            //【时间:2009-3-22 16:40:52】proj.ConfigurationManager.ActiveConfiguration.Properties

            // DLL相关 //
            //【时间:2009-3-22 16:55:14】proj.Properties.Item
            //【时间:2009-3-22 16:55:14】ComVisible ~ False
            //【时间:2009-3-22 16:55:14】EnableSecurityDebugging ~ True
            //【时间:2009-3-22 16:55:14】OptionCompare ~ 0
            //【时间:2009-3-22 16:55:14】StartupObject ~ 
            //【时间:2009-3-22 16:55:14】ManifestCertificateThumbprint ~ 
            //【时间:2009-3-22 16:55:14】Trademark ~ 
            //【时间:2009-3-22 16:55:14】Title ~ PowerControls
            //【时间:2009-3-22 16:55:14】AssemblyOriginatorKeyFileType ~ 1
            //【时间:2009-3-22 16:55:14】FileName ~ PowerControls.csproj
            //【时间:2009-3-22 16:55:14】发生意外。 (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))
            //【时间:2009-3-22 16:55:14】AssemblyOriginatorKeyMode ~ 0
            //【时间:2009-3-22 16:55:14】AssemblyKeyContainerName ~ 
            //【时间:2009-3-22 16:55:14】ProjectType ~ 0
            //【时间:2009-3-22 16:55:14】ReferencePath ~ 
            //【时间:2009-3-22 16:55:14】PreBuildEvent ~ 
            //【时间:2009-3-22 16:55:14】Copyright ~ Copyright ? CCS 2008
            //【时间:2009-3-22 16:55:14】ApplicationIcon ~ 
            //【时间:2009-3-22 16:55:14】ExcludedPermissions ~ 
            //【时间:2009-3-22 16:55:14】RunPostBuildEvent ~ 1
            //【时间:2009-3-22 16:55:14】DefaultTargetSchema ~ 1
            //【时间:2009-3-22 16:55:14】RootNamespace ~ PowerControls
            //【时间:2009-3-22 16:55:14】ManifestTimestampUrl ~ 
            //【时间:2009-3-22 16:55:14】ManifestKeyFile ~ 
            //【时间:2009-3-22 16:55:14】DebugSecurityZoneURL ~ 
            //【时间:2009-3-22 16:55:14】Product ~ PowerControls
            //【时间:2009-3-22 16:55:14】PostBuildEvent ~ 
            //【时间:2009-3-22 16:55:14】OptionStrict ~ 0
            //【时间:2009-3-22 16:55:14】DefaultHTMLPageLayout ~ 1
            //【时间:2009-3-22 16:55:14】DelaySign ~ False
            //【时间:2009-3-22 16:55:14】OutputType ~ 2
            //【时间:2009-3-22 16:55:14】NeutralResourcesLanguage ~ 
            //【时间:2009-3-22 16:55:14】OptionExplicit ~ 1
            //【时间:2009-3-22 16:55:14】OutputFileName ~ PowerControls.dll
            //【时间:2009-3-22 16:55:14】发生意外。 (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))
            //【时间:2009-3-22 16:55:14】AssemblyGuid ~ 6345ef22-e95d-4caa-9cb7-eed14e2f693f
            //【时间:2009-3-22 16:55:14】GenerateManifests ~ False
            //【时间:2009-3-22 16:55:14】AssemblyVersion ~ 1.0.0.0
            //【时间:2009-3-22 16:55:14】Win32ResourceFile ~ 
            //【时间:2009-3-22 16:55:14】Description ~ 
            //【时间:2009-3-22 16:55:14】URL ~ file:///E:\Projects\HomePage\Witch\SRC\PowerControls\
            //【时间:2009-3-22 16:55:14】DefaultClientScript ~ 0
            //【时间:2009-3-22 16:55:14】TargetFramework ~ 131072
            //【时间:2009-3-22 16:55:14】SignManifests ~ False
            //【时间:2009-3-22 16:55:14】发生意外。 (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))
            //【时间:2009-3-22 16:55:14】发生意外。 (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))
            //【时间:2009-3-22 16:55:14】Publish ~ System.__ComObject
            //【时间:2009-3-22 16:55:14】AssemblyType ~ 0
            //【时间:2009-3-22 16:55:14】FullPath ~ E:\Projects\HomePage\Witch\SRC\PowerControls\
            //【时间:2009-3-22 16:55:14】发生意外。 (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))
            //【时间:2009-3-22 16:55:14】AssemblyKeyProviderName ~ 
            //【时间:2009-3-22 16:55:14】TypeComplianceDiagnostics ~ False
            //【时间:2009-3-22 16:55:14】Company ~ CCS
            //【时间:2009-3-22 16:55:14】发生意外。 (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))
            //【时间:2009-3-22 16:55:14】AssemblyOriginatorKeyFile ~ 
            //【时间:2009-3-22 16:55:14】ApplicationManifest ~ DefaultManifest
            //【时间:2009-3-22 16:55:14】AssemblyFileVersion ~ 1.0.0.0
            //【时间:2009-3-22 16:55:14】发生意外。 (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))
            //【时间:2009-3-22 16:55:14】发生意外。 (Exception from HRESULT: 0x80020009 (DISP_E_EXCEPTION))
            //【时间:2009-3-22 16:55:14】AssemblyName ~ PowerControls
            //【时间:2009-3-22 16:55:14】LocalPath ~ E:\Projects\HomePage\Witch\SRC\PowerControls\
            //【时间:2009-3-22 16:55:14】DefaultNamespace ~ PowerControls
            //【时间:2009-3-22 16:55:14】LinkRepair ~ False
            //【时间:2009-3-22 16:55:14】TargetZone ~ 
            //【时间:2009-3-22 16:55:14】SignAssembly ~ False
            //【时间:2009-3-22 16:55:14】proj.ConfigurationManager.ActiveConfiguration.Properties
            //【时间:2009-3-22 16:55:14】LanguageVersion ~ 
            //【时间:2009-3-22 16:55:14】RunCodeAnalysis ~ False
            //【时间:2009-3-22 16:55:14】NoStdLib ~ False
            //【时间:2009-3-22 16:55:14】ErrorReport ~ prompt
            //【时间:2009-3-22 16:55:14】CodeAnalysisUseTypeNameInSuppression ~ True
            //【时间:2009-3-22 16:55:14】CodeAnalysisInputAssembly ~ 
            //【时间:2009-3-22 16:55:14】CodeAnalysisDictionaries ~ 
            //【时间:2009-3-22 16:55:14】GenerateSerializationAssemblies ~ 2
            //【时间:2009-3-22 16:55:14】CodeAnalysisModuleSuppressionsFile ~ GlobalSuppressions.cs
            //【时间:2009-3-22 16:55:14】StartWorkingDirectory ~ 
            //【时间:2009-3-22 16:55:14】Optimize ~ False
            //【时间:2009-3-22 16:55:14】DocumentationFile ~ 
            //【时间:2009-3-22 16:55:14】StartPage ~ 
            //【时间:2009-3-22 16:55:14】OutputPath ~ bin\Debug\
            //【时间:2009-3-22 16:55:14】TreatWarningsAsErrors ~ False
            //【时间:2009-3-22 16:55:14】EnableASPDebugging ~ False
            //【时间:2009-3-22 16:55:14】IncrementalBuild ~ True
            //【时间:2009-3-22 16:55:14】CodeAnalysisLogFile ~ 
            //【时间:2009-3-22 16:55:14】DefineConstants ~ DEBUG;TRACE
            //【时间:2009-3-22 16:55:14】UseVSHostingProcess ~ True
            //【时间:2009-3-22 16:55:14】StartProgram ~ 
            //【时间:2009-3-22 16:55:14】DefineDebug ~ False
            //【时间:2009-3-22 16:55:14】CodeAnalysisCulture ~ 
            //【时间:2009-3-22 16:55:14】CodeAnalysisOverrideRuleVisibilities ~ False
            //【时间:2009-3-22 16:55:14】CodeAnalysisRuleAssemblies ~ 
            //【时间:2009-3-22 16:55:14】DefineTrace ~ False
            //【时间:2009-3-22 16:55:14】DebugSymbols ~ True
            //【时间:2009-3-22 16:55:14】NoWarn ~ 
            //【时间:2009-3-22 16:55:14】CodeAnalysisIgnoreGeneratedCode ~ True
            //【时间:2009-3-22 16:55:14】EnableSQLServerDebugging ~ False
            //【时间:2009-3-22 16:55:14】BaseAddress ~ 4194304
            //【时间:2009-3-22 16:55:14】RemoteDebugEnabled ~ False
            //【时间:2009-3-22 16:55:14】StartURL ~ 
            //【时间:2009-3-22 16:55:14】AllowUnsafeBlocks ~ False
            //【时间:2009-3-22 16:55:14】TreatSpecificWarningsAsErrors ~ 
            //【时间:2009-3-22 16:55:14】PlatformTarget ~ AnyCPU
            //【时间:2009-3-22 16:55:14】EnableUnmanagedDebugging ~ False
            //【时间:2009-3-22 16:55:14】StartWithIE ~ False
            //【时间:2009-3-22 16:55:14】StartArguments ~ 
            //【时间:2009-3-22 16:55:14】IntermediatePath ~ obj\Debug\
            //【时间:2009-3-22 16:55:14】DebugInfo ~ full
            //【时间:2009-3-22 16:55:14】CheckForOverflowUnderflow ~ False
            //【时间:2009-3-22 16:55:14】RemoteDebugMachine ~ 
            //【时间:2009-3-22 16:55:14】CodeAnalysisSpellCheckLanguages ~ 
            //【时间:2009-3-22 16:55:14】CodeAnalysisRules ~ 
            //【时间:2009-3-22 16:55:14】RegisterForComInterop ~ False
            //【时间:2009-3-22 16:55:14】FileAlignment ~ 512
            //【时间:2009-3-22 16:55:14】StartAction ~ 0
            //【时间:2009-3-22 16:55:14】EnableASPXDebugging ~ False
            //【时间:2009-3-22 16:55:14】ConfigurationOverrideFile ~ 
            //【时间:2009-3-22 16:55:14】WarningLevel ~ 4
            //【时间:2009-3-22 16:55:14】RemoveIntegerChecks ~ False



            #endregion


            //try
            //{
            //    EnvDTE.Debugger debugger = GetDebugger(_applicationObject);

            //    Expression expr;

            //    //string str;

            //    //string isDataSetExpression = null;

            //    //string getXmlExpression = null;

            //    //string fileExtintion;

            //    string strSelectText = GetSelectionText(_applicationObject);

            //    //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();

            //    // 失败 //
            //    string strExpression = strSelectText + ".GetType().FullName";

            //    //string strExpression = strSelectText;// +".GetType().FullName";

            //    // expr = debugger.GetExpression(.GetExpression(strExpression, true, 500);
            //    expr = debugger.GetExpression(strExpression, true, 500);

            //    string strResult = GetEntityCode(strSelectText, expr.Value);

            //    SetSelectionText(_applicationObject, strResult);


            //}
            //catch (Exception e)
            //{
            //    System.Windows.Forms.MessageBox.Show(e.Message);
            //}

            //return true;

            // return CreateOpCtrlCode(_applicationObject, _addInInstance);

            // return AddUsing(_applicationObject, _addInInstance);
            //return RemoveCommandBar(_applicationObject, _addInInstance, "SlowX");
 
 */


标签:旧版本插件代码备份 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)
 
  ┈全部┈  
 
(显示默认分类)