示例#1
0
        public bool NavigateTo(HelpUri uri)
        {
            if (uri.Type == HelpUriType.Command)
            {
                if (uri.Target == "!B")
                {
                    if (history.Count >= 2)
                    {
                        history.RemoveAt(history.Count - 1);
                        ActiveTopic = history[history.Count - 1];
                        return(true);
                    }
                }
                return(false);
            }

            HelpTopic topic = system.ResolveUri(activeDatabase, uri);

            if (topic == null)
            {
                if (uri.Type == HelpUriType.GlobalContext &&
                    system.FindDatabase(uri.DatabaseName) == null)
                {
                    string fileName = FindFile(activeDatabase, uri.DatabaseName);
                    if (fileName != null)
                    {
                        LoadDatabases(fileName);
                        topic = system.ResolveUri(activeDatabase, uri);
                    }
                }
            }
            if (topic != null)
            {
                ActiveTopic = topic;
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#2
0
        static void Convert(string[] fileNames, bool isDryRun)
        {
            HelpSystem         system    = new HelpSystem();
            BatchHtmlFormatter converter = new BatchHtmlFormatter(system);

            foreach (string fileName in fileNames)
            {
                var decoder = new BinaryHelpDeserializer();
                foreach (HelpDatabase database in decoder.LoadDatabases(fileName))
                {
                    system.Databases.Add(database);
                }
            }

            // export HTML
            foreach (HelpDatabase database in system.Databases)
            {
                // TODO: check invalid chars in database name
                string htmlPath = database.Name.Replace('.', '_');
                Directory.CreateDirectory(htmlPath);

                int topicIndex = 0;
                foreach (HelpTopic topic in database.Topics)
                {
                    string html         = converter.FormatTopic(topic);
                    string htmlFileName = Path.Combine(htmlPath, string.Format("T{0:X4}.html", topicIndex));
                    if (!isDryRun)
                    {
                        using (StreamWriter writer = new StreamWriter(htmlFileName, false, Encoding.UTF8))
                        {
                            writer.Write(html);
                        }
                    }
                    topicIndex++;
                }

                // Create contents.html.
                HelpTopic topic1 = system.ResolveUri(database, new HelpUri("h.contents"));
                if (topic1 != null && topic1.Database == database)
                {
                    if (!isDryRun)
                    {
                        using (StreamWriter writer = new StreamWriter(Path.Combine(htmlPath, "Contents.html")))
                        {
                            writer.WriteLine("<meta http-equiv=\"refresh\" content=\"0; url=T{0:X4}.html\">",
                                             topic1.TopicIndex);
                        }
                    }
                }
            }
        }
示例#3
0
        protected override string FormatUri(HelpTopic source, HelpUri uri)
        {
            switch (uri.Type)
            {
            case HelpUriType.Context:
            case HelpUriType.GlobalContext:
            case HelpUriType.LocalContext:
            {
                HelpTopic target = system.ResolveUri(source.Database, uri);
                if (target != null)
                {
                    if (target.Database == source.Database)
                    {
                        return(string.Format("T{0:X4}.html", target.TopicIndex));
                    }
                    else
                    {
                        return(string.Format("../{0}/T{1:X4}.html",
                                             GetDatabasePath(target.Database),
                                             target.TopicIndex));
                    }
                }
                else
                {
                    Console.WriteLine("Warning: cannot resolve context string '{0}'", uri);
                }
            }
            break;

            case HelpUriType.LocalTopic:
                return(string.Format("T{0:X4}.html", uri.TopicIndex));

            case HelpUriType.Command:
            case HelpUriType.File:
            default:
                // TODO: would be better if we have the source location.
                Console.WriteLine("Warning: cannot convert link: {0}", uri);
                break;
            }
            return("?" + uri.ToString());
        }