private static int DAYS_FOR_ACCESS_CHECK = 1; // days for checking if session has accessed service in this days /// SUMMARY: See if this customer has made any transaction in past week public static bool CheckIfSessionHasTransactionIsPastWeek(AndroidClientSession session) { int?count = MobilePaywallDirect.Instance.LoadInt(string.Format(@"SELECT COUNT(*) FROM MobilePaywall.core.AndroidClientSession AS acs LEFT OUTER JOIN MobilePaywall.core.AndroidClientSessionOLCacheMap AS acmap ON acmap.AndroidClientSessionID=acs.AndroidClientSessionID LEFT OUTER JOIN MobilePaywall.core.OLCache AS cache ON cache.OLCacheID=acmap.OLCacheID LEFT OUTER JOIN MobilePaywall.core.Service AS s ON s.ServiceID=cache.ServiceID WHERE acs.AndroidClientSessionID={0} AND cache.IsSubseguent=0 AND cache.TransactionID IS NOT NULL AND cache.SessionCreated >= DATEADD(day,-{1}, GETDATE())", session.ID, DAYS_FOR_TRANSACTION_CHECK)); return(count.HasValue && count.Value > 0); }
/// SUMMARY: Get suatable services for specific country (Based on ServiceInfo ordered by 'Live and Active' and 'Active but no active') /// in witch this customer has not made any PaymentReqeust /// ONLY WAP PAYMENT public static SuitableServiceResponse GetWapService(AndroidClientSession session) { MobilePaywallDirect db = MobilePaywallDirect.Instance; // First we get filter list of all services in which this session has made payment request in past time (7days) List <string> servicesWithPaymentRequest = db.LoadContainer(string.Format(@" SELECT s.Name FROM MobilePaywall.core.AndroidClientSession AS acs LEFT OUTER JOIN MobilePaywall.core.AndroidClientSessionOLCacheMap AS acmap ON acmap.AndroidClientSessionID=acs.AndroidClientSessionID LEFT OUTER JOIN MobilePaywall.core.OLCache AS cache ON cache.OLCacheID=acmap.OLCacheID LEFT OUTER JOIN MobilePaywall.core.Service AS s ON s.ServiceID=cache.ServiceID WHERE acs.AndroidClientSessionID={0} AND cache.PaymentRequestID IS NOT NULL AND cache.IsSubseguent=0 AND cache.SessionCreated >= DATEADD(day,-{1}, GETDATE());", session.ID, DAYS_FOR_PAYMENT_REQUEST_CHECK)).GetStringList("Name"); // Then we filter services in which this session has any access in past day List <string> servicesWithAnyAccess = db.LoadContainer(string.Format(@" SELECT s.Name FROM MobilePaywall.core.AndroidClientSession AS acs LEFT OUTER JOIN MobilePaywall.core.AndroidClientSessionOLCacheMap AS acmap ON acmap.AndroidClientSessionID=acs.AndroidClientSessionID LEFT OUTER JOIN MobilePaywall.core.OLCache AS cache ON cache.OLCacheID=acmap.OLCacheID LEFT OUTER JOIN MobilePaywall.core.Service AS s ON s.ServiceID=cache.ServiceID WHERE acs.AndroidClientSessionID={0} AND cache.SessionCreated >= DATEADD(day,-{1}, GETDATE());", session.ID, DAYS_FOR_ACCESS_CHECK)).GetStringList("Name"); // This is the list of all services that are listed as LIVE AND ACTIVE List <string> suitableActiveServices = db.LoadContainer(string.Format(@" SELECT s.Name AS 'Name' FROM MobilePaywall.core.TemplateServiceInfo AS tsi LEFT OUTER JOIN MobilePaywall.core.Service AS s ON tsi.ServiceID=s.ServiceID WHERE s.FallbackCountryID={0} AND tsi.Progress=5 AND tsi.Color = 2 AND IsPremiumSms=0", session.Country.ID)).GetStringList("Name"); // This is filter list for all services that are listed as NOT LIVE BUT ACTIVE List <string> suitableNonActiveServices = db.LoadContainer(string.Format(@" SELECT s.Name AS 'Name' FROM MobilePaywall.core.TemplateServiceInfo AS tsi LEFT OUTER JOIN MobilePaywall.core.Service AS s ON tsi.ServiceID=s.ServiceID WHERE s.FallbackCountryID={0} AND tsi.Progress=5 AND tsi.Color = 1 AND IsPremiumSms=0", session.Country.ID)).GetStringList("Name"); // randomize active and non active services in one single list Random rand = new Random(); List <string> suitableServices = suitableActiveServices.OrderBy(c => rand.Next()).ToList(); suitableServices.AddRange(suitableNonActiveServices.OrderBy(c => rand.Next()).ToList()); foreach (string service in suitableServices) { if (!servicesWithPaymentRequest.Contains(service) && !servicesWithAnyAccess.Contains(service)) { return(new SuitableServiceResponse(service, false)); } } return(null); }
// 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))); }
/// SUMMARY: Get suatable services for specific country (Based on ServiceInfo ordered by 'Live and Active' and 'Active but no active') /// in witch this customer has not made any PaymentReqeust /// ONLY PSMS PAYMENT public static SuitableServiceResponse GetPsmsService(AndroidClientSession session) { MobilePaywallDirect db = MobilePaywallDirect.Instance; // First we create filter list for every service in which this session has requested PSMS payment List <string> servicesWithPaymentRequest = db.LoadContainer(string.Format(@" SELECT s.Name FROM MobilePaywall.core.AndroidPremiumSmsRequest AS psms LEFT OUTER JOIN MobilePaywall.core.Service AS s ON psms.ServiceID=s.ServiceID WHERE AndroidClientSessionID=1 AND psms.Created >= DATEADD(day,-1, GETDATE());", session.ID, DAYS_FOR_PAYMENT_REQUEST_CHECK)).GetStringList("Name"); List <string> suitableActiveServices = db.LoadContainer(string.Format(@" SELECT s.Name AS 'Name' FROM MobilePaywall.core.TemplateServiceInfo AS tsi LEFT OUTER JOIN MobilePaywall.core.Service AS s ON tsi.ServiceID=s.ServiceID WHERE s.FallbackCountryID={0} AND tsi.Progress=5 AND tsi.Color = 2 AND IsPremiumSms=0", session.Country.ID)).GetStringList("Name"); List <string> suitableNonActiveServices = db.LoadContainer(string.Format(@" SELECT s.Name AS 'Name' FROM MobilePaywall.core.TemplateServiceInfo AS tsi LEFT OUTER JOIN MobilePaywall.core.Service AS s ON tsi.ServiceID=s.ServiceID WHERE s.FallbackCountryID={0} AND tsi.Progress=5 AND tsi.Color = 1 AND IsPremiumSms=0", session.Country.ID)).GetStringList("Name"); // randomize active and non active services in one single list Random rand = new Random(); List <string> suitableServices = suitableActiveServices.OrderBy(c => rand.Next()).ToList(); suitableServices.AddRange(suitableNonActiveServices.OrderBy(c => rand.Next()).ToList()); foreach (string service in suitableServices) { if (!servicesWithPaymentRequest.Contains(service)) { return(new SuitableServiceResponse(service, true)); } } return(null); }
public TaskBase(string name, string sessionID, DateTime executionTime) { int _sessionID = -1; if (!Int32.TryParse(sessionID, out _sessionID)) { Log.Error(string.Format("PayTask:: Could not parse sessionID (sessionID='{0})", sessionID)); this.IsExecuted = true; return; } this._session = AndroidClientSession.CreateManager().Load(_sessionID); if (this._session == null) { Log.Error("PayTask:: Could not load session with id:" + _sessionID); this.IsExecuted = true; return; } this._name = name; this._identifier = Guid.NewGuid(); this._executionTime = executionTime; Log.Debug("Task '" + name + "' is set to be executed in " + this._executionTime.ToString()); }
public LiveDeviceModel(AndroidClientSession session, List <AndroidClientLog> logs) { this._session = session; this._logs = logs; }
// 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 })); } }