internal void WriteInputItem(InputItem item) { if (!Settings.Engine.WriteSessionRestoringLog) { return; } if (!recorded_InputItem_ids.Contains(item.__Id)) { if (item.__State != InputItemState.NEW) { throw new Exception("InputItem has state not NEW but was not recorded."); } recorded_InputItem_ids.Add(item.__Id); Dictionary <string, TagItem> tag_item_names2tag_item = item.GetTagItemNames2TagItem(); foreach (KeyValuePair <string, TagItem> n2ti in tag_item_names2tag_item) { if (recorded_TagItem_ids.Contains(n2ti.Value.__Id)) { continue; } recorded_TagItem_ids.Add(n2ti.Value.__Id); if (!restoring) { writeElement(n2ti.Value.GetType().Name, new { id = n2ti.Value.__Id, seed = n2ti.Value.GetSeed() }); } } Dictionary <string, object> d = new Dictionary <string, object>(); d["id"] = item.__Id; d["state"] = item.__State; d["seed"] = item.GetSeed(); if (item.__Queue.Name != item.GetType().Name) { d["queue"] = item.__Queue.Name; } if (item.__ParentItem != null) { d["parent_id"] = item.__ParentItem.__Id; } foreach (KeyValuePair <string, TagItem> kv in tag_item_names2tag_item) { d["id_of_" + kv.Key] = kv.Value.__Id; } if (!restoring) { writeElement(item.GetType().Name, d); } } else if (!restoring) { writeElement(item.GetType().Name, new { id = item.__Id, state = item.__State }); } }
internal void LogInputItem(InputItem item) { if (items_xtw == null) { return; } lock (this) { try { Dictionary <string, TagItem> tag_item_name2tag_items = item.GetTagItemName2TagItems(); foreach (KeyValuePair <string, TagItem> n2ti in tag_item_name2tag_items) { if (logged_input_and_tag_item_ids.Contains(n2ti.Value.__Id)) { continue; } logged_input_and_tag_item_ids.Add(n2ti.Value.__Id); items_xtw.WriteStartElement(n2ti.Value.GetType().Name); items_xtw.WriteAttributeString("id", n2ti.Value.__Id.ToString()); items_xtw.WriteAttributeString("seed", n2ti.Value.GetSeed()); items_xtw.WriteEndElement(); } items_xtw.WriteStartElement(item.GetType().Name); items_xtw.WriteAttributeString("id", item.__Id.ToString()); items_xtw.WriteAttributeString("state", ((uint)item.__State).ToString()); if (!logged_input_and_tag_item_ids.Contains(item.__Id)) { logged_input_and_tag_item_ids.Add(item.__Id); if (item.__Queue.Name != item.GetType().Name) { items_xtw.WriteAttributeString("queue", item.__Queue.Name); } items_xtw.WriteAttributeString("seed", item.GetSeed()); if (item.__ParentItem != null) { items_xtw.WriteAttributeString("parent_id", item.__ParentItem.__Id.ToString()); } foreach (KeyValuePair <string, TagItem> kv in tag_item_name2tag_items) { items_xtw.WriteAttributeString("id_of_" + kv.Key, kv.Value.__Id.ToString()); } } //else if (item.__State == InputItemState.NEW) // throw new Exception("Logged item has state NEW"); items_xtw.WriteEndElement(); } catch (Exception e) { LogMessage.Exit(e); } items_xtw.Flush(); } }
virtual public void __Processor(InputItem item) { MethodInfo mi; if (input_item_types2processor_mi.TryGetValue(item.GetType(), out mi)) { mi.Invoke(this, new object[] { item }); } throw new Exception("No appropriate processor found for " + item.GetType()); }
/// <summary> /// Add item to queue. It is possible to create a named queue. /// Preferred method for adding items. /// </summary> /// <param name="queue_name"></param> /// <param name="item"></param> /// <returns></returns> public bool Add(string queue_name, InputItem item) { if (queue_name == null) { queue_name = item.GetType().Name; } InputItemQueue iiq = Session.GetInputItemQueue(queue_name); return(InputItem.Add2Queue(iiq, current_item, item)); }
/// <summary> /// Add item to queue. It is possible to create a named queue. /// It is the same like BotCycle.Add() but not so efficient. /// </summary> /// <param name="queue_name"></param> /// <param name="item"></param> static public bool Add(string queue_name, InputItem item) { if (queue_name == null) { queue_name = item.GetType().Name; } InputItemQueue iiq = Session.GetInputItemQueue(queue_name); return(InputItem.Add2Queue(iiq, BotCycle.GetCurrentInputItemForThisThread(), item)); }
/// <summary> /// Invoked by default if no particulare processor definition was found. /// </summary> virtual public void PROCESSOR(InputItem item) { //__input_item_type2processor_actions[item.GetType()](item); try { __input_item_type2processor_mis[item.GetType()].Invoke(this, new object[] { item }); } catch (TargetInvocationException e) { throw e.InnerException; } }
virtual public void __Processor(InputItem item) { MethodInfo mi; if (input_item_types2processor_mi.TryGetValue(item.GetType(), out mi)) { mi.Invoke(this, new object[] { item }); } else { Session.This.__Processor(item); } }
void set_parent_members(InputItem parent_item) { lock (item_type2parent_field_fis) { this.GetType().GetField("__ParentItem", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(this, parent_item); foreach (FieldInfo fi in item_type2parent_field_fis[this.GetType()]) { for (InputItem ii = __ParentItem; ii != null; ii = ii.__ParentItem) { if (fi.FieldType != ii.GetType()) { continue; } fi.SetValue(this, ii); break; } //if (fi.GetValue(this) == null) // throw new Exception("Field " + fi.Name + " of " + fi.FieldType + " type is not parent for " + this.GetType()); } } }