private void Connect() { // NLogService.TraceEnteringMethod(Logger); if (this.IsConnected) { return; } if (this.ReconnectCurrentCount >= ReconnectMaxCount) { HostOutputWindowEx.WriteLineLaunchErrorAsync("Reconnect max count"); Logger.Error("Reconnect max count"); return; } try { this.Client = new TcpClient(); this.Client.NoDelay = true; this.Client.ReceiveTimeout = 10000; this.Client.SendTimeout = 10000; this.Client.Connect(this.NotifyServer, this.NotifyPort); ReconnectCurrentCount = 0; } catch (Exception e) { HostOutputWindowEx.WriteLineLaunchErrorAsync(e.ToString()); NLogService.LogError(Logger, e); this.Clear(); ReconnectCurrentCount += 1; } }
private int BuildStartupProject() { ThreadHelper.ThrowIfNotOnUIThread(); var sb = (SolutionBuild2)_dte.Solution.SolutionBuild; try { var startProject = GetStartupProject(); var activeConfiguration = _dte.Solution.SolutionBuild.ActiveConfiguration as SolutionConfiguration2; var activeConfigurationName = activeConfiguration.Name; var activeConfigurationPlatform = activeConfiguration.Name; var startProjectName = startProject.FullName; Logger.Info($"BuildProject {startProject.FullName} {activeConfigurationName}|{activeConfigurationPlatform}"); sb.BuildProject($"{activeConfigurationName}|{activeConfigurationPlatform}", startProject.FullName, true); } catch (Exception ex) { NLogService.LogError(Logger, ex); Logger.Info($"BuildProject failed - Fallback: BuildSolution"); // Build complete solution (fallback solution) return(BuildSolution()); } return(sb.LastBuildInfo); }
public async Task CreateMdbForAllDependantProjectsAsync(Action <string> msgOutput) { NLogService.TraceEnteringMethod(Logger); await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var sb = (SolutionBuild2)_dte.Solution.SolutionBuild; var startProject = GetStartupProject(); var dependantProjects = CollectAllDependentProjects(startProject, msgOutput); var outputDirectories = CollectOutputDirectories(sb, msgOutput); foreach (var projectName in dependantProjects.Keys) { try { if (outputDirectories.ContainsKey(projectName)) { var outputDir = Path.GetFullPath(outputDirectories[projectName]); Logger.Info($"{projectName} - OutputDir: {outputDir}"); await ConvertPdb2MdbAsync(outputDir, msgOutput); } else { Logger.Info($"{projectName} - OutputDir: NOT FOUND!"); } } catch (Exception ex) { NLogService.LogError(Logger, ex); } } }
public VSMonoDebuggerProjectSettings?GetProjectSettingsFromStartupProject() { NLogService.TraceEnteringMethod(Logger); try { ThreadHelper.ThrowIfNotOnUIThread(); var startupProject = GetStartupProject(); var projectFullName = startupProject.FullName; if (File.Exists(projectFullName)) { var projectConfigFile = Path.ChangeExtension(projectFullName, ".VSMonoDebugger.config"); if (File.Exists(projectConfigFile)) { Logger.Info($"Local project config file {projectConfigFile} found."); var projectConfigFileContent = File.ReadAllText(projectConfigFile); return(VSMonoDebuggerProjectSettings.DeserializeFromJson(projectConfigFileContent)); } } } catch (Exception ex) { // *.VSMonoDebugger.config can contain illigal escape characters for WindowsPath "C:\Temp" => "C:\\Temp" // Don't fix it ... user has to be json conform Logger.Info("Please validate that the local project config file (*.VSMonoDebugger.config) conatins no illigal escape character sequences for WindowsDeployPath!"); NLogService.LogError(Logger, ex); } return(null); }
public void AttachMonoDebuggerToRunningProcess(DebugOptions debugOptions) { NLogService.TraceEnteringMethod(Logger); ThreadHelper.ThrowIfNotOnUIThread(); if (DebugEngineGuids.UseAD7Engine == EngineType.XamarinEngine) { // Workaround to get StartProject XamarinEngine.StartupProject = GetStartupProject(); } IntPtr pInfo = GetDebugInfo(debugOptions); var sp = new ServiceProvider((IServiceProvider)_dte); try { var dbg = sp.GetService(typeof(SVsShellDebugger)) as IVsDebugger; if (dbg == null) { Logger.Error($"GetService did not returned SVsShellDebugger"); } int hr = dbg.LaunchDebugTargets(1, pInfo); Marshal.ThrowExceptionForHR(hr); } catch (Exception ex) { NLogService.LogError(Logger, ex); string msg = null; var sh = sp.GetService(typeof(SVsUIShell)) as IVsUIShell; if (sh != null) { sh.GetErrorInfo(out msg); } if (!string.IsNullOrWhiteSpace(msg)) { Logger.Error(msg); } throw; } finally { if (pInfo != IntPtr.Zero) { Marshal.FreeCoTaskMem(pInfo); } } }
private string GetStartArguments() { ThreadHelper.ThrowIfNotOnUIThread(); try { Project startupProject = GetStartupProject(); Configuration configuration = startupProject.ConfigurationManager.ActiveConfiguration; return(configuration.Properties.Item("StartArguments").Value?.ToString() ?? string.Empty); } catch (Exception ex) { NLogService.LogError(Logger, ex); return(string.Empty); } }
private void Receive() { // NLogService.TraceEnteringMethod(Logger); try { if (!this.IsConnected) { return; } int DataCount = this.CurrentDataLength; if (DataCount == 0) { DataCount = DataHeaderSize; } byte[] Data = new byte[DataCount]; if (DataCount > 0 && this.Client.Available >= DataCount) { this.Client.GetStream().Read(Data, 0, DataCount); if (!BitConverter.IsLittleEndian) { Array.Reverse(Data); } if (this.CurrentDataLength == 0) { this.CurrentDataLength = BitConverter.ToInt32(Data, 0); } else { this.CurrentDataLength = 0; string DataText = System.Text.UTF8Encoding.UTF8.GetString(Data); Logger.Debug(string.Format("Receive: {0}", DataText)); // todo 回调 } } } catch (Exception e) { HostOutputWindowEx.WriteLineLaunchErrorAsync(e.ToString()); NLogService.LogError(Logger, e); Clear(); } }
private Task ConvertPdb2MdbAsync(string outputDirectory, Action <string> msgOutput) { return(Task.Run(() => { msgOutput?.Invoke($"Start ConvertPdb2Mdb: {outputDirectory} ..."); var assemblyFiles = Directory.EnumerateFiles(outputDirectory, "*.exe", SearchOption.AllDirectories) .Union(Directory.EnumerateFiles(outputDirectory, "*.dll", SearchOption.AllDirectories)); foreach (string file in assemblyFiles) { var pdbFile = Path.ChangeExtension(file, "pdb"); if (!File.Exists(pdbFile)) { // No *.pdb file found for file continue; } var mdbFile = file + ".mdb"; if (File.GetLastWriteTime(pdbFile) <= File.GetLastWriteTime(mdbFile)) { // No newer *.pdb file found msgOutput?.Invoke($"No mdb file creation needed for {file}. (*.pdb file write time <= *.mdb file write time)"); continue; } msgOutput?.Invoke($"Creating mdb file for {file}"); try { Pdb2Mdb.Converter.Convert(file); } catch (Exception ex) { NLogService.LogError(Logger, ex); msgOutput?.Invoke($"Error while creating mdb file for {file}. {ex.Message}"); } } msgOutput?.Invoke($"End ConvertPdb2Mdb."); })); }
private void Send() { // NLogService.TraceEnteringMethod(Logger); if (!this.IsConnected) { return; } lock (LockObject) { try { while (WaittingToSendDatas.Count > 0) { byte[] Content = WaittingToSendDatas.First.Value; NetworkStream Stream = this.Client.GetStream(); byte[] LengthBytes = BitConverter.GetBytes(Content.Length); if (!BitConverter.IsLittleEndian) { Array.Reverse(LengthBytes); Array.Reverse(Content); } byte[] Data = new byte[Content.Length + LengthBytes.Length]; Array.Copy(LengthBytes, 0, Data, 0, LengthBytes.Length); Array.Copy(Content, 0, Data, LengthBytes.Length, Content.Length); Stream.Write(Data, 0, Data.Length); Stream.Flush(); WaittingToSendDatas.RemoveFirst(); } } catch (Exception e) { HostOutputWindowEx.WriteLineLaunchErrorAsync(e.ToString()); NLogService.LogError(Logger, e); Clear(); } } }
/// <summary> /// We don't want to create a launch.json file /// Currently not working! /// </summary> /// <param name="debugOptions"></param> internal void AttachDotnetDebuggerToRunningProcess2(DebugOptions debugOptions) { NLogService.TraceEnteringMethod(Logger); ThreadHelper.ThrowIfNotOnUIThread(); var extensionInstallationDirectory = GetExtensionInstallationDirectoryOrNull(); if (extensionInstallationDirectory == null) { Logger.Error($"{nameof(extensionInstallationDirectory)} is null!"); } var settings = debugOptions.UserSettings; var launchJson = settings.LaunchJsonContent; var jsonStringPlinkExe = JsonConvert.SerializeObject(Path.Combine(extensionInstallationDirectory, "plink.exe")).Trim('"'); launchJson = launchJson.Replace(settings.PLINK_EXE_PATH, jsonStringPlinkExe); var sshPassword = string.IsNullOrWhiteSpace(settings.SSHPrivateKeyFile) ? $"-pw {settings.SSHPassword} {settings.SSHFullUrl}" : $"-i {settings.SSHPrivateKeyFile} {settings.SSHFullUrl}"; launchJson = launchJson.Replace(settings.PLINK_SSH_CONNECTION_ARGS, $"{sshPassword} "); var jsonStringDeployPath = JsonConvert.SerializeObject(debugOptions.UserSettings.SSHDeployPath).Trim('"'); launchJson = launchJson.Replace(settings.DEPLOYMENT_PATH, jsonStringDeployPath); launchJson = launchJson.Replace(settings.TARGET_EXE_FILENAME, debugOptions.TargetExeFileName); var jsonStringStartArguments = JsonConvert.SerializeObject(debugOptions.StartArguments).Trim('"'); launchJson = launchJson.Replace(settings.START_ARGUMENTS, jsonStringStartArguments); var sp = new ServiceProvider((IServiceProvider)_dte); try { var dbg = sp.GetService(typeof(SVsShellDebugger)) as IVsDebugger4; if (dbg == null) { Logger.Error($"GetService did not returned SVsShellDebugger"); } VsDebugTargetInfo4[] debugTargets = new VsDebugTargetInfo4[1]; debugTargets[0].dlo = (uint)DEBUG_LAUNCH_OPERATION.DLO_CreateProcess; debugTargets[0].bstrExe = debugOptions.StartupAssemblyPath; debugTargets[0].bstrCurDir = debugOptions.OutputDirectory; debugTargets[0].bstrArg = debugOptions.StartArguments; debugTargets[0].bstrRemoteMachine = null; // debug locally //debugTargets[0].grfLaunch = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd; // When this process ends, debugging is stopped. //debugTargets[0].grfLaunch = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_DetachOnStop, // Detaches instead of terminating when debugging stopped. //debugTargets[0].fSendStdoutToOutputWindow = 0, //debugTargets[0].bstrExe = Path.Combine(extensionInstallationDirectory, "plink.exe"); debugTargets[0].bstrOptions = launchJson; debugTargets[0].guidLaunchDebugEngine = new Guid("{541B8A8A-6081-4506-9F0A-1CE771DEBC04}"); VsDebugTargetProcessInfo[] processInfo = new VsDebugTargetProcessInfo[debugTargets.Length]; dbg.LaunchDebugTargets4(1, debugTargets, processInfo); } catch (Exception ex) { NLogService.LogError(Logger, ex); string msg = null; var sh = sp.GetService(typeof(SVsUIShell)) as IVsUIShell; if (sh != null) { sh.GetErrorInfo(out msg); } if (!string.IsNullOrWhiteSpace(msg)) { Logger.Error(msg); } throw; } //var launchJsonFile = @"C:\TFS\launch.json"; //File.WriteAllText(launchJsonFile, launchJson); //Logger.Info($"Project {debugOptions.StartupAssemblyPath} was built successfully. Invoking remote debug command"); //var dte2 = _dte as DTE2; //dte2.ExecuteCommand("DebugAdapterHost.Launch", $"/LaunchJson:\"{launchJsonFile}\" /EngineGuid:541B8A8A-6081-4506-9F0A-1CE771DEBC04"); }
public void OverwriteWithProjectSettingsFromStartupProject(ref UserSettings globalSettings) { NLogService.TraceEnteringMethod(Logger); try { ThreadHelper.ThrowIfNotOnUIThread(); var startupProject = GetStartupProject(); var projectFullName = startupProject.FullName; if (File.Exists(projectFullName)) { var name = Path.GetFileNameWithoutExtension(projectFullName); var dir = Path.GetDirectoryName(projectFullName); var configFiles = new string[] { Path.Combine(dir, name + ".VSMonoDebugger.config"), Path.Combine(dir, "VSMonoDebugger.config"), Path.Combine(dir, "VSMonoDebugger.json"), }; var projectConfigFile = configFiles.FirstOrDefault(x => File.Exists(x)); if (projectConfigFile == null) { Logger.Info($"Local project config file not found."); } else { try { Logger.Info($"Local project config file {projectConfigFile} found."); var projectConfigFileContent = File.ReadAllText(projectConfigFile); var projectSettingsByString = JsonConvert.DeserializeObject(projectConfigFileContent) as IDictionary <string, Newtonsoft.Json.Linq.JToken>; var globalSettingsByString = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(globalSettings)) as IDictionary <string, Newtonsoft.Json.Linq.JToken>; foreach (var projectKeyValue in projectSettingsByString) { if (globalSettingsByString.TryGetValue(projectKeyValue.Key, out Newtonsoft.Json.Linq.JToken globalSettingsValue) && projectKeyValue.Value.Type == globalSettingsValue.Type) { Logger.Info($"Setting {projectKeyValue.Key} was overwritten with local project file: {globalSettingsValue.ToString()} => {projectKeyValue.Value.ToString()}"); globalSettingsByString[projectKeyValue.Key] = projectKeyValue.Value; } } globalSettings = JsonConvert.DeserializeObject <UserSettings>(JsonConvert.SerializeObject(globalSettingsByString)); } catch (Exception ex) { // *.VSMonoDebugger.config can contain illigal escape characters for WindowsPath "C:\Temp" => "C:\\Temp" // Don't fix it ... user has to be json conform Logger.Info("Please validate that the local project config file {projectConfigFile} conatins no illigal escape character sequences for WindowsDeployPath!"); NLogService.LogError(Logger, ex); } } } } catch (Exception ex2) { NLogService.LogError(Logger, ex2); } }