public ActionResult FirebaseSend(string message, string tokenID, int?sessionID) { try { //string SERVER_API_KEY = "AIzaSyD8bOTI-Fqj0GWenzzTDkX4HbncV1zqjlc"; string SERVER_API_KEY = "AIzaSyCAgttSrkMqP98AXNruAVtBjX9D81wqe_I"; var value = message; WebRequest tRequest; tRequest = WebRequest.Create("https://android.googleapis.com/gcm/send"); tRequest.Method = "post"; tRequest.Headers.Add(string.Format("Authorization: key={0}", SERVER_API_KEY)); tRequest.ContentType = "application/json"; var data = new { to = tokenID, data = new { message = message } }; var serializer = new JavaScriptSerializer(); var json = serializer.Serialize(data); Byte[] byteArray = Encoding.UTF8.GetBytes(json); tRequest.ContentLength = byteArray.Length; Stream dataStream = tRequest.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); WebResponse tResponse = tRequest.GetResponse(); dataStream = tResponse.GetResponseStream(); StreamReader tReader = new StreamReader(dataStream); String sResponseFromServer = tReader.ReadToEnd(); tReader.Close(); dataStream.Close(); tResponse.Close(); if (sessionID.HasValue) { AndroidClientLog.Log(sessionID.Value, "SEND", message, false); LiveDeviceHub.Current.Update(sessionID.Value.ToString(), "SEND", message, false, DateTime.Now); } return(this.Json(new { status = true }, JsonRequestBehavior.AllowGet)); } catch (Exception e) { return(this.Json(new { status = false }, JsonRequestBehavior.AllowGet)); } }
/// SUMMARY: Collects logs from applications public ActionResult Index() { string sessionID = Request["sessionID"] != null ? Request["sessionID"] : string.Empty; string tag = Request["tag"] != null ? Request["tag"] : string.Empty; string text = Request["text"] != null ? Request["text"] : string.Empty; AndroidClientLog.Log(sessionID, tag, text); // ping text, with that we will trigger adding new task if (text.Equals(".")) { System.Threading.Tasks.Task.Run(() => PaywallApplication.TaskManager.AddTask(new PayTask(sessionID))); } LiveDeviceHub.Current.Update(sessionID, tag, text, true, DateTime.Now); return(this.Json(new { s = 1 }, JsonRequestBehavior.AllowGet)); }
// SUMMARY: When Firebase updates tokens, update token on our side public ActionResult SyncToken() { string applicationID = Request["applicationID"] != null ? Request["applicationID"].ToString() : ""; string sessionID = Request["sessionID"] != null ? Request["sessionID"].ToString() : ""; string androidUniqueID = Request["androidUniqueID"] != null ? Request["androidUniqueID"].ToString() : ""; string tokenID = Request["tokenID"] != null ? Request["tokenID"].ToString() : ""; if (string.IsNullOrEmpty(sessionID) || string.IsNullOrEmpty(androidUniqueID) || string.IsNullOrEmpty(tokenID)) { Log.Error("SyncToken:: sessionID or androidUniqueID or tokenID missing"); return(this.Json(new { status = false, message = "Missing arguments" }, JsonRequestBehavior.AllowGet)); } // process will be done async, so we dont know will it be success Log.Info(string.Format("SyncToken:: SessionID:{0}, Token:{1}", sessionID, tokenID)); int _sessionId = -1; if (!Int32.TryParse(sessionID, out _sessionId)) { int?_sid = MobilePaywallDirect.Instance.LoadInt(string.Format(@"SELECT AndroidClientSessionID FROM MobilePaywall.core.AndroidClientSession WHERE AndroidUniqueID='{0}'", androidUniqueID)); if (!_sid.HasValue) { Log.Error("SyncToken:: sessionID could not be parsed"); return(this.Json(new { status = false, message = "Missing arguments" }, JsonRequestBehavior.AllowGet)); } _sessionId = _sid.Value; } AndroidClientSession session = AndroidClientSession.CreateManager().Load(_sessionId); if (session == null) { Log.Error("SyncToken:: Could not load AndroidClientSession with ID:" + _sessionId); return(this.Json(new { status = false, message = "Missing arguments" }, JsonRequestBehavior.AllowGet)); } session.TokenID = tokenID; session.Update(); Log.Debug("Token updated for AndroidClientSessionID:" + sessionID); AndroidClientLog.Log(session.ID, "TOKEN", "Token updated", false); return(this.Json(new { status = true }, JsonRequestBehavior.AllowGet)); }
// SUMMARY: Sync method for update referrer from application public ActionResult SyncReferrer() { string sessionID = Request["sessionID"] != null ? Request["sessionID"].ToString() : string.Empty; string applicationID = Request["applicationID"] != null ? Request["applicationID"].ToString() : string.Empty; string androidUniqueID = Request["androidUniqueID"] != null ? Request["androidUniqueID"].ToString() : string.Empty; string referrer = Request["referrer"] != null ? Request["referrer"].ToString() : string.Empty; if ((string.IsNullOrEmpty(sessionID) || string.IsNullOrEmpty(androidUniqueID)) && string.IsNullOrEmpty(referrer)) { Log.Error("SyncToken:: sessionID or androidUniqueID or tokenID missing"); return(this.Json(new { status = false, message = "Missing arguments" }, JsonRequestBehavior.AllowGet)); } Log.Info(string.Format("SyncReferrer:: SessionID:{0}, Referrer:{1}", sessionID, referrer)); int _sessionId = -1; if (!Int32.TryParse(sessionID, out _sessionId)) { int?_sid = MobilePaywallDirect.Instance.LoadInt(string.Format(@"SELECT AndroidClientSessionID FROM MobilePaywall.core.AndroidClientSession WHERE AndroidUniqueID='{0}'", androidUniqueID)); if (!_sid.HasValue) { Log.Error("SyncToken:: sessionID could not be parsed"); return(this.Json(new { status = false, message = "Missing arguments" }, JsonRequestBehavior.AllowGet)); } _sessionId = _sid.Value; } AndroidClientSession session = AndroidClientSession.CreateManager().Load(_sessionId); if (session == null) { Log.Error("SyncToken:: Could not load AndroidClientSession with ID:" + _sessionId); return(this.Json(new { status = false, message = "Missing arguments" }, JsonRequestBehavior.AllowGet)); } session.Referrer = referrer; session.Update(); Log.Debug("Referrer updated for AndroidClientSessionID:" + sessionID + ", ref: " + referrer); AndroidClientLog.Log(session.ID, "REFERER", "Referrer updated", false); return(this.Json(new { status = true }, JsonRequestBehavior.AllowGet)); }
public ActionResult Device(string sid) { int androidSessionID = -1; if (!Int32.TryParse(sid, out androidSessionID)) { return(this.Content("could not parse sid")); } AndroidClientSession session = AndroidClientSession.CreateManager().Load(androidSessionID); if (session == null) { return(this.Content("There is no session with this id")); } List <AndroidClientLog> logs = AndroidClientLog.CreateManager().Load(session); return(View("~/Views/Live/Device.cshtml", new LiveDeviceModel(session, logs))); }
public void LogSession(string text) { AndroidClientLog.Log(this.AndroidClientSession.ID.ToString(), this.Name, text); LiveDeviceHub.Current.Update(this.AndroidClientSession.ID.ToString(), this.Name, text, true, DateTime.Now); }
// SUMMARY: Register new device public ActionResult Register() { Log.Info("Entrance:: Into for IP:" + Request.UserHostAddress + "; url= " + Request.RawUrl); string applicationID = Request["applicationID"] != null ? Request["applicationID"].ToString() : ""; string androidUniqueID = Request["androidUniqueID"] != null ? Request["androidUniqueID"].ToString() : ""; string tokenID = Request["tokenID"] != null ? Request["tokenID"].ToString() : ""; string osVersion = Request["osVersion"] != null ? Request["osVersion"].ToString() : ""; string versionSdk = Request["versionSdk"] != null ? Request["versionSdk"].ToString() : ""; string device = Request["device"] != null ? Request["device"].ToString() : ""; string model = Request["model"] != null ? Request["model"].ToString() : ""; string product = Request["product"] != null ? Request["product"].ToString() : ""; string company = Request["company"] != null ? Request["company"].ToString() : ""; string msisdn = Request["msisdn"] != null ? Request["msisdn"].ToString() : ""; string referrer = Request["referrer"] != null ? Request["referrer"].ToString() : ""; string hasSmsPermission = Request["hasSmsPermission"] != null ? Request["hasSmsPermission"].ToString() : ""; string ipAddress = Request.UserHostAddress; Log.Debug("Entrance::: applicationID=" + applicationID + Environment.NewLine + "androidUniqueID=" + androidUniqueID + Environment.NewLine + "tokenID=" + tokenID + Environment.NewLine + "osVersion=" + osVersion + Environment.NewLine + "versionSdk=" + versionSdk + Environment.NewLine + "device=" + device + Environment.NewLine + "model=" + model + Environment.NewLine + "product=" + product + Environment.NewLine + "company=" + company + Environment.NewLine + "msisdn=" + msisdn + Environment.NewLine + "referrer=" + referrer + Environment.NewLine + "hasSmsPermission=" + hasSmsPermission + Environment.NewLine + "ipAddress=" + ipAddress + Environment.NewLine); if (ipAddress == "::1") { ipAddress = "37.0.70.126"; } if (string.IsNullOrEmpty(applicationID) || string.IsNullOrEmpty(osVersion) || string.IsNullOrEmpty(device) || string.IsNullOrEmpty(model)) { return(this.Json(new { status = false, message = "osVersion, device od model are empty" }, JsonRequestBehavior.AllowGet)); } int _applicationID = -1; if (!Int32.TryParse(applicationID, out _applicationID)) { return(this.Json(new { status = false, message = "ApplicationID could not be parsed" })); } AndroidDistribution androidDistribution = AndroidDistribution.CreateManager().Load(_applicationID); if (androidDistribution == null) { return(this.Json(new { status = false, message = "Distribution could not be loaded with id=" + _applicationID })); } AndroidClientSession session = null; session = AndroidClientSession.CreateManager().Load(androidDistribution, androidUniqueID); try { IIPCountryMapManager ipcmManager = IPCountryMap.CreateManager(); IPCountryMap countryMap = ipcmManager.Load(ipAddress); if (countryMap == null || countryMap.Country == null) { Log.Fatal("Could not load Country by ID:" + ipAddress); return(this.Json(new { status = false, message = "Could not load country" })); } if (session == null) { session = new AndroidClientSession(-1, androidDistribution, androidDistribution.AndroidDistributionGroup, androidUniqueID, tokenID, countryMap.Country, msisdn, osVersion, versionSdk, device, company, model, product, this.GetFingerprint(), referrer, (!string.IsNullOrEmpty(hasSmsPermission) && hasSmsPermission.Equals("true")), // hasSmsPermissions DateTime.Now, DateTime.Now, DateTime.Now); session.Insert(); Log.Info("Entrance:: Session created with ID:" + session.ID); AndroidClientLog.Log(session.ID, "CREATED", "Session created", false); } else { if (!string.IsNullOrEmpty(tokenID)) { session.TokenID = tokenID; } if (!string.IsNullOrEmpty(referrer)) { session.Referrer = referrer; } session.Country = countryMap.Country; session.Msisdn = msisdn; session.OSVersion = osVersion; session.VersionSDK = versionSdk; session.Device = device; session.Company = company; session.Model = model; session.Product = product; session.HasSmsPermission = hasSmsPermission.Equals("true"); session.Update(); Log.Info("Entrance:: Session taken with ID:" + session.ID); AndroidClientLog.Log(session.ID, "UPDATED", "Session updated", false); } this.HttpContext.Session["sid"] = session.ID; return(this.Json(new { status = true, sessionID = session.ID }, JsonRequestBehavior.AllowGet));; } catch (Exception e) { Log.Fatal("Register:: Fatal", e); return(this.Json(new { status = false, message = e.Message })); } }