private void stopTimeoutChecking() { if (timeoutChecking != null) { keepTimeoutChecking = false; if (timeoutChecking.IsAlive) { timeoutChecking.Abort(); } timeoutChecking = null; } this.retryCnt = 0; this.cd_500ms = CD; GF.devLog("== TimeoutChecking Stoped =="); }
private void websocket_Opened(object sender, EventArgs e) { GF.devLog("[WS][opened]"); //TODO 把以下測試刪掉. 並在此處加上設備的註冊機制. //註冊機制:APP第一次啟動時存住一組GUID, 同時傳給 server. 未來連線時就直接傳這組GUID. var t = new Thread(() => { for (int i = 0; i < 10; i++) { webSocket.Send("Hello World! [" + i + "]"); Thread.Sleep(10000); } StopSelf(); }); t.Start(); }
private void startTimeoutChecking() { stopTimeoutChecking(); if (timeoutChecking == null) { timeoutChecking = new Thread(new ThreadStart(delegate { try { while (keepTimeoutChecking) { if (--cd_500ms < 0) { GF.devLog("[WebView][Timeout] " + this.retryCnt); KToast.showCenterToast(mainActivity, "伺服器無法服務 [" + this.retryCnt + "]", ToastLength.Long); if (this.retryCnt >= Ini.WebViewTimeoutRetry) { mainActivity.RunOnUiThread(delegate { this.webview.LoadUrl(Ini.URL_ERR); }); } else { this.retryCnt++; mainActivity.RunOnUiThread(delegate { this.webview.Reload(); }); } break; } else { GF.devLog("[cd_500ms] " + cd_500ms); Thread.Sleep(500); } } } catch { timeoutChecking = null; } })); timeoutChecking.Start(); GF.devLog("== TimeoutChecking Started =="); } }
private void processCMD(string url) { string jsonStr = url.Remove(0, Ini.CMD_PRFIX.Length); GF.devLog("[jsonStr] " + jsonStr); JObject restoredObject = JsonConvert.DeserializeObject <JObject> (jsonStr); GF.devLog("[method] " + restoredObject ["method"]); switch (restoredObject ["method"].ToString()) { case "yo": GF.devLog("[data] N/A"); break; case "yo2": GF.devLog("[data] " + restoredObject ["data"]); GF.devLog("[data.name] " + restoredObject ["data"] ["name"]); GF.devLog("[data.phone] " + restoredObject ["data"] ["phone"]); break; case "startService": mainActivity.StartService(new Intent(mainActivity, typeof(NotificationService))); break; case "stopService": mainActivity.StopService(new Intent(mainActivity, typeof(NotificationService))); break; case "notification": var title = restoredObject ["data"] ["title"].ToString(); var content = restoredObject ["data"] ["content"].ToString(); NotificationToolbox.updateNotification(mainActivity, title, content, "this is extra"); break; case "vibrate": var jArr = restoredObject ["data"] as JArray; long [] pattern = jArr.Select(jv => jv.Value <long> ()).ToArray(); mainActivity.doVibrate(pattern); break; } }
protected override void OnResume() { base.OnResume(); GF.devLog("[OnResume]"); // NOTE 這不會啟動多重的同個 service StartService(new Intent(this, typeof(NotificationService))); // if (Intent.Extras != null) { var msg = Intent.Extras.GetString("msg_from_noti", string.Empty); GF.devLog("[OnResume] extra: " + msg); } else { GF.devLog("[OnResume] no extras"); } // TODO 解析 extra 並做對應動作 }
public static string Encrypt3DES(string msg, string key, string iv) { string resutlt = string.Empty; byte [] arrMsg = System.Text.Encoding.UTF8.GetBytes(msg); var provider = new System.Security.Cryptography.TripleDESCryptoServiceProvider() { Key = System.Text.Encoding.UTF8.GetBytes(GF.getMD5(key)), //Convert.FromBase64String(GF.getMD5(key)), IV = System.Text.Encoding.UTF8.GetBytes(iv), Mode = System.Security.Cryptography.CipherMode.CBC, Padding = System.Security.Cryptography.PaddingMode.PKCS7 }; System.Security.Cryptography.ICryptoTransform ct = provider.CreateEncryptor(); try { var arrResult = ct.TransformFinalBlock(arrMsg, 0, arrMsg.Length); resutlt = Convert.ToBase64String(arrResult); } catch { } return(resutlt); }
protected override void OnMessage(Context context, Intent intent) { Log.Info(TAG, "GCM Message Received!"); //var msg = new StringBuilder(); string msg = string.Empty; int type = 0; //long notiID = 0; string url = string.Empty; //"www.google.com"; if (intent != null && intent.Extras != null) { foreach (var key in intent.Extras.KeySet()) { //msg.AppendLine (key + "=" + intent.Extras.Get (key).ToString ()); if (key == "msg") { msg = intent.Extras.Get(key).ToString(); } else if (key == "type") { int.TryParse(intent.Extras.Get(key).ToString(), out type); } else if (key == "url") { url = intent.Extras.Get(key).ToString(); } } } GF.devLog("[type] ============== " + type.ToString() + " ========="); GF.devLog("[url] ============== " + url + " ========="); //WS_TD888.device_setReceived (notiID); KUserDefault.addNotiCnt(type, 1); if (type < Ini.NotiIdList.Length) { updateNotification(KUserDefault.getNotiCnt(type), msg, Ini.NotiIdList [type], url); BadgeControl.setBadge(context, KUserDefault.getSumNotiCnt()); } /* * switch (type) { * case 0: * KUserDefault.addNotiCnt_0 (1); * updateNotification (KUserDefault.getNotiCnt_0 (), msg, Ini.NotiIdList[0]); * break; * * case 1: * KUserDefault.addNotiCnt_1 (1); * updateNotification (KUserDefault.getNotiCnt_1 (), msg, Ini.NotiIdList[1]); * break; * * case 2: * KUserDefault.addNotiCnt_2 (1); * updateNotification (KUserDefault.getNotiCnt_2 (), msg, Ini.NotiIdList[2]); * break; * * } * * if (type <= 2) { * GF.devLog ("[NotiCnt] " + KUserDefault.getNotiCnt_0 () + ", " + KUserDefault.getNotiCnt_1 () + ", " + KUserDefault.getNotiCnt_2 ()); * BadgeControl.setBadge (context, KUserDefault.getNotiCnt_0 () + KUserDefault.getNotiCnt_1 () + KUserDefault.getNotiCnt_2 ()); * } */ /* * //Store the message * var prefs = GetSharedPreferences(context.PackageName, FileCreationMode.Private); * var edit = prefs.Edit(); * edit.PutString("last_msg", msg.ToString()); * edit.Commit(); * * createNotification("GCM Sample", "Message Received for GCM Sample... Tap to View!"); * * * Log.Info(TAG, "GCM Message Received!"); */ //GF.devLog ("[== Noti Msg ==] " + msg.ToString ()); }
public override void OnWindowFocusChanged(bool hasFocus) { base.OnWindowFocusChanged(hasFocus); GF.devLog("[OnWindowFocusChanged]"); }
private void websocket_Closed(object sender, EventArgs e) { GF.devLog("[WS][closed]"); }
public override IBinder OnBind(Intent intent) { GF.devLog("[SERVICE] OnBind"); return(null); }