Pastebin: 最後のスクリーニング結果 Env.cs

Formato
Plain text
Post date
2015-04-04 22:26
Publication Period
Unlimited
  1. /*
  2. * Copyright (c) Daisuke OKAJIMA All rights reserved.
  3. *
  4. * $Id$
  5. */
  6. using System;
  7. using System.Collections;
  8. using System.Text;
  9. using System.Diagnostics;
  10. using System.IO;
  11. using System.Windows.Forms;
  12. using Travis.Storage;
  13. using Zanetti.UI;
  14. using Zanetti.Forms;
  15. using Zanetti.Commands;
  16. using Zanetti.Data;
  17. using Zanetti.DataSource;
  18. using Zanetti.Parser;
  19. using Zanetti.Config;
  20. using Zanetti.Arithmetic;
  21. using Zanetti.Indicators;
  22. using Zanetti.Indicators.Schema;
  23. namespace Zanetti
  24. {
  25. /// <summary>
  26. /// Env の概要の説明です。
  27. /// </summary>
  28. internal class Env {
  29. private static Preference _preference;
  30. private static Options _options;
  31. private static LayoutInfo _layoutInfo;
  32. private static Bookmark _bookmark;
  33. private static FreeLineCollection _freeLines;
  34. private static BrandCollection _brandCollection;
  35. private static ArithmeticLibrary _arithmeticLibrary;
  36. private static ZanettiSchema _schema;
  37. private static IndicatorSet _currentIndicatorSet;
  38. private static MainFrame _mainFrame;
  39. private static KitTestDialog _kitTestDialog;
  40. private static CommandCollection _command;
  41. private static BrandHistory _history;
  42. private static StorageNode _rootStorageNode;
  43. private static ImageList _imageList16;
  44. private static Zanetti.SystemTrading.SystemTradingResult _lastScreeningResult;
  45. public static Zanetti.SystemTrading.SystemTradingResult LastScreeningResult
  46. {
  47. get
  48. {
  49. return _lastScreeningResult;
  50. }
  51. set
  52. {
  53. _lastScreeningResult = value;
  54. }
  55. }
  56. public static Preference Preference {
  57. get {
  58. return _preference;
  59. }
  60. }
  61. public static Options Options {
  62. get {
  63. return _options;
  64. }
  65. }
  66. public static LayoutInfo Layout {
  67. get {
  68. return _layoutInfo;
  69. }
  70. }
  71. public static BrandCollection BrandCollection {
  72. get {
  73. return _brandCollection;
  74. }
  75. }
  76. public static ZanettiSchema Schema {
  77. get {
  78. return _schema;
  79. }
  80. }
  81. public static IndicatorSet CurrentIndicators {
  82. get {
  83. return _currentIndicatorSet;
  84. }
  85. set {
  86. _currentIndicatorSet = value;
  87. }
  88. }
  89. public static ArithmeticLibrary ArithmeticLibrary {
  90. get {
  91. return _arithmeticLibrary;
  92. }
  93. }
  94. public static MainFrame Frame {
  95. get {
  96. return _mainFrame;
  97. }
  98. }
  99. public static KitTestDialog KitTestDialog {
  100. get {
  101. return _kitTestDialog;
  102. }
  103. set {
  104. _kitTestDialog = value;
  105. }
  106. }
  107. public static CommandCollection Command {
  108. get {
  109. return _command;
  110. }
  111. }
  112. public static BrandHistory BrandHistory {
  113. get {
  114. return _history;
  115. }
  116. }
  117. public static Bookmark Bookmark {
  118. get {
  119. return _bookmark;
  120. }
  121. }
  122. public static FreeLineCollection FreeLines {
  123. get {
  124. return _freeLines;
  125. }
  126. }
  127. //パース済み設定ファイルのルート ネーミングはちとおかしいが
  128. public static StorageNode RootStorageNode {
  129. get {
  130. return _rootStorageNode;
  131. }
  132. }
  133. public static ImageList ImageList16 {
  134. get {
  135. if(_imageList16==null) {
  136. ImageListForm frm = new ImageListForm();
  137. _imageList16 = frm.ImageList16;
  138. }
  139. return _imageList16;
  140. }
  141. }
  142. [STAThread]
  143. public static void Main(string[] args) {
  144. try {
  145. InitEnv();
  146. Application.Run(_mainFrame);
  147. SaveEnv();
  148. }
  149. catch(Exception ex) {
  150. Util.ReportCriticalError(ex);
  151. }
  152. }
  153. private static void InitEnv() {
  154. Application.EnableVisualStyles();
  155. string dir = GetAppDir() + "data";
  156. if(!Directory.Exists(dir))
  157. Directory.CreateDirectory(dir);
  158. ThemeUtil.Init();
  159. _brandCollection = new BrandCollection();
  160. _arithmeticLibrary = new ArithmeticLibrary();
  161. _arithmeticLibrary.InitBuiltins();
  162. _schema = new ZanettiSchema();
  163. _options = new Options();
  164. _bookmark = new Bookmark();
  165. _freeLines = new FreeLineCollection();
  166. _history = new BrandHistory();
  167. InitialAction act = new InitialAction();
  168. _brandCollection.Load(GetAppDir() + "index.txt");
  169. _rootStorageNode = null;
  170. string option_file = GetAppDir() + "options.conf";
  171. if(!File.Exists(option_file)) {
  172. _options.Init();
  173. _bookmark.Clear();
  174. }
  175. else {
  176. StreamReader reader = null;
  177. try {
  178. reader = new StreamReader(option_file, Encoding.Default);
  179. _rootStorageNode = new TextNodeReader(reader).Read().GetChildAt(0);
  180. StorageNode options = _rootStorageNode.FindChildNode("options");
  181. if(options==null)
  182. _options.Init();
  183. else
  184. _options.Load(options);
  185. StorageNode bookmark = _rootStorageNode.FindChildNode("bookmark-group");
  186. if(bookmark==null)
  187. _bookmark.Clear();
  188. else
  189. _bookmark.Load(bookmark);
  190. _freeLines.Load(_rootStorageNode);
  191. }
  192. catch(Exception ex) {
  193. act.AddErrorMessage("オプションファイルの読み込みに失敗しました。" + ex.Message);
  194. }
  195. finally {
  196. if(reader!=null) reader.Close();
  197. }
  198. }
  199. _preference = new Preference(_rootStorageNode==null? null : _rootStorageNode.FindChildNode("preference"));
  200. _command = new CommandCollection(_rootStorageNode==null? null : _rootStorageNode.FindChildNode("command"));
  201. _currentIndicatorSet = new IndicatorSet(_options.ChartFormat); //最低限の内容で初期化
  202. _layoutInfo = new LayoutInfo();
  203. act.BrandCode = (int)BuiltInIndex.Nikkei225;
  204. _mainFrame = new MainFrame();
  205. _mainFrame.StartPosition = FormStartPosition.Manual;
  206. _mainFrame.InitialAction = act;
  207. _mainFrame.Size = Env.Options.FrameLocation.Size;
  208. _mainFrame.Location = Env.Options.FrameLocation.Location;
  209. _mainFrame.WindowState = _options.WindowState;
  210. _mainFrame.Init();
  211. //ここまできたら起動回数を1ふやす
  212. _options.LauchCount++;
  213. }
  214. //Commandから呼ぶためのスキーマ再構成
  215. public static void ReloadSchema() {
  216. _schema = new ZanettiSchema();
  217. _schema.Load(GetAppDir() + "extension", _rootStorageNode==null? null : _rootStorageNode.FindChildNode("params"));
  218. }
  219. public static void ResetWithoutConfig() {
  220. _schema = new ZanettiSchema();
  221. _schema.Load(GetAppDir() + "extension", null);
  222. _preference = new Preference(null);
  223. }
  224. public static void SaveEnv() {
  225. string option_file = GetAppDir() + "options.conf";
  226. StreamWriter writer = null;
  227. try {
  228. writer = new StreamWriter(option_file, false, Encoding.Default);
  229. StorageNode root = new StorageNode();
  230. root.Name = "omega-chart-options";
  231. _options.SaveTo(root);
  232. _bookmark.SaveTo(root);
  233. _preference.SaveTo(root);
  234. _schema.SaveTo(root);
  235. _freeLines.SaveTo(root);
  236. new TextNodeWriter(writer).Write(root);
  237. writer.Close();
  238. }
  239. catch(Exception ex) {
  240. Util.SilentReportCriticalError(ex);
  241. Util.Warning("オプションの保存に失敗しました。"+ex.Message);
  242. }
  243. finally {
  244. if(writer!=null) writer.Close();
  245. }
  246. }
  247. private static string _appDir;
  248. public static string GetAppDir() {
  249. if(_appDir==null)
  250. _appDir = AppDomain.CurrentDomain.BaseDirectory;
  251. return _appDir;
  252. }
  253. internal class Constants {
  254. #if DOJIMA
  255. public const string AppTitle = Zanetti.Dojima.DojimaUtil.AppTitle;
  256. #else
  257. public const string AppTitle = "Omega Chart";
  258. #endif
  259. public const int LaunchCountForPrompt = 30;
  260. public const int MIN_CANDLE_WIDTH = 1;
  261. public const int MAX_CANDLE_WIDTH = 17;
  262. }
  263. }
  264. internal class InitialAction {
  265. private bool _indexConstructionRequired;
  266. private bool _performed;
  267. private string _message;
  268. private int _brandCode;
  269. private ArrayList _errorMessages = new ArrayList();
  270. public bool IndexConstructionRequired {
  271. get {
  272. return _indexConstructionRequired;
  273. }
  274. }
  275. public string Message {
  276. get {
  277. return _message;
  278. }
  279. }
  280. public IEnumerable ErrorMessages {
  281. get {
  282. return _errorMessages;
  283. }
  284. }
  285. public bool Performed {
  286. get {
  287. return _performed;
  288. }
  289. set {
  290. _performed = value;
  291. }
  292. }
  293. public int BrandCode {
  294. get {
  295. return _brandCode;
  296. }
  297. set {
  298. _brandCode = value;
  299. }
  300. }
  301. public void SetIndexConstructionRequired(string msg) {
  302. _indexConstructionRequired = true;
  303. _message = msg;
  304. }
  305. public void AddErrorMessage(string value) {
  306. _errorMessages.Add(value);
  307. }
  308. }
  309. }
Download Printable view

URL of this paste

Embed with JavaScript

Embed with iframe

Raw text