Brunet.Services.Dht.TableServerData.UpdateEntry C# (CSharp) Метод

UpdateEntry() публичный Метод

This should be called if an entry already exists as it will find the entry and update its lease time. If an entry does not exist nothing happens.
public UpdateEntry ( MemBlock key, MemBlock value, DateTime end_time ) : void
key MemBlock The index to store the value.
value MemBlock The data to store.
end_time DateTime The lease time for the data.
Результат void
    public void UpdateEntry(MemBlock key, MemBlock value, DateTime end_time) {
      CheckEntries();
      LinkedList<Entry> data = (LinkedList<Entry>) _data[key];
      if(data != null) {
        Entry entry = null;
        LinkedListNode<Entry> current = data.First;
        while(current != null) {
          if (current.Value.Value.Equals(value)) {
            entry = current.Value;
            data.Remove(current);
            break;
          }
          current = current.Next;
        }
        if(entry != null) {
          count--;
          entry.EndTime = end_time;
          AddEntry(entry);
        }
      }
    }

Usage Example

Пример #1
0
        public void Test0()
        {
            RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
            TableServerData          tsd = new TableServerData("0");

            byte[] key = new byte[20];
            rng.GetBytes(key);
            DateTime now = DateTime.UtcNow;
            Entry    ent = new Entry(key, key, now, now.AddSeconds(100));

            tsd.AddEntry(ent);
            LinkedList <Entry> entries = tsd.GetEntries(key);

            Assert.AreEqual(1, entries.Count, "Count after add");
            Assert.AreEqual(ent, entries.First.Value, "Entries are equal");
            tsd.UpdateEntry(ent.Key, ent.Value, now.AddSeconds(200));
            entries = tsd.GetEntries(key);
            Assert.AreEqual(1, entries.Count, "Count after update");
            Assert.AreEqual(ent, entries.First.Value, "Entries are equal");
            tsd.RemoveEntry(ent.Key, ent.Value);
            entries = tsd.GetEntries(key);
            Assert.AreEqual(tsd.Count, 0, "Count after remove");
            Assert.AreEqual(null, entries, "Entry after remove");
        }
All Usage Examples Of Brunet.Services.Dht.TableServerData::UpdateEntry