private DeviceMonitorResult HandleDeviceMonitorResult(Task <DeviceMonitorResult> devMonitorResult) { DeviceMonitorResult ret = devMonitorResult.Result; if (ret != DeviceMonitorResult.CanceledByUser) { DeviceManager.SelectDevice(null); DeviceManager.DeviceInfoList?.Clear(); DeviceManager.UpdateDebugTargetList(true); string msg = string.Format("SDB Server disconnected.\n({0})\n\nClick 'Retry' or 'Tools -> Tizen -> Restart Sdb Server' to establish the connection.", SDBLib.GetSdbFilePath()); if (MessageBox.Show(msg, "Visual Studio Tools for Tizen", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry) { StartService(); } } return(ret); }
private DeviceMonitorResult DeviceChangeDetectTask() { DeviceMonitorResult ret = DeviceMonitorResult.CanceledByUser; this.sdbconnection = SDBConnection.Create(); if (this.sdbconnection == null) { OutputDeviceInfoMsg("Failed to connect to SDB Server. "); this.taskCancelSource.Cancel(); retryConntectServerCount--; if (retryConntectServerCount > 0) { NotifyConnectServerFailed(); } else { OutputDeviceInfoMsg("Too many retries.\n" + " Please check Tools option and sdb.exe is installed correctly.\n" + " After the problem is fixed, reopen the Solution to start the Device Monitor"); } return(DeviceMonitorResult.SdbEstablishmentError); } Thread.Sleep(100); SDBRequest request = SDBConnection.MakeRequest("host:track-devices"); SDBResponse response = this.sdbconnection.Send(request); if (!response.IOSuccess || !response.Okay) { this.sdbconnection.Close(); this.sdbconnection = null; OutputDeviceInfoMsg("Failed to start device monitor."); this.taskCancelSource.Cancel(); NotifyConnectServerFailed(); return(DeviceMonitorResult.SdbResponseError); } OutputDeviceInfoMsg("Device monitor started."); CancellationToken cancelToken = this.taskCancelSource.Token; bool connectionError = false; while (true) { if (this.sdbconnection.ConnectionError()) { connectionError = true; OutputDeviceInfoMsg("SDB Server disconnected."); ret = DeviceMonitorResult.SdbServerKilled; break; } if (this.sdbconnection.DataAvailable()) { int length = this.sdbconnection.ReadLength(); if (length > 0) { OutputDeviceChangeMsg(); byte[] buffer = new byte[length]; string result = this.sdbconnection.ReadData(buffer); ProcessDeviceData(result); NotifySubscribers(); } else if (length == 0) { if (this.deviceInfoList.Count > 0) { // show message only if there was any device connected // we don't have to show when 0 changed to 0 OutputDeviceChangeMsg(); } ProcessDeviceData(String.Empty); NotifySubscribers(); } else { if (cancelToken.IsCancellationRequested) { ret = DeviceMonitorResult.CanceledByUser; break; } connectionError = true; OutputDeviceInfoMsg("SDB Server disconnected."); ret = DeviceMonitorResult.SdbServerKilled; break; } } else { #if DEBUG ////OutputDeviceInfoMsg("sdb host:track-devices timeout...", false); #endif Thread.Sleep(1); } if (cancelToken.IsCancellationRequested) { ret = DeviceMonitorResult.CanceledByUser; break; } } this.sdbconnection.Close(); this.sdbconnection = null; if (connectionError) { NeedsRestart = true; } return(ret); }