public static WutLinkPoco GetPocoFromObject(WutLink obj) { var emails = (obj.UserAssignments.Count == 0) ? "" : string.Join(", ", obj.UserAssignments.Select(o => { return((o.User != null) ? o.User.PrimaryEmail : o.UserEmail); } )); var res = new WutLinkPoco { LinkId = obj.WutLinkId, Comments = obj.Comments, CreateDate = obj.CreateDate, CreatedByIp = obj.CreatedByIp, IsProtected = obj.IsProtected, UserId = obj.UserId, RealUrl = obj.RealUrl, ShortUrl = obj.ShortUrl, UserEmails = emails, IsAzureBlob = obj.IsAzureBlob }; res.UserEmailColl.AddRange(obj.UserAssignments.Select(u => u.UserEmail).ToList()); return(res); }
public WutLink GetUrl(string shortKey) { WutLink url = null; //check local cache var gid = Cache.UrlColl.SingleOrDefault(a => a.Key == shortKey); if (gid.Value == null) { //check Redis cache var gidObj = TryGetRedisValue(urlcache, shortKey); if (gidObj.HasValue) { url = JsonConvert.DeserializeObject <WutLink>(gidObj.ToString()); //if we're here, it wasn't in the local cache (server restarted) SetLocalUrl(url); } else { //Go to SQL url = wutContext.WutLinks.SingleOrDefault(g => g.ShortUrl == shortKey); //update local and remote cache SetUrl(url); } } else { url = JsonConvert.DeserializeObject <WutLink>(gid.Value); } return(url); }
public bool SetUrl(WutLink url) { try { if (isRedisConnected && conn.IsConnected) { urlcache.StringSet(url.ShortUrl, JsonConvert.SerializeObject(url)); } SetLocalUrl(url); return(true); } catch (Exception ex) { Logging.WriteDebugInfoToErrorLog("Error updating or adding url cache", ex); return(false); } }
public bool RemoveUrl(WutLink url) { try { if (isRedisConnected && conn.IsConnected) { urlcache.KeyDelete(url.ShortUrl); } string sOut; Cache.UrlColl.TryRemove(url.ShortUrl, out sOut); return(true); } catch (Exception ex) { Logging.WriteDebugInfoToErrorLog("Error deleting url from cache", ex); return(false); } }
public void SetLocalUrl(WutLink url) { Cache.UrlColl.AddOrUpdate(url.ShortUrl, JsonConvert.SerializeObject(url)); }