private static void RunTrackableDictionary() { Log.WriteLine("***** TrackableDictionary (Json) *****"); var dict = new TrackableDictionary<int, string>(); dict.SetDefaultTracker(); dict.Add(1, "One"); dict.Add(2, "Two"); dict.Add(3, "Three"); var json = JsonConvert.SerializeObject(dict.Tracker, JsonSerializerSettings); Log.WriteLine(json); dict.Tracker.Clear(); dict.Remove(1); dict[2] = "TwoTwo"; dict.Add(4, "Four"); var json2 = JsonConvert.SerializeObject(dict.Tracker, JsonSerializerSettings); Log.WriteLine(json2); dict.Tracker.Clear(); Log.WriteLine(); }
private static void RunTrackableDictionary() { Log.WriteLine("***** TrackableDictionary (Json) *****"); var dict = new TrackableDictionary <int, string>(); dict.SetDefaultTracker(); dict.Add(1, "One"); dict.Add(2, "Two"); dict.Add(3, "Three"); var json = JsonConvert.SerializeObject(dict.Tracker, JsonSerializerSettings); Log.WriteLine(json); dict.Tracker.Clear(); dict.Remove(1); dict[2] = "TwoTwo"; dict.Add(4, "Four"); var json2 = JsonConvert.SerializeObject(dict.Tracker, JsonSerializerSettings); Log.WriteLine(json2); dict.Tracker.Clear(); Log.WriteLine(); }
private static void RunTrackableDictionary() { Console.WriteLine("***** TrackableDictionary (Protobuf) *****"); var dict = new TrackableDictionary<int, string>(); dict.SetDefaultTracker(); dict.Add(1, "One"); dict.Add(2, "Two"); dict.Add(3, "Three"); var buf = PrintBytes(Serialize(dict.Tracker)); Console.WriteLine(Deserialize<TrackableDictionaryTracker<int, string>>(buf)); dict.Tracker.Clear(); dict.Remove(1); dict[2] = "TwoTwo"; dict.Add(4, "Four"); var buf2 = PrintBytes(Serialize(dict.Tracker)); Console.WriteLine(Deserialize<TrackableDictionaryTracker<int, string>>(buf2)); dict.Tracker.Clear(); Console.WriteLine(); }
private TrackableDictionary <TKey, string> CreateTestDictionary() { var dict = new TrackableDictionary <TKey, string>(); dict.Add(CreateKey(1), "One"); dict.Add(CreateKey(2), "Two"); dict.Add(CreateKey(3), "Three"); return(dict); }
public static int?TryProgress(this TrackableDictionary <int, UserAchievement> dict, AchievementKey key, int increment) { UserAchievement ach; if (dict.TryGetValue((int)key, out ach)) { if (ach.AchieveTime.HasValue) { return(null); } ach = new UserAchievement { Value = ach.Value + increment }; dict[(int)key] = ach; } else { ach = new UserAchievement { Value = increment }; dict.Add((int)key, ach); } return(ach.Value); }
public static bool TryAchieved(this TrackableDictionary <int, UserAchievement> dict, AchievementKey key) { UserAchievement ach; if (dict.TryGetValue((int)key, out ach)) { if (ach.AchieveTime.HasValue) { return(false); } ach = new UserAchievement { AchieveTime = DateTime.UtcNow, Value = ach.Value }; dict[(int)key] = ach; } else { ach = new UserAchievement { AchieveTime = DateTime.UtcNow }; dict.Add((int)key, ach); } return(true); }
public void TestAdd(bool track) { var events = 0; var acc = new Accumulator("test"); var dic = new TrackableDictionary <string, int>(acc, track) { { "one", 1 }, { "two", 2 } }; dic.CollectionChanged += (s, e) => { events++; Assert.AreEqual(e.Action, NotifyCollectionChangedAction.Add); Assert.AreEqual(e.NewItems[0], new KeyValuePair <string, int>("three", 3)); }; dic.Add("three", 3); Assert.IsTrue(dic.ContainsKey("three")); Assert.AreEqual(dic["three"], 3); Assert.AreEqual(1, events); if (track) { Assert.AreEqual(3, acc.Records.Count); } else { Assert.AreEqual(0, acc.Records.Count); } }
public async Task <TrackableDictionary <TKey, TValue> > LoadAsync(DbDataReader reader) { var dictionary = new TrackableDictionary <TKey, TValue>(); while (await reader.ReadAsync()) { dictionary.Add(ConvertToKeyAndValue(reader)); } return(dictionary); }
private TrackableDictionary <TKey, ItemData> CreateTestDictionary() { var dict = new TrackableDictionary <TKey, ItemData>(); var value1 = new ItemData(); value1.Kind = 101; value1.Count = 1; value1.Note = "Handmade Sword"; dict.Add(CreateKey(1), value1); var value2 = new ItemData(); value2.Kind = 102; value2.Count = 3; value2.Note = "Lord of Ring"; dict.Add(CreateKey(2), value2); return(dict); }
private static void RunTrackableDictionary() { Console.WriteLine("***** TrackableDictionary *****"); var dict = new TrackableDictionary<int, string>(); dict.SetDefaultTracker(); dict.Add(1, "One"); dict.Add(2, "Two"); dict.Add(3, "Three"); Console.WriteLine(dict.Tracker); dict.Tracker.Clear(); dict.Remove(1); dict[2] = "TwoTwo"; dict.Add(4, "Four"); Console.WriteLine(dict.Tracker); dict.Tracker.Clear(); Console.WriteLine(); }
private static void RunTrackableDictionary() { Console.WriteLine("***** TrackableDictionary *****"); var dict = new TrackableDictionary <int, string>(); dict.SetDefaultTracker(); dict.Add(1, "One"); dict.Add(2, "Two"); dict.Add(3, "Three"); Console.WriteLine(dict.Tracker); dict.Tracker.Clear(); dict.Remove(1); dict[2] = "TwoTwo"; dict.Add(4, "Four"); Console.WriteLine(dict.Tracker); dict.Tracker.Clear(); Console.WriteLine(); }
private TTrackableContainer CreateTestContainer(bool withTracker) { dynamic container = new TTrackableContainer(); dynamic person = new TTrackablePerson(); container.Person = person; var missions = new TrackableDictionary <int, MissionData>(); container.Missions = missions; var tags = new TrackableList <TagData>(); if (_useList) { container.Tags = tags; } var aliases = new TrackableSet <string>(); if (_useSet) { container.Aliases = aliases; } if (withTracker) { ((ITrackable)container).SetDefaultTracker(); } // Person { person.Name = "Testor"; person.Age = 10; } // Missions { var value1 = new MissionData(); value1.Kind = 101; value1.Count = 1; value1.Note = "Handmade Sword"; missions.Add(1, value1); var value2 = new MissionData(); value2.Kind = 102; value2.Count = 3; value2.Note = "Lord of Ring"; missions.Add(2, value2); } // Tags if (_useList) { tags.Add(new TagData { Text = "Hello", Priority = 1 }); tags.Add(new TagData { Text = "World", Priority = 2 }); } // Aliases if (_useSet) { aliases.Add("alpha"); aliases.Add("beta"); aliases.Add("gamma"); } return(container); }
protected override void Add(TrackableDictionary<TKey, TValue> collection, int index, TKey key, TValue value, MessagePackSerializerOptions options) { collection.Add(key, value); }