Exemplo n.º 1
0
        protected override void OnStart(string[] args)
        {
            try
            {
                serviceHost = new ServiceHost(typeof(ConvRatesService));
                serviceHost.Description.Behaviors.Add(new ServiceMetadataBehavior());

                NetTcpBinding netTcpBinding = new NetTcpBinding(SecurityMode.None)
                {
                    ReceiveTimeout = TimeSpan.FromSeconds(1)
                };

                string serviceUrl = ConfigurationManager.AppSettings["ConvRatesServiceUrl"];

                serviceHost.AddServiceEndpoint(typeof(IConvRate), netTcpBinding, serviceUrl);
                serviceHost.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexTcpBinding(), serviceUrl + "mex");
                serviceHost.Open();

                ConvRatesProvider.GetInstance().Init();

                log.Info("ConvRatesWinService host is UP.");
            }
            catch (Exception e)
            {
                log.Error("ConvRatesWinService OnStart failed:", e);
            }
        }
Exemplo n.º 2
0
        public static ConvRatesProvider GetInstance()
        {
            if (convRatesProvider == null)
            {
                lock (lockObj)
                {
                    if (convRatesProvider == null)
                    {
                        convRatesProvider = new ConvRatesProvider();
                    }
                }
            }

            return(convRatesProvider);
        }
Exemplo n.º 3
0
        public double GetConvRate(string curr1, string curr2)
        {
            log.Info(String.Format("GetConvRate for currencies {0} and {1} starts.", curr1, curr2));
            double rate = 0;

            try
            {
                rate = ConvRatesProvider.GetInstance().GetConvRate(curr1, curr2);
            }
            catch (Exception e)
            {
                log.Error(String.Format("GetConvRate error for currencies {0} and {1}", curr1, curr2), e);
                throw;
            }

            log.Info(String.Format("GetConvRate for currencies {0} and {1} ends.", curr1, curr2));

            return(rate);
        }