public void ParsesDataCorrectly() { var countryCodeHelper = new CountryCodeHelper(Seed.Countries); var fxStreet = new fx.FXStreet(countryCodeHelper); var errors = new List <string>(); ((IEconomicReleaseSource)fxStreet).Error += (s, e) => errors.Add(e.ErrorMessage); var items = fxStreet.parseData(_data); foreach (string error in errors) { TestContext.WriteLine(error); } Assert.AreEqual(0, errors.Count); Assert.AreEqual(88, items.Count); Assert.IsFalse(items.Any(x => string.IsNullOrEmpty(x.Country))); Assert.IsFalse(items.Any(x => string.IsNullOrEmpty(x.Currency))); var allNulls = items.FirstOrDefault(x => x.Name == "BOE's Governor Carney speech"); Assert.AreEqual(null, allNulls.Previous); Assert.AreEqual(null, allNulls.Actual); Assert.AreEqual(null, allNulls.Expected); Assert.AreEqual(1.25, items[1].Previous); Assert.AreEqual(1.25, items[1].Actual); Assert.AreEqual(1.25, items[1].Expected.Value); }
public static OrderManagementAddressInfo ToAddress(this IOrderAddress orderAddress) { var address = new OrderManagementAddressInfo(); address.GivenName = orderAddress.FirstName; address.FamilyName = orderAddress.LastName; address.StreetAddress = orderAddress.Line1; address.StreetAddress2 = orderAddress.Line2; address.PostalCode = orderAddress.PostalCode; address.City = orderAddress.City; address.Country = CountryCodeHelper.GetTwoLetterCountryCode(orderAddress.CountryCode); if (orderAddress.CountryCode != null && address.Country.Equals("us", StringComparison.InvariantCultureIgnoreCase) && !string.IsNullOrEmpty(orderAddress.RegionName)) { address.Region = CountryCodeHelper.GetStateCode(CountryCodeHelper.GetTwoLetterCountryCode(orderAddress.CountryCode), orderAddress.RegionName); } else { address.Region = orderAddress.RegionName; } address.Email = orderAddress.Email; address.Phone = orderAddress.DaytimePhoneNumber ?? orderAddress.EveningPhoneNumber; return(address); }
private void ValidateEvent(Validator <CustomerViewmodel> sender, CustomerViewmodel viewmodel, ValidateEventArgs <CustomerViewmodel> e) { if (e.IsProperty(vm => vm.CountryCode)) { CountryCodeHelper.Validate(e, viewmodel.CountryCode); } }
public virtual PaymentOrderRequest GetPaymentOrderRequest( IOrderGroup orderGroup, IMarket market, PaymentMethodDto paymentMethodDto, string description, string consumerProfileRef = null) { if (orderGroup == null) { throw new ArgumentNullException(nameof(orderGroup)); } if (market == null) { throw new ArgumentNullException(nameof(market)); } var marketCountry = CountryCodeHelper.GetTwoLetterCountryCode(market.Countries.FirstOrDefault()); if (string.IsNullOrWhiteSpace(marketCountry)) { throw new ConfigurationException($"Please select a country in Commerce Manager for market {orderGroup.MarketId}"); } List <OrderItem> orderItems = new List <OrderItem>(); foreach (var orderGroupForm in orderGroup.Forms) { foreach (var shipment in orderGroupForm.Shipments) { orderItems.AddRange(GetOrderItems(market, orderGroup.Currency, shipment.ShippingAddress, shipment.LineItems)); orderItems.Add(GetShippingOrderItem(shipment, market)); } } return(CreatePaymentOrderRequest(orderGroup, market, consumerProfileRef, orderItems, description)); }
public static IOrderAddress ToOrderAddress(this CheckoutAddressInfo address, ICart cart) { var addressId = $"{address.StreetAddress}{address.StreetAddress2}{address.City}"; var orderAddress = cart.CreateOrderAddress(_orderGroupFactory.Service, addressId); orderAddress.FirstName = address.GivenName; orderAddress.LastName = address.FamilyName; orderAddress.Line1 = address.StreetAddress; orderAddress.Line2 = address.StreetAddress2; orderAddress.PostalCode = address.PostalCode; orderAddress.City = address.City; if (!string.IsNullOrEmpty(address.Country) && address.Country.Equals("us", StringComparison.InvariantCultureIgnoreCase) && !string.IsNullOrEmpty(address.Region)) { orderAddress.RegionName = CountryCodeHelper.GetStateName(address.Country, address.Region); orderAddress.RegionCode = address.Region; } else { orderAddress.RegionName = orderAddress.RegionCode = address.Region; } orderAddress.CountryCode = CountryCodeHelper.GetThreeLetterCountryCode(address.Country); orderAddress.Email = address.Email; orderAddress.DaytimePhoneNumber = address.Phone; return(orderAddress); }
public List <OrderLine> GetOrderLines(ICart cart, OrderGroupTotals orderGroupTotals, bool sendProductAndImageUrlField) { var shipment = cart.GetFirstShipment(); var currentCountry = shipment.ShippingAddress?.CountryCode ?? cart.Market.Countries.FirstOrDefault(); var includedTaxesOnLineItems = !CountryCodeHelper.GetContinentByCountry(currentCountry).Equals("NA", StringComparison.InvariantCultureIgnoreCase); return(GetOrderLines(cart, orderGroupTotals, includedTaxesOnLineItems, sendProductAndImageUrlField)); }
public StrainIndexer(Configuration config, IDbDriver database, NcbiClient ncbiClient, CountryCodeHelper countryCodeHelper, DoiClient doiClient, Dictionary <string, int> sitList) { Config = config; Database = database; NcbiClient = ncbiClient; CountryCodeHelper = countryCodeHelper; DoiClient = doiClient; SitList = sitList; }
private CheckoutOrderData GetCheckoutOrderData( ICart cart, IMarket market, PaymentMethodDto paymentMethodDto) { var totals = _orderGroupCalculator.GetOrderGroupTotals(cart); var shipment = cart.GetFirstShipment(); var marketCountry = CountryCodeHelper.GetTwoLetterCountryCode(market.Countries.FirstOrDefault()); if (string.IsNullOrWhiteSpace(marketCountry)) { throw new ConfigurationException($"Please select a country in CM for market {cart.MarketId}"); } var checkoutConfiguration = GetCheckoutConfiguration(market); var orderData = new PatchedCheckoutOrderData { PurchaseCountry = marketCountry, PurchaseCurrency = cart.Currency.CurrencyCode, Locale = ContentLanguage.PreferredCulture.Name, // Non-negative, minor units. Total amount of the order, including tax and any discounts. OrderAmount = AmountHelper.GetAmount(totals.Total), // Non-negative, minor units. The total tax amount of the order. OrderTaxAmount = AmountHelper.GetAmount(totals.TaxTotal), MerchantUrls = GetMerchantUrls(cart), OrderLines = GetOrderLines(cart, totals, checkoutConfiguration.SendProductAndImageUrl) }; if (checkoutConfiguration.SendShippingCountries) { orderData.ShippingCountries = GetCountries().ToList(); } // KCO_6 Setting to let the user select shipping options in the iframe if (checkoutConfiguration.SendShippingOptionsPriorAddresses) { if (checkoutConfiguration.ShippingOptionsInIFrame) { orderData.ShippingOptions = GetShippingOptions(cart, cart.Currency, ContentLanguage.PreferredCulture); } else { if (shipment != null) { orderData.SelectedShippingOption = ShippingManager.GetShippingMethod(shipment.ShippingMethodId) ?.ShippingMethod?.FirstOrDefault() ?.ToShippingOption(); } } } if (paymentMethodDto != null) { orderData.Options = GetOptions(cart.MarketId); } return(orderData); }
private Session GetSessionRequest(ICart cart, PaymentsConfiguration config, Uri siteUrl, bool includePersonalInformation = false) { var market = _marketService.GetMarket(cart.MarketId); var totals = _orderGroupCalculator.GetOrderGroupTotals(cart); var request = new Session { PurchaseCountry = CountryCodeHelper.GetTwoLetterCountryCode(market.Countries.FirstOrDefault()), OrderAmount = AmountHelper.GetAmount(totals.Total), // Non-negative, minor units. The total tax amount of the order. OrderTaxAmount = AmountHelper.GetAmount(totals.TaxTotal), PurchaseCurrency = cart.Currency.CurrencyCode, Locale = _languageService.GetPreferredCulture().Name, OrderLines = GetOrderLines(cart, totals, config.SendProductAndImageUrlField).ToArray() }; var paymentMethod = PaymentManager.GetPaymentMethodBySystemName( Constants.KlarnaPaymentSystemKeyword, _languageService.GetPreferredCulture().Name, returnInactive: true); if (paymentMethod != null) { request.MerchantUrl = new MerchantUrl { Confirmation = ToFullSiteUrl(siteUrl, config.ConfirmationUrl), Notification = ToFullSiteUrl(siteUrl, config.NotificationUrl), }; request.Options = GetWidgetOptions(paymentMethod, cart.MarketId); request.AutoCapture = config.AutoCapture; } if (includePersonalInformation) { var shipment = cart.GetFirstShipment(); var payment = cart.GetFirstForm()?.Payments.FirstOrDefault(); if (shipment?.ShippingAddress != null) { request.ShippingAddress = shipment.ShippingAddress.ToAddress(); } if (payment?.BillingAddress != null) { request.BillingAddress = payment.BillingAddress.ToAddress(); } else if (request.ShippingAddress != null) { request.BillingAddress = new OrderManagementAddressInfo() { Email = request.ShippingAddress?.Email, Phone = request.ShippingAddress?.Phone }; } } return(request); }
static async Task Main(string[] args) { IServiceCollection services = new ServiceCollection(); services.AddEasyCaching(option => { option.UseLiteDB(c => { c.DBConfig = new LiteDBDBOptions { FileName = "doi.db" }; }, "doi"); option.UseLiteDB(c => { c.DBConfig = new LiteDBDBOptions { FileName = "ncbi.db" }; }, "ncbi"); }); IServiceProvider serviceProvider = services.BuildServiceProvider(); var factory = serviceProvider.GetService <IEasyCachingProviderFactory>(); var doiClient = new DoiClient(factory.GetCachingProvider("doi")); var ncbiClient = new NcbiClient(factory.GetCachingProvider("ncbi")); ncbiClient.AllowQuery = true; var config = Configuration.FromYaml("/home/gaetan/API/Web/Data/config.yaml"); Directory.Delete("Index", true); var db = new LiteDatabase("db"); var driver = new LiteDbDriver(db); // var driver = new RavenDbDriver(@"C:\Users\Gaetan\RiderProjects\API\Web\bin\Debug\net5.0\RavenDB"); var countryHelper = new CountryCodeHelper(); var sit = await LoadSIT(@"/home/gaetan/API/Web/Data/spol/sit.tsv"); // var geneIndexer = new GffGeneIndexer(driver, "/home/gaetan/API/Web/Data/genes/H37Rv.gff3"); // await geneIndexer.Index(); // // var snpIndexer = new SnpIndexer(config, driver, doiClient); // await snpIndexer.Index(); var strainIndexer = new StrainIndexer(config, driver, ncbiClient, countryHelper, doiClient, sit); await strainIndexer.Index(); await driver.ComputeKeywordStat(); Console.WriteLine("gg"); }
private void ValidateEvent(Validator <OrderViewmodel> sender, OrderViewmodel viewmodel, ValidateEventArgs <OrderViewmodel> e) { if (e.IsProperty(vm => vm.CustomerID)) { CustomerIdHelper.Validate(e, viewmodel.CustomerID); } else if (e.IsProperty(vm => vm.ShippedDate)) { if (viewmodel.ShippedDate != null && viewmodel.ShippedDate.Value.Year < 2019) { e.Remark = "The date is not correct."; return; } e.IsValid = true; } else if (e.IsProperty(vm => vm.ShipCountryCode)) { CountryCodeHelper.Validate(e, viewmodel.ShipCountryCode); } }
public static OrderManagementAddressInfo ToOrderAddress(this CustomerAddress customerAddress) { var address = new OrderManagementAddressInfo { GivenName = customerAddress.FirstName, FamilyName = customerAddress.LastName, StreetAddress = customerAddress.Line1, StreetAddress2 = customerAddress.Line2, PostalCode = customerAddress.PostalCode, City = customerAddress.City, Email = customerAddress.Email, Phone = customerAddress.DaytimePhoneNumber ?? customerAddress.EveningPhoneNumber }; var countryCode = CountryCodeHelper.GetTwoLetterCountryCode(customerAddress.CountryCode); address.Country = countryCode; if (customerAddress.CountryCode != null && customerAddress.RegionName != null) { address.Region = CountryCodeHelper.GetStateCode(countryCode, customerAddress.RegionName); } return(address); }
private IEnumerable <string> GetCountries() { var countries = CountryManager.GetCountries(); return(CountryCodeHelper.GetTwoLetterCountryCodes(countries.Country.Select(x => x.Code))); }
public bool CanSendPersonalInformation(string countryCode) { var continent = CountryCodeHelper.GetContinentByCountry(countryCode); return(!continent.Equals("EU", StringComparison.InvariantCultureIgnoreCase)); }
public virtual Consumer InitiateConsumerSession(CultureInfo currentLanguage, string email = null, string mobilePhone = null, string ssn = null) { var market = _currentMarket.GetCurrentMarket(); var swedbankPayClient = _swedbankPayClientFactory.Create(market); var config = _checkoutConfigurationLoader.GetConfiguration(market.MarketId); try { var initiateConsumerSessionRequest = _requestFactory.GetConsumerResourceRequest(new Language(currentLanguage.TextInfo.CultureName), config.ShippingAddressRestrictedToCountries.Select(x => new RegionInfo(CountryCodeHelper.GetTwoLetterCountryCode(x))), string.IsNullOrEmpty(email) ? null : new EmailAddress(email), string.IsNullOrEmpty(mobilePhone) ? null : new Msisdn(mobilePhone), string.IsNullOrEmpty(ssn) ? null : new NationalIdentifier(new RegionInfo(currentLanguage.TextInfo.CultureName), ssn)); return(AsyncHelper.RunSync(() => swedbankPayClient.Consumers.InitiateSession(initiateConsumerSessionRequest))); } catch (Exception ex) { _logger.Error(ex.Message, ex); throw; } }
public MainWindow() { Common.Logging.LogManager.Adapter = new NLogLoggerFactoryAdapter(new Common.Logging.Configuration.NameValueCollection()); //make sure we can connect to the database CheckDBConnection(); //set the log directory SetLogDirectory(); //set the connection string DBUtils.SetConnectionString(); //set EF configuration, necessary for MySql to work DBUtils.SetDbConfiguration(); InitializeComponent(); DataContext = this; //load datagrid layout string layoutFile = AppDomain.CurrentDomain.BaseDirectory + "GridLayout.xml"; if (File.Exists(layoutFile)) { try { InstrumentsGrid.DeserializeLayout(File.ReadAllText(layoutFile)); } catch { } } LogMessages = new ConcurrentNotifierBlockingList <LogEventInfo>(); //target is where the log managers send their logs, here we grab the memory target which has a Subject to observe var target = LogManager.Configuration.AllTargets.Single(x => x.Name == "myTarget") as MemoryTarget; //Log unhandled exceptions AppDomain.CurrentDomain.UnhandledException += AppDomain_CurrentDomain_UnhandledException; //we subscribe to the messages and send them all to the LogMessages collection if (target != null) { target.Messages.Subscribe(msg => LogMessages.TryAdd(msg)); } //build the instruments grid context menu //we want a button for each BarSize enum value in the UpdateFreqSubMenu menu foreach (int value in Enum.GetValues(typeof(BarSize))) { var button = new MenuItem { Header = Regex.Replace(((BarSize)value).ToString(), "([A-Z])", " $1").Trim(), Tag = (BarSize)value }; button.Click += UpdateHistoricalDataBtn_ItemClick; ((MenuItem)Resources["UpdateFreqSubMenu"]).Items.Add(button); } //create metadata db if it doesn't exist var entityContext = new MyDBContext(); entityContext.Database.Initialize(false); //seed the datasources no matter what, because these are added frequently Seed.SeedDatasources(entityContext); //check for any exchanges, seed the db with initial values if nothing is found if (!entityContext.Exchanges.Any()) { Seed.DoSeed(); } //create data db if it doesn't exist var dataContext = new DataDBContext(); dataContext.Database.Initialize(false); dataContext.Dispose(); //create quartz db if it doesn't exist QuartzUtils.InitializeDatabase(Settings.Default.databaseType); //build the tags menu var allTags = entityContext.Tags.ToList(); BuildTagContextMenu(allTags); //build session templates menu BuildSetSessionTemplateMenu(); Instruments = new ObservableCollection <Instrument>(); var instrumentRepo = new InstrumentRepository(entityContext); var instrumentList = instrumentRepo.FindInstruments().Result; foreach (Instrument i in instrumentList) { Instruments.Add(i); } //create brokers var cfRealtimeBroker = new ContinuousFuturesBroker(new QDMSClient.QDMSClient( "RTDBCFClient", "127.0.0.1", Properties.Settings.Default.rtDBReqPort, Properties.Settings.Default.rtDBPubPort, Properties.Settings.Default.hDBPort, Properties.Settings.Default.httpPort, Properties.Settings.Default.apiKey, useSsl: Properties.Settings.Default.useSsl), connectImmediately: false); var cfHistoricalBroker = new ContinuousFuturesBroker(new QDMSClient.QDMSClient( "HDBCFClient", "127.0.0.1", Properties.Settings.Default.rtDBReqPort, Properties.Settings.Default.rtDBPubPort, Properties.Settings.Default.hDBPort, Properties.Settings.Default.httpPort, Properties.Settings.Default.apiKey, useSsl: Properties.Settings.Default.useSsl), connectImmediately: false); var localStorage = DataStorageFactory.Get(); RealTimeBroker = new RealTimeDataBroker(cfRealtimeBroker, localStorage, new IRealTimeDataSource[] { //new Xignite(Properties.Settings.Default.xigniteApiToken), //new Oanda(Properties.Settings.Default.oandaAccountId, Properties.Settings.Default.oandaAccessToken), new IB(Properties.Settings.Default.ibClientHost, Properties.Settings.Default.ibClientPort, Properties.Settings.Default.rtdClientIBID), //new ForexFeed(Properties.Settings.Default.forexFeedAccessKey, ForexFeed.PriceType.Mid) }); HistoricalBroker = new HistoricalDataBroker(cfHistoricalBroker, localStorage, new IHistoricalDataSource[] { new Yahoo(), new FRED(), //new Forexite(), new IB(Properties.Settings.Default.ibClientHost, Properties.Settings.Default.ibClientPort, Properties.Settings.Default.histClientIBID), new Quandl(Properties.Settings.Default.quandlAuthCode), new BarChart(Properties.Settings.Default.barChartApiKey) }); var countryCodeHelper = new CountryCodeHelper(entityContext.Countries.ToList()); EconomicReleaseBroker = new EconomicReleaseBroker("FXStreet", new[] { new fx.FXStreet(countryCodeHelper) }); //create the various servers _realTimeServer = new RealTimeDataServer(Properties.Settings.Default.rtDBPubPort, Properties.Settings.Default.rtDBReqPort, RealTimeBroker); _historicalDataServer = new HistoricalDataServer(Properties.Settings.Default.hDBPort, HistoricalBroker); //and start them _realTimeServer.StartServer(); _historicalDataServer.StartServer(); //we also need a client to make historical data requests with _client = new QDMSClient.QDMSClient( "SERVERCLIENT", "localhost", Properties.Settings.Default.rtDBReqPort, Properties.Settings.Default.rtDBPubPort, Properties.Settings.Default.hDBPort, Properties.Settings.Default.httpPort, Properties.Settings.Default.apiKey, useSsl: Properties.Settings.Default.useSsl); _client.Connect(); _client.HistoricalDataReceived += _client_HistoricalDataReceived; ActiveStreamGrid.ItemsSource = RealTimeBroker.ActiveStreams; //create the scheduler var quartzSettings = QuartzUtils.GetQuartzSettings(Settings.Default.databaseType); ISchedulerFactory schedulerFactory = new StdSchedulerFactory(quartzSettings); _scheduler = schedulerFactory.GetScheduler(); _scheduler.JobFactory = new JobFactory(HistoricalBroker, Properties.Settings.Default.updateJobEmailHost, Properties.Settings.Default.updateJobEmailPort, Properties.Settings.Default.updateJobEmailUsername, Properties.Settings.Default.updateJobEmailPassword, Properties.Settings.Default.updateJobEmailSender, Properties.Settings.Default.updateJobEmail, new UpdateJobSettings( noDataReceived: Properties.Settings.Default.updateJobReportNoData, errors: Properties.Settings.Default.updateJobReportErrors, outliers: Properties.Settings.Default.updateJobReportOutliers, requestTimeouts: Properties.Settings.Default.updateJobTimeouts, timeout: Properties.Settings.Default.updateJobTimeout, toEmail: Properties.Settings.Default.updateJobEmail, fromEmail: Properties.Settings.Default.updateJobEmailSender), localStorage, EconomicReleaseBroker); _scheduler.Start(); //Take jobs stored in the qmds db and move them to the quartz db - this can be removed in the next version MigrateJobs(entityContext, _scheduler); var bootstrapper = new CustomBootstrapper( DataStorageFactory.Get(), EconomicReleaseBroker, HistoricalBroker, RealTimeBroker, Properties.Settings.Default.apiKey); var uri = new Uri((Settings.Default.useSsl ? "https" : "http") + "://localhost:" + Properties.Settings.Default.httpPort); var host = new NancyHost(bootstrapper, uri); host.Start(); entityContext.Dispose(); ShowChangelog(); }
protected virtual CheckoutOrder GetCheckoutOrderData( ICart cart, IMarket market, PaymentMethodDto paymentMethodDto) { var totals = _orderGroupCalculator.GetOrderGroupTotals(cart); var shipment = cart.GetFirstShipment(); var marketCountry = CountryCodeHelper.GetTwoLetterCountryCode(market.Countries.FirstOrDefault()); if (string.IsNullOrWhiteSpace(marketCountry)) { throw new ConfigurationException($"Please select a country in CM for market {cart.MarketId}"); } var checkoutConfiguration = GetCheckoutConfiguration(market); var orderData = new CheckoutOrder { PurchaseCountry = marketCountry, PurchaseCurrency = cart.Currency.CurrencyCode, Locale = _languageService.ConvertToLocale(Thread.CurrentThread.CurrentCulture.Name), // Non-negative, minor units. Total amount of the order, including tax and any discounts. OrderAmount = AmountHelper.GetAmount(totals.Total), // Non-negative, minor units. The total tax amount of the order. OrderTaxAmount = AmountHelper.GetAmount(totals.TaxTotal), MerchantUrls = GetMerchantUrls(cart), OrderLines = GetOrderLines(cart, totals, checkoutConfiguration.SendProductAndImageUrl) }; if (checkoutConfiguration.SendShippingCountries) { orderData.ShippingCountries = GetCountries().ToList(); } // KCO_6 Setting to let the user select shipping options in the iframe if (checkoutConfiguration.SendShippingOptionsPriorAddresses) { if (checkoutConfiguration.ShippingOptionsInIFrame) { orderData.ShippingOptions = GetShippingOptions(cart, cart.Currency).ToList(); } else { if (shipment != null) { orderData.SelectedShippingOption = ShippingManager.GetShippingMethod(shipment.ShippingMethodId) ?.ShippingMethod?.FirstOrDefault() ?.ToShippingOption(); } } } if (paymentMethodDto != null) { orderData.CheckoutOptions = GetOptions(cart.MarketId); } if (checkoutConfiguration.PrefillAddress) { // KCO_4: In case of signed in user the email address and default address details will be prepopulated by data from Merchant system. var customerContact = CustomerContext.Current.GetContactById(cart.CustomerId); if (customerContact?.PreferredBillingAddress != null) { orderData.BillingCheckoutAddress = customerContact.PreferredBillingAddress.ToAddress(); } if (orderData.CheckoutOptions.AllowSeparateShippingAddress) { if (customerContact?.PreferredShippingAddress != null) { orderData.ShippingCheckoutAddress = customerContact.PreferredShippingAddress.ToAddress(); } if (shipment?.ShippingAddress != null) { orderData.ShippingCheckoutAddress = shipment.ShippingAddress.ToCheckoutAddress(); } } } return(orderData); }