private IList<int> GetCardMedia(int cardid, Side side, WordType? type) { IList<int> ids = new List<int>(); IList<IMedia> mediaList = Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.GetIdentifier(CacheObject.CardMedia, cardid)] as IList<IMedia>; if (mediaList != null) { foreach(DbMedia cms in mediaList) if(cms.Side == side && (!type.HasValue || cms.Type == type)) ids.Add(cms.Id); return ids; } using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser)) { using (NpgsqlCommand cmd = con.CreateCommand()) { cmd.CommandText = "SELECT id, media_type,side,type,is_default FROM \"Cards_MediaContent\" JOIN \"MediaContent\" ON media_id=id WHERE cards_id=:cardid;"; cmd.Parameters.Add("cardid", cardid); NpgsqlDataReader reader = PostgreSQLConn.ExecuteReader(cmd, Parent.CurrentUser); mediaList = new List<IMedia>(); while (reader.Read()) { IMedia newMedia = null; int id = Convert.ToInt32(reader["id"]); EMedia mtype = (EMedia)Enum.Parse(typeof(EMedia), Convert.ToString(reader["media_type"])); Side cside = (Side)Enum.Parse(typeof(Side), Convert.ToString(reader["side"])); WordType wordtype = (WordType)Enum.Parse(typeof(WordType), Convert.ToString(reader["type"])); bool isDefault = Convert.ToBoolean(reader["is_default"]); switch (mtype) { case EMedia.Audio: newMedia = new DbAudio(id, cardid, false, cside, wordtype, isDefault, (wordtype == WordType.Sentence), Parent); break; case EMedia.Image: newMedia = new DbImage(id, cardid, false, cside, wordtype, isDefault, (wordtype == WordType.Sentence), Parent); break; case EMedia.Video: newMedia = new DbVideo(id, cardid, false, cside, wordtype, isDefault, (wordtype == WordType.Sentence), Parent); break; } mediaList.Add(newMedia); if ((newMedia as DbMedia).Side == side && (!type.HasValue || (newMedia as DbMedia).Type == type)) ids.Add((newMedia as DbMedia).Id); } Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.CardMedia, cardid)] = mediaList; return ids; } } }
public Dictionary<CommentarySoundIdentifier, IMedia> GetCommentarySounds(int id) { if ((Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.GetIdentifier(CacheObject.SettingsCommentarySounds, id)] as Dictionary<CommentarySoundIdentifier, IMedia>) == null) { Dictionary<CommentarySoundIdentifier, IMedia> commentarySounds = new Dictionary<CommentarySoundIdentifier, IMedia>(); using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser)) { using (NpgsqlCommand cmd = con.CreateCommand()) { cmd.CommandText = "SELECT media_id, side, type FROM \"CommentarySounds\" WHERE settings_id=:id"; cmd.Parameters.Add("id", id); NpgsqlDataReader reader = PostgreSQLConn.ExecuteReader(cmd, Parent.CurrentUser); while (reader.Read()) { int mediaid = Convert.ToInt32(reader["media_id"]); Side side = (Side)Enum.Parse(typeof(Side), Convert.ToString(reader["side"])); ECommentarySoundType type = (ECommentarySoundType)Enum.Parse(typeof(ECommentarySoundType), Convert.ToString(reader["type"])); IMedia media = new DbAudio(mediaid, -1, false, side, WordType.Word, true, false, Parent); commentarySounds[CommentarySoundIdentifier.Create(side, type)] = media; } } } //Save to Cache Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.SettingsCommentarySounds, id, Cache.DefaultSettingsValidationTime)] = commentarySounds; } return Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.GetIdentifier(CacheObject.SettingsCommentarySounds, id)] as Dictionary<CommentarySoundIdentifier, IMedia>; }
private IList <int> GetCardMedia(int cardid, Side side, WordType?type) { IList <int> ids = new List <int>(); IList <IMedia> mediaList = Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.GetIdentifier(CacheObject.CardMedia, cardid)] as IList <IMedia>; if (mediaList != null) { foreach (DbMedia cms in mediaList) { if (cms.Side == side && (!type.HasValue || cms.Type == type)) { ids.Add(cms.Id); } } return(ids); } using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser)) { using (NpgsqlCommand cmd = con.CreateCommand()) { cmd.CommandText = "SELECT id, media_type,side,type,is_default FROM \"Cards_MediaContent\" JOIN \"MediaContent\" ON media_id=id WHERE cards_id=:cardid;"; cmd.Parameters.Add("cardid", cardid); NpgsqlDataReader reader = PostgreSQLConn.ExecuteReader(cmd, Parent.CurrentUser); mediaList = new List <IMedia>(); while (reader.Read()) { IMedia newMedia = null; int id = Convert.ToInt32(reader["id"]); EMedia mtype = (EMedia)Enum.Parse(typeof(EMedia), Convert.ToString(reader["media_type"])); Side cside = (Side)Enum.Parse(typeof(Side), Convert.ToString(reader["side"])); WordType wordtype = (WordType)Enum.Parse(typeof(WordType), Convert.ToString(reader["type"])); bool isDefault = Convert.ToBoolean(reader["is_default"]); switch (mtype) { case EMedia.Audio: newMedia = new DbAudio(id, cardid, false, cside, wordtype, isDefault, (wordtype == WordType.Sentence), Parent); break; case EMedia.Image: newMedia = new DbImage(id, cardid, false, cside, wordtype, isDefault, (wordtype == WordType.Sentence), Parent); break; case EMedia.Video: newMedia = new DbVideo(id, cardid, false, cside, wordtype, isDefault, (wordtype == WordType.Sentence), Parent); break; } mediaList.Add(newMedia); if ((newMedia as DbMedia).Side == side && (!type.HasValue || (newMedia as DbMedia).Type == type)) { ids.Add((newMedia as DbMedia).Id); } } Parent.CurrentUser.Cache[ObjectLifetimeIdentifier.Create(CacheObject.CardMedia, cardid)] = mediaList; return(ids); } } }