Ejemplo n.º 1
0
        private void UpdateConnection(int tryNum = 0)
        {
            tryNum++;
            try
            {
                if (transporter != null)
                {
                    transporter.Dispose();
                }

                logger.LogInformation($"try get new transporter try {tryNum}");
                transporter = providerTransporterCreator();
                transporter.OnNeedNewInstance += NeedNewInstance;
                transporter.OnConnectionLost  += () =>
                {
                    Console.WriteLine("CONNECTION LOST :( try to reconnect");
                    UpdateConnection(tryNum);
                };
            }
            catch (SocketException sockEx)
            {
                logger.LogWarning(sockEx, "Error while connecting to remote host");
                UpdateConnection(tryNum);
            }
            catch (AggregateException aggrEx)
            {
                logger.LogWarning(aggrEx, "Error while connecting to remote host");
                UpdateConnection(tryNum);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Unexpected error while creating ITransporter");
                throw;
            }
        }
Ejemplo n.º 2
0
 public void Dispose()
 {
     transporter.Dispose();
     aborted = true;
 }