Pastebin: OmegaChart ダウンロードindex.txtとローカルindex.txtをマージする機能 DownloadIndexFileDialog.cs

Format
Plain text
Post date
2017-12-11 23:52
Publication Period
Unlimited
  1. //現行の、DownloadIndexFileDialog.cs にある private void BrandIndex_Shown(object sender, EventArgs e)に下記内容を差し替え
  2. private void BrandIndex_Shown(object sender, EventArgs e)
  3. {
  4. this.btnClose.Enabled = false;
  5. MemoryStream ms = null;
  6. try
  7. {
  8. Env.Frame.Cursor = Cursors.WaitCursor;
  9. ms = Util.HttpDownload("http://protra.osdn.jp/data/index.txt");
  10. int dt = BrandCollection.GuessDate(ms);
  11. ms.Position = 0;
  12. if (dt > Env.BrandCollection.LastUpdatedDate)
  13. {
  14. System.Collections.Generic.Dictionary<int, string> dic_org = new System.Collections.Generic.Dictionary<int, string>();
  15. System.Collections.Generic.Dictionary<int, string> dic_dest = new System.Collections.Generic.Dictionary<int, string>();//☆この行、追加 ①
  16. string[] lines = File.ReadAllLines(Env.GetAppDir() + "index.txt", Encoding.Default);
  17. foreach (string line in lines)
  18. {
  19. string[] cols = line.Split(',');
  20. int code = 0;
  21. if (int.TryParse(cols[0], out code))
  22. dic_org.Add(code, line);
  23. }
  24. dic_dest = dic_org;//☆この行、追加 ②
  25. label.Text = "新しいインデックスファイルをダウンロードしました。";
  26. this.Width = 520;
  27. this.Height = 400;
  28. Util.StreamToFile(ms, Env.GetAppDir() + "index.txt");
  29. StringBuilder sb = new StringBuilder();
  30. ms.Seek(0, SeekOrigin.Begin);
  31. TextReader tr = new StreamReader(ms, Encoding.Default);
  32. while (tr.Peek() >= 0)
  33. {
  34. string line = tr.ReadLine();
  35. string[] cols = line.Split(',');
  36. int code = 0;
  37. if (int.TryParse(cols[0], out code))
  38. {
  39. if (!dic_org.ContainsKey(code))
  40. {//☆この{、追加 ③
  41. sb.AppendLine("新規銘柄:" + line);
  42. dic_dest.Add(code, line);//☆この行、追加 ④
  43. }//☆この}、追加 ⑤
  44. else
  45. {
  46. if (dic_org[code] != line)
  47. {
  48. sb.AppendLine("変更 :" + line);
  49. sb.AppendLine(" 旧:" + dic_org[code]);
  50. dic_dest[code] = line;//☆この行、追加 ⑥
  51. }
  52. }
  53. }
  54. } //これを利用する手もあり
  55. textBox1.Text = sb.ToString();
  56. this.Refresh();
  57. //MessageBox.Show(sb.ToString(), "新しいindex.txt");
  58. //dic_org.Clear();//☆この行、コメントアウト ⑦
  59. //Env.BrandCollection.Load(Env.GetAppDir() + "index.txt"); //そのまま更新 //☆この行、コメントアウト ⑧
  60. Env.BrandCollection.Load(dic_dest); //そのまま更新 //☆この行、追加 ⑨
  61. dic_org.Clear();//☆この行、追加 ⑩
  62. dic_dest.Clear();//☆この行、追加 ⑪
  63. if (File.Exists(Env.GetAppDir() + "index_append.txt"))
  64. Env.BrandCollection.Load(Env.GetAppDir() + "index_append.txt");
  65. Env.Frame.Cursor = Cursors.Default;
  66. label.Text = "銘柄情報が更新されました。";
  67. }
  68. else
  69. {
  70. label.Text = "新しいインデックスファイルはありません。";
  71. }
  72. }
  73. catch (Exception ex)
  74. {
  75. Util.ReportCriticalError(ex);
  76. }
  77. finally
  78. {
  79. if (ms != null) ms.Close();
  80. this.btnClose.Enabled = true;
  81. }
  82. }
Download Printable view

URL of this paste

Embed with JavaScript

Embed with iframe

Raw text