From 9140673315632b681279e1bb5acbc1fe3916d71d Mon Sep 17 00:00:00 2001 From: mjjo53 Date: Thu, 7 Jun 2018 15:33:33 +0900 Subject: [PATCH] =?UTF-8?q?async=ED=95=98=EA=B2=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + AutoSeller.Designer.cs | 23 +- AutoSeller.cs | 476 +++++++++++++----------- AutoSeller.csproj | 4 + Config.cs | 8 + CybosHelper.cs | 171 +++++---- FluentFTP/Client/FtpClient_HighLevel.cs | 15 +- FluentFTP/Client/FtpClient_LowLevel.cs | 4 +- SimulationHelper.cs | 8 +- Util.cs | 18 +- packages.config | 1 + 11 files changed, 412 insertions(+), 317 deletions(-) diff --git a/.gitignore b/.gitignore index 9ba7f54..3e80b2e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ log/ publish/ *.user simulation/ +packages/ diff --git a/AutoSeller.Designer.cs b/AutoSeller.Designer.cs index a6f0409..351479b 100644 --- a/AutoSeller.Designer.cs +++ b/AutoSeller.Designer.cs @@ -50,6 +50,7 @@ this.chCheckCountLimit = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chCheckCount = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.lvNCItem = new AutoSellerNS.ListViewNF(); + this.chNCOrderNo = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chNCOrgOrderNo = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chNCCode = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.chNCCodeName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); @@ -65,6 +66,7 @@ this.btUpdate = new MaterialSkin.Controls.MaterialRaisedButton(); this.btCybos = new MaterialSkin.Controls.MaterialRaisedButton(); this.tabPage2 = new System.Windows.Forms.TabPage(); + this.cbMockTrading = new System.Windows.Forms.CheckBox(); this.materialLabel18 = new MaterialSkin.Controls.MaterialLabel(); this.tbCFIgnorePrice = new MaterialSkin.Controls.MaterialSingleLineTextField(); this.materialLabel17 = new MaterialSkin.Controls.MaterialLabel(); @@ -332,6 +334,7 @@ // chCheckCountLimit // this.chCheckCountLimit.Text = "조건제한"; + this.chCheckCountLimit.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; // // chCheckCount // @@ -341,6 +344,7 @@ // lvNCItem // this.lvNCItem.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.chNCOrderNo, this.chNCOrgOrderNo, this.chNCCode, this.chNCCodeName, @@ -357,6 +361,10 @@ this.lvNCItem.UseCompatibleStateImageBehavior = false; this.lvNCItem.View = System.Windows.Forms.View.Details; // + // chNCOrderNo + // + this.chNCOrderNo.Text = "주문번호"; + // // chNCOrgOrderNo // this.chNCOrgOrderNo.Text = "원주문번호"; @@ -467,6 +475,7 @@ // tabPage2 // this.tabPage2.BackColor = System.Drawing.Color.White; + this.tabPage2.Controls.Add(this.cbMockTrading); this.tabPage2.Controls.Add(this.materialLabel18); this.tabPage2.Controls.Add(this.tbCFIgnorePrice); this.tabPage2.Controls.Add(this.materialLabel17); @@ -508,6 +517,16 @@ this.tabPage2.TabIndex = 1; this.tabPage2.Text = "Preference"; // + // cbMockTrading + // + this.cbMockTrading.AutoSize = true; + this.cbMockTrading.Location = new System.Drawing.Point(29, 519); + this.cbMockTrading.Name = "cbMockTrading"; + this.cbMockTrading.Size = new System.Drawing.Size(76, 16); + this.cbMockTrading.TabIndex = 38; + this.cbMockTrading.Text = "모의 투자"; + this.cbMockTrading.UseVisualStyleBackColor = true; + // // materialLabel18 // this.materialLabel18.AutoSize = true; @@ -907,7 +926,7 @@ this.materialLabel3.Name = "materialLabel3"; this.materialLabel3.Size = new System.Drawing.Size(165, 19); this.materialLabel3.TabIndex = 6; - this.materialLabel3.Text = "Version : 2018.01.01.20"; + this.materialLabel3.Text = "Version : 2018.01.04.12"; // // materialLabel2 // @@ -1291,5 +1310,7 @@ public System.Windows.Forms.TextBox tbSMIgnorePrice; private System.Windows.Forms.ColumnHeader chNCOrgOrderNo; public MaterialSkin.Controls.MaterialCheckBox chSMHalfTrailing; + private System.Windows.Forms.ColumnHeader chNCOrderNo; + private System.Windows.Forms.CheckBox cbMockTrading; } } \ No newline at end of file diff --git a/AutoSeller.cs b/AutoSeller.cs index cfd0ada..ae6aca8 100644 --- a/AutoSeller.cs +++ b/AutoSeller.cs @@ -1,13 +1,18 @@ using MaterialSkin; using MaterialSkin.Controls; +using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; +using System.IO; using System.Linq; +using System.Net; +using System.Net.Http; using System.Net.NetworkInformation; using System.Text; +using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; @@ -51,6 +56,8 @@ namespace AutoSellerNS string m_strSelectedCode = ""; bool m_bSell = false; + SemaphoreSlim m_UpdateSemaphore = new SemaphoreSlim(1, 1); + SemaphoreSlim m_NCUpdateSemaphore = new SemaphoreSlim(1, 1); System.Timers.Timer m_Timer = new System.Timers.Timer(); public AutoSeller() @@ -100,6 +107,8 @@ namespace AutoSellerNS tbCFTimeDown.Text = Config.GetTimeDown().ToString(); tbCFIgnorePrice.Text = Config.GetIgnorePrice().ToString(); + cbMockTrading.Checked = Config.GetMockTrading(); + m_CybosHelper = new CybosHelper(this); m_iCurPricePanelWith = 240; @@ -114,28 +123,6 @@ namespace AutoSellerNS m_Timer.Start(); } - private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) - { - if(m_bSell == false) - return; - - var ClonedList = m_NCItems.ConvertAll(s => s); - foreach(var NCItem in ClonedList) - { - if(NCItem.m_bAsk == true && DateTime.Now-NCItem.m_Time >= TimeSpan.FromSeconds(5)) - { - var CurItem = m_CybosHelper.GetItem(NCItem.m_strCode); - if(CurItem == null) - continue; - - int iAskPrice = CurItem.m_aiAskPrice[0]; - m_CybosHelper.CorrectionItem(NCItem.m_strCode, NCItem.m_iOrderNo, NCItem.m_iRemainCnt, iAskPrice); - NCItem.m_Time = DateTime.Now; - Util.Log(Util.LOG_TYPE.SELL, string.Format("[{0}] 정정 주문 (주문번호: {1})", NCItem.m_strCodeName, NCItem.m_iOrgOrderNo)); - } - } - } - public void SetAccountList(string[] aAccountList) { cbAccount.Items.Clear(); @@ -157,9 +144,9 @@ namespace AutoSellerNS splitContainer2.SplitterDistance = iDist; } - private void btCybos_Click(object sender, EventArgs e) + private async void btCybos_Click(object sender, EventArgs e) { - m_CybosHelper.InitCybos(); + await m_CybosHelper.InitCybosAsync(); btCybos.Primary = false; btCybos.Enabled = false; @@ -167,147 +154,237 @@ namespace AutoSellerNS btUpdate.Enabled = true; btSell.Enabled = true; - //btUpdate_Click(null, null); + UpdateItem(); } - private void AddItem(ITEM Item) + void SyncItems(List OldItems, List NewItems) { - m_Items.Add(Item); - - if(lvItems.InvokeRequired) + foreach(ITEM newItem in NewItems) { - CybosHelper.STOCK_CUR_ITEM ItemCur = m_CybosHelper.GetItem(Item.m_strCode); - - lvItems.Invoke(new Action(() => { - lvItems.Items.Add(new ListViewItem(new string[] { - Item.m_strCode, - Item.m_strCodeName, - string.Format("{0:n0}", Item.m_iCurPrice), - string.Format("{0:n0}", Item.m_iAvailableQuantity), - string.Format("{0:n2}", Item.m_dBookUnitPrice), - string.Format("{0:n0}", Item.m_iProfitUnitPrice), - string.Format("{0:n0}", Item.m_iAssessedValue), - string.Format("{0:n0}", Item.m_iValuationGains), - string.Format("{0:n2}", Item.m_dYield), - ItemCur != null ? string.Format("{0:n0}", ItemCur.m_iMaxPrice) : "", - ItemCur != null ? string.Format("{0:n2}", ItemCur.m_dCheckCountLimit) : "", - ItemCur != null ? string.Format("{0:n0}", ItemCur.m_iCheckCount) : "", - })); - - var listviewItem = lvItems.Items[lvItems.Items.Count - 1]; - - lvItems.Items[lvItems.Items.Count - 1].UseItemStyleForSubItems = false; - lvItems.Items[lvItems.Items.Count - 1].SubItems[chValuation.Index].ForeColor = (Item.m_iValuationGains > 0) ? Color.Red : (Item.m_iValuationGains < 0) ? Color.Blue : Color.Black; - lvItems.Items[lvItems.Items.Count - 1].SubItems[chYield.Index].ForeColor = (Item.m_dYield > 0) ? Color.Red : (Item.m_dYield < 0) ? Color.Blue : Color.Black; - - m_CybosHelper.Subscribe(Item); - })); - } - else - { - CybosHelper.STOCK_CUR_ITEM ItemCur = m_CybosHelper.GetItem(Item.m_strCode); - - lvItems.Items.Add(new ListViewItem(new string[] { - Item.m_strCode, - Item.m_strCodeName, - string.Format("{0:n0}", Item.m_iCurPrice), - string.Format("{0:n0}", Item.m_iAvailableQuantity), - string.Format("{0:n2}", Item.m_dBookUnitPrice), - string.Format("{0:n0}", Item.m_iProfitUnitPrice), - string.Format("{0:n0}", Item.m_iAssessedValue), - string.Format("{0:n0}", Item.m_iValuationGains), - string.Format("{0:n2}", Item.m_dYield), - ItemCur != null ? string.Format("{0:n0}", ItemCur.m_iMaxPrice) : "", - ItemCur != null ? string.Format("{0:n2}", ItemCur.m_dCheckCountLimit) : "", - ItemCur != null ? string.Format("{0:n0}", ItemCur.m_iCheckCount) : "", - })); - - - - var listviewItem = lvItems.Items[lvItems.Items.Count - 1]; - - lvItems.Items[lvItems.Items.Count - 1].UseItemStyleForSubItems = false; - lvItems.Items[lvItems.Items.Count - 1].SubItems[chValuation.Index].ForeColor = (Item.m_iValuationGains > 0) ? Color.Red : (Item.m_iValuationGains < 0) ? Color.Blue : Color.Black; - lvItems.Items[lvItems.Items.Count - 1].SubItems[chYield.Index].ForeColor = (Item.m_dYield > 0) ? Color.Red : (Item.m_dYield < 0) ? Color.Blue : Color.Black; - - m_CybosHelper.Subscribe(Item); - } - } - - private void btUpdate_Click(object sender, EventArgs e) - { - // 잔고 - var Items = m_CybosHelper.UpdateItems(); - - m_Items.Clear(); - lvItems.Items.Clear(); - foreach(var Item in Items) - AddItem(Item); - - // 미체결 - UpdateNC(); - } - - void UpdateNC() - { - var NCItems = m_CybosHelper.UpdateNC(); - m_NCItems = NCItems; - - lvNCItem.Items.Clear(); - if(lvNCItem.InvokeRequired) - { - lvNCItem.Invoke(new Action(() => { - foreach(var NCItem in NCItems) - { - ListViewItem viewItem = new ListViewItem(new string[] { - NCItem.m_iOrderNo.ToString(), - NCItem.m_iOrgOrderNo.ToString(), - NCItem.m_strCode, - NCItem.m_strCodeName, - NCItem.m_strDesc, - string.Format("{0:n0}", NCItem.m_iOrderPrice), - string.Format("{0:n0}", NCItem.m_iRemainCnt), - }); - lvNCItem.Items.Add(viewItem); - viewItem.UseItemStyleForSubItems = false; - viewItem.SubItems[chNCType.Index].ForeColor = NCItem.m_bAsk ? Color.Blue : Color.Red; - } - })); - } - else - { - foreach(var NCItem in NCItems) + ITEM oldItem = OldItems.FirstOrDefault(s => s.m_strCode == newItem.m_strCode); + if (oldItem != null) { - ListViewItem viewItem = new ListViewItem(new string[] { - NCItem.m_iOrderNo.ToString(), - NCItem.m_iOrgOrderNo.ToString(), - NCItem.m_strCode, - NCItem.m_strCodeName, - NCItem.m_strDesc, - string.Format("{0:n0}", NCItem.m_iOrderPrice), - string.Format("{0:n0}", NCItem.m_iRemainCnt), - }); - lvNCItem.Items.Add(viewItem); - viewItem.UseItemStyleForSubItems = false; - viewItem.SubItems[chNCType.Index].ForeColor = NCItem.m_bAsk ? Color.Blue : Color.Red; + // update + oldItem.m_iItemCnt = newItem.m_iItemCnt; + oldItem.m_iAssessedValue = newItem.m_iAssessedValue; + oldItem.m_iValuationGains = newItem.m_iValuationGains; + oldItem.m_dYield = newItem.m_dYield; + oldItem.m_iAvailableQuantity = newItem.m_iAvailableQuantity; + oldItem.m_dBookUnitPrice = newItem.m_dBookUnitPrice; + oldItem.m_iProfitUnitPrice = newItem.m_iProfitUnitPrice; + oldItem.m_iCurPrice = newItem.m_iCurPrice; + } + else + { + // add + m_Items.Add(newItem); + m_CybosHelper.Subscribe(newItem); + } + } + + // remove + OldItems.RemoveAll(s => (NewItems.Any(k => k.m_strCode == s.m_strCode) == false)); + } + + void SyncListViewItems(List Items) + { + lvItems.Items.Cast().ToList().RemoveAll(s => (Items.Any(t => t.m_strCode == s.SubItems[chCode.Index].Text) == false)); + + foreach(ITEM item in Items) + { + ListViewItem row = lvItems.Items.Cast().FirstOrDefault(s => s.SubItems[chCode.Index].Text == item.m_strCode); + if(row == null) + { + // insert + row = lvItems.Items.Add(new ListViewItem(new string[12])); + row.SubItems[chCode.Index].Text = item.m_strCode; + row.SubItems[chCodeName.Index].Text = item.m_strCodeName; + + row.UseItemStyleForSubItems = false; + } + + // update + CybosHelper.STOCK_CUR_ITEM ItemCur = m_CybosHelper.GetItem(item.m_strCode); + + row.SubItems[chCurPrice.Index].Text = string.Format("{0:n0}", item.m_iCurPrice); + row.SubItems[chCount.Index].Text = string.Format("{0:n0}", item.m_iAvailableQuantity); + row.SubItems[chBookValue.Index].Text = string.Format("{0:n2}", item.m_dBookUnitPrice); + row.SubItems[chCapitalGains.Index].Text = string.Format("{0:n0}", item.m_iProfitUnitPrice); + row.SubItems[chAssessedValue.Index].Text = string.Format("{0:n0}", item.m_iAssessedValue / 1000); + row.SubItems[chValuation.Index].Text = string.Format("{0:n0}", item.m_iValuationGains / 1000); + row.SubItems[chYield.Index].Text = string.Format("{0:n2}", item.m_dYield); + row.SubItems[chMaxPrice.Index].Text = ItemCur != null ? string.Format("{0:n0}", ItemCur.m_iMaxPrice) : ""; + row.SubItems[chCheckCountLimit.Index].Text = ItemCur != null ? string.Format("{0:n2}", ItemCur.m_dCheckCountLimit) : ""; + row.SubItems[chCheckCount.Index].Text = ItemCur != null ? string.Format("{0:n0}", ItemCur.m_iCheckCount) : ""; + + row.SubItems[chValuation.Index].ForeColor = (item.m_iValuationGains > 0) ? Color.Red : (item.m_iValuationGains < 0) ? Color.Blue : Color.Black; + row.SubItems[chYield.Index].ForeColor = (item.m_dYield > 0) ? Color.Red : (item.m_dYield < 0) ? Color.Blue : Color.Black; + } + } + + public async void UpdateItem() + { + await m_UpdateSemaphore.WaitAsync(); + List Items = await m_CybosHelper.UpdateItemsAsync(); + SyncItems(m_Items, Items); + SyncListViewItems(m_Items); + m_UpdateSemaphore.Release(); + } + + void SyncNCItems(List oldList, List newList) + { + oldList.RemoveAll(s => newList.Any(t => t.m_iOrgOrderNo == s.m_iOrgOrderNo) == false); + foreach (var NCItem in newList) + { + if (oldList.Any(s => s.m_iOrgOrderNo == NCItem.m_iOrgOrderNo) == false) + { + NCItem.m_Time = DateTime.Now; + oldList.Add(NCItem); } } } - public void UpdateItem(string strCode, string strCodeName, bool bBid, int iConclusionCnt, int iRemainCnt, int iBookValue) + void SyncNCListVIewItems(List NCItems) { - // 잔고 - var Items = m_CybosHelper.UpdateItems(); + lvNCItem.Items.Cast().ToList().RemoveAll(r => + NCItems.Any(t => (t.m_iOrgOrderNo.ToString() == r.SubItems[chNCOrgOrderNo.Index].Text) == false)); - m_Items.Clear(); - lvItems.Items.Clear(); - foreach(var Item in Items) - AddItem(Item); + foreach (var NCItem in NCItems) + { + ListViewItem row = lvNCItem.Items.Cast().FirstOrDefault(r => r.SubItems[chNCOrgOrderNo.Index].Text == NCItem.m_iOrgOrderNo.ToString()); + if(row == null) + { + // insert + row = new ListViewItem(new string[7]); + row.SubItems[chNCOrderNo.Index].Text = NCItem.m_iOrderNo.ToString(); + row.SubItems[chNCOrgOrderNo.Index].Text = NCItem.m_iOrgOrderNo.ToString(); + row.SubItems[chNCCode.Index].Text = NCItem.m_strCode; + row.SubItems[chNCCodeName.Index].Text = NCItem.m_strCodeName; + row.SubItems[chNCType.Index].Text = NCItem.m_strDesc; + + row.UseItemStyleForSubItems = false; + lvNCItem.Items.Add(row); + } + + // update + row.SubItems[chNCPrice.Index].Text = NCItem.m_iOrderPrice.ToString("n0"); + row.SubItems[chNCCount.Index].Text = NCItem.m_iRemainCnt.ToString("n0"); + row.SubItems[chNCType.Index].ForeColor = NCItem.m_bAsk ? Color.Blue : Color.Red; + } } - public void UpdateNCItem() + public async void UpdateNCItem() { - UpdateNC(); + await m_NCUpdateSemaphore.WaitAsync(); + List NCItems = await m_CybosHelper.UpdateNCAsync(); + SyncNCItems(m_NCItems, NCItems); + SyncNCListVIewItems(m_NCItems); + m_NCUpdateSemaphore.Release(); + } + + async void CorrectItems() + { + if (m_bSell == false) + return; + + var ClonedList = m_NCItems.ConvertAll(s => s); + foreach (var NCItem in ClonedList) + { + if (NCItem.m_bAsk == true && DateTime.Now - NCItem.m_Time >= TimeSpan.FromSeconds(3)) + { + var CurItem = m_CybosHelper.GetItem(NCItem.m_strCode); + if (CurItem == null) + continue; + + int iPrice = CurItem.m_aiBidPrice[0]; + await m_CybosHelper.CorrectionItem(NCItem.m_strCode, NCItem.m_iOrderNo, NCItem.m_iRemainCnt, iPrice); + NCItem.m_Time = DateTime.Now; + Util.Log(Util.LOG_TYPE.SELL, string.Format("[{0}] 정정 주문 (주문번호: {1})", NCItem.m_strCodeName, NCItem.m_iOrgOrderNo)); + } + } + } + + private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) + { + CorrectItems(); + } + + private void btUpdate_Click(object sender, EventArgs e) + { + UpdateItem(); + } + + public class HttpResult + { + public HttpStatusCode StatusCode; + public string strData; + }; + + async Task Request(string url, HttpMethod method, + string data = null, + Dictionary headers = null) + { + HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); + req.Method = method.ToString(); + req.ContentType = "application/json"; + if (headers != null) + { + foreach (var kv in headers) + req.Headers[kv.Key] = kv.Value; + } + + if (data != null) + { + Stream writeStream = req.GetRequestStream(); + byte[] buffer = Encoding.UTF8.GetBytes(data); + await writeStream.WriteAsync(buffer, 0, buffer.Length); + } + + HttpWebResponse resp = null; + HttpResult result = null; + try + { + resp = await req.GetResponseAsync() as HttpWebResponse; + } + catch (WebException ex) + { + if (ex.Status == WebExceptionStatus.ProtocolError) + resp = ex.Response as HttpWebResponse; + } + finally + { + Stream readStream = resp.GetResponseStream(); + StreamReader sr = new StreamReader(readStream); + result = new HttpResult() + { + StatusCode = resp.StatusCode, + strData = await sr.ReadToEndAsync() + }; + } + + return result; + } + + async void SendConfiguration() + { + var oData = new + { + Mac = NetworkInterface.GetAllNetworkInterfaces()[0].GetPhysicalAddress().ToString(), + Date = DateTime.Now.ToString("yyyy-MM-dd"), + Config = Config.GetAllConfig(), + }; + + string serverURL = "http://mjjo53.us.to:9200"; + string index = "trading-autoseller"; + string doc = "default"; + string id = $"{oData.Mac}-{oData.Date}"; + JObject data = JObject.FromObject(oData); + string json = data.ToString(Newtonsoft.Json.Formatting.Indented); + + Dictionary headers = new Dictionary(); + headers["Authorization"] = "Basic dHJhZGVyOnNidG1hb2Fv"; + + var result = await Request($"{serverURL}/{index}/{doc}/{id}?pretty", HttpMethod.Post, json, headers); } private void btSell_Click(object sender, EventArgs e) @@ -317,12 +394,14 @@ namespace AutoSellerNS if(m_bSell == true) { - FileTransfer ft = new FileTransfer(); - string today = DateTime.Now.ToString("yyyy-MM-dd"); - string macAddr = NetworkInterface.GetAllNetworkInterfaces()[0].GetPhysicalAddress().ToString(); - ft.SendDir("/configure", macAddr + "/AutoSeller/" + today); + //FileTransfer ft = new FileTransfer(); + //string today = DateTime.Now.ToString("yyyy-MM-dd"); + //string macAddr = NetworkInterface.GetAllNetworkInterfaces()[0].GetPhysicalAddress().ToString(); + //ft.SendDir("/configure", macAddr + "/AutoSeller/" + today); //ft.SendDir("/log", macAddr + "/AutoSeller"); //ft.SendDir("/simulation", macAddr + "/AutoSeller"); + + SendConfiguration(); } } @@ -342,50 +421,30 @@ namespace AutoSellerNS Item.m_iValuationGains = (iPrice-Item.m_iProfitUnitPrice)*Item.m_iItemCnt; Item.m_dYield = (iPrice-Item.m_iProfitUnitPrice)*100 / (double)Item.m_iProfitUnitPrice; - if (lvItems.InvokeRequired) - { - lvItems.Invoke(new Action(() => - { - ListViewItem row = lvItems.Items.Cast().FirstOrDefault(s => s.SubItems[chCode.Index].Text == strCode); - if (row == default(ListViewItem)) - return; - - row.SubItems[chCurPrice.Index].Text = string.Format("{0}{1:n0}", bReal?"":"*", Item.m_iCurPrice); - row.SubItems[chAssessedValue.Index].Text = string.Format("{0:n0}", Item.m_iAssessedValue); - row.SubItems[chValuation.Index].Text = string.Format("{0:n0}", Item.m_iValuationGains); - row.SubItems[chYield.Index].Text = string.Format("{0:n2}", Item.m_dYield); - row.SubItems[chMaxPrice.Index].Text = string.Format("{0:n0}", iMaxPrice); - row.SubItems[chCheckCountLimit.Index].Text = string.Format("{0:n2}", dCheckCountLimit); - row.SubItems[chCheckCount.Index].Text = string.Format("{0:n0}", iCheckCount); - })); - } - else - { + Action update = delegate { ListViewItem row = lvItems.Items.Cast().FirstOrDefault(s => s.SubItems[chCode.Index].Text == strCode); if (row == default(ListViewItem)) return; - row.SubItems[chCurPrice.Index].Text = string.Format("{0}{1:n0}", bReal?"":"*", Item.m_iCurPrice); - row.SubItems[chAssessedValue.Index].Text = string.Format("{0:n0}", Item.m_iAssessedValue); - row.SubItems[chValuation.Index].Text = string.Format("{0:n0}", Item.m_iValuationGains); + row.SubItems[chCurPrice.Index].Text = string.Format("{0}{1:n0}", bReal ? "" : "*", Item.m_iCurPrice); + row.SubItems[chAssessedValue.Index].Text = string.Format("{0:n0}", Item.m_iAssessedValue / 1000); + row.SubItems[chValuation.Index].Text = string.Format("{0:n0}", Item.m_iValuationGains / 1000); row.SubItems[chYield.Index].Text = string.Format("{0:n2}", Item.m_dYield); row.SubItems[chMaxPrice.Index].Text = string.Format("{0:n0}", iMaxPrice); row.SubItems[chCheckCountLimit.Index].Text = string.Format("{0:n2}", dCheckCountLimit); row.SubItems[chCheckCount.Index].Text = string.Format("{0:n0}", iCheckCount); - } + }; + + if (lvItems.InvokeRequired) + lvItems.BeginInvoke(update); + else + update(); if(strCode == m_strSelectedCode) { - if (lvCurPrice.InvokeRequired) - { - lvCurPrice.Invoke(new Action(() => { - lvCurPrice.Items[10].SubItems[chCallPrice.Index].Text = string.Format("{0:n0}", Item.m_iCurPrice); - })); - } - else - { + lvCurPrice.BeginInvoke((MethodInvoker)(() => { lvCurPrice.Items[10].SubItems[chCallPrice.Index].Text = string.Format("{0:n0}", Item.m_iCurPrice); - } + })); } } @@ -398,43 +457,27 @@ namespace AutoSellerNS if (Item == default(ITEM)) return; - if (lvCurPrice.InvokeRequired) - { - lvCurPrice.Invoke(new Action(() => { - - if(iCurPrice > 0) - lvCurPrice.Items[10].SubItems[chCallPrice.Index].Text = string.Format("{0:n0}", iCurPrice); - - for (int i = 0; i < 10; i++) - { - lvCurPrice.Items[i].SubItems[chAskCount.Index].Text = string.Format("{0:n0}", aiAskCount[9-i]); - lvCurPrice.Items[i].SubItems[chCallPrice.Index].Text = string.Format("{0:n0}", aiAskPrice[9-i]); - } - - for (int i = 0; i < 10; i++) - { - lvCurPrice.Items[11 + i].SubItems[chBidCount.Index].Text = string.Format("{0:n0}", aiBidCount[i]); - lvCurPrice.Items[11 + i].SubItems[chCallPrice.Index].Text = string.Format("{0:n0}", aiBidPrice[i]); - } - })); - } - else - { - if(iCurPrice > 0) + Action update = delegate { + if (iCurPrice > 0) lvCurPrice.Items[10].SubItems[chCallPrice.Index].Text = string.Format("{0:n0}", iCurPrice); for (int i = 0; i < 10; i++) { - lvCurPrice.Items[i].SubItems[chAskCount.Index].Text = string.Format("{0:n0}", aiAskCount[9-i]); - lvCurPrice.Items[i].SubItems[chCallPrice.Index].Text = string.Format("{0:n0}", aiAskPrice[9-i]); + lvCurPrice.Items[i].SubItems[chAskCount.Index].Text = string.Format("{0:n0}", aiAskCount[9 - i]); + lvCurPrice.Items[i].SubItems[chCallPrice.Index].Text = string.Format("{0:n0}", aiAskPrice[9 - i]); } for (int i = 0; i < 10; i++) { - lvCurPrice.Items[11+i].SubItems[chBidCount.Index].Text = string.Format("{0:n0}", aiBidCount[i]); - lvCurPrice.Items[11+i].SubItems[chCallPrice.Index].Text = string.Format("{0:n0}", aiBidPrice[i]); + lvCurPrice.Items[11 + i].SubItems[chBidCount.Index].Text = string.Format("{0:n0}", aiBidCount[i]); + lvCurPrice.Items[11 + i].SubItems[chCallPrice.Index].Text = string.Format("{0:n0}", aiBidPrice[i]); } - } + }; + + if (lvCurPrice.InvokeRequired) + lvCurPrice.BeginInvoke(update); + else + update(); } public int GetSellableCount(string strCode) @@ -499,6 +542,8 @@ namespace AutoSellerNS double.TryParse(tbCFTimeDown.Text, out dTimeDown); int.TryParse(tbCFIgnorePrice.Text, out iIgnorePrice); Config.SetVolatility(iListSize, dFastSD, dFastUp, dFastDown, dSlowSD, dSlowUp, dSlowDown, iTimeLimit, dTimeDown, iIgnorePrice); + + Config.SetMockTrading(cbMockTrading.Checked); } #region Simulation @@ -514,5 +559,6 @@ namespace AutoSellerNS helper.StartSimuation2(); } #endregion + } } diff --git a/AutoSeller.csproj b/AutoSeller.csproj index 1d140a9..a8b1e07 100644 --- a/AutoSeller.csproj +++ b/AutoSeller.csproj @@ -76,6 +76,10 @@ packages\MaterialSkin.0.2.1\lib\MaterialSkin.dll True + + packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + True + diff --git a/Config.cs b/Config.cs index 56eadbd..1255705 100644 --- a/Config.cs +++ b/Config.cs @@ -32,6 +32,7 @@ namespace AutoSellerNS m_Data.Add("time-limit", 5); m_Data.Add("time-down", 0.02); m_Data.Add("ignore-price", 50000); + m_Data.Add("mock-trading", false); Load(); } @@ -144,5 +145,12 @@ namespace AutoSellerNS public static int GetTimeLimit() { return (int)m_Data["time-limit"]; } public static double GetTimeDown() { return (double)m_Data["time-down"]; } public static int GetIgnorePrice() { return (int)m_Data["ignore-price"]; } + public static void SetMockTrading(bool bMockTrading) { m_Data["mock-trading"] = bMockTrading; Save(); } + public static bool GetMockTrading() { return (bool)m_Data["mock-trading"]; } + + public static Dictionary GetAllConfig() + { + return m_Data; + } } } diff --git a/CybosHelper.cs b/CybosHelper.cs index 6b3c668..248380d 100644 --- a/CybosHelper.cs +++ b/CybosHelper.cs @@ -51,7 +51,7 @@ namespace AutoSellerNS int m_iPrevTime = 0; - public void OnRecievedPrice() + public async void OnRecievedPrice() { bool bOpeningHour = (m_StockCur.GetHeaderValue(19) == '2'); m_iCurPrice = m_StockCur.GetHeaderValue(13); @@ -117,7 +117,7 @@ namespace AutoSellerNS if(m_iCheckCount >= m_dCheckCountLimit && m_Listener.IsSelling() == true) { - m_CybosHelper.SellItem(m_strCode, m_Listener.GetSellableCount(m_strCode), m_aiAskPrice[0]); + await m_CybosHelper.SellItem(m_strCode, m_Listener.GetSellableCount(m_strCode), m_aiAskPrice[0]); Util.Log(Util.LOG_TYPE.SELL, string.Format("[조건 완료 매도] {0} ({1}회) (현재가 {2:n0}원, 최고가 {3:n0}원)", m_strCodeName, Config.GetBidCount(), @@ -129,7 +129,7 @@ namespace AutoSellerNS m_iTrailingCount++; if(m_iTrailingCount >= Config.GetTrailingCnt() && m_Listener.IsSelling() == true) { - m_CybosHelper.SellItem(m_strCode, m_Listener.GetSellableCount(m_strCode), m_aiAskPrice[0]); + await m_CybosHelper.SellItem(m_strCode, m_Listener.GetSellableCount(m_strCode), m_aiAskPrice[0]); Util.Log(Util.LOG_TYPE.SELL, string.Format("[트레일링 매도] {0} ({1}% {2}회) (현재가 {3:n0}원, 최고가 {4:n0}원)", m_strCodeName, Config.GetTrailingRate(), @@ -140,7 +140,7 @@ namespace AutoSellerNS if(iTimeDiff >= Config.GetTimeLimit() && m_Listener.IsSelling() == true) { - m_CybosHelper.SellItem(m_strCode, m_Listener.GetSellableCount(m_strCode), m_aiAskPrice[0]); + await m_CybosHelper.SellItem(m_strCode, m_Listener.GetSellableCount(m_strCode), m_aiAskPrice[0]); Util.Log(Util.LOG_TYPE.SELL, string.Format("[시간제한 매도] {0} ({1}초) (현재가 {2:n0}원, 최고가 {3:n0}원)", m_strCodeName, iTimeDiff, @@ -236,6 +236,14 @@ namespace AutoSellerNS m_CpConclusion.Subscribe(); } + public async Task InitCybosAsync() + { + await Task.Run(() => + { + InitCybos(); + }); + } + public void SavePrice(STOCK_CUR_ITEM item) { if (Directory.Exists(Util.GetLogPath()) == false) @@ -259,37 +267,36 @@ namespace AutoSellerNS public List UpdateItems() { List aItems = new List(); - if (Config.GetAccount() == "") return aItems; m_6033.SetInputValue(0, Config.GetAccount()); m_6033.SetInputValue(1, Config.GetSubAccount()); - m_6033.BlockRequest2(1); + m_6033.BlockRequest2(0); string strCodeList = ""; bool bContinue = true; - while(bContinue == true) + while (bContinue == true) { int iCount = m_6033.GetHeaderValue(7); - for(int i = 0; i < iCount; i++) + for (int i = 0; i < iCount; i++) { AutoSeller.ITEM Item = new AutoSeller.ITEM(); Item.m_strCodeName = m_6033.GetDataValue(0, i); - if(Item.m_strCodeName != "") + if (Item.m_strCodeName != "") { Item.m_strCode = m_6033.GetDataValue(12, i); Item.m_iItemCnt = m_6033.GetDataValue(7, i); - Item.m_iAssessedValue = m_6033.GetDataValue(9, i); - Item.m_iValuationGains = m_6033.GetDataValue(10, i); + Item.m_iAssessedValue = m_6033.GetDataValue(9, i) / 1000; + Item.m_iValuationGains = m_6033.GetDataValue(10, i) / 1000; Item.m_dYield = m_6033.GetDataValue(11, i); Item.m_iAvailableQuantity = m_6033.GetDataValue(15, i); Item.m_dBookUnitPrice = m_6033.GetDataValue(17, i); Item.m_iProfitUnitPrice = m_6033.GetDataValue(18, i); - if(strCodeList.Length > 0) + if (strCodeList.Length > 0) strCodeList += ","; strCodeList += Item.m_strCode; @@ -298,15 +305,16 @@ namespace AutoSellerNS } bContinue = (m_6033.Continue != 0); - if(bContinue == true) - m_6033.BlockRequest2(1); + bContinue = false; + if (bContinue == true) + m_6033.BlockRequest2(0); } if (strCodeList.Length > 0) { DSCBO1Lib.StockMst2 StockMst = new DSCBO1Lib.StockMst2(); StockMst.SetInputValue(0, strCodeList); - StockMst.BlockRequest2(1); + StockMst.BlockRequest2(0); int iCnt = StockMst.GetHeaderValue(0); for (int i = 0; i < iCnt; i++) { @@ -320,13 +328,13 @@ namespace AutoSellerNS // sync List aRemoveKeys = new List(); - foreach(var Item in m_aStockCur) + foreach (var Item in m_aStockCur) { - if(aItems.Any(s => s.m_strCode == Item.Key) == false) + if (aItems.Any(s => s.m_strCode == Item.Key) == false) aRemoveKeys.Add(Item.Key); } - foreach(var Key in aRemoveKeys) + foreach (var Key in aRemoveKeys) { m_aStockCur[Key].m_StockCur.Unsubscribe(); m_aStockCur[Key].m_Jpbid.Unsubscribe(); @@ -337,14 +345,16 @@ namespace AutoSellerNS return aItems; } - static int iUpdateNCIdx = 1; + public async Task> UpdateItemsAsync() + { + return await Task>.Run(() => + { + return UpdateItems(); + }); + } + public List UpdateNC() { - int iIdx = iUpdateNCIdx++; - Util.Log(Util.LOG_TYPE.DEBUG, string.Format("UpdateNC Start ({0}, {1}, {2}, {3})", iIdx, - GetLimitRemainCountRQ(), GetLimitRemainCountSB(), GetLimitRemainCountTrade() - )); - while(GetLimitRemainCountTrade() < 1) Thread.Sleep(500); @@ -353,14 +363,12 @@ namespace AutoSellerNS CPTRADELib.CpTd5339 CP5339 = new CPTRADELib.CpTd5339(); CP5339.SetInputValue(0, Config.GetAccount()); CP5339.SetInputValue(1, Config.GetSubAccount()); - CP5339.BlockRequest2(1); + CP5339.BlockRequest2(0); bool bContinue = true; while(bContinue) { int iCnt = CP5339.GetHeaderValue(5); - Console.WriteLine("icnt : {0}", iCnt); - for(int i = 0; i> UpdateNCAsync() + { + return await Task>.Run(() => { + return UpdateNC(); + }); + } + private void CpConclusion_Received() { string strType = m_CpConclusion.GetHeaderValue(14); @@ -416,7 +431,7 @@ namespace AutoSellerNS switch (iType) { case 1: // 체결 - m_Listener.UpdateItem(strCode, strCodeName, bBid, iConclusionCnt, iRemainCnt, iBookValue); + m_Listener.UpdateItem(); m_Listener.UpdateNCItem(); Util.Log(bBid?Util.LOG_TYPE.BUY:Util.LOG_TYPE.SELL, string.Format("{0}:{1} {2} 체결 ({3:n0}원 {4}주) - {5}", strCodeName, strCode, strBidOrAsk, iPrice, iConclusionCnt, strOrderCondition)); break; @@ -432,7 +447,7 @@ namespace AutoSellerNS case 4: // 접수 m_Listener.UpdateNCItem(); Util.Log(bBid ? Util.LOG_TYPE.BUY : Util.LOG_TYPE.SELL, string.Format("{0}:{1} {2} 접수 ({3:n0}원 {4}주) - {5}", strCodeName, strCode, strBidOrAsk, iPrice, iConclusionCnt, strOrderCondition)); - if (bBid == true) + if (bBid == false) { if(m_aStockCur.ContainsKey(strCode) == true) { @@ -489,7 +504,7 @@ namespace AutoSellerNS DSCBO1Lib.StockJpbid2 JpBid = new DSCBO1Lib.StockJpbid2(); JpBid.SetInputValue(0, Item.m_strCode); - JpBid.BlockRequest2(1); + JpBid.BlockRequest2(0); for(int i=0; i<10; i++) { StockCur.m_aiAskPrice[i] = JpBid.GetDataValue(0, i); @@ -539,62 +554,60 @@ namespace AutoSellerNS return (iValue/iUnit)*iUnit; } - static int iSellIdx = 1; - public void SellItem(string strCode, int iCnt, int iAskPrice) + public async Task SellItem(string strCode, int iCnt, int iAskPrice) { - int iIdx = iSellIdx++; - Util.Log(Util.LOG_TYPE.DEBUG, string.Format("SellItem Start ({0})", iIdx)); + await Task.Run(() => + { + int iSellPrice = iAskPrice - GetUnitValue(iAskPrice); - int iSellPrice = iAskPrice-GetUnitValue(iAskPrice); - - CPTRADELib.CpTd0311 Td0311 = new CPTRADELib.CpTd0311(); - Td0311.SetInputValue(0, "1"); - Td0311.SetInputValue(1, Config.GetAccount()); - Td0311.SetInputValue(2, Config.GetSubAccount()); - Td0311.SetInputValue(3, strCode); - Td0311.SetInputValue(4, iCnt); - Td0311.SetInputValue(5, iSellPrice); - Td0311.SetInputValue(8, "01"); - Td0311.BlockRequest2(1); - - Util.Log(Util.LOG_TYPE.DEBUG, string.Format("SellItem End ({0})", iIdx)); + CPTRADELib.CpTd0311 Td0311 = new CPTRADELib.CpTd0311(); + Td0311.SetInputValue(0, "1"); + Td0311.SetInputValue(1, Config.GetAccount()); + Td0311.SetInputValue(2, Config.GetSubAccount()); + Td0311.SetInputValue(3, strCode); + Td0311.SetInputValue(4, iCnt); + Td0311.SetInputValue(5, iSellPrice); + Td0311.SetInputValue(8, "01"); + Td0311.BlockRequest2(1); + }); } - static int iCancelIdx = 1; - public void CancelItem(string strCode, int iOrgOrderNo) + public async Task CancelItem(string strCode, int iOrgOrderNo) { - int iIdx = iCancelIdx++; - Util.Log(Util.LOG_TYPE.DEBUG, string.Format("CancelItem Start ({0})", iIdx)); - - CPTRADELib.CpTd0314 Td0314 = new CPTRADELib.CpTd0314(); - Td0314.SetInputValue(1, iOrgOrderNo); - Td0314.SetInputValue(2, Config.GetAccount()); - Td0314.SetInputValue(3, Config.GetSubAccount()); - Td0314.SetInputValue(4, strCode); - Td0314.SetInputValue(5, 0); - Td0314.BlockRequest2(1); - - Util.Log(Util.LOG_TYPE.DEBUG, string.Format("CancelItem End ({0})", iIdx)); + await Task.Run(() => + { + CPTRADELib.CpTd0314 Td0314 = new CPTRADELib.CpTd0314(); + Td0314.SetInputValue(1, iOrgOrderNo); + Td0314.SetInputValue(2, Config.GetAccount()); + Td0314.SetInputValue(3, Config.GetSubAccount()); + Td0314.SetInputValue(4, strCode); + Td0314.SetInputValue(5, 0); + Td0314.BlockRequest2(1); + }); } - static int iCorrectIdx = 1; - public void CorrectionItem(string strCode, int iOrgOrderNo, int iCnt, int iAskPrice) + public async Task CorrectionItem(string strCode, int iOrgOrderNo, int iCnt, int iAskPrice) { - int iIdx = iCorrectIdx++; - Util.Log(Util.LOG_TYPE.DEBUG, string.Format("CorrectionItem Start ({0})", iIdx)); + if(Config.GetMockTrading() == true) + { + await CancelItem(strCode, iOrgOrderNo); + await SellItem(strCode, iCnt, iAskPrice); + return; + } - int iSellPrice = iAskPrice; + await Task.Run(() => + { + int iSellPrice = iAskPrice; - CPTRADELib.CpTd0313 Td0313 = new CPTRADELib.CpTd0313(); - Td0313.SetInputValue(1, iOrgOrderNo); - Td0313.SetInputValue(2, Config.GetAccount()); - Td0313.SetInputValue(3, Config.GetSubAccount()); - Td0313.SetInputValue(4, strCode); - Td0313.SetInputValue(5, 0); - Td0313.SetInputValue(6, iSellPrice); - Td0313.BlockRequest2(1); - - Util.Log(Util.LOG_TYPE.DEBUG, string.Format("CorrectionItem End ({0})", iIdx)); + CPTRADELib.CpTd0313 Td0313 = new CPTRADELib.CpTd0313(); + Td0313.SetInputValue(1, iOrgOrderNo); + Td0313.SetInputValue(2, Config.GetAccount()); + Td0313.SetInputValue(3, Config.GetSubAccount()); + Td0313.SetInputValue(4, strCode); + Td0313.SetInputValue(5, 0); + Td0313.SetInputValue(6, iSellPrice); + Td0313.BlockRequest2(1); + }); } } } diff --git a/FluentFTP/Client/FtpClient_HighLevel.cs b/FluentFTP/Client/FtpClient_HighLevel.cs index 3af6228..30607cd 100644 --- a/FluentFTP/Client/FtpClient_HighLevel.cs +++ b/FluentFTP/Client/FtpClient_HighLevel.cs @@ -1067,7 +1067,7 @@ namespace FluentFTP { // seek to required offset fileData.Position = offset; - } catch (Exception ex2) { + } catch (Exception) { } } @@ -1208,12 +1208,15 @@ namespace FluentFTP { Stream upStream = null; try { long offset = 0; - bool checkFileExistsAgain = false; + //bool checkFileExistsAgain = false; // check if the file exists, and skip, overwrite or append - if (existsMode == FtpExists.NoCheck) { - checkFileExistsAgain = true; - } else { + if (existsMode == FtpExists.NoCheck) + { + //checkFileExistsAgain = true; + } + else + { if (!fileExistsKnown) { fileExists = await FileExistsAsync(remotePath); } @@ -1254,7 +1257,7 @@ namespace FluentFTP { // seek to required offset fileData.Position = offset; - } catch (Exception ex2) { + } catch (Exception) { } } diff --git a/FluentFTP/Client/FtpClient_LowLevel.cs b/FluentFTP/Client/FtpClient_LowLevel.cs index 7475fd3..64ef603 100644 --- a/FluentFTP/Client/FtpClient_LowLevel.cs +++ b/FluentFTP/Client/FtpClient_LowLevel.cs @@ -313,7 +313,7 @@ namespace FluentFTP { try { stream.Listen(m_stream.LocalEndPoint.Address, port); success = true; - } catch (SocketException se) { + } catch (SocketException) { #if NETFX // Already in use if (se.ErrorCode != 10048) @@ -448,7 +448,7 @@ namespace FluentFTP { stream.Listen(m_stream.LocalEndPoint.Address, port); success = true; } - catch (SocketException se) + catch (SocketException) { #if NETFX // Already in use diff --git a/SimulationHelper.cs b/SimulationHelper.cs index 1c0b543..c1b7b54 100644 --- a/SimulationHelper.cs +++ b/SimulationHelper.cs @@ -67,7 +67,7 @@ namespace AutoSellerNS CPStockBid.SetInputValue(2, 20000); CPStockBid.SetInputValue(3, 'C'); CPStockBid.SetInputValue(4, "2000"); - CPStockBid.BlockRequest2(1); + CPStockBid.BlockRequest2(0); List aaRows = new List(); @@ -93,7 +93,7 @@ namespace AutoSellerNS { while(m_CybosHelper.GetLimitRemainCountRQ() < 2) Thread.Sleep(100); - CPStockBid.BlockRequest2(1); + CPStockBid.BlockRequest2(0); } m_tbLogView.AppendText(string.Format("RequestRQ({0}) ", m_CybosHelper.GetLimitRemainCountRQ())); @@ -114,7 +114,7 @@ namespace AutoSellerNS void InsertLog(string strMsg) { - m_tbLogView.Invoke(new Action(() => { + m_tbLogView.BeginInvoke(new Action(() => { int iPrevSelectionStart = m_tbLogView.SelectionStart; int iPrevSelectionLength = m_tbLogView.SelectionLength; bool bScroll = m_tbLogView.SelectionStart == m_tbLogView.TextLength; @@ -739,7 +739,7 @@ namespace AutoSellerNS bHalfTrailing = m_AutoSeller.chSMHalfTrailing.Checked; string strMethod = ""; - m_AutoSeller.cbSMMethod.Invoke(new Action(() => { + m_AutoSeller.cbSMMethod.BeginInvoke(new Action(() => { strMethod = (string)m_AutoSeller.cbSMMethod.SelectedItem; })); diff --git a/Util.cs b/Util.cs index dc20a63..5e4f2a6 100644 --- a/Util.cs +++ b/Util.cs @@ -23,8 +23,6 @@ namespace AutoSellerNS static string m_strLogFile = null; static RichTextBox m_LogBox = null; - delegate void InsertLogDelegate(RichTextBox LogBox, LOG_TYPE enType, string strLog); - static InsertLogDelegate m_InsertLogDelegate = new InsertLogDelegate(InsertLog); static object m_LogLock = new object(); public static void SetLogView(RichTextBox logBox) @@ -42,14 +40,9 @@ namespace AutoSellerNS if(IsDebugging() == false && enType == LOG_TYPE.DEBUG) return; - if(LogBox.InvokeRequired) - { - LogBox.Invoke(m_InsertLogDelegate, LogBox, enType, strLog); - } - else - { + Action update = delegate { Color LogColor; - switch(enType) + switch (enType) { case LOG_TYPE.DEBUG: LogColor = Color.Gray; @@ -81,7 +74,12 @@ namespace AutoSellerNS LogBox.SelectionStart = LogBox.TextLength; LogBox.ScrollToCaret(); - } + }; + + if (LogBox.InvokeRequired) + LogBox.BeginInvoke(update); + else + update(); } public static void Log(LOG_TYPE enType, string strLog) diff --git a/packages.config b/packages.config index dcbcc9e..003e51b 100644 --- a/packages.config +++ b/packages.config @@ -2,4 +2,5 @@ + \ No newline at end of file