コード例 #1
0
        public static async Task <List <DocumentationPageViewModel> > FetchGettingStartedPages(IViewModelServiceProvider serviceProvider, string version)
        {
            string urlData = null;
            var    result  = new List <DocumentationPageViewModel>();

            try
            {
                WebRequest request = WebRequest.Create(string.Format(Urls.GettingStarted, version));
                using (var reponse = await request.GetResponseAsync())
                {
                    using (var str = reponse.GetResponseStream())
                    {
                        if (str != null)
                        {
                            using (var reader = new StreamReader(str))
                            {
                                urlData = reader.ReadToEnd();
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                // Unable to reach the url, return an empty list.
                return(result);
            }

            if (urlData == null)
            {
                return(result);
            }

            try
            {
                var urls = urlData.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var url in urls)
                {
                    var match = ParsingRegex.Match(url);
                    if (match.Success && match.Groups.Count == 4)
                    {
                        var link = match.Groups[3].Value;
                        if (link.StartsWith(DocPageScheme))
                        {
                            link = GetDocumentationPageUrl(version, link.Substring(DocPageScheme.Length));
                        }
                        var page = new DocumentationPageViewModel(serviceProvider, version)
                        {
                            Title       = match.Groups[1].Value.Trim(),
                            Description = match.Groups[2].Value.Trim(),
                            Url         = link.Trim()
                        };
                        result.Add(page);
                    }
                }
            }
            catch (Exception)
            {
                result.Clear();
            }
            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Fetches the documentation pages corresponding to this version from the server.
        /// </summary>
        internal async void FetchDocumentation()
        {
            var pages = await DocumentationPageViewModel.FetchGettingStartedPages(ServiceProvider, $"{Major}.{Minor}");

            Dispatcher.Invoke(() => { DocumentationPages.Clear(); DocumentationPages.AddRange(pages); });
        }