public override IDTableEntry[] GetKeys(string prefix, ID id) { var key = new IdTableIdKey(prefix, id.Guid); if (_idById.ContainsKey(key)) { return _idById[key].ToArray(); } return new IDTableEntry[0]; }
public override void Add(IDTableEntry entry) { var idTableStringKey = new IdTableStringKey(entry.Prefix, entry.Key); if (!_idByKey.ContainsKey(idTableStringKey)) { _idByKey[idTableStringKey] = entry; } var key = new IdTableIdKey(entry.Prefix, entry.ID.Guid); if (!_idById.ContainsKey(key)) { _idById.Add(key, new List<IDTableEntry> {entry}); } }
public IDTableEntry[] GetKeys(string prefix, ID id) { var key = new IdTableIdKey(prefix, id.Guid); //if (_idById.ContainsKey(key)) //{ // return _idById[key].ToArray(); //} _idById[key] = IDTable.GetKeys(prefix, id).ToList(); if (_idById.ContainsKey(key)) { return _idById[key].ToArray(); } return new IDTableEntry[0]; }
internal IDTableEntry Add(string prefix, string key, ID id, ID parentId) { var idTableIdKey = new IdTableIdKey(prefix, id.Guid); var tableEntry = new IDTableEntry(prefix, key, id, parentId, ""); if (!_idById.ContainsKey(idTableIdKey)) { _idById.Add(idTableIdKey, new List<IDTableEntry> { tableEntry }); } var idTableStringKey = new IdTableStringKey(prefix, key); if (!_idByKey.ContainsKey(idTableStringKey)) { _idByKey[idTableStringKey] = tableEntry; } return IDTable.Add(prefix, key, id, parentId); }
public void RemoveID(string prefix, ID id) { var key = new IdTableIdKey(prefix, id.Guid); if (_idById.ContainsKey(key)) { _idById.Remove(key); } IDTable.RemoveID(prefix, id); }
private void LoadDictionaries() { string sql = "SELECT [ID],[Prefix],[Key],[ParentID] FROM IDTable"; string connectionString = ConfigurationManager.ConnectionStrings[_databaseConnectionStringName].ConnectionString; List<IDTableEntry> idTableEntries = new List<IDTableEntry>(); using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); using (SqlCommand command = new SqlCommand(sql, connection)) { using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { idTableEntries.Add( new IDTableEntry( reader.GetString(1), reader.GetString(2), ID.Parse(reader.GetGuid(0)), ID.Parse(reader.GetGuid(3)), "" )); } } } } _idByKey = new Dictionary<IdTableStringKey, IDTableEntry>(); _idById = new Dictionary<IdTableIdKey, List<IDTableEntry>>(); foreach (IDTableEntry entry in idTableEntries) { IdTableStringKey idTableStringKey = new IdTableStringKey(entry.Prefix, entry.Key); if (!_idByKey.ContainsKey(idTableStringKey)) { _idByKey.Add(idTableStringKey, entry); } IdTableIdKey idTableIdKey = new IdTableIdKey(entry.Prefix, entry.ID.Guid); if (!_idById.ContainsKey(idTableIdKey)) { _idById.Add(idTableIdKey, new List<IDTableEntry> { entry }); } else { _idById[idTableIdKey].Add(entry); } } }