Example #1
0
        /// <param name="bookRoot">Root of the project.</param>
        /// <param name="dumpLocation">It's location. Where the file will be stored.</param>
        public void EnsureAllIsSaved(IEnumerable <EntryBase> allData, string bookRoot, string dumpLocation)
        {
            // Files. We store them in a local path.
            Uri[] urls = _eph.GetFiles(allData);
            using (IFileStorage fstorage = _fsf.CreateOn(dumpLocation))
            {
                foreach (Uri u in urls)
                {
                    DownloadAndStoreIfNotAvailable(fstorage, u);
                }
            }

            // Userpics. We store them in the book's root subfolder.
            Tuple <string, Userpic>[] userpics = _eph.GetUserpics(allData);
            using (IUserpicStorage ustorage = _ups.CreateOn(bookRoot))
            {
                foreach (var tuple in userpics)
                {
                    Userpic userpic = tuple.Item2;
                    Uri     u       = userpic.GetUri();

                    DownloadAndStoreIfNotAvailable(ustorage, u);
                }
            }
        }
        public void ParsesTestPage()
        {
            string content = TestingShared.GetFileContent("testpage_247911.xml");

            LayerParser p    = new LayerParser();
            EntryPage   page = p.ParseAsAnEntryPage(content);

            Assert.IsNotNull(page);
            Assert.IsNotNull(page.Replies);

            // Has userpic.
            Userpic userpic = page.Entry.PosterUserpic;

            Assert.IsNotNull(userpic);

            // Comment deserialization
            Comment firstComment = page.Replies.Comments[0];

            Assert.AreEqual(91506535, firstComment.Id);
            Assert.IsTrue(firstComment.IsFull, "By default a comment is treated as full.");

            Assert.AreEqual(new DateTime(2015, 6, 25, 15, 16, 50), firstComment.Date.Value);
            Assert.AreEqual("1", firstComment.Text);

            Comment innerComment = firstComment.Replies.Comments[0];

            Assert.AreEqual("http://galkovsky.livejournal.com/247911.html?thread=91589479#t91589479", innerComment.Url);

            // Entry text deserialization
            string entryText = page.Entry.Text;

            Assert.IsTrue(entryText.StartsWith("<p><center><img"));
        }
Example #3
0
        public async Task <JsonResult> UploadUserpic(IFormFile file, [FromHeader] string Authorization)
        {
            string token = Authorization.Split(' ')[1];
            var    user  = from bb in _context.Auths
                           join aa in _context.Tokens on bb.id equals aa.user_id
                           join cc in _context.Accounts on bb.id equals cc.id_user
                           where aa.access == token
                           select cc;
            var usercheck = user.FirstOrDefault();

            if (usercheck == null)
            {
                return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.NotFound, null, "Пользователь не найден")));
            }
            var responce = await _imageHandler.UploadUserpic(file);


            if (responce[0] == "OK")
            {
                var checkuser = await _context.Userpics.Where(x => x.account_id == 1).FirstOrDefaultAsync();

                if (checkuser == null)
                {
                    Userpic userpic = new Userpic
                    {
                        path       = responce[2],
                        name       = responce[1],
                        dttmadd    = DateTime.UtcNow,
                        account_id = 1
                    };
                    await _context.Userpics.AddAsync(userpic);
                }
                else
                {
                    System.IO.File.Delete(checkuser.path);
                    _context.Entry(checkuser).State = EntityState.Modified;
                    checkuser.dttmadd = DateTime.UtcNow;
                    checkuser.name    = responce[1];
                    checkuser.path    = responce[2];
                }

                await _context.SaveChangesAsync();

                return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.OK, null, "Изображение сохранено")));
            }
            else
            {
                //var er = _localizer["error_image"];

                return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.BadRequest, responce[1], "Изображение не сохранено")));
            }
        }
        public void RemovesDuplicateUserpicsProperly()
        {
            Userpic a = new Userpic() { Url = "ABC" };
            Tuple<string, Userpic> ta = Tuple.Create("User", a);

            EntryPage source = new EntryPage();

            EntryBaseHelper eh = MockRepository.GeneratePartialMock<EntryBaseHelper>( _fileUrlExtractor);
            eh.Expect(z => z.CreateUserpicTuple(Arg<EntryBase>.Is.Anything)).Return(ta);

            // Should return only single userpic as their URL are the same.
            Tuple<string, Userpic>[] result = eh.GetUserpics(new EntryBase[] {null,null});
            Assert.AreEqual(1, result.Length);

            eh.VerifyAllExpectations();
        }
        public void RemovesDuplicateUserpicsProperly()
        {
            Userpic a = new Userpic {
                Url = "ABC"
            };
            Tuple <string, Userpic> ta = Tuple.Create("User", a);

            EntryPage source = new EntryPage();

            EntryBaseHelper eh = MockRepository.GeneratePartialMock <EntryBaseHelper>(_fileUrlExtractor);

            eh.Expect(z => z.CreateUserpicTuple(Arg <EntryBase> .Is.Anything))
            .Return(ta);

            // Should return only single userpic as their URL are the same.
            Tuple <string, Userpic>[] result = eh.GetUserpics(new EntryBase[] { null, null });
            Assert.AreEqual(1, result.Length);

            eh.VerifyAllExpectations();
        }
 public EntryBase()
 {
     Poster = new UserLite();
     PosterUserpic = new Userpic();
 }