コード例 #1
0
ファイル: Session.Storage.cs プロジェクト: aTiKhan/CliverBot
            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 });
                }
            }
コード例 #2
0
        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();
            }
        }