Пример #1
0
        private void importToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var    path         = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "//ComediaNotes.json";
            string input_string = File.ReadAllText(path);

            JsonSerializer serializer = new JsonSerializer();

            using (StreamReader sr = new StreamReader(path))
            {
                ISession session = SQLiteSessionManager.GetCurrentSession();
                using (ITransaction transaction = session.BeginTransaction())
                {
                    while (sr.Peek() >= 0)
                    {
                        var jsonString = sr.ReadLine();
                        var resnote    = JsonConvert.DeserializeObject <Note>(jsonString);
                        if (resnote.Term != null)
                        {
                            Term term = DBHelper.GetAllWithRestrictionsEq <Term>("Name", resnote.Term.Name)[0];
                            term.AddNote(resnote);
                            DBUtil <Term> dBUtilTerm = new DBUtil <Term>();
                            dBUtilTerm.save(term);
                        }

                        session.Merge(resnote);
                    }

                    transaction.Commit();
                }
            }
        }
Пример #2
0
        private void importToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            // Import term first
            {
                var path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "//ComediaTerms.json";

                using (StreamReader sr = new StreamReader(path))
                {
                    ISession session = SQLiteSessionManager.GetCurrentSession();

                    while (sr.Peek() >= 0)
                    {
                        var jsonString = sr.ReadLine();
                        var resnote    = JsonConvert.DeserializeObject <Term>(jsonString);
                        using (ITransaction transaction = session.BeginTransaction())
                        {
                            resnote.Id = 0;



                            session.SaveOrUpdate(resnote);
                            transaction.Commit();
                        }
                    }
                }
            }
            {
                var path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "//ComediaNotes.json";

                using (StreamReader sr = new StreamReader(path))
                {
                    while (sr.Peek() >= 0)
                    {
                        var jsonString = sr.ReadLine();
                        var resnote    = JsonConvert.DeserializeObject <Note>(jsonString);
                        resnote.Id = 0;
                        ISession session = SQLiteSessionManager.GetCurrentSession();
                        using (ITransaction transaction = session.BeginTransaction())
                        {
                            if (resnote.Term != null)
                            {
                                Term term = DBHelper.GetAllWithRestrictionsEq <Term>("Name", resnote.Term.Name)[0];
                                term.AddNote(resnote);
                                session.SaveOrUpdate(term);
                            }


                            session.SaveOrUpdate(resnote);
                            transaction.Commit();
                        }
                    }
                }
            }
        }
Пример #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            var name     = textBoxName.Text;
            var bookName = "Inferno";

            if (textBoxBook.Text == "2")
            {
                bookName = "Purgatorio";
            }
            if (textBoxBook.Text == "3")
            {
                bookName = "Paridiso";
            }
            Note note = new Note
            {
                Name       = name,
                Commentary = textBoxCommentary.Text
            };

            note.Loc = new Loc
            {
                Book  = bookName,
                Canto = int.Parse(textBoxCanto.Text),
                Start = int.Parse(textBoxStart.Text),
                End   = int.Parse(textBoxEnd.Text),
            };
            if (checkBoxTerm.Checked == true)
            {
                var terms = _dBUtilTerm.GetAllWithOrRestrictionsStringInsentiveLike("Name", name, "Alias");
                if (terms == null || terms.Count == 0)
                {
                    var itemType = (string)comboBoxTermItemType.SelectedItem;
                    var term     = new Term
                    {
                        Name = name
                    };
                    if (!string.IsNullOrEmpty(itemType))
                    {
                        if (itemType == "Item")
                        {
                            itemType = "Metaphor";
                        }
                        ;
                        term.SetMetaphorItem(itemType, "");

                        switch (itemType)
                        {
                        case "Place":
                        {
                            var placeUtil = new DBUtil <Place>();
                            var places    = placeUtil.GetAllWithOrRestrictionsStringInsentiveLike("Name", name, "Alias");
                            if (places == null || places.Count == 0)
                            {
                                var place = new Place
                                {
                                    Name = name
                                };
                                placeUtil.save(place);
                            }
                        }
                        break;

                        case "Politician":
                        {
                            var placeUtil = new DBUtil <Politician>();
                            var places    = placeUtil.GetAllWithOrRestrictionsStringInsentiveLike("Name", name, "Alias");
                            if (places == null || places.Count == 0)
                            {
                                var place = new Politician
                                {
                                    Name = name
                                };
                                placeUtil.save(place);
                            }
                        }
                        break;

                        case "Poet":
                        {
                            var placeUtil = new DBUtil <Poet>();
                            var places    = placeUtil.GetAllWithOrRestrictionsStringInsentiveLike("Name", name, "Alias");
                            if (places == null || places.Count == 0)
                            {
                                var place = new Poet
                                {
                                    Name = name
                                };
                                placeUtil.save(place);
                            }
                        }
                        break;

                        case "Character":
                        {
                            var placeUtil = new DBUtil <Character>();
                            var places    = placeUtil.GetAllWithOrRestrictionsStringInsentiveLike("Name", name, "Alias");
                            if (places == null || places.Count == 0)
                            {
                                var place = new Character
                                {
                                    Name = name
                                };
                                placeUtil.save(place);
                            }
                        }
                        break;

                        case "Person":
                        {
                            var personUtil = new DBUtil <Person>();
                            var people     = personUtil.GetAllWithOrRestrictionsStringInsentiveLike("Name", name, "Alias");
                            if (people == null || people.Count == 0)
                            {
                                var person = new Person
                                {
                                    Name = name
                                };
                                personUtil.save(person);
                            }
                        }
                        break;
                        }
                    }
                    term.AddNote(note);
                    _dBUtilTerm.save(term);
                }
                else
                {
                    var term = terms[0];
                    term.AddNote(note);
                    _dBUtilTerm.save(term);
                }
            }
            _dBUtilNote.save(note);
        }
Пример #4
0
        public static void build_notes()
        {
            var midway = new Note
            {
                Name       = "midway",
                Commentary = "Dante was 35 years old, 1300 C.E.",
                Loc        = new Loc
                {
                    Book  = "Inferno",
                    Canto = 1,
                    Start = 1,
                    End   = 1,
                }
            };
            var forest = new Note
            {
                Name = "wood",
                Loc  = new Loc
                {
                    Book  = "Inferno",
                    Canto = 1,
                    Start = 2,
                    End   = 2,
                }
            };
            Term wood = DBHelper.GetAllWithRestrictionsEq <Term>("Name", "wood")[0];

            if (wood != null)
            {
                wood.AddNote(forest);
            }

            var leopardNote = new Note
            {
                Loc = new Loc
                {
                    Book  = "Inferno",
                    Canto = 1,
                    Start = 33,
                    End   = 33,
                }
            };
            Term leopard = DBHelper.GetAllWithRestrictionsEq <Term>("Name", "leopard")[0];

            leopard.AddNote(leopardNote);

            ISession session1 = SQLiteSessionManager.GetCurrentSession();

            using (ITransaction transaction = session1.BeginTransaction())
            {
                session1.SaveOrUpdate(midway);
                session1.SaveOrUpdate(forest);

                session1.SaveOrUpdate(leopard);
                if (wood != null)
                {
                    session1.SaveOrUpdate(wood);
                }
                session1.SaveOrUpdate(leopardNote);
                transaction.Commit();
            }
        }
Пример #5
0
        public void init()
        {
            sqliteSessionFactory = new InMemorySqLiteSessionFactory();


            Line line1 = new Line
            {
                Number = 1,
                Text   = "Halfway along our journey to life's end"
            };
            Line line2 = new Line
            {
                Number = 2,
                Text   = "I found myself astray in a dark wood,"
            };
            Line line3 = new Line
            {
                Number = 3,
                Text   = "Since the rightway was no where to be found."
            };
            Line line4 = new Line
            {
                Number = 4,
                Text   = "How hard a thing it is to express the horr"
            };
            Line line5 = new Line
            {
                Number = 5,
                Text   = "of that wild wood, so difficult, so dense"
            };
            Line line6 = new Line
            {
                Number = 6,
                Text   = "Even to think of it renews my terror."
            };
            Canto canto1 = new Canto
            {
                Number = 1
            };

            canto1.AddLine(line1);
            canto1.AddLine(line2);
            canto1.AddLine(line3);
            canto1.AddLine(line4);
            canto1.AddLine(line5);
            canto1.AddLine(line6);

            Book inferno = new Book
            {
                Number = 1,
                Name   = "Inferno"
            };

            inferno.AddCanto(canto1);

            Note note = new Note
            {
                Loc = new Loc
                {
                    Book  = "Inferno",
                    Canto = 1,
                    Start = 2,
                    End   = 2
                }
            };

            Term wildness = new Term
            {
                Name  = "wood",
                Alias = "forest,wildness"
            };

            wildness.AddNote(note);
            wildness.SetMetaphorItem("metaphor", "");

            session = sqliteSessionFactory.Session;
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    Assert.That(note.Id == 0);
                    session.SaveOrUpdate(inferno);
                    session.SaveOrUpdate(note);
                    session.SaveOrUpdate(wildness);

                    transaction.Commit();
                }
            }
        }