Formato
Plain text
Post date
2015-01-29 03:06
Publication Period
Unlimited
  1. /*
  2. * Copyright (c) Daisuke OKAJIMA All rights reserved.
  3. *
  4. * $Id$
  5. */
  6. using System;
  7. using System.IO;
  8. using System.Text;
  9. using System.Drawing;
  10. using System.Windows.Forms;
  11. using Zanetti.SystemTrading.Screening;
  12. using Zanetti.DataSource;
  13. using Travis.Storage;
  14. namespace Zanetti.Config
  15. {
  16. internal enum DataFeedAction {
  17. None,
  18. FullDownload,
  19. DailyDownload
  20. }
  21. //各種オプション設定(プロテクトの必要ないもの)を書き出す
  22. internal class Options {
  23. private Rectangle _frameLocation;
  24. private FormWindowState _windowState;
  25. private bool _showsBookmark;
  26. private ChartFormat _chartFormat;
  27. private DataFeedAction _dataFeedAction;
  28. private DownloadOrderCollection _downloadOrders;
  29. private KeyConfig _keyConfig;
  30. private ProxyConfig _proxyConfig;
  31. private string _rawCertString;
  32. private int _launchCount;
  33. //以下はserializeの必要はない
  34. private ScreeningOrder _prevScreeningOrder;
  35. private SimpleUserKey _certificate;
  36. //ケンミレからのダウンロードキー
  37. private int _kenmilleKey;
  38. //無尽蔵で使用するサイトが過去データかどうか
  39. private bool _mujinzou_uses_kakodata;
  40. public Options() {
  41. _showsBookmark = false;
  42. _downloadOrders = new DownloadOrderCollection();
  43. _keyConfig = new KeyConfig();
  44. _proxyConfig = new ProxyConfig();
  45. }
  46. public void Init() {
  47. _windowState = FormWindowState.Normal;
  48. _chartFormat = ChartFormat.Daily;
  49. Rectangle r = Screen.PrimaryScreen.Bounds;
  50. _frameLocation = new Rectangle(r.Width/6, r.Height/6, r.Width*2/3, r.Height*2/3);
  51. _dataFeedAction = DataFeedAction.FullDownload;
  52. _keyConfig.Reset();
  53. }
  54. public DownloadOrderCollection DownloadOrders {
  55. get {
  56. return _downloadOrders;
  57. }
  58. }
  59. public KeyConfig KeyConfig {
  60. get {
  61. return _keyConfig;
  62. }
  63. set {
  64. _keyConfig = value;
  65. }
  66. }
  67. public ProxyConfig ProxyConfig {
  68. get {
  69. return _proxyConfig;
  70. }
  71. set {
  72. _proxyConfig = value;
  73. }
  74. }
  75. public int LauchCount {
  76. get {
  77. return _launchCount;
  78. }
  79. set {
  80. _launchCount = value;
  81. }
  82. }
  83. public Rectangle FrameLocation {
  84. get {
  85. return _frameLocation;
  86. }
  87. set {
  88. _frameLocation = value;
  89. }
  90. }
  91. public FormWindowState WindowState {
  92. get {
  93. return _windowState;
  94. }
  95. set {
  96. _windowState = value;
  97. }
  98. }
  99. public DataFeedAction DataFeedAction {
  100. get {
  101. return _dataFeedAction;
  102. }
  103. set {
  104. _dataFeedAction = value;
  105. }
  106. }
  107. public bool ShowsBookmark {
  108. get {
  109. return _showsBookmark;
  110. }
  111. set {
  112. _showsBookmark = value;
  113. }
  114. }
  115. public ChartFormat ChartFormat {
  116. get {
  117. return _chartFormat;
  118. }
  119. set {
  120. _chartFormat = value;
  121. }
  122. }
  123. public ScreeningOrder PrevScreeningOrder {
  124. get {
  125. return _prevScreeningOrder;
  126. }
  127. set {
  128. _prevScreeningOrder = value;
  129. }
  130. }
  131. public string RawCertString {
  132. get {
  133. return _rawCertString;
  134. }
  135. set {
  136. _rawCertString = value;
  137. }
  138. }
  139. public SimpleUserKey Certificate {
  140. get {
  141. if(_certificate==null) _certificate = SimpleUserKey.Load(_rawCertString);
  142. return _certificate;
  143. }
  144. set {
  145. _certificate = value;
  146. }
  147. }
  148. public int KenmilleKey {
  149. get {
  150. return _kenmilleKey;
  151. }
  152. }
  153. public bool MujinzouUsesKakoData {
  154. get {
  155. return _mujinzou_uses_kakodata;
  156. }
  157. }
  158. public void SaveTo(StorageNode parent) {
  159. StorageNode node = new StorageNode();
  160. node.Name = "options";
  161. node["window-state"] = _windowState.ToString();
  162. if(_windowState==FormWindowState.Normal) {
  163. node["frameX"] = _frameLocation.X.ToString();
  164. node["frameY"] = _frameLocation.Y.ToString();
  165. node["frameW"] = _frameLocation.Width.ToString();
  166. node["frameH"] = _frameLocation.Height.ToString();
  167. }
  168. node["chart-format"] = _chartFormat.ToString();
  169. node["data-feed-action"] = _dataFeedAction.ToString();
  170. if(_rawCertString!=null) node["user-code"] = _rawCertString;
  171. node["launch-count"] = _launchCount.ToString();
  172. node["kenmille-key"] = _kenmilleKey.ToString("X");
  173. node["mujinzou-uses-kakodata"] = _mujinzou_uses_kakodata.ToString();
  174. #if DOJIMA
  175. node["dojima-password-verified"] = _dojimaPasswordVerified.ToString();
  176. #endif
  177. _downloadOrders.SaveTo(node);
  178. _keyConfig.SaveTo(node);
  179. _proxyConfig.SaveTo(node);
  180. parent.AddChild(node);
  181. }
  182. public void Load(StorageNode sec) {
  183. _windowState = ParseWindowState(sec["window-state"]);
  184. if(_windowState==FormWindowState.Normal) {
  185. _frameLocation.X = ParseInt(sec["frameX"], 0);
  186. _frameLocation.Y = ParseInt(sec["frameY"], 0);
  187. _frameLocation.Width = ParseInt(sec["frameW"], 0);
  188. _frameLocation.Height = ParseInt(sec["frameH"], 0);
  189. }
  190. else {
  191. if(_windowState==FormWindowState.Minimized) _windowState = FormWindowState.Normal;
  192. Rectangle r = Screen.PrimaryScreen.Bounds;
  193. _frameLocation = new Rectangle(r.Width/6, r.Height/6, r.Width*2/3, r.Height*2/3);
  194. }
  195. _chartFormat = ParseChartFormat(sec["chart-format"]);
  196. _dataFeedAction = ParseDataFeedAction(sec["data-feed-action"]);
  197. _rawCertString = sec["user-code"];
  198. _launchCount = ParseInt(sec["launch-count"], 0);
  199. _downloadOrders.Load(sec);
  200. _keyConfig.Load(sec);
  201. _proxyConfig.Load(sec);
  202. //このキーがケンミレからのダウンロードでは必要になる。
  203. //別途調べたキーの値をoptions.confファイルに書き、OmegaChartを起動するとここで読み込まれる。
  204. //2005年11月時点ではこの方法でOKであるが、いつまで有効かはわからない。
  205. //キーを調べるためのヒント:
  206. // * まず、何でもよいのでJavaのデコンパイラを用意する。
  207. // * ケンミレのチャート表示JavaAppletを構成するファイルのうち、ChForbidden.classの中をデコンパイラで表示する
  208. // * その中にキーが書いてある。どれがキーかはKenmille.csファイルのコードを見れば分かるであろう。
  209. //
  210. //ついでにケンミレへのコメント:
  211. // 俺が最も恐れていたのは、チャートを見るにはユーザ登録を必須にして、ちゃんと認証するようにWebサイトを変えられるか、
  212. // Flashなどコード解析がより困難なプラットフォームにチャートのアプリが変更されることだった。
  213. // 今回はそのどちらでもなかったので、正直安心した。
  214. _kenmilleKey = Util.ParseHexInt(sec["kenmille-key"], 0);
  215. _mujinzou_uses_kakodata = ParseBool(sec["mujinzou-uses-kakodata"], false);
  216. #if DOJIMA
  217. _dojimaPasswordVerified = Util.ParseBool(sec["dojima-password-verified"], false);
  218. #endif
  219. }
  220. private static FormWindowState ParseWindowState(string t) {
  221. if(t=="Minimized")
  222. return FormWindowState.Minimized;
  223. else if(t=="Maximized")
  224. return FormWindowState.Maximized;
  225. else
  226. return FormWindowState.Normal;
  227. }
  228. private static int ParseInt(string value, int def) {
  229. try {
  230. if(value.Length==0) return def;
  231. return Int32.Parse(value);
  232. }
  233. catch(Exception) {
  234. return def;
  235. }
  236. }
  237. private static bool ParseBool(string value, bool def) {
  238. try {
  239. if(value.Length==0) return def;
  240. return Boolean.Parse(value);
  241. }
  242. catch(Exception) {
  243. return def;
  244. }
  245. }
  246. private static float ParseFloat(string value, float def) {
  247. try {
  248. if(value.Length==0) return def;
  249. return Single.Parse(value);
  250. }
  251. catch(Exception) {
  252. return def;
  253. }
  254. }
  255. private static ChartFormat ParseChartFormat(string value) {
  256. if(value=="Monthly")
  257. return ChartFormat.Monthly;
  258. else if(value=="Weekly")
  259. return ChartFormat.Weekly;
  260. else if (value == "Yearly")
  261. return ChartFormat.Yearly;
  262. else // daily
  263. return ChartFormat.Daily;
  264. }
  265. private static DataFeedAction ParseDataFeedAction(string value) {
  266. if(value=="None")
  267. return DataFeedAction.None;
  268. else if(value=="DailyDownload")
  269. return DataFeedAction.DailyDownload;
  270. else
  271. return DataFeedAction.FullDownload;
  272. }
  273. #if DOJIMA
  274. private bool _dojimaPasswordVerified;
  275. public bool DojimaPasswordVerified {
  276. get {
  277. return _dojimaPasswordVerified;
  278. }
  279. set {
  280. _dojimaPasswordVerified = value;
  281. }
  282. }
  283. #endif
  284. }
  285. internal class ProxyConfig {
  286. private bool _useIESetting;
  287. private string _address;
  288. private int _port;
  289. public ProxyConfig() {
  290. _useIESetting = true;
  291. }
  292. public bool UseIESetting {
  293. get {
  294. return _useIESetting;
  295. }
  296. set {
  297. _useIESetting = value;
  298. }
  299. }
  300. public string Address {
  301. get {
  302. return _address;
  303. }
  304. set {
  305. _address = value;
  306. }
  307. }
  308. public int Port {
  309. get {
  310. return _port;
  311. }
  312. set {
  313. _port = value;
  314. }
  315. }
  316. public void SaveTo(StorageNode node) {
  317. node["use-ie-proxy"] = _useIESetting.ToString();
  318. node["proxy-address"] = _address;
  319. node["proxy-port"] = _port.ToString();
  320. }
  321. public void Load(StorageNode node) {
  322. _useIESetting = Util.ParseBool(node["use-ie-proxy"], true);
  323. _address = node["proxy-address"];
  324. _port = Util.ParseInt(node["proxy-port"], 80);
  325. }
  326. }
  327. }
Download Printable view

URL of this paste

Embed with JavaScript

Embed with iframe

Raw text