コード例 #1
0
        protected override void Dispose(bool disposing)
        {
            if (useEvents)
            {
                connection.MessageArrived -= ProcessMessage;
                if (connection is not LocalServiceHubConsumer)
                {
                    connection.OperationalChanged -= ConnectivityChanged;
                }
            }

            connection.Dispose();
            base.Dispose(disposing);
        }
コード例 #2
0
        private void TryReconnect(object state)
        {
            if (Monitor.TryEnter(reconnLock))
            {
                try
                {
                    if (hubClient != null && !hubClient.Operational)
                    {
                        try
                        {
                            hubClient.MessageArrived -= ClientInvokation;
                            if (hubClient is not LocalServiceHubConsumer)
                            {
                                hubClient.OperationalChanged -= ConnectedChanges;
                            }

                            hubClient.Dispose();
                        }
                        catch (Exception ex)
                        {
                            LogEnvironment.LogDebugEvent($"Un-Expected Disconnection Error: {ex.OutlineException()}", LogSeverity.Error);
                        }
                        finally
                        {
                            hubClient = null;
                        }
                    }
                    if (hubClient == null)
                    {
                        try
                        {
                            ConnectToHub();
                        }
                        catch (Exception ex)
                        {
                            LogEnvironment.LogEvent($"Error when connecting to hub: {ex.OutlineException()}", LogSeverity.Warning);
                        }
                    }
                    else
                    {
                        reconnector.Change(Timeout.Infinite, Timeout.Infinite);
                    }
                }
                finally
                {
                    Monitor.Exit(reconnLock);
                }
            }
        }
コード例 #3
0
 public override void Dispose()
 {
     base.Dispose();
     hubClient?.Dispose();
     hubClient = null;
     reconnector.Dispose();
 }
コード例 #4
0
        /// <summary>
        /// Tests the connection to the given target-proxy object
        /// </summary>
        /// <returns>a value indicating whether the connection is OK</returns>
        protected override bool Test()
        {
            if (connected || !initCalled)
            {
                if (!connection.Initialized)
                {
                    try
                    {
                        connection.Initialize();
                        if (isBidirectional != IsBidirectional)
                        {
                            throw new Exception("Failed to Register return-channel. Check permissions on server.");
                        }
                    }
                    finally
                    {
                        initCalled = true;
                    }
                }

                if (!connection.Operational)
                {
                    ConnectivityChanged(null, null);
                    return(connected = false);
                }

                return(connected = connection.DiscoverService(targetService));
            }
            else
            {
                try
                {
                    ReConnectClient();
                    //return Test();
                }
                catch
                {
                    connection?.Dispose();
                    connection = null;
                    connected  = false;
                }
            }

            return(false);
        }