public async Task InitializeListenersAsync()
        {
            string MethodName = "InitializeListenersAsync";

            try
            {
                await JoinableTaskFactory.SwitchToMainThreadAsync();

                string PluginVersion = GetVersion();
                Logger.Info(string.Format("Initializing Code Time v{0}", PluginVersion));
                Logger.FileLog("Initializing Code Time", MethodName);

                _statusBarButton = new StatusBarButton();

                await this.InitializeUserInfoAsync();

                // VisualStudio Object
                Events2 events = (Events2)ObjDte.Events;
                _textDocKeyEvent = events.TextDocumentKeyPressEvents;
                _docEvents       = events.DocumentEvents;
                _solutionEvents  = events.SolutionEvents;

                // _solutionEvents.Opened += this.SolutionEventOpenedAsync;
                Task.Delay(3000).ContinueWith((task) =>
                {
                    SolutionEventOpenedAsync();
                });
            }
            catch (Exception ex)
            {
                Logger.Error("Error Initializing SoftwareCo", ex);
            }
        }
 internal CodeWindowHandler(DTE2 application, PatternNameProvider nameProvider, Options options)
 {
     _application           = application;
     _textDocKeyPressEvents = ((Events2)application.Events).TextDocumentKeyPressEvents[null];
     _textDocKeyPressEvents.AfterKeyPress  += AfterTextDocumentKeyPress;
     _textDocKeyPressEvents.BeforeKeyPress += BeforeTextDocumentKeyPress;
     _nameProvider = nameProvider;
     _options      = options;
 }
 internal CodeWindowHandler(DTE2 application, PatternNameProvider nameProvider, Options options)
 {
     _application = application;
     _textDocKeyPressEvents = ((Events2)application.Events).TextDocumentKeyPressEvents[null];
     _textDocKeyPressEvents.AfterKeyPress += AfterTextDocumentKeyPress;
     _textDocKeyPressEvents.BeforeKeyPress += BeforeTextDocumentKeyPress;
     _nameProvider = nameProvider;
     _options = options;
 }
 public BackspaceDeleteKeyFilter(_DTE app, IWpfTextView textView)
     : base(textView)
 {
     var events = (Events2) app.Events;
     // ReSharper disable RedundantArgumentDefaultValue
     _keyPressEvents = events.TextDocumentKeyPressEvents[null];
     // ReSharper restore RedundantArgumentDefaultValue
     _keyPressEvents.BeforeKeyPress += BeforeKeyPress;
 }
示例#5
0
        /// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary>
        /// <param name="application">Root object of the host application.</param>
        /// <param name='connectMode'>Describes how the Add-in is being loaded.</param>
        /// <param name='addInInst'>Object representing this Add-in.</param>
        /// <param name='custom'>Array of parameters that are host application specific.</param>
        /// <seealso class='IDTExtensibility2' />
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            _applicationObject = (DTE2)application;
            _addInInstance = (AddIn)addInInst;

            _outputWindowPane = _applicationObject.ToolWindows.OutputWindow.OutputWindowPanes.Add("SmartBackspace");
            _outputWindowPane.OutputString("SmartBackspace loaded" + Environment.NewLine);

            _textDocumentKeyPressEvents = ((Events2)_applicationObject.Events).get_TextDocumentKeyPressEvents(null);
            _textDocumentKeyPressEvents.BeforeKeyPress += _OnTextDocumentBeforeKeyPress;
        }
示例#6
0
        /// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary>
        /// <param term='application'>Root object of the host application.</param>
        /// <param term='connectMode'>Describes how the Add-in is being loaded.</param>
        /// <param term='addInInst'>Object representing this Add-in.</param>
        /// <seealso class='IDTExtensibility2' />
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            _applicationObject = (DTE2)application;
            _addInInstance = (AddIn)addInInst;
            _textDocKeyEvents = ((Events2) _applicationObject.Events).get_TextDocumentKeyPressEvents();
            _commands = (Commands2) _applicationObject.Commands;

            try {
                _commands.AddNamedCommand2(_addInInstance, "Toggle", "Toggle TestCase", "Toggle test naming replacements on or off", false);
            } catch (Exception) {
            }

            _textDocKeyEvents.BeforeKeyPress += new _dispTextDocumentKeyPressEvents_BeforeKeyPressEventHandler(BeforeKeyPress);
        }
示例#7
0
        /// <summary>实现 IDTExtensibility2 接口的 OnConnection 方法。接收正在加载外接程序的通知。</summary>
        /// <param term='application'>宿主应用程序的根对象。</param>
        /// <param term='connectMode'>描述外接程序的加载方式。</param>
        /// <param term='addInInst'>表示此外接程序的对象。</param>
        /// <seealso class='IDTExtensibility2' />
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            _applicationObject = (DTE2)application;
            _addInInstance = (AddIn)addInInst;
            if ((connectMode == ext_ConnectMode.ext_cm_UISetup || connectMode == Extensibility.ext_ConnectMode.ext_cm_Startup)&&!_initialized)
            {
                _usefulFunctions = new UsefulFunctions(_applicationObject, _addInInstance);
                string keyGlobal = "Global::";

                outliner.setApplicationObject(_applicationObject);
                docEvents = _applicationObject.Events.get_DocumentEvents(null);
                docEvents.DocumentOpened += new _dispDocumentEvents_DocumentOpenedEventHandler(docEvents_DocumentOpened);
                eventTextEditor = _applicationObject.Events.get_TextEditorEvents(null);
                eventTextEditor.LineChanged += new _dispTextEditorEvents_LineChangedEventHandler(eventTextEditor_LineChanged);
                EnvDTE80.Events2 events = (EnvDTE80.Events2)_applicationObject.Events;
                eventTextEditor2 = events.get_TextDocumentKeyPressEvents(null);
                eventTextEditor2.BeforeKeyPress += new _dispTextDocumentKeyPressEvents_BeforeKeyPressEventHandler(eventTextEditor2_BeforeKeyPress);

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

                try
                {
                    //若要将此命令移动到另一个菜单,则将“工具”一词更改为此菜单的英文版。
                    //  此代码将获取区域性,将其追加到菜单名中,然后将此命令添加到该菜单中。
                    //  您会在此文件中看到全部顶级菜单的列表
                    //  CommandBar.resx.
                    string resourceName;
                    ResourceManager resourceManager = new ResourceManager("JrtCoder.CommandBar", Assembly.GetExecutingAssembly());
                    CultureInfo cultureInfo = new CultureInfo(_applicationObject.LocaleID);

                    if (cultureInfo.TwoLetterISOLanguageName == "zh")
                    {
                        System.Globalization.CultureInfo parentCultureInfo = cultureInfo.Parent;
                        resourceName = String.Concat(parentCultureInfo.Name, "Tools");
                        keyGlobal = "全局::";
                    }
                    else
                    {
                        resourceName = String.Concat(cultureInfo.TwoLetterISOLanguageName, "Tools");
                    }
                    toolsMenuName = resourceManager.GetString(resourceName);
                }
                catch
                {
                    //我们试图查找“工具”一词的本地化版本,但未能找到。
                    //  默认值为 en-US 单词,该值可能适用于当前区域性。
                    toolsMenuName = "Tools";
                }

                //将此命令置于“工具”菜单上。
                //查找 MenuBar 命令栏,该命令栏是容纳所有主菜单项的顶级命令栏:
                Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["MenuBar"];

                //在 MenuBar 命令栏上查找“工具”命令栏:
                CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName];
                CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl;

                //如果希望添加多个由您的外接程序处理的命令,可以重复此 try/catch 块,
                //  只需确保更新 QueryStatus/Exec 方法,使其包含新的命令名。
                try
                {

                    try
                    {
                        formatAllCmd = _applicationObject.Commands.Item(GetFullCmd(FormatAll), -1);
                        formatSelectedCmd = _applicationObject.Commands.Item(GetFullCmd(FormatSelected), -1);
                        formatSettingsCmd = _applicationObject.Commands.Item(GetFullCmd(FormatSettings), -1);
                        AddRegionCmd = _applicationObject.Commands.Item(GetFullCmd(AddRegion), -1);
                    }
                    catch (System.Exception e)
                    {

                    }

                    try
                    {
                        if (formatAllCmd == null)
                        {
                            formatAllCmd = commands.AddNamedCommand2(_addInInstance, FormatAll, "格式化Js", "格式化全部javascript代码", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                        }
                        if (formatSelectedCmd == null)
                        {
                            formatSelectedCmd = commands.AddNamedCommand2(_addInInstance, FormatSelected, "格式化选定的Js", "格式化选定的javascript代码", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                            try
                            {
                                CommandBar cb = _usefulFunctions.GetCommandBar("HTML Context", null);
                                formatSelectedCmd.AddControl(cb, cb.accChildCount + 1);
                                cb = _usefulFunctions.GetCommandBar("Script Context", null);
                                formatSelectedCmd.AddControl(cb, cb.accChildCount + 1);
                                cb = _usefulFunctions.GetCommandBar("ASPX Context", null);
                                formatSelectedCmd.AddControl(cb, cb.accChildCount + 1);
                            }
                            catch (System.Exception)
                            { }

                        }
                        if (AddRegionCmd == null)
                        {
                            AddRegionCmd = commands.AddNamedCommand2(_addInInstance, AddRegion, "加入折叠区域", "加入折叠区域", true, 72, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                            try
                            {
                                CommandBar cb = _usefulFunctions.GetCommandBar("HTML Context", null);
                                AddRegionCmd.AddControl(cb, cb.accChildCount + 1);
                                cb = _usefulFunctions.GetCommandBar("Script Context", null);
                                AddRegionCmd.AddControl(cb, cb.accChildCount + 1);
                                cb = _usefulFunctions.GetCommandBar("ASPX Context", null);
                                AddRegionCmd.AddControl(cb, cb.accChildCount + 1);
                            }
                            catch (System.Exception)
                            { }
                        }
                        if (formatSettingsCmd == null)
                        {
                            formatSettingsCmd = commands.AddNamedCommand2(_addInInstance, FormatSettings, "js格式化参数选项", "js格式化参数配置", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                        }

                        formatAllCmd.Bindings = new object[] { keyGlobal + "ctrl+R,ctrl+F" };
                        formatSelectedCmd.Bindings = new object[] { keyGlobal + "ctrl+R,ctrl+G" };
                        AddRegionCmd.Bindings = new object[] { keyGlobal + "ctrl+alt+K" };
                    }
                    catch (System.Exception e)
                    {

                    }

                    foreach (CommandBarControl control in toolsPopup.Controls)
                    {
                        if (control.Caption == "JrtCoder")
                        {
                            jrtCoderCmd = control as CommandBarPopup;
                            break;
                        }
                    }
                    if (jrtCoderCmd == null)
                    {
                        try
                        {
                            jrtCoderCmd = (CommandBarPopup)toolsPopup.Controls.Add(vsCommandBarType.vsCommandBarTypePopup, 1, null, 1, false);
                            jrtCoderCmd.Caption = "JrtCoder";
                            if ((jrtCoderCmd != null))
                            {
                                formatAllCmd.AddControl(jrtCoderCmd.CommandBar, 1);
                                formatSelectedCmd.AddControl(jrtCoderCmd.CommandBar, 2);
                                formatSettingsCmd.AddControl(jrtCoderCmd.CommandBar, 3);

                            }
                        }
                        catch (System.Exception e)
                        {
                        }
                    }
                    jrtCoderCmd.Visible = true;
                }
                catch (System.ArgumentException)
                {
                    //如果出现此异常,原因很可能是由于具有该名称的命令已存在。如果确实如此,则无需重新创建此命令,并且可以放心忽略此异常。
                }
                _initialized = true;
            }
        }
        public async Task InitializeListenersAsync()
        {
            await JoinableTaskFactory.SwitchToMainThreadAsync(DisposalToken);

            try
            {
                string PluginVersion = GetVersion();
                Logger.Info(string.Format("Initializing Code Time v{0}", PluginVersion));

                // VisualStudio Object
                Events2 events = (Events2)ObjDte.Events;
                _textDocKeyEvent = events.TextDocumentKeyPressEvents;
                _docEvents       = ObjDte.Events.DocumentEvents;

                // setup event handlers
                _textDocKeyEvent.AfterKeyPress += AfterKeyPressedAsync;
                _docEvents.DocumentOpened      += DocEventsOnDocumentOpenedAsync;
                _docEvents.DocumentClosing     += DocEventsOnDocumentClosedAsync;
                _docEvents.DocumentSaved       += DocEventsOnDocumentSaved;
                _docEvents.DocumentOpening     += DocEventsOnDocumentOpeningAsync;

                //initialize the StatusBar
                await InitializeSoftwareStatusAsync();

                if (_sessionSummary == null)
                {
                    _sessionSummary = new SessionSummary();
                }
                // initialize the menu commands
                await SoftwareLaunchCommand.InitializeAsync(this);

                await SoftwareDashboardLaunchCommand.InitializeAsync(this);

                await SoftwareTopFortyCommand.InitializeAsync(this);

                await SoftwareLoginCommand.InitializeAsync(this);

                await SoftwareToggleStatusInfoCommand.InitializeAsync(this);

                if (_softwareRepoUtil == null)
                {
                    _softwareRepoUtil = new SoftwareRepoManager();
                }



                // Create an AutoResetEvent to signal the timeout threshold in the
                // timer callback has been reached.
                var autoEvent = new AutoResetEvent(false);

                // setup timer to process events every 1 minute
                timer = new System.Threading.Timer(
                    ProcessSoftwareDataTimerCallbackAsync,
                    autoEvent,
                    ONE_MINUTE,
                    ONE_MINUTE);

                offlineDataTimer = new System.Threading.Timer(
                    SendOfflineData,
                    null,
                    THIRTY_MINUTES,
                    THIRTY_MINUTES);

                // this.SendOfflineData();

                // start in 5 seconds every 5 min
                //int delay = 1000 * 5;
                //kpmTimer = new System.Threading.Timer(
                //    ProcessFetchDailyKpmTimerCallbackAsync,
                //    autoEvent,
                //    delay,
                //    ONE_MINUTE * 5);

                int delay = 1000 * 45;

                delay            = ONE_MINUTE + (1000 * 10);
                repoCommitsTimer = new System.Threading.Timer(
                    ProcessHourlyJobs,
                    autoEvent,
                    delay,
                    ONE_HOUR);

                musicTimer = new System.Threading.Timer(
                    ProcessMusicTracksAsync,
                    autoEvent,
                    1000 * 5,
                    1000 * 30);

                statusMsgTimer = new System.Threading.Timer(
                    UpdateStatusMsg,
                    autoEvent,
                    1000 * 30,
                    1000 * 10);

                userStatusTimer = new System.Threading.Timer(
                    UpdateUserStatus,
                    autoEvent,
                    ONE_MINUTE,
                    1000 * 120);

                this.InitializeUserInfo();
            }
            catch (Exception ex)
            {
                Logger.Error("Error Initializing SoftwareCo", ex);
            }
        }