예제 #1
0
        public void Attach(IEnumerable <V1ReplicaStatus> replicas)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var replicaList = replicas.ToList();

            _logger.Log($"Attaching to {replicaList.Count} replicas");
            foreach (var replica in replicaList)
            {
                _logger.Log($"Attaching {replica.Name} (PID: {replica.Pid}, State: {replica.State})");
            }

            var dte = _package.GetService <SDTE, DTE2>();

            try
            {
                var attachedReplicas = new List <V1ReplicaStatus>();
                foreach (var localProcess in dte.Debugger.LocalProcesses.Cast <Process>())
                {
                    var pid     = localProcess.ProcessID;
                    var replica = replicaList.FirstOrDefault(r => r.Pid == pid);

                    if (replica == null)
                    {
                        continue;
                    }

                    attachedReplicas.Add(replica);
                    localProcess.Attach();
                }

                var unattachedReplicas = replicaList.Except(attachedReplicas).ToList();
                if (unattachedReplicas.Any())
                {
                    _logger.Log($"Did not attach to replicas {string.Join(", ", unattachedReplicas.Select(r => r.Name))}.");
                }
            }
            catch (Exception ex)
            {
                _logger.Log($"Failed to attach debugger to process. {ex}");
            }
        }
예제 #2
0
        private async Task <bool> InnerRefreshAsync(bool isBackground)
        {
            if (_isRefreshRunning)
            {
                return(true);
            }

            try
            {
                _isRefreshRunning = true;

                await ThreadHelper.JoinableTaskFactory.RunAsync(async() =>
                {
                    await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(_package.DisposalToken);
                    OnServicesRequestStarted(new ServiceRequestStartedEventArgs
                    {
                        IsBackground = isBackground
                    });
                });

                var sw = new Stopwatch();
                sw.Start();
                var response = await _client.GetAsync("services");

                response.EnsureSuccessStatusCode();
                sw.Stop();

                var services = await DeserializeResponseAsync <V1Service[]>(response);

                await ThreadHelper.JoinableTaskFactory.RunAsync(async() =>
                {
                    await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(_package.DisposalToken);
                    OnServicesReceived(new ServicesReceivedEventArgs
                    {
                        Services = services
                    });
                });

                _services = services ?? throw new Exception("Failed to deserialize services response from API.");

                if (!isBackground)
                {
                    _logger.Log($"Reloaded services, found {services.Length} services in {sw.Elapsed.TotalMilliseconds:0}ms.");
                }

                await CalcRunAllAvailableAsync();

                return(true);
            }
            catch (Exception e)
            {
                _logger.Log($"Failed to reload services: {e.Message}");

                await ThreadHelper.JoinableTaskFactory.RunAsync(async() =>
                {
                    await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(_package.DisposalToken);
                    OnServiceRequestFailure(new ServiceRequestFailureEventArgs
                    {
                        Reason       = e.Message,
                        IsBackground = isBackground
                    });
                });

                return(false);
            }
            finally
            {
                _isRefreshRunning = false;
            }
        }