public static Dictionary <string, string> HTTPPost(string postUrl, string paramData) { LW.D("HTTP - POST-rqst: " + postUrl + " WITH DATA : " + paramData); byte[] byteArray = Encoding.UTF8.GetBytes(paramData); HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl)); webReq.Method = "POST"; webReq.ContentType = "application/x-www-form-urlencoded"; webReq.ContentLength = byteArray.Length; Stream newStream = webReq.GetRequestStream(); newStream.Write(byteArray, 0, byteArray.Length); newStream.Flush(); newStream.Close(); newStream.Dispose(); HttpWebResponse response = (HttpWebResponse)webReq.GetResponse(); StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8); string ret = sr.ReadToEnd(); sr.Close(); response.Close(); LW.D("HTTP - POST-rply: " + ret); Dictionary <string, string> dict = new Dictionary <string, string>(); foreach (KeyValuePair <string, object> item in JsonConvert.DeserializeObject <Dictionary <string, object> >(ret)) { dict.Add(item.Key, item.Value == null ? "" : item.Value.ToString()); } return(dict); }
public static bool InitialiseExcryptor() { LW.D("Initialising WeChat Data Packet Encryptor....."); WeChatEncryptor = new WXEncryptedXMLHelper(XConfig.Current.WeChat.sToken, XConfig.Current.WeChat.AESKey, XConfig.Current.WeChat.CorpID); LW.D("WeChat Data Packet Encryptor Initialisation Finished!"); return(true); }
public static Dictionary <string, string> HTTPGet(string URL) { LW.D("HTTP - GET-rqst: " + URL); HttpWebRequest request = WebRequest.Create(URL) as HttpWebRequest; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream); string resp = reader.ReadToEnd(); LW.D("HTTP - GET-rply: " + resp); return(JsonConvert.DeserializeObject <Dictionary <string, string> >(resp)); }
public ExcelApplication() { try { ExcelApp = new Excel.Application(); IsExcelOpened = true; LW.E("Excel Opened!"); } catch (Exception ex) { LW.E("Excel Opening Error: " + ex.Message); } }
public static bool ToParsedObject <T>(this string JSON, out T data) { try { data = JsonConvert.DeserializeObject <T>(JSON); return(data != null); } catch (Exception ex) { LW.E(ex); data = default(T); return(false); } }
public bool OpenExcelFile(string FilePath, bool ReadOnly, bool Editable) { try { xWorkbook = ExcelApp.Workbooks._Open(FilePath, ReadOnly: ReadOnly, Editable: Editable); LW.E($"Excel Open File Seccess: FilePath: {FilePath}, ReadOnly: {ReadOnly.ToString()}"); return(true); } catch (Exception ex) { LW.E("Excel Open File Error: " + ex.Message); return(false); } }
public static bool ReNewWCCodes() { LW.D("Started Renew WeChat Operation Codes....."); LW.D("\tChecking Access Tickets..."); if (AvailableTime_Ticket.Subtract(DateTime.Now).TotalMilliseconds <= 0) { InitialiseWeChatCodes(); return(false); } LW.D("\tChecking Tokens..."); if (AvailableTime_Token.Subtract(DateTime.Now).TotalMilliseconds <= 0) { InitialiseWeChatCodes(); return(false); } return(true); }
private static bool InitialiseWeChatCodes() { LW.D("Query New WeChat Keys...."); Dictionary <string, string> JSON; LW.D("\tGetting Access Token...."); JSON = PublicTools.HTTPGet(GetAccessToken_Url); AccessToken = JSON["access_token"]; AvailableTime_Token = DateTime.Now.AddSeconds(int.Parse(JSON["expires_in"])); LW.D("\tGetting Ticket...."); JSON = PublicTools.HTTPGet("https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=" + AccessToken); AccessTicket = JSON["ticket"]; AvailableTime_Ticket = DateTime.Now.AddSeconds(int.Parse(JSON["expires_in"])); LW.D("WeChat Keys Initialised Successfully!"); return(true); }
public bool QuitExcel() { try { ExcelApp.Quit(); IsExcelOpened = false; LW.E("Excel Quited!"); return(true); } catch (Exception ex) { LW.E("Excel Quiting Error: " + ex.Message); return(false); } GC.Collect(); GC.WaitForPendingFinalizers(); }
public static bool LoadConfig(string ConfigFile) { LW.D("Reading Config...."); if (!File.Exists(ConfigFile)) { return(false); } string ConfigString = File.ReadAllText(ConfigFile); var config = JsonConvert.DeserializeObject <ConfigCollection>(ConfigString); LW.D("Finished Reading Config...."); LW.D("Loading Config...."); if (config == null) { LW.E("Failed Load Config.... Exiting..."); return(false); } Current = config; LW.D("Finished Loading Config...."); return(true); }
public static bool LoadMessages(string MessageFile) { LW.D("Reading Messages...."); if (!File.Exists(MessageFile)) { return(false); } string ConfigString = File.ReadAllText(MessageFile); var msg = JsonConvert.DeserializeObject <LocalisedMessages>(ConfigString); LW.D("Finished Reading Messages...."); LW.D("Loading Messages...."); if (msg == null) { LW.E("Failed Load Messages.... Exiting..."); return(false); } Messages = msg; LW.D("Finished Loading Messages...."); return(true); }