示例#1
0
        private static void DoStory2HtmlTest()
        {
            // Get the story
            WInteractiveStory story;

            var currentDir     = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            var inputFilename  = currentDir + "\\test-story.bin";
            var outputFilename = currentDir + "\\test-story.html";

            using (System.IO.FileStream fs = new System.IO.FileStream(inputFilename, System.IO.FileMode.Open))
            {
                var bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                story = (WInteractiveStory)bf.Deserialize(fs);
            }

            // Try to convert it to HTML
            var converter   = new WStoryToHtml();
            var htmlPayload = converter.ConvertStory(story);

            // Save it, because why not
            System.IO.File.WriteAllText(outputFilename, htmlPayload);
        }
        public void ExportStory(WInteractiveStory story)
        {
            UpdateStatusMessage("Exporting story to HTML");

            try
            {
                var sfd = new SaveFileDialog();
                sfd.Filter           = STORY_EXPORT_DIALOG_FILTER;
                sfd.InitialDirectory = LastFileDir;
                sfd.FileName         = $"{story.UrlID}.{STORY_EXPORT_DIALOG_SUFFIX}";
                sfd.ValidateNames    = true;
                sfd.OverwritePrompt  = true;
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    var htmlPayload = new WStoryToHtml().ConvertStory(story);
                    File.WriteAllText(sfd.FileName, htmlPayload);

                    if (MessageBox.Show(
                            "The story has been exported.\n\nWould you like to see it?",
                            "Story exported",
                            MessageBoxButtons.YesNo,
                            MessageBoxIcon.Information
                            ) == DialogResult.Yes)
                    {
                        string args = $"/select,\"{sfd.FileName}\"";
                        Process.Start("explorer", args);
                    }

                    LastFileDir = Path.GetDirectoryName(sfd.FileName);
                    UpdateStatusMessage("Story exported to HTML");
                    log.Info("Story exported to HTML");
                }
            }
            catch (Exception ex)
            {
                log.Error("Error while exporting story to HTML", ex);
                UpdateStatusMessage("Failed to export story to HTML");
            }
        }