Пример #1
0
		public void A_configuration_object_is_bound()
		{
			const string json = @"{ Name: ""phatboyg"", Password: ""default""}";
			var jsonStream = new MemoryStream(Encoding.UTF8.GetBytes(json));

			string commandLineText = "-password:really_long_one --secure";

			_binder = ConfigurationBinderFactory.New(x =>
				{

                    // least specific to most specific
                    // I assume that is reasonable

					x.AddJson(jsonStream);
					x.AddCommandLine(commandLineText);
				});

			_configuration = _binder.Bind<IMyConfiguration>();
		}
 public static void ResetToDefault()
 {
     configuration = new MyConfiguration();
 }
Пример #3
0
 public ConsoleApp(IMyConfiguration configurationRoot, ILogger <ConsoleApp> logger)
 {
     _logger = logger;
     _config = configurationRoot;
 }
Пример #4
0
        public static List <AliExpressOrder> ScrapeAliExpressOrders(IMyConfiguration configuration, DateTime from)
        {
            string userDataDir         = configuration.GetValue("UserDataDir");
            string cacheDir            = configuration.GetValue("CacheDir");
            string aliExpressUsername  = configuration.GetValue("AliExpressUsername");
            string aliExpressPassword  = configuration.GetValue("AliExpressPassword");
            string chromeDriverExePath = configuration.GetValue("ChromeDriverExePath");

            var aliExpressOrders = new List <AliExpressOrder>();

            // http://blog.hanxiaogang.com/2017-07-29-aliexpress/
            var driver = Utils.GetChromeWebDriver(userDataDir, chromeDriverExePath);

            driver.Navigate().GoToUrl("https://login.aliexpress.com");

            var waitLoginPage = new WebDriverWait(driver, TimeSpan.FromSeconds(30));

            waitLoginPage.Until(d => ((IJavaScriptExecutor)d).ExecuteScript("return document.readyState").Equals("complete"));

            // login if login form is present
            // https://philipcaande.wordpress.com/2016/01/17/iframe-in-selenium-c/
            if (SeleniumUtils.IsElementPresent(driver, By.Id("alibaba-login-box")))
            {
                // switch to login iframe
                IWebElement iframe = driver.FindElement(By.Id("alibaba-login-box"));
                driver.SwitchTo().Frame(iframe);

                // login if login form is present
                if (SeleniumUtils.IsElementPresent(driver, By.XPath("//input[@id='fm-login-id']")) &&
                    SeleniumUtils.IsElementPresent(driver, By.XPath("//input[@id='fm-login-password']")))
                {
                    IWebElement username = driver.FindElement(By.XPath("//input[@id='fm-login-id']"));
                    IWebElement password = driver.FindElement(By.XPath("//input[@id='fm-login-password']"));

                    username.Clear();
                    username.SendKeys(aliExpressUsername);

                    password.Clear();
                    password.SendKeys(aliExpressPassword);

                    // use password field to submit form
                    password.Submit();

                    var waitLoginIFrame = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
                    waitLoginIFrame.Until(d => ((IJavaScriptExecutor)d).ExecuteScript("return document.readyState").Equals("complete"));
                }

                // switch back to main frame
                driver.SwitchTo().DefaultContent();
            }

            try
            {
                var waitMainPage = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
                waitMainPage.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.UrlToBe("https://www.aliexpress.com/"));
            }
            catch (WebDriverTimeoutException)
            {
                Console.WriteLine("Timeout - Logged in to AliExpress to late. Stopping.");
                return(aliExpressOrders);
            }

            // go to order list
            driver.Navigate().GoToUrl("https://trade.aliexpress.com/orderList.htm");

            // identify how many pages on order page (1/20)
            var tuple    = GetAliExpressOrderPageNumber(driver);
            int curPage  = tuple.Item1;
            int numPages = tuple.Item2;

            Console.WriteLine("Found {0} Pages", numPages);

            // scrape one and one page
            for (int i = 1; i <= numPages; i++)
            {
                // if this method returns false, it means we have reached the from date
                if (!ScrapeAliExpressOrderPage(aliExpressOrders, driver, i, from))
                {
                    break;
                }
            }

            driver.Close();
            return(aliExpressOrders);
        }
Пример #5
0
 public GrpcClient(IMyConfiguration configuration)
 {
     _configuration = configuration;
 }
Пример #6
0
 public abstract Task <List <T> > GetCombinedUpdatedAndExistingAsync(IMyConfiguration configuration, TextWriter writer, FileDate lastCacheFileInfo, DateTime from, DateTime to);
Пример #7
0
 public abstract Task <List <T> > GetListAsync(IMyConfiguration configuration, TextWriter writer, DateTime from, DateTime to);
Пример #8
0
        public override async Task <List <PayPalTransaction> > GetListAsync(IMyConfiguration configuration, TextWriter writer, DateTime from, DateTime to)
        {
            await writer.WriteLineAsync(string.Format("Finding PayPal transactions from {0:yyyy-MM-dd} to {1:yyyy-MM-dd}", from, to));

            return(await PayPal.GetPayPalTransactionsAsync(configuration, writer, from, to));
        }
Пример #9
0
        public override async Task <List <PayPalTransaction> > GetCombinedUpdatedAndExistingAsync(IMyConfiguration configuration, TextWriter writer, FileDate lastCacheFileInfo, DateTime from, DateTime to)
        {
            // we have to combine two files:
            // the original cache file and the new transactions file
            await writer.WriteLineAsync(string.Format("Finding PayPal transactions from {0:yyyy-MM-dd} to {1:yyyy-MM-dd}", from, to));

            var newPayPalTransactions = await PayPal.GetPayPalTransactionsAsync(configuration, writer, from, to);

            var originalPayPalTransactions = Utils.ReadCacheFile <PayPalTransaction>(lastCacheFileInfo.FilePath);

            // copy all the original PayPal transactions into a new file, except entries that are
            // from the from date or newer
            var updatedPayPalTransactions = originalPayPalTransactions.Where(p => p.Timestamp < from).ToList();

            // and add the new transactions to beginning of list
            updatedPayPalTransactions.InsertRange(0, newPayPalTransactions);

            return(updatedPayPalTransactions);
        }