namespace GMLL00ImportadorXsd.Utilidades.Corp.Wcf
{
    using System;
    using System.ServiceModel;
    using CanalClienteGenerico;

    internal abstract class WcfBase<T> : IDisposable where T : IClientChannel
    {
        private readonly CanalClienteGenerico<T> channelFactory;

        protected WcfBase(string ficheroConfiguracion)
        {
            this.channelFactory = new CanalClienteGenerico<T>(ficheroConfiguracion);
        }

        public void Dispose()
        {
            this.Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected T CrearCanal()
        {
            return this.channelFactory.CreateChannel();
        }

        private void Dispose(bool disposing)
        {
            if (disposing && this.channelFactory != null)
            {
                try
                {
                    this.channelFactory.Close();
                }
                catch
                {
                    this.channelFactory.Abort();
                    throw;
                }
            }
        }
    }
}