public async Task <List <Host> > GetListOfHostAsync() { var db = _redisCache.GetDatabase(RedisDatabases.CacheData); var value = await db.HashGetAllAsync("HostId"); var list = value.Select(c => Newtonsoft.Json.JsonConvert.DeserializeObject <Host>(c.Value)); return(list.ToList()); }
public async Task <MembershipData> FindMembershipByStickyIdAsync(long stickyId) { var membershipData = new MembershipData { StickyUserId = stickyId }; var redisDb = _redisCache.GetDatabase(RedisDatabases.UserSegmentsZero); //var redisData = await redisDb.StringGetAsync(stickyId.ToString()); var redisDruidData = await redisDb.StringGetAsync("Full_General:" + stickyId.ToString()); var redisRequestDb = _redisCache.GetDatabase(RedisDatabases.UserSegmentsRequest); //Adding General Segment Membership if (redisDruidData.HasValue) { membershipData.Segments.AddRange(Newtonsoft.Json.JsonConvert.DeserializeObject <List <UserSegment> >(redisDruidData)); } else { await redisRequestDb.ListLeftPushAsync($"Empty_General", stickyId); } //Adding Special Segment Membership var excludedSegments = await _redisCache.GetDatabase(RedisDatabases.CacheData).StringGetAsync("ExcludedSegments"); if (excludedSegments.HasValue) { var excludedIds = excludedSegments.ToString().Split(','); foreach (var exid in excludedIds) { var specialSegmentData = await redisDb.StringGetAsync($"Full_{exid}:" + stickyId.ToString()); if (specialSegmentData.HasValue) { membershipData.Segments.AddRange(Newtonsoft.Json.JsonConvert.DeserializeObject <List <UserSegment> >(specialSegmentData)); } else { await redisRequestDb.ListLeftPushAsync($"Empty_{exid}", stickyId); } } } //Adding Special Segment Membership var redisCategoryData = await redisDb.StringGetAsync("Full_Category:" + stickyId.ToString()); if (redisCategoryData.HasValue) { membershipData.Segments.AddRange(Newtonsoft.Json.JsonConvert.DeserializeObject <List <UserSegment> >(redisCategoryData)); } else { await redisRequestDb.ListLeftPushAsync($"Empty_Category", stickyId); } return(membershipData); }
public async Task <HostProduct> FindProduct(int hostId, string productId) { var db = _redisCache.GetDatabase(RedisDatabases.CacheData); var current = await db.HashGetAsync("Host_" + hostId.ToString() + "_Products", productId); if (current.HasValue) { return(Newtonsoft.Json.JsonConvert.DeserializeObject <HostProduct>(current)); } return(new HostProduct()); }
public async Task <RedisSegment> FindSegmentAsync(int segmentId) { var database = _redisCache.GetDatabase(RedisDatabases.CacheData); var data = await database.HashGetAsync("Segments", segmentId.ToString()); if (data.HasValue) { return(Newtonsoft.Json.JsonConvert.DeserializeObject <RedisSegment>(data)); } return(new RedisSegment()); }
public async Task IncreaseClick(string fullloghash, string uniqueId) { var cachedDb = _redisCache.GetDatabase(RedisDatabases.CacheData); if ((await cachedDb.StringGetAsync("FullClickLog")).HasValue) { var db = _redisCache.GetDatabase(RedisDatabases.SegmentStats); await db.HashIncrementAsync("Clicks", uniqueId, 1); await db.HashIncrementAsync("FullClickLog", fullloghash); } }
public async Task <Partner> FindPartner(string hashCode) { Partner partner = new Partner(); IDatabase db = _redisCache.GetDatabase(RedisDatabases.CacheData); var result = (await db.HashGetAsync("Partners", hashCode)); if (result.HasValue) { partner = Newtonsoft.Json.JsonConvert.DeserializeObject <Partner>(result); } return(partner); }
public async Task UpdateTotalVisit(int hostId) { var database = _redisCache.GetDatabase(RedisDatabases.UserTotalVisits); var hashkey = DateTime.Now.ToString("yyyy_MM_dd"); await database.HashIncrementAsync(hostId.ToString(), hashkey); //using (SqlConnection sqlConnection = new SqlConnection(_configurations.ConnectionString)) //{ // SqlCommand sqlCommand = new SqlCommand("UpdateTotalVisit", sqlConnection); // sqlCommand.CommandType = CommandType.StoredProcedure; // sqlCommand.Parameters.AddWithValue("@HostId", hostId); // await sqlConnection.OpenAsync(); // await sqlCommand.ExecuteNonQueryAsync(); // sqlConnection.Close(); //} }
public async Task <long?> FindStickyUserIdAsync(int partnerId, string userId) { IDatabase db = _redisCache.GetDatabase(RedisDatabases.PartnerCookieMatch); var cachedUserId = await db.StringGetAsync($"{partnerId.ToString()}:{userId}"); if (cachedUserId.HasValue) { return(int.Parse(cachedUserId)); } IMongoDatabase _database = _mongoClient.GetDatabase("TrackEm"); IMongoCollection <PartnersCookieMatch> CookieMatches = _database.GetCollection <PartnersCookieMatch>(name: "Partner_" + partnerId + "_CookieMatch", settings: new MongoCollectionSettings() { AssignIdOnInsert = true }); var filter_Builder = Builders <PartnersCookieMatch> .Filter; var filter = filter_Builder.Eq(c => c.Id, userId); var userData = await CookieMatches.Find(filter).Limit(1).FirstOrDefaultAsync(); if (userData == null) { return(null); } await db.StringSetAsync($"{partnerId.ToString()}:{userId}", userData.StickyId.ToString(), TimeSpan.FromHours(2)); return(userData.StickyId); }
public async Task <List <HostProduct> > FindResultAsync(string key) { var database = _redisCache.GetDatabase(RedisDatabases.ResultZero); var data = await database.StringGetAsync(key); if (data.HasValue) { return(ZeroFormatter.ZeroFormatterSerializer.Deserialize <List <HostProduct> >(data)); } else if (!data.HasValue) { var database2 = _redisCache.GetDatabase(RedisDatabases.EmptyResult); await database2.ListLeftPushAsync("EmptyResult", key); } return(new List <HostProduct>()); }
public async Task LogError(string error) { var logdb = _redisCache.GetDatabase(RedisDatabases.Logs); var key = Guid.NewGuid().ToString(); await logdb.StringSetAsync(key, error); await logdb.KeyExpireAsync(key, DateTime.Now.AddMinutes(3)); }
public VerficateCode GetVerficationCode(string lastid = default(string)) { if (!string.IsNullOrEmpty(lastid)) { _redisCache.GetDatabase().KeyDelete(string.Format(V_CODE_FORMAT, lastid)); } string code = StringGenerator.GetMixString(4); byte[] image = VerificationCode.Generate(code, DrawFormat.Png); VerficateCode vcode = new VerficateCode(); vcode.Image = string.Format("data:image/png;base64,{0}", Convert.ToBase64String(image)); vcode.AntiForgetCode = Guid.NewGuid().ToShortGuidString().ToLower(); Task.Factory.StartNew(() => { string key = string.Format(V_CODE_FORMAT, vcode.AntiForgetCode); _redisCache.Set(key, code, TimeSpan.FromMinutes(5)); }); return(vcode); }
public async Task <List <string> > GetBlockedCategoriesForHostAsync(int hostId) { List <string> blockedCategories = new List <string>(); IDatabase db = _redisCache.GetDatabase(RedisDatabases.BlockedCategory); var result = await db.HashGetAllAsync(hostId.ToString()); if (result.Any()) { foreach (var resultItem in result) { blockedCategories.Add(resultItem.Value.ToString()); } } return(blockedCategories); }
public async Task UpdateBuyValidation(int hostId) { await _redisCache.GetDatabase(RedisDatabases.ResponseTiming).HashSetAsync(hostId.ToString(), "Buy", true); }
public async Task AddUserToCrowlers(long userId) { IDatabase db = _redisCache.GetDatabase(RedisDatabases.CacheData); await db.HashSetAsync("Crowlers", userId, userId); }
public async Task <AdvertisingText> CreateAdvertisingText(int segmentId, string name, int?price) { if (price == null || price == 0) { return new AdvertisingText() { ProductText = name, TemplateText = "NoTemplate" } } ; if (name.Contains("مدل")) { name = name.Split("مدل")[0]; } if (name.Contains("طرح")) { name = name.Split("طرح")[0]; } if (name.Contains(" کد ")) { name = name.Split(" کد ")[0]; } var database = _redisCache.GetDatabase(RedisDatabases.TextTemplateV2); var templates = await database.HashGetAllAsync(segmentId.ToString()); List <string> acceptedTemplates = new List <string>(); var count = templates.Count(); if (count == 0) { return new AdvertisingText() { ProductText = name, TemplateText = "NoTemplate" } } ; foreach (var item in templates) { var templateData = item.Value.ToString().Split("%%%"); var templateBody = templateData[0]; var minprice = int.Parse(templateData[1]); var maxPrice = int.Parse(templateData[1]); if ((maxPrice == 0 && minprice == 0) || (maxPrice == 0 && minprice != 0 && price >= minprice) || (minprice == 0 && maxPrice != 0 && price <= maxPrice) || (minprice != 0 && maxPrice != 0 && price <= maxPrice && price >= minprice)) { acceptedTemplates.Add(templateBody); } } if (acceptedTemplates.Count() == 0) { return new AdvertisingText() { ProductText = name, TemplateText = "NoTemplate" } } ; var templateFinalText = acceptedTemplates.OrderBy(c => Guid.NewGuid()).FirstOrDefault().ToString(); var templateCp = templateFinalText; templateFinalText = templateFinalText.Replace("@Name", name); if (templateFinalText.Contains("تومان") || templateFinalText.Contains("تومن")) { templateFinalText = templateFinalText.Replace("@Price", ((price ?? 0) / 10).ToString("N0")); } else { templateFinalText = templateFinalText.Replace("@Price", ((price ?? 0)).ToString("N0")); } return(new AdvertisingText() { ProductText = templateFinalText, TemplateText = templateCp }); }
public async Task LogResponseTime(long timePeriod, double counter) { var categoryDatabase = _redisCache.GetDatabase(RedisDatabases.ResponseTiming); var str = timePeriod < 10 ? "10" : timePeriod < 20 ? "20" : timePeriod < 30 ? "30" : timePeriod < 40 ? "40" : timePeriod < 50 ? "50" : "BAAAAAAD"; await categoryDatabase.HashIncrementAsync("Timing", str, counter); }
public async Task LogCategory(int hostId, string category, double counter) { var categoryDatabase = _redisCache.GetDatabase(RedisDatabases.Categories); await categoryDatabase.HashIncrementAsync(hostId.ToString(), category, counter); }
public async Task <long> GetNewUserIdAsync() { var db = _redisCache.GetDatabase(RedisDatabases.CacheData); return(await db.StringIncrementAsync("UniqueCookieNumber")); }