Ejemplo n.º 1
0
 public BoardCatalogModel(INavigation navigation, ISiteAPI api, BoardId boardId)
 {
     Title = "/" + boardId + "/";
     _api = api;
     _boardId = boardId;
     _navigation = navigation;
     Posts = new ObservableCollection<Post>();
 }
Ejemplo n.º 2
0
 public async Task<IEnumerable<Post>> GetCatalog(BoardId boardId)
 {
     Uri uri = new Uri("https://a.4cdn.org/" + boardId + "/catalog.json");
     var request = WebRequest.Create(uri);
     var response = await request.GetResponseAsync();
     var reader = new StreamReader(response.GetResponseStream());
     var catalogJson = await reader.ReadToEndAsync();
     var pages = JsonConvert.DeserializeObject<Page[]>(catalogJson);
     var posts = pages.SelectMany(x => x.Threads).ToArray();
     ProcessPosts(boardId, posts);
     return posts;
 }
Ejemplo n.º 3
0
        private static void ProcessPosts(BoardId boardId, Post[] posts)
        {
            Regex htmlTag = new Regex("<[^>]*>");
            Regex emptySpace = new Regex(@"\s+");
            foreach (var post in posts)
            {
                post.BoardId = boardId;
                if (post.Comment != null)
                {
                    post.CommentPlain = WebUtility.HtmlDecode(emptySpace.Replace(htmlTag.Replace(post.Comment, " "), " "));
                    var fixedNewlines = post.Comment.Replace("<br>", Environment.NewLine);
                    post.CommentParsed = WebUtility.HtmlDecode(htmlTag.Replace(fixedNewlines, ""));
                }

                if (!string.IsNullOrWhiteSpace(post.FileName))
                {
                    post.ThumbnailPath = CreateThumbnailUri(boardId, post.FileName);
                    post.ImagePath = CreateImageUri(boardId, post.FileName, post.FileExtension);
                }
            }
        }
Ejemplo n.º 4
0
 private static Uri CreateThumbnailUri(BoardId boardId, string fileName)
 {
     return new Uri("https://i.4cdn.org/" + boardId + "/" + fileName + "s.jpg ");
 }
Ejemplo n.º 5
0
 private static Uri CreateImageUri(BoardId boardId, string fileName, string extension)
 {
     return new Uri("https://i.4cdn.org/" + boardId + "/" + fileName + extension);
 }
 public void OpenBoard(BoardId boardId)
 {
     AddOrSelectScreen(x => x.BoardId.Equals(boardId), () => new BoardCatalogModel(this, new FourChanAPI(), boardId));
 }
Ejemplo n.º 7
0
        public void Openning_a_board_sets_it_as_current()
        {
            var boardId = new Model.BoardId("g");
            Views.ApplicationNavigationViewModel model = new Views.ApplicationNavigationViewModel();

            var prevItems = model.Items.ToList();
            model.OpenBoard(boardId);
            var addedScreen = model.Items.Except(prevItems).Single();

            Assert.AreSame(addedScreen, model.CurrentScreen);
        }
Ejemplo n.º 8
0
        public void Openning_a_board_again_sets_it_as_current()
        {
            var boardId = new Model.BoardId("g");
            Views.ApplicationNavigationViewModel model = new Views.ApplicationNavigationViewModel();

            model.OpenBoard(boardId);
            var boardScreen = model.CurrentScreen;
            model.ItemClicked(model.BoardsScreen);

            model.OpenBoard(boardId);

            Assert.AreSame(boardScreen, model.CurrentScreen);
        }
Ejemplo n.º 9
0
        public void Openning_a_board_again_doesnt_add_it_again()
        {
            var boardId = new Model.BoardId("g");
            Views.ApplicationNavigationViewModel model = new Views.ApplicationNavigationViewModel();
            model.OpenBoard(boardId);

            var prevItems = model.Items.ToList();
            model.OpenBoard(boardId);
            var addedScreens = model.Items.Except(prevItems).ToList();

            Assert.AreEqual(0, addedScreens.Count, "Screen was added when it shouldn't be!");
        }
Ejemplo n.º 10
0
        public void Openning_a_board_adds_it_to_items()
        {
            var boardId = new Model.BoardId("g");
            Views.ApplicationNavigationViewModel model = new Views.ApplicationNavigationViewModel();

            var prevItems = model.Items.ToList();
            model.OpenBoard(boardId);
            var newItems = model.Items.Except(prevItems).ToList();

            Assert.AreEqual(1, newItems.Count, "Not exactly one screen was added");

            var addedScreen = newItems.First();
            Assert.IsInstanceOfType(addedScreen, typeof(BoardCatalogModel), "Added screen didn't seem to be correct type!");
            Assert.AreEqual(boardId, (addedScreen as BoardCatalogModel).BoardId, "Added screen didn't seem to have correct id!");
        }
Ejemplo n.º 11
0
 public void OpenBoard(BoardId boardId)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 12
0
 public ThreadId(BoardId board, UInt64 thread)
 {
     _board = board;
     _thread = thread;
 }