Esempio n. 1
0
        protected override void ExecuteAction(Context context, Step step)
        {
            string first = step.GetParameterValue<string>("String", 1);
            string second = step.GetParameterValue<string>("String", 2);

            ServiceAgent.Currency from = (ServiceAgent.Currency)Enum.Parse(typeof(ServiceAgent.Currency), first, true);
            ServiceAgent.Currency to = (ServiceAgent.Currency)Enum.Parse(typeof(ServiceAgent.Currency), second, true);

            ConfigurationChannelFactory<ServiceAgent.CurrencyConvertorSoap> channelFactory = null;
            double rate;
            try
            {
                channelFactory = new ConfigurationChannelFactory<ServiceAgent.CurrencyConvertorSoap>("CurrencyConvertorSoap", conf.Configuration, null);
                var client = channelFactory.CreateChannel();
                rate = client.ConversionRate(from, to);
            }
            catch (Exception)
            {
                rate = double.NaN;
            }
            finally
            {
                if (channelFactory != null)
                    channelFactory.Close();
            }

            context.AddPublishedItem("Number", step.Id, rate);
        }
Esempio n. 2
0
        public TOut GetData <TOut>(string endpointConfigurationName, Configuration configuration, EndpointAddress remoteAddress, Func <T, TOut> getData)
        {
            TOut data = default(TOut);

            using (var channelFactory = new ConfigurationChannelFactory <T>(endpointConfigurationName, configuration, remoteAddress))
            {
                try
                {
                    var channel = channelFactory.CreateChannel();
                    data = getData(channel);
                    channelFactory.Close();
                }
                catch (ConfigurationErrorsException ex)
                {
                    _logger.WarnFormat($"{ ex.Message }");
                }
                catch (TimeoutException ex)
                {
                    _logger.WarnFormat($"Cannot connect to { nameof(T) }.\n { ex.Message }");
                }
                catch (FaultException <Service::CommercialNotFound> ex)
                {
                    _logger.WarnFormat($"{ ex.Message }");
                }
                catch (FaultException ex)
                {
                    _logger.WarnFormat($"Cannot connect to { nameof(T) }.\n { ex.Message }");
                }
                catch (CommunicationException ex)
                {
                    _logger.WarnFormat($"Cannot connect to { nameof(T) }.\n { ex.Message }");
                }
                catch (Exception ex)
                {
                    _logger.WarnFormat($"Cannot connect to { nameof(T) }.\n { ex.Message }");
                }
            }

            return(data);
        }