Alla aktier + uppdattimes
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
using Autofac;
|
using Autofac;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using StockDal;
|
using StockDal;
|
||||||
using StockDal.Interface;
|
using StockDal.Interface;
|
||||||
using System;
|
using System;
|
||||||
@ -22,7 +23,7 @@ namespace RepositoryPattern
|
|||||||
Application.EnableVisualStyles();
|
Application.EnableVisualStyles();
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
Container = Configure();
|
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>
|
/// <summary>
|
||||||
/// Setting dependency injection
|
/// Setting dependency injection
|
||||||
|
|||||||
@ -10,6 +10,11 @@
|
|||||||
<PackageReference Include="Autofac" Version="6.1.0" />
|
<PackageReference Include="Autofac" Version="6.1.0" />
|
||||||
<PackageReference Include="Dapper" Version="2.0.78" />
|
<PackageReference Include="Dapper" Version="2.0.78" />
|
||||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.29" />
|
<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="Selenium.WebDriver.ChromeDriver" Version="87.0.4280.8800" />
|
||||||
<PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
|
<PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@ -20,4 +25,10 @@
|
|||||||
<ProjectReference Include="..\StockDomain\StockDomain.csproj" />
|
<ProjectReference Include="..\StockDomain\StockDomain.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="App.config">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
24
RepositoryPattern/frmMyStocks.Designer.cs
generated
24
RepositoryPattern/frmMyStocks.Designer.cs
generated
@ -49,6 +49,8 @@ namespace RepositoryPattern
|
|||||||
this.txtCurrValue = new System.Windows.Forms.TextBox();
|
this.txtCurrValue = new System.Windows.Forms.TextBox();
|
||||||
this.timer1 = new System.Windows.Forms.Timer(this.components);
|
this.timer1 = new System.Windows.Forms.Timer(this.components);
|
||||||
this.chkAutoReload = new System.Windows.Forms.CheckBox();
|
this.chkAutoReload = new System.Windows.Forms.CheckBox();
|
||||||
|
this.lbUpdateTimes = new System.Windows.Forms.ListBox();
|
||||||
|
this.label4 = new System.Windows.Forms.Label();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// lvMyStocks
|
// lvMyStocks
|
||||||
@ -205,11 +207,31 @@ namespace RepositoryPattern
|
|||||||
this.chkAutoReload.UseVisualStyleBackColor = true;
|
this.chkAutoReload.UseVisualStyleBackColor = true;
|
||||||
this.chkAutoReload.CheckedChanged += new System.EventHandler(this.chkAutoReload_CheckedChanged);
|
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
|
// frmMyStocks
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(935, 481);
|
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.chkAutoReload);
|
||||||
this.Controls.Add(this.label3);
|
this.Controls.Add(this.label3);
|
||||||
this.Controls.Add(this.txtCurrValue);
|
this.Controls.Add(this.txtCurrValue);
|
||||||
@ -248,5 +270,7 @@ namespace RepositoryPattern
|
|||||||
private System.Windows.Forms.TextBox txtCurrValue;
|
private System.Windows.Forms.TextBox txtCurrValue;
|
||||||
private System.Windows.Forms.Timer timer1;
|
private System.Windows.Forms.Timer timer1;
|
||||||
private System.Windows.Forms.CheckBox chkAutoReload;
|
private System.Windows.Forms.CheckBox chkAutoReload;
|
||||||
|
private System.Windows.Forms.ListBox lbUpdateTimes;
|
||||||
|
private System.Windows.Forms.Label label4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -60,8 +60,10 @@ namespace RepositoryPattern
|
|||||||
|
|
||||||
private void TotalReload()
|
private void TotalReload()
|
||||||
{
|
{
|
||||||
|
_stockMarketRepository.LoadStockMarketList();
|
||||||
Stocks = _stockMarketRepository.StockMarketList;
|
Stocks = _stockMarketRepository.StockMarketList;
|
||||||
ReloadData();
|
ReloadData();
|
||||||
|
lbUpdateTimes.Items.Add(DateTime.Now.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void lvMyStocks_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
|
private void lvMyStocks_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
using OpenQA.Selenium;
|
using Newtonsoft.Json;
|
||||||
|
using OpenQA.Selenium;
|
||||||
using OpenQA.Selenium.Chrome;
|
using OpenQA.Selenium.Chrome;
|
||||||
using StockDal.Interface;
|
using StockDal.Interface;
|
||||||
using StockDomain;
|
using StockDomain;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -13,10 +15,14 @@ namespace StockDal
|
|||||||
public class StockMarketRepository : IStockMarketRepository
|
public class StockMarketRepository : IStockMarketRepository
|
||||||
{
|
{
|
||||||
public Dictionary<string, DiTraderStockRow> StockMarketList { get; set; }
|
public Dictionary<string, DiTraderStockRow> StockMarketList { get; set; }
|
||||||
|
|
||||||
|
public List<DiTraderStockRow> DumpObjects { get; set; } = new List<DiTraderStockRow>();
|
||||||
public DiTraderStockRow SaveRow { get; set; }
|
public DiTraderStockRow SaveRow { get; set; }
|
||||||
public StringBuilder TextResults { get; set; }
|
public StringBuilder TextResults { get; set; }
|
||||||
public bool ViewBrowser { get; set; }
|
public bool ViewBrowser { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public IWebDriver driver;
|
public IWebDriver driver;
|
||||||
|
|
||||||
public StockMarketRepository()
|
public StockMarketRepository()
|
||||||
@ -27,7 +33,6 @@ namespace StockDal
|
|||||||
private void Find_Data()
|
private void Find_Data()
|
||||||
{
|
{
|
||||||
TextResults = new StringBuilder();
|
TextResults = new StringBuilder();
|
||||||
StockMarketList = new Dictionary<string, DiTraderStockRow>();
|
|
||||||
IList<IWebElement> searchElements = driver.FindElements(By.TagName("tbody"));
|
IList<IWebElement> searchElements = driver.FindElements(By.TagName("tbody"));
|
||||||
foreach (IWebElement i in searchElements)
|
foreach (IWebElement i in searchElements)
|
||||||
{
|
{
|
||||||
@ -60,8 +65,16 @@ namespace StockDal
|
|||||||
|
|
||||||
TextResults.Append("\r\n");
|
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)
|
private void AddValueToListRow(int pos, string value)
|
||||||
{
|
{
|
||||||
switch (pos)
|
switch (pos)
|
||||||
@ -115,16 +128,24 @@ namespace StockDal
|
|||||||
}
|
}
|
||||||
case 9:
|
case 9:
|
||||||
{
|
{
|
||||||
SaveRow.TimeOfDay = TimeSpan.Parse(value);
|
SaveRow.TimeOfDay = value==""?TimeSpan.Parse("00:01"): TimeSpan.Parse(value);
|
||||||
//StockMarketList.Add(SaveRow.StockName, SaveRow);
|
//StockMarketList.Add(SaveRow.StockName, SaveRow);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
StockMarketList.Add(SaveRow.StockName, SaveRow);
|
StockMarketList.Add(SaveRow.StockName, SaveRow);
|
||||||
}
|
}
|
||||||
catch (ArgumentException ae)
|
catch (ArgumentException ae)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
StockMarketList.Add(SaveRow.StockName + "-2", SaveRow);
|
StockMarketList.Add(SaveRow.StockName + "-2", SaveRow);
|
||||||
}
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
DumpObjects.Add(SaveRow);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -132,7 +153,7 @@ namespace StockDal
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OpenBrowser()
|
private void OpenBrowser(bool burl2 = false)
|
||||||
{
|
{
|
||||||
var driverService = ChromeDriverService.CreateDefaultService();
|
var driverService = ChromeDriverService.CreateDefaultService();
|
||||||
driverService.HideCommandPromptWindow = true;
|
driverService.HideCommandPromptWindow = true;
|
||||||
@ -152,9 +173,10 @@ namespace StockDal
|
|||||||
{
|
{
|
||||||
//var url0 = "https://money.cnn.com/data/hotstocks/index.html";
|
//var url0 = "https://money.cnn.com/data/hotstocks/index.html";
|
||||||
var url = "https://trader.di.se/index.php/stocklist/index/2055?list=7126";
|
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/";
|
//var url1 = "https://www.finansportalen.se/aktiekurser/";
|
||||||
|
driver.Navigate().GoToUrl(burl2 ? url2 : url);
|
||||||
|
|
||||||
driver.Navigate().GoToUrl(url);
|
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@ -165,13 +187,22 @@ namespace StockDal
|
|||||||
|
|
||||||
public void LoadStockMarketList()
|
public void LoadStockMarketList()
|
||||||
{
|
{
|
||||||
|
StockMarketList = new Dictionary<string, DiTraderStockRow>();
|
||||||
|
DumpObjects = new List<DiTraderStockRow>();
|
||||||
OpenBrowser();
|
OpenBrowser();
|
||||||
Find_Data();
|
Find_Data();
|
||||||
|
OpenBrowser(true);
|
||||||
|
Find_Data();
|
||||||
|
if (DumpObjects.Any())
|
||||||
|
{
|
||||||
|
SaveLogging();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void LoadStockMarketList(bool viewBrowser)
|
public void LoadStockMarketList(bool viewBrowser)
|
||||||
{
|
{
|
||||||
|
StockMarketList = new Dictionary<string, DiTraderStockRow>();
|
||||||
ViewBrowser = viewBrowser;
|
ViewBrowser = viewBrowser;
|
||||||
OpenBrowser();
|
OpenBrowser();
|
||||||
Find_Data();
|
Find_Data();
|
||||||
@ -179,6 +210,7 @@ namespace StockDal
|
|||||||
|
|
||||||
public void RefreshMarketList()
|
public void RefreshMarketList()
|
||||||
{
|
{
|
||||||
|
StockMarketList = new Dictionary<string, DiTraderStockRow>();
|
||||||
driver.Navigate().Refresh();
|
driver.Navigate().Refresh();
|
||||||
Find_Data();
|
Find_Data();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user