/// <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='addIn'> /// 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 addIn, ref Array custom) { _application = (DTE2)application; _addIn = (AddIn)addIn; try { if (connectMode == ext_ConnectMode.ext_cm_Startup || connectMode == ext_ConnectMode.ext_cm_AfterStartup) { _listener = CreateTraceListener(); _env = new ControllerEnvironment(new WindowHandle(_application.MainWindow.HWnd), _listener); _controller = CreateController(); _controller.OnConnectionStateChange += OnConnectionStateChange; CreateCommands(); CreateToolWindow(); _listener.WriteLine("Addin initialized"); if (connectMode == ext_ConnectMode.ext_cm_AfterStartup) { OnStartupComplete(ref custom); } } } catch (Exception ex) { if (_listener != null) { _listener.WriteLine(ex); } } }
public void TestConnect() { var env = new DummyControllerEnvironment(); var ctl = new Controller(new DummyTimeTrackingRepository(), new DummyWebServicesFactory(), env); Assert.IsFalse(ctl.Connected); ctl.Disconnect(); }
internal void Init(DTE2 applicationObject, Controller controller, ControllerEnvironment env) { if (applicationObject == null) { throw new ArgumentNullException("applicationObject"); } if (controller == null) { throw new ArgumentNullException("controller"); } if (env == null) { throw new ArgumentNullException("env"); } if (_application != null) { throw new InvalidOperationException("Already initialized"); } _application = applicationObject; _controller = controller; _env = env; _controller.OnConnect += Controller_OnConnect; _controller.OnDisconnect += Controller_OnDisconnect; _controller.OnAssignmentTimeStarted += Controller_OnCurrentAssignmentChanged; _controller.OnAssignmentTimeStopped += Controller_OnCurrentAssignmentChanged; _controller.OnListRefresh += Controller_OnListRefresh; }
public void TestOptions() { var env = new DummyControllerEnvironment(); using (var ctl = new Controller(new DummyTimeTrackingRepository(), new DummyWebServicesFactory(), env)) { env.DialogResult = DialogResult.OK; ctl.Options(); env.DialogResult = DialogResult.Cancel; ctl.Options(); } }
public void TestConnectDisconnect() { var settings = new Settings {Uri = new Uri("http://localhost"), Login = "******", DecryptedPassword = "******",}; settings.Save(); var env = new DummyControllerEnvironment(); Controller ctl; using (ctl = new Controller(new DummyTimeTrackingRepository(), new DummyWebServicesFactory(), env)) { Assert.IsFalse(ctl.Connected); env.DialogResult = DialogResult.OK; ctl.Connect(true); Assert.IsTrue(ctl.Connected); ctl.Disconnect(); Assert.IsFalse(ctl.Connected); env.DialogResult = DialogResult.Cancel; ctl.Connect(true); Assert.IsFalse(ctl.Connected); env.DialogResult = DialogResult.OK; ctl.Connect(true); Assert.IsTrue(ctl.Connected); } Assert.IsFalse(ctl.Connected); }
/// <summary> /// Receives notification that the Add-in is being unloaded. /// </summary> /// <param name='disconnectMode'> /// Describes how the Add-in is being unloaded. /// </param> /// <param name='custom'> /// Array of parameters that are host application specific. /// </param> /// <seealso class='IDTExtensibility2' /> public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom) { if (disconnectMode == ext_DisconnectMode.ext_dm_HostShutdown || disconnectMode == ext_DisconnectMode.ext_dm_UserClosed) { if (_commandBarPopup != null) { _commandBarPopup.Delete(null); _commandBarPopup = null; } if (_controller != null) { _controller.Dispose(); _controller = null; } if (_listener != null) { _listener.WriteLine("Disposed"); _listener.Dispose(); _listener = null; } } }