Exemple #1
0
        public DirectoryResult ShowHome()
        {
            var result = new DirectoryResult();

            result.Items.Add(new DirectoryItem("Macintosh Garden - Gopher Edition"));
            result.Items.Add(new DirectoryItem("================================="));
            result.Items.Add(new DirectoryItem(""));
            result.Items.Add(new DirectoryItem(ItemType.INDEXSEARCH, "Search the Garden", Settings.HomePath + "/search/"));

            return(result);
        }
        public DirectoryResult ProxyPage(string url)
        {
            var result = new DirectoryResult();

            var html = HttpHelpers.GetUrl(url);

            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(html);
            var title = doc.DocumentNode.Descendants("title").SingleOrDefault();

            result.Items.Add(new DirectoryItem("Title: " + title));
            result.Items.Add(new DirectoryItem("Url:   " + url));
            result.Items.Add(new DirectoryItem("---------------"));
            result.Items.Add(new DirectoryItem(""));
            result.Items.AddRange(html.ToDirectoryItems());

            return(result);
        }
        /// <summary>
        /// Gets the first 100 categories from the blog ordered by their use.
        /// </summary>
        /// <returns></returns>
        public DirectoryResult GetCategories()
        {
            List <Category> result = client.GetCategories(new CategoriesQuery()
            {
                HideEmpty = true, OrderBy = "count", Order = "desc", PerPage = 100
            }).Result;

            var directory = new DirectoryResult();

            directory.Items.Add(new DirectoryItem("Categories"));

            directory.Items.AddRange(result.Select(c => new DirectoryItem()
            {
                Description = string.Format("{0} ({1})", c.Name, c.Count),
                ItemType    = ItemType.DIRECTORY,
                Selector    = "/category/" + c.Id
            }));

            return(directory);
        }
        /// <summary>
        /// Peforms a search of the blog
        /// </summary>
        /// <param name="q"></param>
        /// <returns></returns>
        public DirectoryResult Search(string q)
        {
            var posts = client.GetPosts(new PostsQuery {
                Search = q, PerPage = 100, OrderBy = OrderBy.title.ToString()
            }).Result;
            var directory = new DirectoryResult();

            directory.Items.Add(new DirectoryItem("Search for '" + q + "'"));

            if (posts.Count > 0)
            {
                directory.Items.AddRange(posts.ToDirectoryItems());
            }
            else
            {
                directory.Items.Add(new DirectoryItem("No results found."));
            }

            // TODO - add paging!

            return(directory);
        }
        /// <summary>
        /// Returns the post as a DirectoryListing for the spcified ID
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DirectoryResult GetPost(int id)
        {
            var result = new DirectoryResult();

            var post = client.GetPost(new PostQuery {
            }, id).Result;

            result.Items.Add(new DirectoryItem(post.Title.Rendered.CleanHtml()));
            result.Items.Add(new DirectoryItem("---"));
            result.Items.Add(new DirectoryItem("Author: " + post.Author));
            result.Items.Add(new DirectoryItem("Date Posted: " + post.DateGmt.ToString()));
            result.Items.Add(new DirectoryItem(" "));
            result.Items.Add(new DirectoryItem(ItemType.DOC, "Text Version", "/posts/text/" + id));
            result.Items.Add(new DirectoryItem(ItemType.HTML, "Web Link", "URL:" + post.Link));
            result.Items.Add(new DirectoryItem("---"));

            result.Items.AddRange(post.Content.Rendered.ToDirectoryItems());

            result.Items.Add(new DirectoryItem("----------------------------"));

            return(result);
        }
        /// <summary>
        /// Produces a basic Homepage for the blog
        /// </summary>
        /// <returns></returns>
        public DirectoryResult GetHomePage()
        {
            var result = new DirectoryResult();

            result.Items.Add(new DirectoryItem("Welcome"));
            result.Items.Add(new DirectoryItem("-------"));

            result.Items.Add(new DirectoryItem("Latest Posts"));

            var latestPosts = client.GetPosts(new PostsQuery {
                PerPage = 10
            }).Result;

            result.Items.AddRange(latestPosts.ToDirectoryItems());

            result.Items.Add(new DirectoryItem("---"));
            result.Items.Add(new DirectoryItem(ItemType.DIRECTORY, "Categories", "/categories/"));
            result.Items.Add(new DirectoryItem(ItemType.INDEXSEARCH, "Search", "/search/"));

            // TODO: Add Tags and Pages

            return(result);
        }
Exemple #7
0
        private void SetWorkspaceClick()
        {
            DirectoryResult selectedDirectory = (DirectoryResult)null;

            try
            {
                selectedDirectory = this._selectDirectoryService.GetDirectoryLocation(Environment.GetFolderPath(Environment.SpecialFolder.Personal));
            }
            catch (Exception ex)
            {
                this._loggerService.Log(LogType.Error, "Selecting folder resulted in an exception. " + ex.Message, ex.StackTrace);
                this._messenger.Send <OnWorkspaceDirectoryAccessDeniedPopupOpened>(new OnWorkspaceDirectoryAccessDeniedPopupOpened(new OkPopupViewModel(this.WorkspaceDirectoryAccessDeniedErrorText, this.WorkspaceDirectoryAccessDeniedErrorButtonText, this._messenger)));
            }
            DirectoryResult directoryResult = selectedDirectory;

            if ((directoryResult != null ? (directoryResult.HasSelected ? 1 : 0) : 0) == 0)
            {
                return;
            }
            Task.Factory.StartNew((Action)(() =>
            {
                bool canWriteToDirectory = this._directoryAccessValidator.HasWriteAccess(selectedDirectory.Path);
                bool isPathLengthAcceptable = this._directoryAccessValidator.IsPathLengthAcceptable(selectedDirectory.Path);
                DispatcherHelper.CheckBeginInvokeOnUI((Action)(() =>
                {
                    if (canWriteToDirectory & isPathLengthAcceptable)
                    {
                        this.WorkspaceBasePath = selectedDirectory.Path;
                        this.UpdateWorkspace(this.WorkspaceBasePath);
                    }
                    else
                    {
                        this._messenger.Send <OnWorkspaceDirectoryAccessDeniedPopupOpened>(new OnWorkspaceDirectoryAccessDeniedPopupOpened(new OkPopupViewModel(this.WorkspaceDirectoryAccessDeniedErrorText, this.WorkspaceDirectoryAccessDeniedErrorButtonText, this._messenger)));
                    }
                }));
            }));
        }