public void Initialize()
 {
     if (_isSubscribing)
     {
         _connectionWatcherThread = new Thread(ConnectionWatcher);
         _connectionWatcherThread.Start();
     }
     else
     {
         _processManagerServiceClient.Register(false);
         Status = ProcessManagerServiceHandlerStatus.Connected;
     }
 }
        private void ConnectionWatcher()
        {
            try
            {
                bool connectionLost = false, connectionAttempted = false;
                while (true)
                {
                    if (_processManagerServiceClient.State == CommunicationState.Faulted)
                    {
                        Logger.Add(LogType.Debug, $"{Machine}: ConnectionWatcher: state = Faulted");
                        _processManagerServiceClient.Abort();
                    }

                    if (_processManagerServiceClient.State == CommunicationState.Closed)
                    {
                        Logger.Add(LogType.Debug, $"{Machine}: ConnectionWatcher: state = Closed");
                        SetupClient();
                    }

                    if (_processManagerServiceClient.State == CommunicationState.Created)
                    {
                        try
                        {
                            Logger.Add(LogType.Debug, $"{Machine}: ConnectionWatcher: state = Created");
                            _processManagerServiceClient.Register(true);
                            Status = ProcessManagerServiceHandlerStatus.Connected;
                            if (!connectionAttempted)
                            {
                                RaiseInitializationCompletedEvent();
                            }
                            else if (connectionLost)
                            {
                                connectionLost = false;
                                RaiseConnectionChangedEvent();
                            }
                        }
                        catch (Exception ex)
                        {
                            Status = ProcessManagerServiceHandlerStatus.Disconnected;
                            if (!connectionAttempted)
                            {
                                connectionLost = true;
                                RaiseInitializationCompletedEvent(ex);
                            }
                            else if (!connectionLost)
                            {
                                connectionLost = true;
                                RaiseConnectionChangedEvent();
                            }
                        }
                        connectionAttempted = true;
                    }

                    Thread.Sleep(1000);
                }
            }
            catch (ThreadAbortException) { /* exit */ }
            catch (Exception ex)
            {
                Logger.Add($"Connection watcher thread for host {Machine.HostName} exited due to an unexpected exception", ex);
            }
        }
Exemple #3
0
 public ServiceHandlerConnectionChangedEventArgs(ProcessManagerServiceHandler serviceHandler, ProcessManagerServiceHandlerStatus status, Exception exception)
 {
     ServiceHandler = serviceHandler;
     Status         = status;
     Exception      = exception;
 }
Exemple #4
0
 public ServiceHandlerConnectionChangedEventArgs(ProcessManagerServiceHandler serviceHandler, ProcessManagerServiceHandlerStatus status)
     : this(serviceHandler, status, null)
 {
 }
 private void RaiseServiceHandlerConnectionChangedEvent(ProcessManagerServiceHandler serviceHandler, ProcessManagerServiceHandlerStatus status, Exception exception = null)
 {
     ServiceHandlerConnectionChanged?.Invoke(this, new ServiceHandlerConnectionChangedEventArgs(serviceHandler, status, exception));
 }