private async Task <bool> BuildProjectWithMDBFilesAsync()
        {
            try
            {
                NLogService.Logger.Info($"===== {nameof(BuildProjectWithMDBFilesAsync)} =====");

                if (!_monoExtension.IsStartupProjectAvailable())
                {
                    NLogService.Logger.Info($"No startup project/solution loaded yet.");
                    return(false);
                }

                UserSettings         settings;
                DebugOptions         debugOptions;
                SshDeltaCopy.Options options;
                CreateDebugOptions(out settings, out debugOptions, out options);

                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                await _monoExtension.BuildStartupProjectAsync();

                await _monoExtension.CreateMdbForAllDependantProjectsAsync(HostOutputWindowEx.WriteLineLaunchError);

                return(true);
            }
            catch (Exception ex)
            {
                await HostOutputWindowEx.WriteLineLaunchErrorAsync(ex.Message);

                NLogService.Logger.Error(ex);
                MessageBox.Show(ex.Message, "VSMonoDebugger", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            return(false);
        }
Example #2
0
 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;
     }
 }
Example #3
0
 protected override bool HandleException(Exception ex)
 {
     if (ex is Mono.Debugger.Soft.VMNotSuspendedException)
     {
         return(true);
     }
     if (ex is Mono.Debugger.Soft.CommandException)
     {
         return(true);
     }
     if (ex is Mono.Debugger.Soft.VMDisconnectedException)
     {
         HostOutputWindowEx.WriteLineLaunchErrorAsync(ex.ToString());
         return(true);
     }
     return(base.HandleException(ex));
 }
Example #4
0
        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();
            }
        }
Example #5
0
 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();
         }
     }
 }
        private async Task <bool> DeployAndRunCommandOverSSHAsync(DebuggerMode debuggerMode)
        {
            // TODO error handling
            // TODO show ssh output stream
            // TODO stop monoRemoteSshDebugTask properly
            try
            {
                NLogService.Logger.Info($"===== {nameof(DeployAndRunCommandOverSSHAsync)} =====");

                if (!_monoExtension.IsStartupProjectAvailable())
                {
                    NLogService.Logger.Info($"No startup project/solution loaded yet.");
                    return(false);
                }

                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                UserSettings         settings;
                DebugOptions         debugOptions;
                SshDeltaCopy.Options options;
                CreateDebugOptions(out settings, out debugOptions, out options);

                if (debuggerMode.HasFlag(DebuggerMode.DeployOverSSH))
                {
                    await _monoExtension.BuildStartupProjectAsync();

                    await _monoExtension.CreateMdbForAllDependantProjectsAsync(HostOutputWindowEx.WriteLineLaunchError);
                }

                var monoRemoteSshDebugTask = System.Threading.Tasks.Task.CompletedTask;

                if (debuggerMode.HasFlag(DebuggerMode.DeployOverSSH) && debuggerMode.HasFlag(DebuggerMode.DebugOverSSH))
                {
                    monoRemoteSshDebugTask = await SSHDebugger.DeployAndDebugAsync(options, debugOptions, HostOutputWindowEx.WriteLaunchErrorAsync, settings.RedirectOutputOption);
                }
                else if (debuggerMode.HasFlag(DebuggerMode.DeployOverSSH))
                {
                    monoRemoteSshDebugTask = await SSHDebugger.DeployAsync(options, debugOptions, HostOutputWindowEx.WriteLaunchErrorAsync, settings.RedirectOutputOption);
                }
                else if (debuggerMode.HasFlag(DebuggerMode.DebugOverSSH))
                {
                    monoRemoteSshDebugTask = await SSHDebugger.DebugAsync(options, debugOptions, HostOutputWindowEx.WriteLaunchErrorAsync, settings.RedirectOutputOption);
                }

                if (debuggerMode.HasFlag(DebuggerMode.AttachProcess))
                {
                    _monoExtension.AttachDebuggerToRunningProcess(debugOptions);
                }

                await monoRemoteSshDebugTask;

                return(true);
            }
            catch (Exception ex)
            {
                HostOutputWindowEx.WriteLineLaunchErrorAsync(ex.Message);
                NLogService.Logger.Error(ex);
                MessageBox.Show(ex.Message, "VSMonoDebugger", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            return(false);
        }
Example #7
0
 private void OnTargetDebugOutput(int level, string category, string message)
 {
     HostOutputWindowEx.WriteLineLaunchErrorAsync(string.Format("[{0,3:###}]:{1}: {2}", level.ToString("000"), category, message));
 }
Example #8
0
        private async Task <bool> DeployAndRunCommandOverSSHAsync(DebuggerMode debuggerMode)
        {
            // TODO error handling
            // TODO show ssh output stream
            // TODO stop monoRemoteSshDebugTask properly
            try
            {
                Logger.Info($"===== {nameof(DeployAndRunCommandOverSSHAsync)} =====");

                if (!_monoExtension.IsStartupProjectAvailable())
                {
                    Logger.Info($"No startup project/solution loaded yet.");
                    return(false);
                }

                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                UserSettings         settings;
                DebugOptions         debugOptions;
                SshDeltaCopy.Options options;
                CreateDebugOptions(out settings, out debugOptions, out options);

                if (debuggerMode.HasFlag(DebuggerMode.DeployOverSSH))
                {
                    await _monoExtension.BuildStartupProjectAsync();

                    if (settings.UseDotnetCoreDebugger == false)
                    {
                        await _monoExtension.CreateMdbForAllDependantProjectsAsync(HostOutputWindowEx.WriteLineLaunchError);
                    }
                }

                IDebugger debugger = settings.DeployAndDebugOnLocalWindowsSystem ?
                                     (IDebugger) new LocalWindowsDebugger() :
                                     settings.UseDotnetCoreDebugger ? (IDebugger) new SSHDebuggerDotnet(options) : new SSHDebuggerMono(options);

                System.Threading.Tasks.Task <bool> monoRemoteSshDebugTask = null;

                if (debuggerMode.HasFlag(DebuggerMode.DeployOverSSH) && debuggerMode.HasFlag(DebuggerMode.DebugOverSSH))
                {
                    monoRemoteSshDebugTask = debugger.DeployRunAndDebugAsync(debugOptions, HostOutputWindowEx.WriteLaunchErrorAsync, settings.RedirectOutputOption);
                }
                else if (debuggerMode.HasFlag(DebuggerMode.DeployOverSSH))
                {
                    monoRemoteSshDebugTask = debugger.DeployAsync(debugOptions, HostOutputWindowEx.WriteLaunchErrorAsync, settings.RedirectOutputOption);
                }
                else if (debuggerMode.HasFlag(DebuggerMode.DebugOverSSH))
                {
                    monoRemoteSshDebugTask = debugger.RunAndDebugAsync(debugOptions, HostOutputWindowEx.WriteLaunchErrorAsync, settings.RedirectOutputOption);
                }

                if (debuggerMode.HasFlag(DebuggerMode.AttachProcess))
                {
                    if (settings.UseDotnetCoreDebugger)
                    {
                        var myresult = await monoRemoteSshDebugTask;
                        _monoExtension.AttachDotnetDebuggerToRunningProcess(debugOptions);
                    }
                    else
                    {
                        _monoExtension.AttachMonoDebuggerToRunningProcess(debugOptions);
                    }
                }

                if (monoRemoteSshDebugTask != null)
                {
                    var myresult = await monoRemoteSshDebugTask;
                }

                return(true);
            }
            catch (Exception ex)
            {
                await HostOutputWindowEx.WriteLineLaunchErrorAsync(ex.Message);

                Logger.Error(ex);
                MessageBox.Show(ex.Message, "VSMonoDebugger", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            return(false);
        }