Ejemplo n.º 1
0
 public static AvaLogger GetLogger()
 {
     if (instance == null)
     {
         instance = new AvaLogger();
     }
     return(instance);
 }
        public virtual void Dispose()
        {
            _avaLog.Debug(string.Format("Disposing BaseSvc class: {0}", _uniqueId));

            _svcProxy = null;
            _avaLog   = null;
            _config   = null;
            _profile  = null;
            _security = null;

            // Suppress finalization of this disposed instance.
            GC.SuppressFinalize(this);
        }
        /// <include file='Avalara.AvaTax.Adapter.Doc.xml' path='adapter/common/members[@name="Constructor"]/*' />
        public BaseSvc()
        {
            //this should be done first upon entering the assembly; expected that AddressSvc and TaxSvc will be
            //    the only instantiated classes and therefore its safe to do this here.

            _avaLog = AvaLogger.GetLogger();
            _avaLog.Debug(string.Format("Instantiating BaseSvc: {0}", _uniqueId));

            string configFileName = Utilities.ConfigFileName();

            if (configFileName != null && configFileName != "")
            {
                _config = (ServiceConfig)XmlSerializerSectionHandler.CreateFromXmlFile(configFileName, "ServiceConfig");
            }
            if (_config == null)
            {
                //no config file or an invalid config file was found.
                //let's create a default one in case the consumer wants to fill in all fields manually
                _config = new ServiceConfig();
            }
        }
        /// <summary>
        /// Inspects an exception for type and determines the appropriate custom or generic exception that should be rethrown.
        /// </summary>
        /// <param name="e">The exception caught by a consumer-facing method.</param>
        internal static BaseResult HandleException(Exception e)
        {
            AvaTaxException avaEx;
            Exception       ex;
            AvaLogger       _avaLog1 = AvaLogger.GetLogger();

            if ((e.GetType() == typeof(System.Reflection.TargetInvocationException)) && (e.InnerException != null))
            {
                ex = e.InnerException;
            }
            else if (e.InnerException != null && (e.InnerException.GetType() == typeof(System.Net.WebException)))
            {
                ex = e.InnerException;
            }
            else
            {
                ex = e;
            }

            if (ex.GetType() == typeof(System.Net.WebException))
            {
                System.Net.WebException webEx = (System.Net.WebException)ex;
                _avaLog1.Error(webEx.Message);

                ProxyBaseResult proxyResult = new ProxyBaseResult();
                proxyResult.ResultCode           = ProxySeverityLevel.Error;
                proxyResult.Messages             = new ProxyMessage[1];
                proxyResult.Messages[0]          = new ProxyMessage();
                proxyResult.Messages[0].Severity = ProxySeverityLevel.Error;
                proxyResult.Messages[0].Summary  = webEx.Message;
                proxyResult.Messages[0].Source   = webEx.Source;
                proxyResult.Messages[0].HelpLink = webEx.HelpLink;
                proxyResult.Messages[0].Name     = webEx.GetType().ToString();

                BaseResult result = new BaseResult();
                result.CopyFrom(proxyResult);

                return(result);
            }
            else if (ex.GetType() == typeof(SoapException))
            {
                SoapException soapEx = (SoapException)ex;
                _avaLog1.Fail(soapEx.Message);
                avaEx = new AvaTaxException(soapEx);
                throw avaEx;
            }
            else if (ex.GetType() == typeof(SoapHeaderException))
            {
                SoapHeaderException soapHeaderEx = (SoapHeaderException)ex;
                avaEx = new AvaTaxException(soapHeaderEx);
                _avaLog1.Fail(soapHeaderEx.Message);
                throw avaEx;
            }
            else if (ex.GetType() == typeof(InvalidOperationException))
            {
                InvalidOperationException operationEx = (InvalidOperationException)ex;
                _avaLog1.Fail(operationEx.Message);
                if (operationEx.InnerException != null)
                {
                    throw operationEx.InnerException;
                }
                else
                {
                    throw operationEx;
                }
            }
            else
            {
                _avaLog1.Fail(ex.Message);
                throw ex;
            }
        }
 /// <include file='Avalara.AvaTax.Adapter.Doc.xml' path='adapter/common/members[@name="InternalConstructor"]/*' />
 internal ExceptionManager()
 {
     _avaLog = AvaLogger.GetLogger();
 }