public void RemoveLink(Link link) { if (link == null) throw new ArgumentNullException("link"); if (!links.Contains(link)) return; links.Remove(link); }
public void AddLink(Link link) { if (link == null) throw new ArgumentNullException("link"); if (links.Contains(link)) return; links.Add(link); }
private void SaveArtistLink(Artist artist, Link link) { if (artist == null || link == null) return; var artistId = cache.GetArtistId(artist); if (artistId == 0) return; var id = cache.GetArtistLinkId(link); if (id > 0) { database.UpdateArtistLink(connection, link, id, artistId); } else { id = database.InsertArtistLink(connection, link, artistId); cache.Add(id, artist, link); } }
public void Add(uint id, Artist artist, Link link) { if (artistLinksById.ContainsKey(id)) return; var artistId = GetArtistId(artist); if (artistId == 0) return; artistLinksById.Add(id, link); if (linksByArtistId.ContainsKey(artistId)) { if (linksByArtistId[artistId].Contains(link)) return; linksByArtistId[artistId].Add(link); } else linksByArtistId[artistId] = new List<Link> { link }; }
private void LoadArtistLinks(IDbConnection connection, GlobalCache cache) { var command = GetCommand(connection, "select * from ArtistLink;"); using (var reader = command.ExecuteReader()) { while (reader.Read()) { var id = (uint)reader.GetInt64(0); var artist = cache.GetArtist((uint)reader.GetInt64(1)); var name = reader.GetString(2); var relationship = (Relationship)reader.GetInt32(3); var source = (Source)reader.GetInt32(4); var target = reader.GetString(5); if (artist == null) continue; var link = new Link(name, relationship, source, target); cache.Add(id, artist, link); artist.AddLink(link); } } }
private void SaveWorkLink(Work work, Link link) { if (work == null || link == null) return; var workId = cache.GetWorkId(work); if (workId == 0) return; var id = cache.GetWorkLinkId(link); if (id > 0) { database.UpdateWorkLink(connection, link, id, workId); } else { id = database.InsertWorkLink(connection, link, workId); cache.Add(id, work, link); } }
public void Add(uint id, Work work, Link link) { if (workLinksById.ContainsKey(id)) return; var workId = GetWorkId(work); if (workId == 0) return; workLinksById.Add(id, link); if (linksByWorkId.ContainsKey(workId)) { if (linksByWorkId[workId].Contains(link)) return; linksByWorkId[workId].Add(link); } else linksByWorkId[workId] = new List<Link> { link }; }
public uint GetWorkLinkId(Link link) { if (link == null) return 0; return workLinksById.Where(x => x.Value == link).FirstOrDefault().Key; }
public void Remove(Work work, Link link) { var id = GetWorkLinkId(link); if (id == 0) return; if (!workLinksById.ContainsKey(id)) return; var workId = GetWorkId(work); if (linksByWorkId.ContainsKey(workId)) { if (linksByWorkId[workId].Contains(link)) linksByWorkId[workId].Remove(link); } workLinksById.Remove(id); }
public void Remove(Artist artist, Link link) { var id = GetArtistLinkId(link); if (id == 0) return; if (!artistLinksById.ContainsKey(id)) return; var artistId = GetArtistId(artist); if (linksByArtistId.ContainsKey(artistId)) { if (linksByArtistId[artistId].Contains(link)) linksByArtistId[artistId].Remove(link); } artistLinksById.Remove(id); }
public void UpdateWorkLink(IDbConnection connection, Link link, uint id, uint workId) { if (!link.IsChanged) return; var command = connection.CreateCommand(); AddParameter(command, "@Work", workId); AddParameter(command, "@Name", link.Name); AddParameter(command, "@Relationship", (ushort)link.Relationship); AddParameter(command, "@Source", (ushort)link.Source); AddParameter(command, "@Target", link.Target); AddParameter(command, "@Id", id); command.CommandText = "update WorkLink set Work = @Work, Name = @Name, Relationship = @Relationship, Source = @Source, Target = @Target where Id = @Id;"; command.ExecuteNonQuery(); }
public uint InsertWorkLink(IDbConnection connection, Link link, uint workId) { var command = connection.CreateCommand(); AddParameter(command, "@Work", workId); AddParameter(command, "@Name", link.Name); AddParameter(command, "@Relationship", (ushort)link.Relationship); AddParameter(command, "@Source", (ushort)link.Source); AddParameter(command, "@Target", link.Target); command.CommandText = "insert into WorkLink (Work, Name, Relationship, Source, Target) values (@Work, @Name, @Relationship, @Source, @Target); select last_insert_rowid();"; var result = command.ExecuteScalar(); uint id = 0; return (result != null && uint.TryParse(result.ToString(), out id)) ? id : 0; }