Exemplo n.º 1
0
        internal IReadOnlyList <INamedItemInfo> LoadFunctionInfoFromPackageHelpIndex()
        {
            List <INamedItemInfo> functions = new List <INamedItemInfo>();
            string content = null;

            try {
                string htmlFile = Path.Combine(this.InstallPath, this.Name, "html", "00index.html");
                if (File.Exists(htmlFile))
                {
                    using (StreamReader sr = new StreamReader(htmlFile, Encoding.UTF8)) {
                        content = sr.ReadToEnd();
                    }
                }
            } catch (IOException) { }

            if (!string.IsNullOrEmpty(content))
            {
                HtmlTree tree = new HtmlTree(new TextStream(content));
                tree.Build();

                FunctionSearch functionSearch = new FunctionSearch(functions);
                tree.Accept(functionSearch, null);
            }

            Dictionary <string, INamedItemInfo> functionIndex = new Dictionary <string, INamedItemInfo>();

            foreach (INamedItemInfo ni in functions)
            {
                functionIndex[ni.Name] = ni;
            }

            IReadOnlyDictionary <string, string> mappedNames = GetMappedNames();

            foreach (string mappedName in mappedNames.Keys)
            {
                INamedItemInfo ni;
                string         actualName = mappedNames[mappedName];
                if (functionIndex.TryGetValue(actualName, out ni))
                {
                    INamedItemInfo niAlias = new NamedItemInfo()
                    {
                        Name        = mappedName,
                        Description = ni.Description,
                        ItemType    = ni.ItemType
                    };
                    functions.Add(niAlias);
                }
            }

            return(functions);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Downloads the index html page specified, and extracts a set of known fields from it.
        /// </summary>
        /// <param name="packageUri">Location of index.html page.</param>
        /// <param name="result">RPackage object to fill in. A new one is created if none is passed in.</param>
        /// <returns>RPackage object populated with the information found in the html page.</returns>
        /// <exception cref="WebException">Page cannot be loaded.</exception>
        /// <remarks>
        /// If an existing RPackage object is passed in, the fields that are already filled in
        /// won't be overwritten by the ones extracted from the html page.
        /// </remarks>
        public static async Task <RPackage> RetrievePackageInfo(Uri packageUri, RPackage result = null)
        {
            string content;

            using (var webClient = new WebClient()) {
                content = await webClient.DownloadStringTaskAsync(packageUri);
            }

            var pkg = result ?? new RPackage();

            var tree = new HtmlTree(new Microsoft.Web.Core.Text.TextStream(content));

            tree.Build();

            var search = new IndexVisitor(pkg);

            tree.Accept(search, null);

            return(pkg);
        }