コード例 #1
0
        private StockTrend GetStockTrendInstance(CompanyQuote companyQuote)
        {
            StockTrend newstockTrend = new StockTrend();

            newstockTrend.StockSymbol = companyQuote.Symbol;
            newstockTrend.StockName   = companyQuote.name;
            newstockTrend.Price       = companyQuote.Price;
            newstockTrend.Change      = companyQuote.Change;
            newstockTrend.YearHigh    = companyQuote.YearHigh;
            newstockTrend.YearLow     = companyQuote.YearLow;

            return(newstockTrend);
        }
コード例 #2
0
        private void InsertStockTrendList(CompanyQuote companyQuote)
        {
            StockTrend newstockTrend = GetStockTrendInstance(companyQuote);

            lock (stocktrendLocker)
            {
                stockTrend.Add(newstockTrend);
                if (stockTrend.Count > 1)//save at least 2 entries at a time to minimize the db access.
                {
                    InsertStockTrendToDB(stockTrend);
                    stockTrend.Clear();
                }
            }
        }
コード例 #3
0
 public IActionResult GetCompanyQuote()
 {
     inputSymbol      = Convert.ToString(TempData["value"]);
     detailsOfCompany = GetCompanyQuote(inputSymbol);
     if (detailsOfCompany.Symbol == null)
     {
         ViewBag.IsModelEmpty = true;
     }
     else
     {
         ViewBag.IsModelEmpty = false;
     }
     _repository.SaveCompanyQuote(detailsOfCompany);
     return(View(detailsOfCompany));
 }
コード例 #4
0
        private CompanyQuote GetCompanyQuote(string symbol)
        {
            CompanyQuote cQ = new CompanyQuote();
            string       CompanyQuote_End_Point = BASE_URL + "stock/" + symbol + "/quote";
            string       apiResponse            = string.Empty;

            httpClient.BaseAddress = new Uri(CompanyQuote_End_Point);
            HttpResponseMessage response = httpClient.GetAsync(CompanyQuote_End_Point).GetAwaiter().GetResult();

            if (response.IsSuccessStatusCode)
            {
                apiResponse = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
            }
            if (!string.IsNullOrEmpty(apiResponse))
            {
                cQ = JsonConvert.DeserializeObject <CompanyQuote>(apiResponse);
            }
            return(cQ);
        }
コード例 #5
0
 private void CheckToExludeDuplicateCompanyStocksInList(CompanyQuote item)
 {
     _dispatcherWrapper.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
     {
         lock (locker)
         {
             var ExistingQuote = CompanyQuotes.FirstOrDefault(x => x.Symbol == item.Symbol);
             if (ExistingQuote == null)
             {
                 CompanyQuotes.Add(item);
             }
             else
             {
                 CompanyQuotes.Remove(ExistingQuote);
                 CompanyQuotes.Add(item);
             }
         }
     }));
 }
コード例 #6
0
 public CompanyQuote CreateDummyQuote(string sym)
 {
     if (sym == "testSymbol")
     {
         CompanyQuote companyQuote = new CompanyQuote();
         companyQuote.Symbol = "testSymbol";
         companyQuote.name   = "TestCompanyName";
         companyQuote.Price  = "200";
         return(companyQuote);
     }
     else
     {
         CompanyQuote companyQuote1 = new CompanyQuote();
         companyQuote1.Symbol = "testSymbol2";
         companyQuote1.name   = "TestCompanyName2";
         companyQuote1.Price  = "202";
         return(companyQuote1);
     }
 }