From 021d70d758dc2e73c929526784a9909f23b6f4e0 Mon Sep 17 00:00:00 2001 From: mjjo Date: Wed, 28 Dec 2016 07:58:54 +0900 Subject: [PATCH] =?UTF-8?q?-=208092S=20=EA=B0=9D=EC=B2=B4=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=20-=20=EC=A4=91=EB=B3=B5=EC=A2=85=EB=AA=A9=20?= =?UTF-8?q?=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CybosHelper.cs | 30 ++++++++++++++++++++++++++++-- NewsForm.cs | 30 +++++++++++++++++++++--------- Util.cs | 2 +- 3 files changed, 50 insertions(+), 12 deletions(-) diff --git a/CybosHelper.cs b/CybosHelper.cs index 24cd5c5..60e6c20 100644 --- a/CybosHelper.cs +++ b/CybosHelper.cs @@ -19,6 +19,8 @@ namespace NewsCrawler System.Timers.Timer m_timer = new System.Timers.Timer(); ushort m_uiLastReqT = 0; + DSCBO1Lib.CpSvr8092S m_Cp8092S = new DSCBO1Lib.CpSvr8092S(); + NewsForm m_Listener = null; public CybosHelper(NewsForm Listener) @@ -52,9 +54,33 @@ namespace NewsCrawler m_timer.Interval = 1000; m_timer.Elapsed += M_timer_Elapsed; - m_timer.Start(); + //m_timer.Start(); + + m_Cp8092S.SetInputValue(0, "*"); + m_Cp8092S.Received += Cp8092S_Received; + m_Cp8092S.Subscribe(); } - + + private void Cp8092S_Received() + { + byte cType = m_Cp8092S.GetHeaderValue(0); + string strCode = m_Cp8092S.GetHeaderValue(1); + short iTime = m_Cp8092S.GetHeaderValue(2); + string strName = m_Cp8092S.GetHeaderValue(3); + short iType = m_Cp8092S.GetHeaderValue(4); + string strContents = m_Cp8092S.GetHeaderValue(5); + + if(iType == 1 || iType == 2) + { + m_Listener.InsertItem(strContents, "", strCode, + DateTime.ParseExact(iTime.ToString("0000"), "HHmm", CultureInfo.CurrentCulture), + DateTime.Now, + "", "CYBOS", 0, false); + } + + //Console.WriteLine(string.Format("[8092S] {0} ({1}:{2})", strContents, strName, strCode)); + } + private void M_timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { m_timer.Enabled = false; diff --git a/NewsForm.cs b/NewsForm.cs index 80f2b4e..beb50e4 100644 --- a/NewsForm.cs +++ b/NewsForm.cs @@ -63,6 +63,9 @@ namespace NewsCrawler if(lvList.SelectedItems.Count > 0) lvList.SelectedItems[0].EnsureVisible(); } + lvList.Columns[chTime.Index].TextAlign = HorizontalAlignment.Right; + lvList.Columns[chResponseT.Index].TextAlign = HorizontalAlignment.Right; + lvList.Columns[chResT.Index].TextAlign = HorizontalAlignment.Right; Console.WriteLine(string.Format("{0} ddd", m_CrawlTimer.SynchronizingObject)); Console.WriteLine(string.Format("init thread {0}", System.Threading.Thread.CurrentThread.ManagedThreadId.ToString())); @@ -92,11 +95,20 @@ namespace NewsCrawler if(m_bBuy == false) return; - if(m_CodeList.IsBuyableCode(Code) == true) + if((Code.m_enType & CodeList.CODE_TYPE.DENIAL) == CodeList.CODE_TYPE.DENIAL) { - m_CybosHelper.Buy(Code, Config.GetBuyPrice()); - m_CodeList.AddDuplicatedList(Code.m_strCode, Code.m_strName); + Util.Log(Util.LOG_TYPE.DENIAL, string.Format("거부종목 ({0})", Code)); + return; } + + if((Code.m_enType & CodeList.CODE_TYPE.DUPLICATED) == CodeList.CODE_TYPE.DUPLICATED) + { + Util.Log(Util.LOG_TYPE.DUPLICATED, string.Format("중복종목 ({0})", Code)); + return; + } + + m_CybosHelper.Buy(Code, Config.GetBuyPrice()); + m_CodeList.AddDuplicatedList(Code.m_strCode, Code.m_strName); } public void OnManualItemBuy(CodeList.CODE_VALUE Code) @@ -122,8 +134,6 @@ namespace NewsCrawler break; case TextCondition.TYPE.POSITIVE: - m_CodeList.AddDuplicatedList(Code.m_strCode, Code.m_strName); - if((Code.m_enType&CodeList.CODE_TYPE.DENIAL) == CodeList.CODE_TYPE.DENIAL) Util.Log(Util.LOG_TYPE.DENIAL, string.Format("[{0}] {1} (keyword:{2}, code:{3})", strRef, strTitle, MatchResult.m_strKeyword, Code.ToString())); else if((Code.m_enType&CodeList.CODE_TYPE.DENIAL) == CodeList.CODE_TYPE.DUPLICATED) @@ -135,11 +145,11 @@ namespace NewsCrawler Util.Log(Util.LOG_TYPE.POSITIVE, string.Format("[{0}] {1} (keyword:{2}, code:{3})", strRef, strTitle, MatchResult.m_strKeyword, Code.ToString())); BuyItem(Code); } + + m_CodeList.AddDuplicatedList(Code.m_strCode, Code.m_strName); break; case TextCondition.TYPE.MANUAL: - m_CodeList.AddDuplicatedList(Code.m_strCode, Code.m_strName); - Util.Log(Util.LOG_TYPE.MANUAL_KEYWORD, string.Format("[{0}] {1} (keyword:{2}, code:{3})", strRef, strTitle, MatchResult.m_strKeyword, Code.ToString())); if(m_bBuy == true) @@ -151,6 +161,8 @@ namespace NewsCrawler ManualPopup.TopMost = true; ManualPopup.Show(); } + + m_CodeList.AddDuplicatedList(Code.m_strCode, Code.m_strName); break; case TextCondition.TYPE.NOT_MATCHED: @@ -171,10 +183,10 @@ namespace NewsCrawler } else { - if(lvList.Items.Cast().Any(s => s.SubItems[chLink.Index].Text == strURL)) + if(strURL != "" && lvList.Items.Cast().Any(s => s.SubItems[chLink.Index].Text == strURL)) return; - lvList.Items.Add(new ListViewItem(new string[] { time.ToString("HH:mm:ss"), ResTime.ToString("HH:mm:ss"), strRef, strTitle, string.Format("{0} ms", responseT), strURL })); + lvList.Items.Add(new ListViewItem(new string[] { time.ToString("HH:mm:ss"), ResTime.ToString("HH:mm:ss:fff"), strRef, strTitle, string.Format("{0:0.0000} ms", responseT), strURL })); if(bInitial == false && chAutoSelect.Checked == true) { diff --git a/Util.cs b/Util.cs index df33c34..c0653b2 100644 --- a/Util.cs +++ b/Util.cs @@ -103,7 +103,7 @@ namespace NewsCrawler } string strLogLevel = "["+enType+"] "; - string strTime = DateTime.Now.ToString("[hh:mm:ss] "); + string strTime = DateTime.Now.ToString("[HH:mm:ss:fff] "); string strMessage = strTime+strLogLevel+strLog; File.AppendAllText(m_strLogFile, strMessage+Environment.NewLine, new UTF8Encoding(true));