Compare commits

..

2 Commits

Author SHA1 Message Date
9864e46d5f update 2018-12-04 23:24:24 +09:00
6ca9067be0 ListView 성능 개선 2018-10-11 17:27:45 +09:00
5 changed files with 83 additions and 54 deletions

View File

@@ -157,6 +157,13 @@ namespace NewsCrawler
LoadCodeType(strPath, CODE_TYPE.DENIAL); LoadCodeType(strPath, CODE_TYPE.DENIAL);
} }
public void ClearDuplicatedList()
{
string strPath = Util.GetConfigPath() + "/code-duplicated.txt";
File.WriteAllBytes(strPath, new byte[] { });
LoadCodeType(strPath, CODE_TYPE.DUPLICATED);
}
public void LoadDuplicatedList() public void LoadDuplicatedList()
{ {
string strPath = Util.GetConfigPath()+"/code-duplicated.txt"; string strPath = Util.GetConfigPath()+"/code-duplicated.txt";

View File

@@ -658,7 +658,7 @@
this.label9.Name = "label9"; this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(132, 12); this.label9.Size = new System.Drawing.Size(132, 12);
this.label9.TabIndex = 20; this.label9.TabIndex = 20;
this.label9.Text = "Version : 2018.01.04.12"; this.label9.Text = "Version : 2018.12.04.13";
// //
// cbMockTrading // cbMockTrading
// //

14
NewsForm.Designer.cs generated
View File

@@ -58,6 +58,7 @@
this.chBuy = new System.Windows.Forms.CheckBox(); this.chBuy = new System.Windows.Forms.CheckBox();
this.cbPriceCheck = new System.Windows.Forms.CheckBox(); this.cbPriceCheck = new System.Windows.Forms.CheckBox();
this.btnManualBuy = new System.Windows.Forms.Button(); this.btnManualBuy = new System.Windows.Forms.Button();
this.btClearDuplicate = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout();
@@ -317,11 +318,23 @@
this.btnManualBuy.UseVisualStyleBackColor = true; this.btnManualBuy.UseVisualStyleBackColor = true;
this.btnManualBuy.Click += new System.EventHandler(this.btnManualBuy_Click); this.btnManualBuy.Click += new System.EventHandler(this.btnManualBuy_Click);
// //
// btClearDuplicate
//
this.btClearDuplicate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btClearDuplicate.Location = new System.Drawing.Point(864, 3);
this.btClearDuplicate.Name = "btClearDuplicate";
this.btClearDuplicate.Size = new System.Drawing.Size(91, 23);
this.btClearDuplicate.TabIndex = 12;
this.btClearDuplicate.Text = "중복종목 삭제";
this.btClearDuplicate.UseVisualStyleBackColor = true;
this.btClearDuplicate.Click += new System.EventHandler(this.btClearDuplicate_Click);
//
// NewsForm // NewsForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1040, 649); this.ClientSize = new System.Drawing.Size(1040, 649);
this.Controls.Add(this.btClearDuplicate);
this.Controls.Add(this.btnManualBuy); this.Controls.Add(this.btnManualBuy);
this.Controls.Add(this.splitContainer1); this.Controls.Add(this.splitContainer1);
this.Controls.Add(this.cbPriceCheck); this.Controls.Add(this.cbPriceCheck);
@@ -378,6 +391,7 @@
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel4; private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel4;
private System.Windows.Forms.ColumnHeader chCodeName; private System.Windows.Forms.ColumnHeader chCodeName;
private System.Windows.Forms.Button btnManualBuy; private System.Windows.Forms.Button btnManualBuy;
private System.Windows.Forms.Button btClearDuplicate;
} }
} }

View File

@@ -79,24 +79,17 @@ namespace NewsCrawler
int m_iCrawlInterval = 500; int m_iCrawlInterval = 500;
bool m_bBuy = false; bool m_bBuy = false;
List<string> m_URLs = new List<string>(); ConcurrentQueue<ListViewItem> m_NewItems = new ConcurrentQueue<ListViewItem>();
ConcurrentBag<string> m_URLs = new ConcurrentBag<string>();
System.Timers.Timer m_SystemTimer = new System.Timers.Timer(); System.Timers.Timer m_SystemTimer = new System.Timers.Timer();
ConcurrentQueue<PRICE_CHECK_DATA> m_PriceCheckList = new ConcurrentQueue<PRICE_CHECK_DATA>(); ConcurrentQueue<PRICE_CHECK_DATA> m_PriceCheckList = new ConcurrentQueue<PRICE_CHECK_DATA>();
System.Timers.Timer m_PriceCheckTimer = new System.Timers.Timer(); System.Timers.Timer m_PriceCheckTimer = new System.Timers.Timer();
delegate void InsertListView(string strTitle, string strName, string strCode, DateTime time, DateTime ResTime, string strURL, string strRef, double responseT, bool bInitial);
InsertListView m_InsertListViewDelegate = null;
Crawler m_Crawler = null; Crawler m_Crawler = null;
ExcelHandler m_Excel = null; ExcelHandler m_Excel = null;
object m_lvListLock = new object();
public NewsForm() public NewsForm()
{ {
@@ -116,8 +109,6 @@ namespace NewsCrawler
//MessageBox.Show("Keywords : \n\n" + m_Condition.GetKeywordsCnt()); //MessageBox.Show("Keywords : \n\n" + m_Condition.GetKeywordsCnt());
m_InsertListViewDelegate = new InsertListView(this.InsertItem);
m_Crawler.ReadKIND(true); m_Crawler.ReadKIND(true);
m_Crawler.ReadDart(true); m_Crawler.ReadDart(true);
m_Crawler.ReadEtoday(true); m_Crawler.ReadEtoday(true);
@@ -532,30 +523,21 @@ namespace NewsCrawler
if(strURL == "") if(strURL == "")
return false; return false;
lock(m_URLs) return m_URLs.Any(s => s == strURL);
return m_URLs.Any(s => s == strURL);
} }
public void InsertItem(string strTitle, string strName, string strCode, DateTime time, DateTime ResTime, string strURL, string strRef, double dElapseT, bool bInitial) public void InsertItem(string strTitle, string strName, string strCode, DateTime time, DateTime ResTime, string strURL, string strRef, double dElapseT, bool bInitial)
{ {
try if (IsDuplicatedURL(strURL) == true)
{ return;
if(this.InvokeRequired)
{
this.Invoke(m_InsertListViewDelegate, strTitle, strName, strCode, time, ResTime, strURL, strRef, dElapseT, bInitial);
}
else
{
if(IsDuplicatedURL(strURL) == true)
return;
int iID = lvList.Items.Count+1; int iID = lvList.Items.Count + 1;
CodeList.CODE_VALUE Code = m_CodeList.SearchCode(strTitle); CodeList.CODE_VALUE Code = m_CodeList.SearchCode(strTitle);
if(bInitial == false && Code != null) if (bInitial == false && Code != null)
ProcessSearchAndBuy(new NEWS_ITEM(iID, strTitle, strCode, Code, time, ResTime, strRef, strURL, (float)dElapseT)); ProcessSearchAndBuy(new NEWS_ITEM(iID, strTitle, strCode, Code, time, ResTime, strRef, strURL, (float)dElapseT));
var AddedItem = lvList.Items.Add(new ListViewItem(new string[] { var newItem = new ListViewItem(new string[] {
iID.ToString(), iID.ToString(),
time.ToString("HH:mm:ss"), time.ToString("HH:mm:ss"),
ResTime.ToString("HH:mm:ss:fff"), ResTime.ToString("HH:mm:ss:fff"),
@@ -568,31 +550,42 @@ namespace NewsCrawler
"", "",
"", "",
"", "",
strURL })); strURL });
newItem.UseItemStyleForSubItems = false;
if (Code == null && strCode != "")
newItem.SubItems[chCodeName.Index].BackColor = Color.Gray;
AddedItem.UseItemStyleForSubItems = false; m_NewItems.Enqueue(newItem);
if(Code == null && strCode != "") m_URLs.Add(strURL);
AddedItem.SubItems[chCodeName.Index].BackColor = Color.Gray;
if(lvList.Items.Count < 2) Action insert = delegate
{
if (m_NewItems.IsEmpty == false)
{
List<ListViewItem> itemList = new List<ListViewItem>();
ListViewItem item;
while (m_NewItems.TryDequeue(out item))
itemList.Add(item);
lvList.BeginUpdate();
lvList.Items.AddRange(itemList.ToArray());
if (lvList.Items.Count < 2)
{ {
foreach(ColumnHeader col in lvList.Columns) foreach (ColumnHeader col in lvList.Columns)
col.Width = -2; col.Width = -2;
} }
lock(m_URLs) if (bInitial == false)
m_URLs.Add(strURL);
if(bInitial == false)
lvList.Sort(); lvList.Sort();
} lvList.EndUpdate();
} }
catch(Exception ex) };
{
Util.Log(Util.LOG_TYPE.ERROR, ex.Message + Environment.NewLine + ex.StackTrace);
}
}
if (lvList.InvokeRequired)
lvList.Invoke(insert);
else
insert();
}
private void SystemTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) private void SystemTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{ {
@@ -639,6 +632,9 @@ namespace NewsCrawler
private void UpdateStartPrice(int iID, int iPrice) private void UpdateStartPrice(int iID, int iPrice)
{ {
if (iID < 0)
return;
if(lvList.InvokeRequired) if(lvList.InvokeRequired)
{ {
lvList.BeginInvoke((MethodInvoker)delegate () lvList.BeginInvoke((MethodInvoker)delegate ()
@@ -774,9 +770,11 @@ namespace NewsCrawler
{ {
SortOrder Order = (lvList.Sorting == SortOrder.Descending || lvList.Sorting == SortOrder.None) ? SortOrder.Ascending : SortOrder.Descending; SortOrder Order = (lvList.Sorting == SortOrder.Descending || lvList.Sorting == SortOrder.None) ? SortOrder.Ascending : SortOrder.Descending;
lvList.BeginUpdate();
lvList.ListViewItemSorter = new ListViewItemComparer(e.Column, Order); lvList.ListViewItemSorter = new ListViewItemComparer(e.Column, Order);
lvList.Sorting = Order; lvList.Sorting = Order;
lvList.Sort(); lvList.Sort();
lvList.EndUpdate();
} }
private void lvList_DoubleClick(object sender, EventArgs e) private void lvList_DoubleClick(object sender, EventArgs e)
@@ -1009,6 +1007,13 @@ namespace NewsCrawler
{ {
Config.SetAccount(strAccount, strAccountSub); Config.SetAccount(strAccount, strAccountSub);
} }
private void btClearDuplicate_Click(object sender, EventArgs e)
{
DialogResult dialogResult = MessageBox.Show("중복 종목을 삭제합니다", "확인", MessageBoxButtons.YesNo);
if(dialogResult == DialogResult.Yes)
m_CodeList.ClearDuplicatedList();
}
} }
@@ -1033,7 +1038,10 @@ namespace NewsCrawler
if(double.TryParse(item1.SubItems[m_iColumn].Text, out num1) && if(double.TryParse(item1.SubItems[m_iColumn].Text, out num1) &&
double.TryParse(item2.SubItems[m_iColumn].Text, out num2)) double.TryParse(item2.SubItems[m_iColumn].Text, out num2))
{ {
return (num1>num2)?1:-1; if (m_Order == SortOrder.Ascending)
return (num1 > num2) ? 1 : -1;
else
return (num1 > num2) ? -1 : 1;
} }
else else
{ {

View File

@@ -14,16 +14,16 @@ namespace NewsCrawler
[STAThread] [STAThread]
static void Main() static void Main()
{ {
//try try
//{ {
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new NewsForm()); Application.Run(new NewsForm());
//} }
//catch(Exception ex) catch (Exception ex)
//{ {
// Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace); Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
//} }
} }
} }
} }