Esempio n. 1
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {
                    try
                    {
                        if (dispatcher != null)
                        {
                            dispatcher.Dispose();
                            logger?.LogDebugAsync($"CoAP adapter disposed dispatcher on channel {Channel.Id}")
                            .GetAwaiter();
                        }
                    }
                    catch (Exception ex)
                    {
                        logger?.LogErrorAsync(ex, $"CoAP adapter error on channel '{Channel.Id}'.").GetAwaiter();
                    }

                    try
                    {
                        if (Channel != null)
                        {
                            string channelId = Channel.Id;
                            Channel.Dispose();
                            logger?.LogDebugAsync($"CoAP adapter channel {channelId} disposed.");
                        }
                    }
                    catch (Exception ex)
                    {
                        logger?.LogErrorAsync(ex, $"CoAP adapter disposing error on channel '{Channel.Id}'.")
                        .GetAwaiter();
                    }

                    try
                    {
                        if (session != null)
                        {
                            session.Dispose();
                            logger?.LogDebugAsync("CoAP adapter disposed session.");
                        }
                    }
                    catch (Exception ex)
                    {
                        logger?.LogErrorAsync(ex, $"CoAP adapter Disposing session on channel '{Channel.Id}'.")
                        .GetAwaiter();
                    }
                }

                disposed = true;
            }
        }
Esempio n. 2
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposed)
            {
                Trace.TraceInformation("MQTT Protocol Adapter disposing on Channel '{0}'.", Channel.Id);
                if (disposing)
                {
                    try
                    {
                        if (dispatcher != null)
                        {
                            dispatcher.Dispose();
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError("{0} - CoAP adapter on channel '{1}' dispatcher dispose fault '{2}'", DateTime.UtcNow.ToString("yyyy-MM-ddTHH-MM-ss.fffff"), Channel.Id, ex.Message);
                        Console.WriteLine("Fault disposing CoAP dispatcher in CoAP adapter - '{0}'", ex.Message);
                    }

                    try
                    {
                        if (Channel != null)
                        {
                            Channel.Dispose();
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError("{0} - CoAP adapter channel dispose fault '{1}'", DateTime.UtcNow.ToString("yyyy-MM-ddTHH-MM-ss.fffff"), ex.Message);
                        Console.WriteLine("Fault disposing Channel in CoAP adapter - '{0}'", ex.Message);
                    }

                    try
                    {
                        if (session != null)
                        {
                            session.Dispose();
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError("{0} - CoAP adapter session dispose fault '{1}'", DateTime.UtcNow.ToString("yyyy-MM-ddTHH-MM-ss.fffff"), ex.Message);
                        Console.WriteLine("Fault disposing Session in CoAP adapter - '{0}'", ex.Message);
                    }
                }
                disposed = true;
            }
        }