コピペ: OmegaChart 任意のローソク足でルーラーを止める Env.cs 追加・修正ポイントには//☆FixDate

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

このコピペの URL

JavaScript での埋め込み

iframe での埋め込み

元のテキスト