You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
220 lines
6.8 KiB
220 lines
6.8 KiB
using CounsellorBL.BLStructure;
|
|
using log4net;
|
|
using log4net.Config;
|
|
using Microsoft.Extensions.Configuration;
|
|
using MonumentDefine;
|
|
using Newtonsoft.Json;
|
|
using OT.COM.SignalerMessage;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace TaskUserConnect
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
#region 自定義變量區
|
|
|
|
private readonly static ILog mo_Log = LogManager.GetLogger(typeof(Form1));
|
|
private readonly Dictionary<string, string> dicAppSetting = new Dictionary<string, string>();
|
|
public Form1()
|
|
{
|
|
LoadLog4netConfig();
|
|
mo_Log.Info("Form1 Constructor start");
|
|
InitializeComponent();
|
|
GetConfig();
|
|
mo_Log.Info("Form1 Constructor End");
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 頁面事件觸發區
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
{
|
|
string sMsg = null;
|
|
mo_Log.Info("Form1 Form1_Load start");
|
|
try
|
|
{
|
|
_HandlePost();
|
|
Thread.Sleep(500);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sMsg = ex.Message;
|
|
}
|
|
if (sMsg != null)
|
|
{
|
|
mo_Log.Info($"Form1_Load end with exception. {sMsg}");
|
|
}
|
|
else
|
|
{
|
|
mo_Log.Info($"Form1_Load end Success.");
|
|
}
|
|
this.Close();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 私有方法區
|
|
|
|
#region LoadLog4netConfig
|
|
/// <summary>
|
|
/// 加載Log4netConfig
|
|
/// </summary>
|
|
private static void LoadLog4netConfig()
|
|
{
|
|
var repository = LogManager.CreateRepository(
|
|
Assembly.GetEntryAssembly(),
|
|
typeof(log4net.Repository.Hierarchy.Hierarchy)
|
|
);
|
|
XmlConfigurator.Configure(repository, new FileInfo("Log4Net.config"));
|
|
}
|
|
#endregion
|
|
|
|
#region GetConfig
|
|
/// <summary>
|
|
/// 取得設定值
|
|
/// </summary>
|
|
private void GetConfig()
|
|
{
|
|
mo_Log.Info($"Form1 GetConfig start. Current Dir={Directory.GetCurrentDirectory()}");
|
|
|
|
IConfigurationRoot configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build();
|
|
|
|
IEnumerable<IConfigurationSection> ics = configuration.GetSection("appSettings").GetChildren();
|
|
|
|
foreach (IConfigurationSection ic in ics)
|
|
{
|
|
dicAppSetting.Add(ic.Key, ic.Value);
|
|
}
|
|
|
|
mo_Log.Info("Form1 GetConfig end");
|
|
}
|
|
#endregion
|
|
|
|
private static string _Action(string i_sURL, string i_sAppId, string i_sModule, string i_sMethod, out CResponseMessage o_crpResult,
|
|
Dictionary<string, object> i_ldicPara)
|
|
{
|
|
string sMsg;
|
|
|
|
CResponseMessage crpResult = null;
|
|
try
|
|
{
|
|
do
|
|
{
|
|
SendWebApiRequest swr = new SendWebApiRequest();
|
|
CRequestMessage crm = new CRequestMessage()
|
|
{
|
|
module = i_sModule,
|
|
method = i_sMethod,
|
|
param = i_ldicPara,
|
|
customparam = new Dictionary<string, object>() { { BLWording.APP_ID, i_sAppId } }//把appid傳過去
|
|
};
|
|
|
|
CReqestPack crqp = new CReqestPack
|
|
{
|
|
Reqs = new List<CReqestItem>()
|
|
{
|
|
new CReqestItem(){ Req = crm }
|
|
}
|
|
};
|
|
|
|
sMsg = swr.RunEncryptRequest(i_sURL, crqp, out string sResult);
|
|
if (sMsg != null)
|
|
{
|
|
mo_Log.Error($"Result = {sMsg}");
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
mo_Log.Info($"Response = {sResult}");
|
|
|
|
CResponsePack crppResult = JsonConvert.DeserializeObject<CResponsePack>(sResult);
|
|
|
|
if (crppResult == null)
|
|
{
|
|
sMsg = "Covert CResponsePack Fail";
|
|
break;
|
|
}
|
|
CResponseMessage crp = crppResult.Reps[0];
|
|
|
|
if (crp.result == EResponseResult.RR_FALSE)
|
|
{
|
|
sMsg = crp.msg;
|
|
break;
|
|
}
|
|
crpResult = crp;
|
|
}
|
|
}
|
|
while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sMsg = ex.Message;
|
|
}
|
|
|
|
o_crpResult = crpResult;
|
|
return sMsg;
|
|
}
|
|
|
|
private string FbCheckToken(string i_sURL,string i_sAppId ,string i_sModule, out CResponseMessage o_crpResult,
|
|
Dictionary<string, object> i_dicData, Dictionary<string, object> i_dicWhere)
|
|
{
|
|
mo_Log.Info("FbCheckToken");
|
|
|
|
Dictionary<string, object> dicPara = new Dictionary<string, object>();
|
|
dicPara.Add(BLWording.QRY_MASTER, new List<Dictionary<string, object>>() { new Dictionary<string, object>() {
|
|
{ BLWording.DATA, i_dicData },
|
|
{ BLWording.WHEREDATA, i_dicWhere }
|
|
} });
|
|
|
|
return _Action(i_sURL, i_sAppId, i_sModule, "FbCheckToken", out o_crpResult, dicPara);
|
|
}
|
|
|
|
private void _HandlePost()
|
|
{
|
|
string sMsg = null;
|
|
|
|
mo_Log.Info("Start _HandlePost");
|
|
try
|
|
{
|
|
do
|
|
{
|
|
string g_apiServer = dicAppSetting["apiserver"];
|
|
string strAppId = dicAppSetting["app_id"];
|
|
string sServerURL = g_apiServer;
|
|
string sURL = $"{sServerURL}/Cmd";
|
|
|
|
mo_Log.Debug("_HandlePost f1");
|
|
|
|
FbCheckToken(sURL, strAppId, "GROUP.GroupUserConnectService", out CResponseMessage crpArticleWait, null,null);
|
|
|
|
mo_Log.Debug("_HandlePost f2");
|
|
}
|
|
while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sMsg = $"Process fail. ErrorMsg={ex.Message}";
|
|
}
|
|
|
|
if (sMsg != null)
|
|
{
|
|
mo_Log.Error(sMsg);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|