Пример #1
0
        public Task Publish()
        {
            MarkpadDocument.MarkdownContent = Document.Text;

            return(MarkpadDocument.Publish()
                   .ContinueWith(t =>
            {
                if (t.Result != null)
                {
                    MarkpadDocument = t.Result;
                    Original = MarkpadDocument.MarkdownContent;
                }
            }, TaskScheduler.FromCurrentSynchronizationContext()));
        }
Пример #2
0
        public Task <bool> SaveAs()
        {
            MarkpadDocument.MarkdownContent = Document.Text;
            return(MarkpadDocument
                   .SaveAs()
                   .ContinueWith(t =>
            {
                if (t.IsFaulted)
                {
                    return false;
                }

                MarkpadDocument = t.Result;
                Original = Document.Text;
                return true;
            }, TaskScheduler.FromCurrentSynchronizationContext()));
        }
Пример #3
0
        public Task <bool> Save()
        {
            if (Document.Text == Original)
            {
                return(TaskEx.FromResult(false));
            }

            MarkpadDocument.MarkdownContent = Document.Text;

            //TODO async all the things
            var dispatcher = Dispatcher.CurrentDispatcher;

            return(MarkpadDocument.Save()
                   .ContinueWith(t =>
            {
                if (t.IsCanceled)
                {
                    return false;
                }

                if (t.IsFaulted)
                {
                    var saveResult = false;

                    dispatcher.Invoke(new Action(() =>
                    {
                        dialogService.ShowConfirmation(
                            "MarkPad", "Cannot save file",
                            "You may not have permission to save this file to the selected location, or the location may not be currently available. Error: " + t.Exception.InnerException.Message,
                            new ButtonExtras(ButtonType.Yes, "Select a different location", "Save this file to a different location."),
                            new ButtonExtras(ButtonType.No, "Cancel", ""));
                    }));

                    return saveResult == true && SaveAs().Result;
                }

                dispatcher.Invoke(new Action(() =>
                {
                    MarkpadDocument = t.Result;
                    Original = MarkpadDocument.MarkdownContent;
                    Document.Text = MarkpadDocument.MarkdownContent;
                }));
                return true;
            }));
        }
        private void TimerTick(object sender, EventArgs e)
        {
            if (MarkpadDocument == null)
            {
                return;
            }
            timer.Stop();

            Task.Factory.StartNew(text => documentParser.Parse(text.ToString()), Document.Text)
            .ContinueWith(s =>
            {
                if (s.IsFaulted)
                {
                    Log.Error(s.Exception);
                    return;
                }

                var result = MarkpadDocument.ConvertToAbsolutePaths(s.Result);

                Render = result;
                UpdateWordCount();
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }