Exemple #1
0
        private void OnReplicaChanged(ReplicaEvent replicaEvent)
        {
            var replica = replicaEvent.Replica;

            if (!(replica is ProcessStatus process))
            {
                // This temporarily only works for processes launched
                return;
            }

            switch (replicaEvent.State)
            {
            case ReplicaState.Started:
            {
                var cts   = new CancellationTokenSource();
                var state = new DiagnosticsState
                {
                    StoppingTokenSource = cts,
                    Thread = new Thread(() =>
                        {
                            // TODO: Finding the application name requires msbuild knowledge
                            _diagnosticsCollector.ProcessEvents(Path.GetFileNameWithoutExtension(process.Service.Status.ProjectFilePath),
                                                                process.Service.Description.Name,
                                                                process.Pid.Value,
                                                                replica.Name,
                                                                replica.Metrics,
                                                                cts.Token);
                        })
                };

                replica.Items[typeof(DiagnosticsState)] = state;

                state.Thread.Start();
            }

            break;

            case ReplicaState.Stopped:
            {
                if (replica.Items.TryGetValue(typeof(DiagnosticsState), out var item) && item is DiagnosticsState state)
                {
                    state.StoppingTokenSource.Cancel();

                    state.Thread.Join();
                }
            }
            break;

            default:
                break;
            }
        }
Exemple #2
0
 public HttpState()
 {
     Client             = new HttpClient();
     PathSections       = new Stack <string>();
     Preferences        = new Dictionary <string, string>();
     DefaultPreferences = CreateDefaultPreferencs();
     Headers            = new Dictionary <string, IEnumerable <string> >(StringComparer.OrdinalIgnoreCase)
     {
         { "User-Agent", new[] { "HTTP-REPL" } }
     };
     Preferences = new Dictionary <string, string>(DefaultPreferences);
     LoadPreferences();
     DiagnosticsState = new DiagnosticsState();
 }