示例#1
0
        private void do_ext_add(object sender, RoutedEventArgs e)
        {
            this.update_selected_topic();
            ExternalNote note = new ExternalNote("", DateTime.Now);

            note.topics.Add(this.guid);
            NoteWindow dialog_window = new NoteWindow(this.save_state, note, topics: this.topics)
            {
                Owner = this
            };

            dialog_window.ShowDialog();
            ExternalNote             new_note = dialog_window.get_note() as ExternalNote;
            Dictionary <Guid, Topic> topics   = dialog_window.get_topics();

            if ((new_note is null) || (topics is null))
            {
                return;
            }
            this.add_topics(topics, new_note);
            this.notes[Guid.NewGuid()] = new_note;
            this.topic_cache.Clear();
            this.populate_topic_cache();
            this.set_topic(this.guid);
        }
示例#2
0
        private void do_external_note_add(object sender, RoutedEventArgs e)
        {
            if ((this.topics is null) || (this.notes is null) || (this.save_state is null))
            {
                return;
            }
            ExternalNote note = new ExternalNote("", DateTime.Now);
            Guid?        sel  = this.topic_list.SelectedValue as Guid?;

            if ((sel is not null) && (sel.Value != Guid.Empty))
            {
                note.topics.Add(sel.Value);
            }
            NoteWindow dialog_window = new NoteWindow(this.save_state, note)
            {
                Owner = Window.GetWindow(this)
            };

            dialog_window.ShowDialog();
            ExternalNote             new_note = dialog_window.get_note() as ExternalNote;
            Dictionary <Guid, Topic> topics   = dialog_window.get_topics();

            if ((new_note is null) || (topics is null))
            {
                return;
            }
            this.add_topics(topics, new_note);
            this.notes[Guid.NewGuid()] = new_note;
            this.topic_cache.Clear();
            this.change_callback(null, topics: this.topics, topic_refs: this.topic_refs, notes: this.notes);
        }
示例#3
0
        public void test_serialization()
        {
            ExternalNote foo = new ExternalNote("Some note", DateTime.Now), bar;

            foo.topics.Add(Guid.NewGuid());

            DataContractSerializer fmt = new DataContractSerializer(typeof(ExternalNote));

            using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) {
                fmt.WriteObject(ms, foo);
                ms.Seek(0, System.IO.SeekOrigin.Begin);
                System.Xml.XmlDictionaryReader xr = System.Xml.XmlDictionaryReader.CreateTextReader(ms, new System.Xml.XmlDictionaryReaderQuotas());
                bar = (ExternalNote)(fmt.ReadObject(xr, true));
            }
            Assert.AreEqual(foo.contents, bar.contents);
            Assert.AreEqual(foo.timestamp, bar.timestamp);
            Assert.AreEqual(foo.topics.Count, bar.topics.Count);
            foreach (Guid guid in foo.topics)
            {
                Assert.IsTrue(bar.topics.Contains(guid));
            }
        }
示例#4
0
        private void do_entity_view(object sender, RoutedEventArgs e)
        {
            EntityRow sel = this.entity_list.SelectedValue as EntityRow;

            if ((sel is null) || (sel.type is null) || (sel.guid is null))
            {
                return;
            }

            switch (sel.type.Value)
            {
            //TODO: view selection (ITEM, EVENT, TASK)
            case EntityType.NOTE:
            {
                if (!this.state.notes.notes.ContainsKey(sel.guid.Value))
                {
                    return;
                }
                Note       note          = this.state.notes.notes[sel.guid.Value];
                NoteWindow dialog_window = new NoteWindow(this.save_state, note, this.now, this.topics)
                {
                    Owner = this
                };
                dialog_window.ShowDialog();
                Note new_note = dialog_window.get_note() as Note;
                if (new_note is null)
                {
                    return;
                }
                Dictionary <Guid, int> adjust_topics = new Dictionary <Guid, int>();
                foreach (Guid topic_guid in note.topics)
                {
                    if (!new_note.topics.Contains(topic_guid))
                    {
                        adjust_topics[topic_guid] = -1;
                    }
                }
                foreach (Guid topic_guid in new_note.topics)
                {
                    if (!note.topics.Contains(topic_guid))
                    {
                        adjust_topics[topic_guid] = 1;
                    }
                }
                if ((new_note.contents != note.contents) || (adjust_topics.Count > 0))
                {
                    string contents_from = null, contents_to = null;
                    if (new_note.contents != note.contents)
                    {
                        contents_from = note.contents;
                        contents_to   = new_note.contents;
                        note.contents = contents_to;
                    }
                    if (adjust_topics.Count > 0)
                    {
                        foreach (Guid topic_guid in adjust_topics.Keys)
                        {
                            if (adjust_topics[topic_guid] > 0)
                            {
                                note.topics.Add(topic_guid);
                            }
                            else
                            {
                                note.topics.Remove(topic_guid);
                            }
                        }
                    }
                    else
                    {
                        adjust_topics = null;
                    }
                    this.actions.Add(new ActionNoteUpdate(sel.guid.Value, contents_from, contents_to, adjust_topics));
                    sel._contents = contents_to;
                    if (adjust_topics.Count > 0)
                    {
                        sel.topics.Clear();
                        foreach (Guid topic_guid in note.topics)
                        {
                            if (this.topics.ContainsKey(topic_guid))
                            {
                                sel.topics.Add(new TopicRow(topic_guid, this.topics[topic_guid].name));
                            }
                        }
                        sel.topics.Sort((x, y) => x.name.CompareTo(y.name));
                    }
                    this.entity_list.Items.Refresh();
                }
            }
            break;

            case EntityType.EXTERNAL_NOTE:
            {
                if (!this.notes.ContainsKey(sel.guid.Value))
                {
                    return;
                }
                ExternalNote note          = this.notes[sel.guid.Value];
                NoteWindow   dialog_window = new NoteWindow(this.save_state, note, topics: this.topics)
                {
                    Owner = this
                };
                dialog_window.ShowDialog();
                ExternalNote new_note = dialog_window.get_note() as ExternalNote;
                if (new_note is null)
                {
                    return;
                }
                Dictionary <Guid, int> adjust_topics = new Dictionary <Guid, int>();
                foreach (Guid topic_guid in note.topics)
                {
                    if (!new_note.topics.Contains(topic_guid))
                    {
                        adjust_topics[topic_guid] = -1;
                    }
                }
                foreach (Guid topic_guid in new_note.topics)
                {
                    if (!note.topics.Contains(topic_guid))
                    {
                        adjust_topics[topic_guid] = 1;
                    }
                }
                if ((new_note.contents != note.contents) || (adjust_topics.Count > 0))
                {
                    note.contents = new_note.contents;
                    sel._contents = note.contents;
                    if (adjust_topics.Count > 0)
                    {
                        foreach (Guid topic_guid in adjust_topics.Keys)
                        {
                            if (adjust_topics[topic_guid] > 0)
                            {
                                note.topics.Add(topic_guid);
                            }
                            else
                            {
                                note.topics.Remove(topic_guid);
                            }
                        }
                        sel.topics.Clear();
                        foreach (Guid topic_guid in note.topics)
                        {
                            if (this.topics.ContainsKey(topic_guid))
                            {
                                sel.topics.Add(new TopicRow(topic_guid, this.topics[topic_guid].name));
                            }
                        }
                        sel.topics.Sort((x, y) => x.name.CompareTo(y.name));
                    }
                    this.entity_list.Items.Refresh();
                }
            }
            break;

            default: return;
            }
        }
示例#5
0
        public void test_serialization()
        {
            Character      chr = new Character("Somebody");
            Note           note = new Note("Some note", Guid.NewGuid());
            Task           task = new Task(Guid.NewGuid(), "Some task");
            CalendarEvent  evt = new CalendarEvent(Guid.NewGuid(), 42, "Some event");
            Entry          ent = new Entry(42, DateTime.Now, "Some log entry", 1);
            Topic          topic = new Topic("Some topic");
            ExternalNote   oog_note = new ExternalNote("Some out-of-game note", DateTime.Now);
            CampaignDomain foo = new CampaignDomain(), bar;

            Guid chr_guid = foo.state.characters.add_character(chr);
            Guid inv_guid = foo.state.inventories.new_inventory("Somebody's Inventory");

            foo.state.character_inventory[chr_guid] = inv_guid;
            Guid note_guid  = foo.state.notes.add_note(note);
            Guid task_guid  = foo.state.tasks.add_task(task);
            Guid event_guid = foo.state.events.add_event(evt);

            foo.entries.Add(ent);
            foo.valid_entries = 1;
            Guid topic_guid = Guid.NewGuid();

            foo.topics[topic_guid] = topic;
            Guid oog_note_guid = Guid.NewGuid();

            foo.notes[oog_note_guid] = oog_note;

            DataContractSerializer fmt = new DataContractSerializer(typeof(CampaignDomain));

            using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) {
                fmt.WriteObject(ms, foo);
                ms.Seek(0, System.IO.SeekOrigin.Begin);
                System.Xml.XmlDictionaryReader xr = System.Xml.XmlDictionaryReader.CreateTextReader(ms, new System.Xml.XmlDictionaryReaderQuotas());
                bar = (CampaignDomain)(fmt.ReadObject(xr, true));
            }
            Assert.AreEqual(foo.state.characters.characters.Count, bar.state.characters.characters.Count);
            Assert.IsTrue(bar.state.characters.characters.ContainsKey(chr_guid));
            Assert.AreEqual(bar.state.characters.characters[chr_guid].name, "Somebody");
            Assert.AreEqual(foo.state.inventories.inventories.Count, bar.state.inventories.inventories.Count);
            Assert.IsTrue(bar.state.inventories.inventories.ContainsKey(inv_guid));
            Assert.AreEqual(bar.state.inventories.inventories[inv_guid].name, "Somebody's Inventory");
            Assert.AreEqual(foo.state.character_inventory.Count, bar.state.character_inventory.Count);
            Assert.IsTrue(bar.state.character_inventory.ContainsKey(chr_guid));
            Assert.AreEqual(bar.state.character_inventory[chr_guid], inv_guid);
            Assert.AreEqual(foo.state.notes.notes.Count, bar.state.notes.notes.Count);
            Assert.IsTrue(bar.state.notes.notes.ContainsKey(note_guid));
            Assert.AreEqual(bar.state.notes.notes[note_guid].contents, "Some note");
            Assert.AreEqual(foo.state.tasks.tasks.Count, bar.state.tasks.tasks.Count);
            Assert.IsTrue(bar.state.tasks.tasks.ContainsKey(task_guid));
            Assert.AreEqual(bar.state.tasks.tasks[task_guid].name, "Some task");
            Assert.AreEqual(foo.state.events.events.Count, bar.state.events.events.Count);
            Assert.IsTrue(bar.state.events.events.ContainsKey(event_guid));
            Assert.AreEqual(bar.state.events.events[event_guid].name, "Some event");
            Assert.AreEqual(foo.entries.Count, bar.entries.Count);
            for (int i = 0; i < foo.entries.Count; i++)
            {
                Assert.AreEqual(foo.entries[i].guid, bar.entries[i].guid);
            }
            Assert.AreEqual(foo.valid_entries, bar.valid_entries);
            Assert.AreEqual(foo.topics.Count, bar.topics.Count);
            Assert.IsTrue(bar.topics.ContainsKey(topic_guid));
            Assert.AreEqual(bar.topics[topic_guid].name, "Some topic");
            Assert.AreEqual(foo.notes.Count, bar.notes.Count);
            foreach (Guid guid in foo.notes.Keys)
            {
                Assert.AreEqual(foo.notes[guid].contents, bar.notes[guid].contents);
            }
        }