Exemplo n.º 1
0
        public IActionResult HttpGetTest()
        {
            //Task<string> taskGetToken = _weChatAPI.GetAccessTokenAsync();
            //taskGetToken.Wait();
            //_logger.Debug(taskGetToken.Result);



            //Task<string> taskGetAccessToken = _weChatAPI.GetAccessTokenAsync();

            //taskGetAccessToken.Wait();

            //string _accessToken = JSONFormatting<AccessToken>.JsonToClass(taskGetAccessToken.Result).access_token;

            string _accessToken = "28_K2O8C0JWZGM2XguSgS8x-frs3nQyiQywTn85uuqubhMhnBGNCmVD96p0YoqtQ7GF_v9_sT9-20ORuN1FDlI4c3ecSZi1Whx3RQbQbocvaTWHq4u_VZEmOopvcBWBh6GjTHuNvmJj2WY91VdZGVBjABANCI";

            _logger.Debug(_accessToken);

            Task <string> getUserInfo = _weChatAPI.GetSubscriberInfo(_accessToken, "oQn7Pv0i5Y65EL-mdgT11KbhLK6g");

            getUserInfo.Wait();

            var userInfo = Formatting <WeChatUserInfo> .JsonToClass(getUserInfo.Result);

            _logger.Debug(userInfo.nickname);


            return(Ok());
        }
Exemplo n.º 2
0
 /// <summary>
 /// Add new book in list
 /// </summary>
 /// <param name="newBook">New book</param>
 public void AddBook(Book newBook)
 {
     logger.Debug("Adding a new book");
     if (newBook == null)
     {
         throw new ArgumentNullException(nameof(newBook));
     }
     if (bookList.Contains(newBook))
     {
         logger.Info("The book is already there");
         throw new Exception("The book is already there");
     }
     bookList.Add(newBook);
 }
        /// <summary>
        /// Store serialized list of books in binary file
        /// </summary>
        /// <param name="logger">Logger</param>
        /// <param name="books">List of books</param>
        public void StoreData(IMyLogger logger, IEnumerable <Book> books)
        {
            logger.Debug("Saving book's list");

            BinaryFormatter formatter = new BinaryFormatter();

            using (FileStream fs = new FileStream(FileName, FileMode.OpenOrCreate))
                formatter.Serialize(fs, books);
        }
        /// <summary>
        /// Load books from binary file and deserialize it
        /// </summary>
        /// <param name="logger">Logger</param>
        /// <returns>List of books</returns>
        public List <Book> LoadData(IMyLogger logger)
        {
            List <Book> result;

            logger.Debug("Loading book's list");

            BinaryFormatter formatter = new BinaryFormatter();

            using (FileStream fs = new FileStream(FileName, FileMode.OpenOrCreate))
                result = (List <Book>)formatter.Deserialize(fs);

            return(result);
        }
        public List <Book> LoadData(IMyLogger logger)
        {
            List <Book> result = new List <Book>();

            logger.Debug("Loading book's list");
            using (Stream s = new FileStream(FileName, FileMode.Open))
            {
                var r = new BinaryReader(s);
                while (r.PeekChar() != -1)
                {
                    result.Add(new Book(r.ReadString(), r.ReadString(), r.ReadString(), r.ReadString()));
                }
            }
            return(result);
        }
 public void StoreData(IMyLogger logger, IEnumerable <Book> books)
 {
     logger.Debug("Saving book's list");
     using (Stream s = new FileStream(FileName, FileMode.Create))
     {
         var w = new BinaryWriter(s);
         foreach (Book book in books)
         {
             w.Write(book.Name);
             w.Write(book.Author);
             w.Write(book.PublishingHouse);
             w.Write(book.Text);
         }
         w.Flush();
     }
 }
        /// <summary>
        /// Store list of books in xml formate
        /// </summary>
        /// <param name="logger">Logger</param>
        /// <param name="books">List of books</param>
        public void StoreData(IMyLogger logger, IEnumerable <Book> books)
        {
            logger.Debug("Saving book's list");

            XDocument xdoc   = new XDocument();
            XElement  phones = new XElement("books");
            XElement  book;

            foreach (var item in books)
            {
                book = new XElement("book");
                book.Add(new XAttribute("name", item.Name));
                book.Add(new XElement("author", item.Author));
                book.Add(new XElement("text", item.Text));
                book.Add(new XElement("ph", item.PublishingHouse));
                phones.Add(book);
            }
            xdoc.Add(phones);
            xdoc.Save(FileName);
        }
        /// <summary>
        /// Load books from file in xml formate
        /// </summary>
        /// <param name="logger">Logger</param>
        /// <returns>List of books</returns>
        public List <Book> LoadData(IMyLogger logger)
        {
            List <Book> result = new List <Book>();

            logger.Debug("Loading book's list");

            XDocument xdoc = XDocument.Load(FileName);

            foreach (XElement bookElement in xdoc.Element("books").Elements("book"))
            {
                XAttribute nameAttribute = bookElement.Attribute("name");
                XElement   authorElement = bookElement.Element("author");
                XElement   textElement   = bookElement.Element("text");
                XElement   phElement     = bookElement.Element("ph");

                if (nameAttribute != null && authorElement != null && phElement != null && textElement != null)
                {
                    result.Add(new Book(nameAttribute.Value, authorElement.Value, phElement.Value, textElement.Value));
                }
            }
            return(result);
        }