Alla aktier + uppdattimes

This commit is contained in:
2021-02-08 00:01:39 +01:00
parent f51d6e9689
commit e4fee01015
5 changed files with 78 additions and 8 deletions

View File

@ -1,4 +1,5 @@
using Autofac;
using Microsoft.Extensions.Configuration;
using StockDal;
using StockDal.Interface;
using System;
@ -22,7 +23,7 @@ namespace RepositoryPattern
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Container = Configure();
Application.Run(new frmInitial(Container.Resolve<IProductRepository>(),Container.Resolve<IStockMemberRepository>(),Container.Resolve<IStockMarketRepository>()));
Application.Run(new frmInitial(Container.Resolve<IProductRepository>(), Container.Resolve<IStockMemberRepository>(), Container.Resolve<IStockMarketRepository>()));
}
/// <summary>
/// Setting dependency injection

View File

@ -10,6 +10,11 @@
<PackageReference Include="Autofac" Version="6.1.0" />
<PackageReference Include="Dapper" Version="2.0.78" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.29" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="87.0.4280.8800" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
</ItemGroup>
@ -20,4 +25,10 @@
<ProjectReference Include="..\StockDomain\StockDomain.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="App.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -49,6 +49,8 @@ namespace RepositoryPattern
this.txtCurrValue = new System.Windows.Forms.TextBox();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.chkAutoReload = new System.Windows.Forms.CheckBox();
this.lbUpdateTimes = new System.Windows.Forms.ListBox();
this.label4 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// lvMyStocks
@ -205,11 +207,31 @@ namespace RepositoryPattern
this.chkAutoReload.UseVisualStyleBackColor = true;
this.chkAutoReload.CheckedChanged += new System.EventHandler(this.chkAutoReload_CheckedChanged);
//
// lbUpdateTimes
//
this.lbUpdateTimes.FormattingEnabled = true;
this.lbUpdateTimes.ItemHeight = 15;
this.lbUpdateTimes.Location = new System.Drawing.Point(14, 375);
this.lbUpdateTimes.Name = "lbUpdateTimes";
this.lbUpdateTimes.Size = new System.Drawing.Size(120, 94);
this.lbUpdateTimes.TabIndex = 8;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(12, 354);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(76, 15);
this.label4.TabIndex = 9;
this.label4.Text = "LatestUpdate";
//
// frmMyStocks
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(935, 481);
this.Controls.Add(this.label4);
this.Controls.Add(this.lbUpdateTimes);
this.Controls.Add(this.chkAutoReload);
this.Controls.Add(this.label3);
this.Controls.Add(this.txtCurrValue);
@ -248,5 +270,7 @@ namespace RepositoryPattern
private System.Windows.Forms.TextBox txtCurrValue;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.CheckBox chkAutoReload;
private System.Windows.Forms.ListBox lbUpdateTimes;
private System.Windows.Forms.Label label4;
}
}

View File

@ -60,8 +60,10 @@ namespace RepositoryPattern
private void TotalReload()
{
_stockMarketRepository.LoadStockMarketList();
Stocks = _stockMarketRepository.StockMarketList;
ReloadData();
lbUpdateTimes.Items.Add(DateTime.Now.ToString());
}
private void lvMyStocks_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)

View File

@ -1,9 +1,11 @@
using OpenQA.Selenium;
using Newtonsoft.Json;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using StockDal.Interface;
using StockDomain;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -13,10 +15,14 @@ namespace StockDal
public class StockMarketRepository : IStockMarketRepository
{
public Dictionary<string, DiTraderStockRow> StockMarketList { get; set; }
public List<DiTraderStockRow> DumpObjects { get; set; } = new List<DiTraderStockRow>();
public DiTraderStockRow SaveRow { get; set; }
public StringBuilder TextResults { get; set; }
public bool ViewBrowser { get; set; }
public IWebDriver driver;
public StockMarketRepository()
@ -27,7 +33,6 @@ namespace StockDal
private void Find_Data()
{
TextResults = new StringBuilder();
StockMarketList = new Dictionary<string, DiTraderStockRow>();
IList<IWebElement> searchElements = driver.FindElements(By.TagName("tbody"));
foreach (IWebElement i in searchElements)
{
@ -60,8 +65,16 @@ namespace StockDal
TextResults.Append("\r\n");
}
var oxe = StockMarketList;
// var oxe = StockMarketList;
}
private void SaveLogging()
{
var output = JsonConvert.SerializeObject(DumpObjects, Formatting.Indented);
File.WriteAllText($"D:\\TimCoDemos\\DemoLogs\\Log{DateTime.Now.ToShortDateString()}.txt",output);
}
private void AddValueToListRow(int pos, string value)
{
switch (pos)
@ -115,7 +128,7 @@ namespace StockDal
}
case 9:
{
SaveRow.TimeOfDay = TimeSpan.Parse(value);
SaveRow.TimeOfDay = value==""?TimeSpan.Parse("00:01"): TimeSpan.Parse(value);
//StockMarketList.Add(SaveRow.StockName, SaveRow);
try
{
@ -123,7 +136,15 @@ namespace StockDal
}
catch (ArgumentException ae)
{
StockMarketList.Add(SaveRow.StockName + "-2", SaveRow);
try
{
StockMarketList.Add(SaveRow.StockName + "-2", SaveRow);
}
catch (Exception)
{
DumpObjects.Add(SaveRow);
}
}
break;
}
@ -132,7 +153,7 @@ namespace StockDal
}
}
private void OpenBrowser()
private void OpenBrowser(bool burl2 = false)
{
var driverService = ChromeDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = true;
@ -152,9 +173,10 @@ namespace StockDal
{
//var url0 = "https://money.cnn.com/data/hotstocks/index.html";
var url = "https://trader.di.se/index.php/stocklist/index/2055?list=7126";
var url2 = "https://trader.di.se/index.php/stocklist/index/2055?list=7116";
//var url1 = "https://www.finansportalen.se/aktiekurser/";
driver.Navigate().GoToUrl(burl2 ? url2 : url);
driver.Navigate().GoToUrl(url);
}
catch
{
@ -165,13 +187,22 @@ namespace StockDal
public void LoadStockMarketList()
{
StockMarketList = new Dictionary<string, DiTraderStockRow>();
DumpObjects = new List<DiTraderStockRow>();
OpenBrowser();
Find_Data();
OpenBrowser(true);
Find_Data();
if (DumpObjects.Any())
{
SaveLogging();
}
}
public void LoadStockMarketList(bool viewBrowser)
{
StockMarketList = new Dictionary<string, DiTraderStockRow>();
ViewBrowser = viewBrowser;
OpenBrowser();
Find_Data();
@ -179,6 +210,7 @@ namespace StockDal
public void RefreshMarketList()
{
StockMarketList = new Dictionary<string, DiTraderStockRow>();
driver.Navigate().Refresh();
Find_Data();
}