private void btn_readFile_Click(object sender, EventArgs e) { // ファイル読み込み string readed_file = File_CTRL.file_Read(txt_readFile.Text); // 各種初期化 dynamic json_obj = ""; bool status = false; string error = ""; string out_put_file_name = ""; if (readed_file.Length > 0) { if (rdo_add_user.Checked) { json_obj = Json_add_user_action.add_user_motion(readed_file, out status, out error); out_put_file_name = "end_init.json"; } if (rdo_request.Checked) { json_obj = Json_request_action.request_motion(readed_file, out status, out error); out_put_file_name = "Response.json"; } if (json_obj != null) { string file_path = System.IO.Path.GetDirectoryName(txt_readFile.Text) + "\\" + out_put_file_name; File_CTRL.file_OverWrite(json_obj.ToString(), file_path); //MessageBox.Show("結果ファイル出力完了!"); } } }
/// <summary> /// 正常操作時の証跡ログ出力ユーティリティ /// </summary> /// <param name="write_obj">出力文字列</param> /// <param name="file_full_path">出力先ファイルパス</param> public static void Write_OK_Log(string write_obj, string file_full_path) { //ファイル出力 try { // App.configのSuccess_log_switchで出力制御を行います // 読み込みはProgramクラス(Program.cs)で行っています。 if (Program.Success_log_switch) { File_CTRL.file_OverWrite(write_obj, file_full_path); } } catch (System.Exception ex) { logger.Error(" 正常処理結果証跡ファイル生成失敗: " + ex.Message); } }
/// <summary> /// EA用のパラメータファイルを出力します。 /// STC_サーバーからOpe_Tagの内容をそのままファイル出力します。 /// </summary> /// <param name="read_req"></param> /// <param name="error"></param> /// <returns></returns> public static bool output_ea_param(dynamic read_req, out string error) { error = ""; try { // 更新or作成前にファイルのタイムスタンプを取得予定地 // mod_ea用のパラメータファイルを比較してチェック string folder_path = File_CTRL.get_folder_path(read_req) + @"\MQL4\Files"; // EAパラメータファイル出力先のパス string read_full_path = folder_path + @"\read_parameters.csv"; DateTime read_parameters = System.IO.File.GetLastWriteTime(read_full_path); // EAパラメータファイル出力先のMT4起動プログラムのパス string out_put_full_path = read_full_path; string param = ""; param += Json_Util.get_Ope_Tag_Value(read_req, "header"); param += "\r\n"; param += Json_Util.get_Ope_Tag_Value(read_req, "param"); File_CTRL.file_OverWrite(param, out_put_full_path, false); // 更新後、ファイルのタイムスタンプが更新されているかチェック予定地 DateTime after_read_parameters = System.IO.File.GetLastWriteTime(read_full_path); TimeSpan timeSpan = after_read_parameters - read_parameters; //DateTime の差が TimeSpan として返る // 更新されたか判定 if ((int)timeSpan.TotalSeconds > 0) { return(true); } return(false); } catch (System.Exception ex) { logger.Error(ex.Message); error = ex.Message; return(false); } }
/// <summary> /// 受け取った最終指示が可能されているdcitをそのままall_setting.txtに書き出します。 /// </summary> /// <param name="dict">全顧客の指示一覧</param> /// <returns>書き込み成功時true,失敗時false</returns> public static bool csv_writer(string file_name, Dictionary <string, string> dict) { try { string write_text = ""; foreach (var pair in dict) { write_text += pair.Key + "," + pair.Value + "\r\n"; } // 指示ファイル上書き指示 //File_CTRL.file_OverWrite(write_text, get_CodeBase_path() + "\\all_setting.txt", false); File_CTRL.file_OverWrite(write_text, get_CodeBase_path() + "\\" + file_name, false); return(true); } catch (System.Exception ex) { // ファイルを開くのに失敗したとき logger.Error(" CSV書き込み失敗: " + ex.Message); return(false); } }
private void btn_http_get_Click(object sender, EventArgs e) { if (!System.IO.Directory.Exists(txt_out_put.Text)) { MessageBox.Show("指定されたフォルダが見当たりません!デスクトップの所定フォルダに強制設定します!"); // パスをend_initとend_ea_add用のフォルダにします string output_path = System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); if (rdo_url_add_user.Checked) { // ユーザー追加 output_path += @"\end_init"; } else if (rdo_url_add_EA.Checked) { // EA追加 output_path += @"\end_ea_add"; } txt_out_put.Text = output_path; } // URL用文字列 string request_machine = ""; string order_url = ""; string add_user = ""; string add_EA = ""; if (txt_get_url.Text == "") { add_user = add_user_url; request_machine = request; add_EA = add_EA_url; } else { add_user = txt_get_url.Text; request_machine = txt_get_url.Text; add_EA = txt_get_url.Text; } // ラジオボタンはadd_userだけだが取り敢えずrequest_machineも分岐してみる if (rdo_url_add_user.Checked) { // ユーザー追加 order_url = add_user; } else if (rdo_url_request.Checked) { // 操作リクエスト order_url = request_machine; } else if (rdo_url_add_EA.Checked) { // EA追加 order_url = add_EA; } dynamic json_obj = ""; bool status = false; string error = ""; string result = http_Request_CTRL.http_get(order_url, out status); if (status) { string out_put_file_name = ""; if (rdo_url_add_user.Checked || rdo_url_add_EA.Checked) { add_mt4_folder(result); /* * json_obj = Json_add_user_action.add_user_motion(result, out status, out error); * * if (json_obj == null) * { * MessageBox.Show("対象データが取得できませんでした!con_setting.txtの記載順でreal_server_urlが2行目ですか?"); * return; * } * /* * //jsonを1レコード単位に分解してファイル出力する * foreach (dynamic read_user in (object[])json_obj) * { * string created_user = read_user.Stc_ID + "_" + read_user.MT4_Server + "_" + read_user.MT4_ID + "_" + read_user.Ccy + "_" + read_user.Time_Period + "_" + read_user.EA_ID; + + System.Console.WriteLine(created_user); + + if (rdo_url_add_user.Checked) + { + // ユーザー追加 + out_put_file_name = "ei_" + created_user + ".json"; + } + else if (rdo_url_add_EA.Checked) + { + // EA追加 + out_put_file_name = "ea_" + created_user + ".json"; + } + + if (read_user != null) + { + File_CTRL.file_OverWrite("[" + read_user.ToString() + "]", txt_out_put.Text + "\\" + out_put_file_name); + + } + + } */ /* * // 登録結果としてインストールフォルダのログを出力して保管 * File_CTRL.get_folders(); * * MessageBox.Show("結果ファイル出力完了!"); * */ } else { json_obj = Json_request_action.request_motion(result, out status, out error); out_put_file_name = "Response.json"; if (json_obj != null) { File_CTRL.file_OverWrite(json_obj.ToString(), txt_out_put.Text + "\\" + out_put_file_name); MessageBox.Show("結果ファイル出力完了!"); } } } else { MessageBox.Show(result); } }
private async void btn_http_post_Click(object sender, EventArgs e) { //if (txt_word.Text != "") //{ // if (!System.IO.File.Exists(txt_word.Text)) // { // MessageBox.Show("ファイルが見つかりません!", "ファイル存在チェック", MessageBoxButtons.OK, MessageBoxIcon.Error); // return; // } //} string request_string = ""; bool status = false; if (txt_word.Text != "") { // ファイル読み込み request_string = File_CTRL.file_Read(txt_word.Text); } else { string get_url = ""; if (rdo_get_url_add_user.Checked) { get_url = add_user_url; } else { get_url = request; } request_string = http_Request_CTRL.http_get(get_url, out status); if (!status) { MessageBox.Show(request_string); return; } } string post_url = ""; if (rdo_stc.Checked) { if (rdo_get_url_add_user.Checked) { post_url = upload; } else { post_url = resultbox; } } if (rdo_kakuninn.Checked) { post_url = "http://www.kojikoji.net/"; } if (rdo_set_post_url.Checked) { post_url = txt_post_url.Text; } if (post_url == "") { MessageBox.Show("post url が未指定です!", "post対象チェック", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // 各種初期化 dynamic json_obj = ""; //bool status = false; string error = ""; if (rdo_get_url_add_user.Checked) { json_obj = Json_add_user_action.add_user_motion(request_string, out status, out error); } else { json_obj = Json_request_action.request_motion(request_string, out status, out error); } if (status) { if (json_obj != null) { //Console.WriteLine("呼出し:" + MT4_CTLR.operation(json_obj)); MessageBox.Show("Http Post開始!"); string result = await http_Request_CTRL.http_post(json_obj.ToString(), post_url); string file_path = System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\結果.html"; File_CTRL.file_OverWrite(result, file_path); MessageBox.Show("Http Post終了!結果.htmlが生成されました"); } else { MessageBox.Show("postするべきデータが作れませんでした"); } } }
/// <summary> /// 指定されたユーザー追加若しくはEA追加データを使ってインストールフォルダの準備を行う /// </summary> /// <param name="add_target">インストールフォルダ生成情報文字列add_user/add_EA</param> /// <returns></returns> private bool add_mt4_folder(string add_target) { MessageBox.Show("デスクトップの所定フォルダに強制設定します!"); // パスをend_initとend_ea_add用のフォルダにします string output_path = System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); if (rdo_url_add_user.Checked) { // ユーザー追加 output_path += @"\end_init"; } else if (rdo_url_add_EA.Checked) { // EA追加 output_path += @"\end_ea_add"; } txt_out_put.Text = output_path; string out_put_file_name = ""; if (rdo_url_add_user.Checked || rdo_url_add_EA.Checked) { dynamic json_obj = ""; bool status = false; string error = ""; json_obj = Json_add_user_action.add_user_motion(add_target, out status, out error); if (json_obj == null) { MessageBox.Show("対象データが取得できませんでした!\n\r対象を選択していますか?\n\rcon_setting.txtの記載順でreal_server_urlが2行目ですか?"); return(false); } //jsonを1レコード単位に分解してファイル出力する foreach (dynamic read_user in (object[])json_obj) { string created_user = read_user.Stc_ID + "_" + read_user.MT4_Server + "_" + read_user.MT4_ID + "_" + read_user.Ccy + "_" + read_user.Time_Period + "_" + read_user.EA_ID; System.Console.WriteLine(created_user); if (rdo_url_add_user.Checked) { // ユーザー追加 out_put_file_name = "ei_" + created_user + ".json"; } else if (rdo_url_add_EA.Checked) { // EA追加 out_put_file_name = "ea_" + created_user + ".json"; } if (read_user != null) { File_CTRL.file_OverWrite("[" + read_user.ToString() + "]", txt_out_put.Text + "\\" + out_put_file_name); } } // 登録結果としてインストールフォルダのログを出力して保管 File_CTRL.get_folders(); MessageBox.Show("結果ファイル出力完了!"); } return(true); }
private static dynamic Create_Install_folder(dynamic json_obj, out string error) { // エラー初期化 error = ""; try { bool status = false; // インストール設定ファイル string ins_file_name = System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); // フォルダ生成 foreach (dynamic read_user in (object[])json_obj) { /* VPSでのMT4大量稼働試験で確認出来た、1つのOSユーザーで多数のMT4を稼働させる方式で検討を進めています。 * 現在の想定は * c:\Users\GFIT\"Stc_ID"\"Broker_Name"\"MT4_ID"\"Ccy"\"Time_Period" * のパスをMT4のインストールパスにしようと考えております。 */ string stc_id = ""; // インストールパス応答初期化 string ins_path = ""; status = File_CTRL.CreateUserFolder(read_user, out stc_id, out ins_path); if (!status) { error = error + " Stc_ID:" + stc_id + "\n\r"; read_user.Check_Status = "NG"; } else { // デスクトップにインストールパス格納ファイル生成 if (MainForm.mt4_opt) { // 動作時オプション有効ボタンがtrueの場合はフォルダ特定可能なので直接セッティングテキストを出力 string files_path = File_CTRL.get_folder_path(read_user) + @"\MQL4\Files"; // filesフォルダーの生成 File_CTRL.file_OverWrite(ins_path, files_path + @"\setting.txt"); // 一旦空でread_parametersファイル出力 string read_full_path = files_path + @"\read_parameters.csv"; string param = ""; File_CTRL.file_OverWrite(param, read_full_path, false); //eaのパラメータファイルを出力する機能を追加 string dummy_error = ""; MT4_CTLR.output_ea_param(read_user, out dummy_error); } else { // 動作時オプション有効ボタンがfalseの場合は手動でセッティングテキストを設定してもらうため任意の場所にファイル出力 File_CTRL.file_OverWrite(ins_path, ins_file_name + "\\" + stc_id + "_setting.txt"); } // 全ユーザーのインストールパス格納ファイルを出力する(稼働監視用) File_CTRL.file_AddWrite(ins_path + ",Setup", File_CTRL.get_CodeBase_path() + "\\all_setting.txt"); } } return(json_obj); } catch (System.Exception ex) { logger.Error(ex.Message); error = "追加時フォルダ生成エラー"; return(null); } }