Ejemplo n.º 1
0
        public async Task <IMarkpadDocument> SaveDocumentAs(IMarkpadDocument document)
        {
            var path = dialogService.GetFileSavePath("Save As", "*.md", Constants.ExtensionFilter + "|All Files (*.*)|*.*");

            if (string.IsNullOrEmpty(path))
            {
                throw new TaskCanceledException("Save As Cancelled");
            }

            await fileSystem.File.WriteAllTextAsync(path, document.MarkdownContent);

            var siteContext = siteContextGenerator.GetContext(path);

            var newDocumentAssociatedFiles = new List <FileReference>();
            var newFileDirectory           = Path.GetDirectoryName(path);

            foreach (var associatedFile in document.AssociatedFiles)
            {
                var newAbsolutePath = Path.Combine(newFileDirectory, associatedFile.RelativePath);
                var newRelativePath = associatedFile.RelativePath;

                newAbsolutePath = newAbsolutePath.Replace(document.Title + "_images", Path.GetFileNameWithoutExtension(path) + "_images");
                newRelativePath = newRelativePath.Replace(document.Title + "_images", Path.GetFileNameWithoutExtension(path) + "_images");

                if (associatedFile.FullPath != newAbsolutePath)
                {
                    fileSystem.File.Copy(associatedFile.FullPath, newAbsolutePath);
                }
                newDocumentAssociatedFiles.Add(new FileReference(newAbsolutePath, newRelativePath, true));
            }

            var newMarkdownFile = new FileMarkdownDocument(path, document.MarkdownContent, siteContext, newDocumentAssociatedFiles, this, eventAggregator, dialogService, fileSystem);

            return(newMarkdownFile);
        }
Ejemplo n.º 2
0
        public void Open(IMarkpadDocument document, bool isNew = false)
        {
            MarkpadDocument = document;
            Document.Text   = document.MarkdownContent ?? string.Empty;
            Original        = isNew ? null : document.MarkdownContent;

            Update();
        }
Ejemplo n.º 3
0
        public void Open(IMarkpadDocument document)
        {
            MarkpadDocument = document;
            Document.Text   = document.MarkdownContent;
            Original        = document.MarkdownContent;

            Update();
        }
Ejemplo n.º 4
0
        public Task <IMarkpadDocument> SaveDocumentAs(IMarkpadDocument document)
        {
            var path = dialogService.GetFileSavePath("Save As", "*.md", Constants.ExtensionFilter + "|All Files (*.*)|*.*");

            if (string.IsNullOrEmpty(path))
            {
                return(TaskEx.FromResult(document));
            }

            return(NewMarkdownFile(path, document.MarkdownContent));
        }
		public void SavePage(IMarkpadDocument documentViewModel)
		{
			if (documentViewModel == null) return;

			var dialogService = new DialogService();
			var fileName = dialogService.GetFileSavePath(SAVE_TITLE, SAVE_DEFAULT_EXT, SAVE_FILTER);
			if (string.IsNullOrEmpty(fileName)) return;

			var markdown = documentViewModel.MarkdownContent;
			var html = _documentParser.ParseClean(markdown);

			File.WriteAllText(fileName, html);
		}
Ejemplo n.º 6
0
        /// <summary>
        /// Publishes any document
        /// </summary>
        /// <param name="postId"></param>
        /// <param name="document"></param>
        /// <returns></returns>
        public Task <IMarkpadDocument> PublishDocument(string postId, IMarkpadDocument document)
        {
            var blogs = blogService.GetBlogs();

            if (blogs == null || blogs.Count == 0)
            {
                if (!blogService.ConfigureNewBlog("Publish document"))
                {
                    return(TaskEx.FromResult <IMarkpadDocument>(null));
                }
                blogs = blogService.GetBlogs();
                if (blogs == null || blogs.Count == 0)
                {
                    return(TaskEx.FromResult <IMarkpadDocument>(null));
                }
            }

            var categories  = new List <string>();
            var webDocument = document as WebDocument;

            if (webDocument != null)
            {
                categories = webDocument.Categories;
            }
            var pd = new Details {
                Title = document.Title, Categories = categories.ToArray()
            };
            var detailsResult = windowManager.ShowDialog(new PublishDetailsViewModel(pd, blogs));

            if (detailsResult != true)
            {
                return(TaskEx.FromResult <IMarkpadDocument>(null));
            }

            var newDocument = new WebDocument(pd.Blog, null, pd.Title, document.MarkdownContent, new FileReference[0], this,
                                              webDocumentService.Value, siteContextGenerator.GetWebContext(pd.Blog), fileSystem);

            foreach (var associatedFile in document.AssociatedFiles)
            {
                newDocument.AddFile(new FileReference(associatedFile.FullPath, associatedFile.RelativePath, false));
            }

            return(newDocument.Save());
        }
Ejemplo n.º 7
0
        public void SavePage(IMarkpadDocument documentViewModel)
        {
            if (documentViewModel == null)
            {
                return;
            }

            var dialogService = new DialogService();
            var fileName      = dialogService.GetFileSavePath(SAVE_TITLE, SAVE_DEFAULT_EXT, SAVE_FILTER);

            if (string.IsNullOrEmpty(fileName))
            {
                return;
            }

            var markdown = documentViewModel.MarkdownContent;
            var html     = _documentParser.ParseClean(markdown);

            File.WriteAllText(fileName, html);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Publishes any document
        /// </summary>
        /// <param name="postId"></param>
        /// <param name="document"></param>
        /// <returns></returns>
        public Task <IMarkpadDocument> PublishDocument(string postId, IMarkpadDocument document)
        {
            var blogs = blogService.GetBlogs();

            if (blogs == null || blogs.Count == 0)
            {
                if (!blogService.ConfigureNewBlog("Publish document"))
                {
                    return(TaskEx.FromResult <IMarkpadDocument>(null));
                }
                blogs = blogService.GetBlogs();
                if (blogs == null || blogs.Count == 0)
                {
                    return(TaskEx.FromResult <IMarkpadDocument>(null));
                }
            }

            var categories  = new List <string>();
            var webDocument = document as WebDocument;

            if (webDocument != null)
            {
                categories = webDocument.Categories;
            }
            var pd = new Details {
                Title = document.Title, Categories = categories.ToArray()
            };
            var detailsResult = windowManager.ShowDialog(new PublishDetailsViewModel(pd, blogs));

            if (detailsResult != true)
            {
                return(TaskEx.FromResult <IMarkpadDocument>(null));
            }

            var newDocument = new WebDocument(pd.Blog, null, pd.Title, document.MarkdownContent, this,
                                              webDocumentService.Value,
                                              siteContextGenerator.GetWebContext(pd.Blog));

            return(newDocument.Save());
        }
Ejemplo n.º 9
0
        public async Task<IMarkpadDocument> SaveDocumentAs(IMarkpadDocument document)
        {
            var path = dialogService.GetFileSavePath("Save As", "*.md", Constants.ExtensionFilter + "|All Files (*.*)|*.*");

            if (string.IsNullOrEmpty(path))
                throw new TaskCanceledException("Save As Cancelled");

            await fileSystem.File.WriteAllTextAsync(path, document.MarkdownContent);

            var siteContext = siteContextGenerator.GetContext(path);

            var newDocumentAssociatedFiles = new List<FileReference>();
            var newFileDirectory = Path.GetDirectoryName(path);

            foreach (var associatedFile in document.AssociatedFiles)
            {
                var newAbsolutePath = Path.Combine(newFileDirectory, associatedFile.RelativePath);
                var newRelativePath = associatedFile.RelativePath;

                newAbsolutePath = newAbsolutePath.Replace(document.Title + "_images", Path.GetFileNameWithoutExtension(path) + "_images");
                newRelativePath = newRelativePath.Replace(document.Title + "_images", Path.GetFileNameWithoutExtension(path) + "_images");

                if (associatedFile.FullPath != newAbsolutePath)
                {
                    fileSystem.File.Copy(associatedFile.FullPath, newAbsolutePath);
                }
                newDocumentAssociatedFiles.Add(new FileReference(newAbsolutePath, newRelativePath, true));
            }

            var newMarkdownFile = new FileMarkdownDocument(path, document.MarkdownContent, siteContext, newDocumentAssociatedFiles, this, eventAggregator, dialogService, fileSystem);

            return newMarkdownFile;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Publishes any document
        /// </summary>
        /// <param name="postId"></param>
        /// <param name="document"></param>
        /// <returns></returns>
        public Task<IMarkpadDocument> PublishDocument(string postId, IMarkpadDocument document)
        {
            var blogs = blogService.GetBlogs();
            if (blogs == null || blogs.Count == 0)
            {
                if (!blogService.ConfigureNewBlog("Publish document"))
                    return TaskEx.FromResult<IMarkpadDocument>(null);
                blogs = blogService.GetBlogs();
                if (blogs == null || blogs.Count == 0)
                    return TaskEx.FromResult<IMarkpadDocument>(null);
            }

            var categories = new List<string>();
            var webDocument = document as WebDocument;
            if (webDocument != null)
                categories = webDocument.Categories;
            var pd = new Details { Title = document.Title, Categories = categories.ToArray()};
            var detailsResult = windowManager.ShowDialog(new PublishDetailsViewModel(pd, blogs));
            if (detailsResult != true)
                return TaskEx.FromResult<IMarkpadDocument>(null);

            var newDocument = new WebDocument(pd.Blog, null, pd.Title, document.MarkdownContent, new FileReference[0], this,
                                              webDocumentService.Value, siteContextGenerator.GetWebContext(pd.Blog), fileSystem);

            foreach (var associatedFile in document.AssociatedFiles)
            {
                newDocument.AddFile(new FileReference(associatedFile.FullPath, associatedFile.RelativePath, false));
            }

            return newDocument.Save();
        }
Ejemplo n.º 11
0
        public Task<IMarkpadDocument> SaveDocumentAs(IMarkpadDocument document)
        {
            var path = dialogService.GetFileSavePath("Save As", "*.md", Constants.ExtensionFilter + "|All Files (*.*)|*.*");

            if (string.IsNullOrEmpty(path))
                return TaskEx.FromResult(document);

            return NewMarkdownFile(path, document.MarkdownContent);
        }
Ejemplo n.º 12
0
        public Task<IMarkpadDocument> PublishDocument(IMarkpadDocument document)
        {
            var blogs = blogService.GetBlogs();
            if (blogs == null || blogs.Count == 0)
            {
                if (!blogService.ConfigureNewBlog("Publish document"))
                    return TaskEx.FromResult<IMarkpadDocument>(null);
                blogs = blogService.GetBlogs();
                if (blogs == null || blogs.Count == 0)
                    return TaskEx.FromResult<IMarkpadDocument>(null);
            }

            var post = new Post();
            var pd = new Details { Title = document.Title, Categories = post.categories };
            var detailsResult = windowManager.ShowDialog(new PublishDetailsViewModel(pd, blogs));
            if (detailsResult != true)
                return TaskEx.FromResult<IMarkpadDocument>(null);

            return TaskEx.Run(() => CreateNewWebMarkdownFile(null, pd.Title, pd.Categories, document.MarkdownContent, pd.Blog));
        }