public void Staleness() { Chat c; List <Chat> chats = new List <Chat>(); chats.Add(c = Chat.Create("c1")); c.SetMeta("dev", "hello"); c.Staleness(2); chats.Add(c = Chat.Create("c2")); c.SetMeta("dev", "2"); c.Staleness(3); chats.Add(c = Chat.Create("c3")); c.SetMeta("dev", "3"); c.Staleness(4); var res = new ChatRuntime(chats).DoFindAll (null, new Constraint(Operator.LT, "staleness", "3")); Assert.That(res.Count, Is.EqualTo(1)); Assert.That(res[0].text, Is.EqualTo("c1")); string[] lines = { "CHAT c0", "FIND {dev=1,day=fri,staleness<5}", "CHAT c1 {day=fri}", "CHAT c2 {dev=2,day=fri}", "CHAT c3 {}" }; string contents = String.Join("\n", lines); chats = ChatParser.ParseText(contents, NO_VALIDATORS); Command finder = chats[0].commands[0]; finder.Resolve(null); Assert.That(finder.GetType(), Is.EqualTo(typeof(Find))); var crt = new ChatRuntime(chats); c = crt.FindChatByLabel("#c1"); c.Staleness(6); Assert.That(c, Is.Not.Null); Assert.That(c.text, Is.EqualTo("c1")); chats = crt.DoFindAll((Find)finder, null); Assert.That(chats, Is.Not.Null); Assert.That(chats.Count, Is.EqualTo(1)); Assert.That(chats[0], Is.Not.Null); Assert.That(chats[0].text, Is.EqualTo("c3")); }
private IUpdateEvent ChatUpdateHandler(ref EventArgs ea, IDictionary <string, object> globals) { IChatUpdate evt = (IChatUpdate)ea; var findBy = evt.FindByCriteria(); var action = evt.GetAction(); ea = null; if (String.IsNullOrEmpty(findBy)) // apply action to all chats { runtime.Chats().ForEach(action); } else if (findBy.StartsWith(Util.LABEL_IDENT, Util.IC)) // to one chat { action.Invoke(runtime.FindChatByLabel(findBy)); } else // to all those matching findBy { UpdateFinder(ref updateDelegate, findBy); runtime.FindAllAsync(updateDelegate, action, globals); } return(null); }
public void StalenessEventTest() { string[] lines = { "CHAT c1 {type=a}", "CHAT c2 {type=a,day=fri}", "CHAT c3 {type=b,day=thurs}", "CHAT c4" }; string contents = String.Join("\n", lines); List <Chat> chats = ChatParser.ParseText(contents, NO_VALIDATORS); ChatRuntime rt = new ChatRuntime(chats); //chats.ForEach(Console.WriteLine); chats.ForEach(c => Assert.That(c.Staleness(), Is.EqualTo(Defaults.CHAT_STALENESS))); EventArgs icu = new StalenessUpdate(5); rt.Update(null, ref icu); chats.ForEach(c => Assert.That(c.Staleness(), Is.EqualTo(5))); icu = new StalenessUpdate(100, "#c4"); rt.Update(null, ref icu); Assert.That(rt.FindChatByLabel("c1").Staleness(), Is.EqualTo(5)); Assert.That(rt.FindChatByLabel("c4").Staleness(), Is.EqualTo(100)); icu = new StalenessUpdate(10, "{!type=a}"); rt.Update(null, ref icu); new AutoResetEvent(false).WaitOne(20); // async hack for C# 4.0 //chats.ForEach(Console.WriteLine); Assert.That(rt.FindChatByLabel("c1").Staleness(), Is.EqualTo(10)); Assert.That(rt.FindChatByLabel("c2").Staleness(), Is.EqualTo(10)); Assert.That(rt.FindChatByLabel("c3").Staleness(), Is.EqualTo(5)); Assert.That(rt.FindChatByLabel("c4").Staleness(), Is.EqualTo(100)); }
internal int Launch(string label, bool resetCursor = true) { return(Launch(runtime.FindChatByLabel(label), resetCursor)); }