Пример #1
0
        public static bool SaveDocument(Document document)
        {
            if (document.IsTemporal)
            {
                var dialog = new SaveFileDialog { DefaultExt = "md", AddExtension = true };
                dialog.Filter = "Markdown files (*.md)|*.md|All files (*.*)|*.*";
                if (dialog.ShowDialog().Value)
                {
                    string destinationFolder = string.Empty;
                    destinationFolder = new FileInfo(dialog.FileName).DirectoryName;
                    try
                    {
                        var sourceFolder = new FileInfo(document.FullFilename).DirectoryName;
                        DirectoryCopy(sourceFolder, destinationFolder, true);
                        document.FolderPath = destinationFolder;
                        File.Move(document.FullFilename, Path.Combine(document.FolderPath, dialog.FileName));
                    }
                    catch (Exception ex)
                    {
                        throw;
                    }
                }
                else
                {
                    return false;
                }
            }
            else
            {
            }

            document.HasChanges = false;
            return true;
        }
Пример #2
0
        public void UpdatePreview(Document document)
        {
            var parsedHtml = MarkdownParser.ToHtml(document.Text);
            if (string.IsNullOrEmpty(parsedHtml))
            {
                return;
            }

            var htmlBody = string.Format("{0}{1}{2}", HtmlHeader, parsedHtml, HtmlFooter);

            this.fileStream = new FileStream(document.PreviewFileName, FileMode.Create, FileAccess.ReadWrite);
            var writer = new StreamWriter(this.fileStream);
            writer.Write(htmlBody);
            writer.Close();
            var reader = new Uri(document.PreviewFileName);
            this.previewer.Navigate(reader);
            this.fileStream.Close();
        }
Пример #3
0
        public static Document NewDocument()
        {
            var tempFolderName = Guid.NewGuid().ToString();
            var newDocumentFolder = Path.Combine(TemporalFolder, tempFolderName);
            try
            {
                Directory.CreateDirectory(newDocumentFolder);
                var document = new Document
                                   {
                                       FileName = string.Format("{0}.md", Guid.NewGuid()),
                                       FolderPath = newDocumentFolder,
                                       PreviewFileName = Path.Combine(newDocumentFolder, string.Format("{0}.html", Guid.NewGuid())),
                                   };

                var fileStream = new FileStream(document.FullFilename, FileMode.CreateNew, FileAccess.Write);
                fileStream.Close();
                return document;
            }
            catch (Exception ex)
            {
                throw new Exception("Could not create temporal document.", ex);
            }
        }
Пример #4
0
 private static void SaveMarkdownFile(Document document, string destinationFolder)
 {
 }