示例#1
0
        public static void TestJSON()
        {
            Bll.Book book     = new Bll.Book();
            BookJson bookJson = new BookJson(book);

            bookJson.ConnectionString = @"Data/Book2";
            bookJson.Book             = book;
            bookJson.ReadAll();
            Console.WriteLine(bookJson.Message);
            Pl.BookConsole view = new Pl.BookConsole(book);
            view.List();
        }
示例#2
0
        private IBook ConvertJsonBook(BookJson bookJson)
        {
            IBook book = new Book.Book(bookJson.Title);

            foreach (var item in bookJson.Paragraphs)
            {
                IParagraph paragraph = new Paragraph.Paragraph(item.Id, item.Label, item.ColorStart, item.ColorEnd);
                foreach (var answer in item.Answers)
                {
                    paragraph.AddAnswer(new Answer.Answer(answer.Label, answer.Id));
                }
                book.AddParagraph(paragraph);
            }
            return(book);
        }
示例#3
0
 public IBook Read(string path)
 {
     try
     {
         using (var reader = new StreamReader(path))
         {
             string   lines = reader.ReadToEnd();
             BookJson book  = JsonConvert.DeserializeObject <BookJson>(lines);
             return(ConvertJsonBook(book));
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(null);
     }
 }
示例#4
0
        public static void CreateJSON()
        {
            Console.WriteLine("".PadLeft(60, '*'));
            Console.WriteLine("\n\n\nDe BookApp JSON\n\n\n");
            Console.WriteLine("".PadLeft(60, '*'));

            Bll.Book    book    = new Bll.Book();
            Dal.BookXml bookXml = new Dal.BookXml(book);
            bookXml.Book = book;
            bookXml.ReadAll();
            Console.WriteLine(bookXml.Message);


            BookJson bookJson = new BookJson(book);

            bookJson.ConnectionString = @"Data/Book2";
            bookJson.Create();
            Console.WriteLine(bookJson.Message);
        }
示例#5
0
        public List <Book> GetBooks()
        {
            var books = new List <Book>();

            string json;

            using (WebClient wc = new WebClient())
            {
                wc.QueryString.Add("name", "Полужизнь");
                wc.QueryString.Add("k", "20");
                json = wc.DownloadString("http://188.134.65.35");
            }

            BookJson ser = JsonConvert.DeserializeObject <BookJson>(json);

            for (int i = 0; i < 20; i++)
            {
                books.Add(new Book(ser.names[i], ser.authors[i]));
            }

            return(books);
        }