/// <summary>
        /// Do all operation that checks for new version, brings up the change
        /// dialog, allows downloading etc. UI can just call this method to
        /// do it all.
        /// </summary>
        /// <param name="force">Forces the version check even if it was done recently. Otherwise LastChecked and Interval is used to decide if to hit the server</param>
        /// <param name="closeApplication">It trye forces MM to be shutdown after downloading</param>
        /// <param name="failTimeout">Max time to for the HTTP check to take before considering failed</param>
        /// <returns></returns>
        public static bool  CheckForNewVersion(bool force, bool closeApplication = true, int failTimeout = 2000)
        {
            var  updater      = new ApplicationUpdater(typeof(MainWindow));
            bool isNewVersion = updater.IsNewVersionAvailable(!force, timeout: failTimeout);

            if (isNewVersion)
            {
                var res = MessageBox.Show(updater.VersionInfo.Detail + "\r\n\r\n" +
                                          "Do you want to download and install this version?",
                                          updater.VersionInfo.Title,
                                          MessageBoxButton.YesNo,
                                          MessageBoxImage.Information);

                if (res == MessageBoxResult.Yes)
                {
                    ShellUtils.GoUrl(mmApp.Urls.InstallerDownloadUrl);
                    if (closeApplication)
                    {
                        mmApp.Model.Window.Close();
                    }
                }
            }


            return(isNewVersion);
        }
示例#2
0
 public void Command_Settings()
 {
     SettingsCommand = new CommandBase((parameter, command) =>
     {
         ShellUtils.GoUrl(Path.Combine(mmApp.Configuration.CommonFolder, "KavaDocsAddin.json"));
     });
 }
示例#3
0
        private void Button_BackupToFolder(object sender, RoutedEventArgs e)
        {
            var outputFolder = Path.Combine(Model.AppModel.Configuration.CommonFolder, "Backups");

            if (!Directory.Exists(outputFolder))
            {
                Directory.CreateDirectory(outputFolder);
            }

            var folder = mmWindowsUtils.ShowFolderDialog(outputFolder, "Backup Configuration Files Folder");

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

            outputFolder = Path.Combine(folder, $"{DateTime.Now:yyyy-MM-dd}-Markdown-Monster-Confguration");
            if (Directory.Exists(folder))
            {
                outputFolder = Path.Combine(folder, $"{DateTime.Now:yyyy-MM-dd-HH-mm}-Markdown-Monster-Confguration");
            }

            var bu = new BackupManager();

            if (!bu.BackupToFolder(outputFolder))
            {
                StatusBar.ShowStatusError("Backup failed. Files have not been backed up to a Zip file.");
            }
            else
            {
                StatusBar.ShowStatusSuccess("Backup to Folder completed.");
                ShellUtils.GoUrl(outputFolder);
            }
        }
示例#4
0
        public void UploadCompletePost()
        {
            var  medium = new MediumApiClient(WeblogInfo);
            bool result = medium.GetUser();

            Assert.IsTrue(result, medium.ErrorMessage);

            // make sure there is at least one publication available
            var pubs = medium.GetBlogs();

            Assert.IsNotNull(pubs, medium.ErrorMessage);
            Assert.IsTrue(pubs.Count > 0);

            string pubId = pubs.FirstOrDefault().BlogId as string;

            WeblogInfo.BlogId = pubId;

            var post = new Post
            {
                Tags  = new string[] { "Markdown", "Test" },
                Title = "Test Post #" + DataUtils.GenerateUniqueId(),
                Body  = @"<h1>New Post</h1>
<img src=""MarkdownMonster.png"" />
<p>This is a new post and text and image</p>
"
            };


            var mediumPost = medium.PublishCompletePost(post, documentBasePath: FileUtils.GetPhysicalPath(".\\"));

            Assert.IsNotNull(mediumPost.url, medium.ErrorMessage);
            Console.WriteLine(mediumPost.url);
            Console.WriteLine(mediumPost.id);
            ShellUtils.GoUrl(mediumPost.url);
        }
示例#5
0
        public void UploadPostToPublication()
        {
            var  medium = new MediumApiClient(WeblogInfo);
            bool result = medium.GetUser();

            Assert.IsTrue(result, medium.ErrorMessage);

            // make sure there is at least one publication available
            var pubs = medium.GetBlogs();

            Assert.IsNotNull(pubs, medium.ErrorMessage);

            string pubId = pubs.FirstOrDefault().BlogId as string;


            var post = new MediumPost()
            {
                tags            = new string[] { "Markdown", "Test" },
                title           = "Test Post #" + DataUtils.GenerateUniqueId(),
                content         = "This is a **test post**.",
                contentFormat   = "markdown",
                publishStatus   = "draft",
                notifyFollowers = false,
                canonicalUrl    = "https://weblog.west-wind.com"
            };

            post = medium.PublishPost(post, pubId);

            Assert.IsNotNull(post.url, medium.ErrorMessage);
            Console.WriteLine(post.url);
            Console.WriteLine(post.id);
            ShellUtils.GoUrl(post.url);
        }
        void OpenOnGithub()
        {
            OpenOnGithubCommand = new CommandBase((parameter, command) =>
            {
                var filename = parameter as string;
                if (parameter == null)
                {
                    return;
                }

                var CommitModel = new GitCommitModel(filename);

                using (var repo = CommitModel.GitHelper.OpenRepository(CommitModel.Filename))
                {
                    var remoteUrl = repo?.Network.Remotes.FirstOrDefault()?.Url;
                    if (remoteUrl == null)
                    {
                        return;
                    }

                    var relativeFilename = FileUtils.GetRelativePath(filename, repo.Info.WorkingDirectory)
                                           .Replace("\\", "/");

                    remoteUrl  = remoteUrl.Replace(".git", "");
                    remoteUrl += "/blob/master/" + relativeFilename;

                    Model.Window.ShowStatus("Opening Url: " + remoteUrl);
                    ShellUtils.GoUrl(remoteUrl);
                }
            });
        }
示例#7
0
 /// <summary>
 /// Allows the PreviewBrowser to navigate to a URL for external links
 /// so links open in the default browser rather than IE.
 /// </summary>
 /// <param name="url"></param>
 public void NavigateExternalUrl(string url)
 {
     if (!string.IsNullOrEmpty(url))
     {
         ShellUtils.GoUrl(url);
     }
 }
示例#8
0
        public void UploadPost()
        {
            var  medium = new MediumApiClient(WeblogInfo);
            bool result = medium.GetUser();

            Assert.IsTrue(result, medium.ErrorMessage);

            var post = new MediumPost()
            {
                tags            = new string[] { "Markdown", "Test" },
                title           = "Test Post #" + DataUtils.GenerateUniqueId(),
                content         = "This is a **test post**.",
                contentFormat   = "markdown",
                publishStatus   = "draft",
                notifyFollowers = false,
                canonicalUrl    = "https://weblog.west-wind.com"
            };

            post = medium.PublishPost(post);

            Assert.IsNotNull(post.url, medium.ErrorMessage);
            Console.WriteLine(post.url);
            Console.WriteLine(post.id);
            ShellUtils.GoUrl(post.url);
        }
示例#9
0
        private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (ActiveAddin == null)
            {
                return;
            }

            ShellUtils.GoUrl(ActiveAddin.gitUrl);
        }
        private void ButtonMoreInfo_Click(object sender, RoutedEventArgs e)
        {
            if (ActiveAddin == null)
            {
                return;
            }

            ShellUtils.GoUrl(ActiveAddin.gitUrl);
        }
示例#11
0
        protected override void OnStartup(StartupEventArgs e)
        {
            if (_noStart)
            {
                return;
            }

#if true
            var dotnetVersion = MarkdownMonster.Utilities.mmWindowsUtils.GetDotnetVersion();
            if (string.Compare(dotnetVersion, "4.7.2", StringComparison.Ordinal) < 0)
            {
                Task.Run(() => MessageBox.Show("Markdown Monster requires .NET 4.7.2 or later to run.\r\n\r\n" +
                                               "Please download and install the latest .NET Framework version from:\r\n" +
                                               "https://dotnet.microsoft.com/download/dotnet-framework\r\n\r\n" +
                                               "Exiting application and navigating to .NET Runtime Downloads page.",
                                               "Markdown Monster",
                                               MessageBoxButton.OK,
                                               MessageBoxImage.Warning
                                               ));

                Thread.Sleep(10000);
                ShellUtils.GoUrl("https://dotnet.microsoft.com/download/dotnet-framework");

                mmApp.Log("Dotnet Framework Version not met: " + dotnetVersion, logLevel: LogLevels.Warning);
                Environment.Exit(0);
            }
#endif

            if (mmApp.Configuration.DisableHardwareAcceleration)
            {
                RenderOptions.ProcessRenderMode = System.Windows.Interop.RenderMode.SoftwareOnly;
            }

            // always set directory tocurrent location
            var dir = Assembly.GetExecutingAssembly().Location;
            Directory.SetCurrentDirectory(Path.GetDirectoryName(dir));

            if (!mmApp.Configuration.DisableAddins)
            {
                ThreadPool.QueueUserWorkItem(p => LoadAddins());
            }

            ThemeCustomizations();

            ThreadPool.QueueUserWorkItem(p =>
            {
                mmFileUtils.EnsureBrowserEmulationEnabled("MarkdownMonster.exe");
                mmFileUtils.EnsureSystemPath();
                mmFileUtils.EnsureAssociations();

                if (!Directory.Exists(mmApp.Configuration.InternalCommonFolder))
                {
                    Directory.CreateDirectory(mmApp.Configuration.InternalCommonFolder);
                }
            });
        }
        public void PackageLooseFilesWebUrlTest()
        {
            var    packager   = new HtmlPackager();
            string outputFile = @"c:\temp\GeneratedHtml\Output.html";
            bool   result     = packager.PackageHtmlToFolder("http://west-wind.com/", outputFile, null, true);

            Assert.IsTrue(result);

            ShellUtils.GoUrl(outputFile);
        }
示例#13
0
        public void PackageLooseFilesWebUrlToZipTest()
        {
            var    packager = new HtmlPackager();
            string zipFile  = @"c:\temp\GeneratedHtml\HtmlOutput.zip";
            bool   result   = packager.PackageHtmlToZipFile("https://MarkdownMonster.west-wind.com/", zipFile);

            Assert.IsTrue(result, packager.ErrorMessage);

            ShellUtils.GoUrl(zipFile);
        }
        public void UploadFileTest()
        {
            var addin = new SaveToAzureBlobStorageAddin();
            var url   = addin.SaveFileToAzureBlobStorage("c:\\sailbig.jpg", "West Wind Weblog Images");

            Assert.IsNotNull(url);

            Console.WriteLine(url);
            ShellUtils.GoUrl(url);
        }
示例#15
0
        /// <summary>
        /// Allows the PreviewBrowser to navigate to a URL for external links
        /// so links open in the default browser rather than IE.
        /// </summary>
        /// <param name="url"></param>
        /// <returns>true if handled (navigated) false if passed through and expected to navigate</returns>
        public bool NavigateExternalUrl(string url)
        {
            if (mmApp.Configuration.PreviewHttpLinksExternal && !string.IsNullOrEmpty(url))
            {
                ShellUtils.GoUrl(url);
                return(true);
            }

            return(false);
        }
示例#16
0
        public void OpenFile(string file, bool forceEditorFocus = false)
        {
            string format = mmFileUtils.GetEditorSyntaxFromFileType(file);

            if (!string.IsNullOrEmpty(format))
            {
                if (forceEditorFocus && Window.PreviewTab != null)
                {
                    Window.CloseTab(Window.PreviewTab);
                }
                Window.RefreshTabFromFile(file, noFocus: !forceEditorFocus, isPreview: false);
                Window.BindTabHeaders();
                return;
            }

            var ext = Path.GetExtension(file).ToLower().Replace(".", "");

            if (StringUtils.Inlist(ext, "jpg", "png", "gif", "jpeg"))
            {
                Window.OpenBrowserTab(file, isImageFile: true);

                //if (!mmFileUtils.OpenImageInImageViewer(file))
                //{
                //    MessageBox.Show("Unable to launch image viewer " +
                //                    Path.GetFileName(mmApp.Configuration.ImageViewer) +
                //                    "\r\n\r\n" +
                //                    "Most likely the image viewer configured in settings is not valid. Please check the 'ImageEditor' key in the Markdown Monster Settings." +
                //                    "\r\n\r\n" +
                //                    "We're opening the Settings file for you in the editor now.",
                //        "Image Launching Error",
                //        MessageBoxButton.OK, MessageBoxImage.Warning);

                //    Window.OpenTab(Path.Combine(mmApp.Configuration.CommonFolder, "MarkdownMonster.json"),noFocus: !forceEditorFocus);
                //}
            }
            else
            {
                try
                {
                    ShellUtils.GoUrl(file);
                }
                catch
                {
                    Window.ShowStatusError($"Unable to open file {file}");

                    if (MessageBox.Show(
                            "Unable to open this file. Do you want to open it as a text document in the editor?",
                            mmApp.ApplicationName,
                            MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
                    {
                        Window.OpenTab(file, rebindTabHeaders: true, noFocus: true);
                    }
                }
            }
        }
示例#17
0
 public static void OpenFileInExplorer(string filename)
 {
     if (Directory.Exists(filename))
     {
         ShellUtils.GoUrl(filename);
     }
     else
     {
         Process.Start("explorer.exe", $"/select,\"{filename}\"");
     }
 }
        private void ButtonBrowseToGist_Click(object sender, RoutedEventArgs e)
        {
            var gist = ((Button)sender).DataContext as GistItem;

            if (gist == null)
            {
                return;
            }

            ShellUtils.GoUrl(gist.htmlUrl);
        }
示例#19
0
        protected override void OnStartup(StartupEventArgs e)
        {
            if (_noStart)
            {
                return;
            }

            var dotnetVersion = ComputerInfo.GetDotnetVersion();

            if (String.Compare(dotnetVersion, "4.6", StringComparison.Ordinal) < 0)
            {
                new TaskFactory().StartNew(() => MessageBox.Show("Markdown Monster requires .NET 4.6 or later to run.\r\n\r\n" +
                                                                 "Please download and install the latest version of .NET version from:\r\n" +
                                                                 "https://www.microsoft.com/net/download/framework\r\n\r\n" +
                                                                 "Exiting application and navigating to .NET Runtime Downloads page.",
                                                                 "Markdown Monster",
                                                                 MessageBoxButton.OK,
                                                                 MessageBoxImage.Warning
                                                                 ));

                Thread.Sleep(10000);
                ShellUtils.GoUrl("https://www.microsoft.com/net/download/framework");
                Environment.Exit(0);
            }

            new TaskFactory().StartNew(LoadAddins);

            if (mmApp.Configuration.DisableHardwareAcceleration)
            {
                RenderOptions.ProcessRenderMode = System.Windows.Interop.RenderMode.SoftwareOnly;
            }

            // always set directory tocurrent location
            var dir = Assembly.GetExecutingAssembly().Location;

            Directory.SetCurrentDirectory(Path.GetDirectoryName(dir));

            ThemeCustomizations();

            if (!mmApp.Configuration.DisableAddins)
            {
                new TaskFactory().StartNew(() =>
                {
                    ComputerInfo.EnsureBrowserEmulationEnabled("MarkdownMonster.exe");
                    ComputerInfo.EnsureSystemPath();
                    ComputerInfo.EnsureAssociations();

                    if (!Directory.Exists(mmApp.Configuration.InternalCommonFolder))
                    {
                        Directory.CreateDirectory(mmApp.Configuration.InternalCommonFolder);
                    }
                });
            }
        }
示例#20
0
        /// <summary>
        /// Displays the Premium Feature dialog and returns the number of the button 0-n
        /// that was pressed. 1 if the close box was used (same as Cancel or ButtonCancel)
        /// </summary>
        /// <param name="premiumFeatureName">Name of the feature displayed in the dialog</param>
        /// <param name="premiumFeatureLink">Optional doc link - if provided a button for Feature Info is shown</param>
        /// <returns></returns>
        public static int ShowPremiumDialog(string premiumFeatureName, string premiumFeatureLink = null)
        {
            var form = new BrowserMessageBox();

            form.Owner  = mmApp.Model?.Window;
            form.Title  = "Premium Feature not available";
            form.Width  = 580;
            form.Height = 380;
            form.SetMessage(string.Empty);

            string md = $@"<h4 style=""color: steelblue"">{premiumFeatureName} is a Premium Feature</h4>

This premium feature is only available in the registered version
of Markdown Monster. If you would like to use **{premiumFeatureName}** in Markdown Monster,
you can purchase a licensed copy of the software in our Web Store.


<p style=""font-size: 0.8em; font-color: #888"">
<b>Note</b>:  Premium features are <b>randomly disabled</b> in the evaluation edition.</br>
You can retry the operation to access this feature.

";


            form.ShowMarkdown(md);
            form.Icon = mmApp.Model.Window.Icon;
            form.ButtonOkText.Text     = "Buy a License";
            form.ButtonCancelText.Text = "Continue Unlicensed";

            Button featureButton = null;

            if (!string.IsNullOrEmpty(premiumFeatureLink))
            {
                featureButton = form.AddButton("Feature Info", FontAwesomeIcon.InfoCircle, Brushes.SteelBlue);
            }

            var result = form.ShowDialog();

            if (form.ButtonResult == form.ButtonOk)
            {
                ShellUtils.GoUrl("https://markdownmonster.west-wind.com/purchase.aspx");
            }
            else if (form.ButtonResult == featureButton && !string.IsNullOrEmpty(premiumFeatureLink))
            {
                ShellUtils.GoUrl(premiumFeatureLink);
            }

            if (form.ButtonResult == null)
            {
                return(1);
            }

            return(form.PanelButtonContainer.Children.IndexOf(form.ButtonResult));
        }
示例#21
0
        private void Exit_Click(object sender, MouseButtonEventArgs e)
        {
            var accessCount = mmApp.Configuration.ApplicationUpdates.AccessCount;

            if (accessCount > 70)
            {
                ShellUtils.GoUrl(mmApp.Urls.RegistrationUrl);
            }

            Close();
        }
示例#22
0
        private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
        {
            var addin = ListViewAddins.SelectedItem as AddinItem;

            if (addin == null)
            {
                return;
            }

            ShellUtils.GoUrl(addin.gitUrl);
        }
        public void PackageLooseFilesLocalTest()
        {
            var    packager   = new HtmlPackager();
            string outputFile = @"c:\temp\GeneratedHtml\Output.html";
            bool   result     = packager.PackageHtmlToFolder(@"c:\temp\tmpFiles\_MarkdownMonster_Preview.html", outputFile,
                                                             null, true);

            Assert.IsTrue(result);

            ShellUtils.GoUrl(outputFile);
        }
        public void PandocConfigurationItem()
        {
            var    item       = new PandocConfigurationItem();
            string outputFile = "c:\\temp\\test.pdf";

            item.CommandLineArguments = "-markdown -s \"{fileIn}\" -o \"{fileOut}\"";
            var res = item.Execute("Hello **Cruel** ~~world~~!\n\n* item 1\n* item 2", outputFile, null, "c:\\temp");

            Assert.IsTrue(res.Item1);

            ShellUtils.GoUrl(outputFile);
        }
示例#25
0
 public static void ShowExternalBrowser(string url)
 {
     if (string.IsNullOrEmpty(mmApp.Configuration.WebBrowserPreviewExecutable) ||
         !File.Exists(mmApp.Configuration.WebBrowserPreviewExecutable))
     {
         mmApp.Configuration.WebBrowserPreviewExecutable = null;
         ShellUtils.GoUrl(url);
     }
     else
     {
         ExecuteProcess(mmApp.Configuration.WebBrowserPreviewExecutable, $"\"{url}\"");
     }
 }
示例#26
0
        public void UploadImage()
        {
            var  medium = new MediumApiClient(WeblogInfo);
            bool result = medium.GetUser();

            Assert.IsTrue(result, medium.ErrorMessage);

            string url = medium.PublishImage(".\\MarkdownMonster.png");

            Assert.IsNotNull(url, medium.ErrorMessage);
            Console.WriteLine(url);
            ShellUtils.GoUrl(url);
        }
示例#27
0
        bool CheckForNewVersion(bool force, bool closeForm = true)
        {
            var  updater      = new ApplicationUpdater(typeof(MainWindow));
            bool isNewVersion = updater.IsNewVersionAvailable(!force);

            if (isNewVersion)
            {
                var res = MessageBox.Show(updater.VersionInfo.Detail + "\r\n\r\n" +
                                          "Do you want to download and install this version?",
                                          updater.VersionInfo.Title,
                                          MessageBoxButton.YesNo,
                                          MessageBoxImage.Information);

                if (res == MessageBoxResult.Yes)
                {
                    updater.DownloadProgressChanged += (sender, e) =>
                    {
                        WindowUtilities.DoEvents();
                        ShowStatus("Downloading Update: " +
                                   (e.BytesReceived / 1000).ToString("n0") + "kb  of  " +
                                   (e.TotalBytesToReceive / 1000).ToString("n0") + "kb");
                    };
                    ShowStatus("Downloading Update...");

                    WindowUtilities.DoEvents();

                    if (!updater.Download() || !updater.ExecuteDownloadedFile())
                    {
                        MessageBox.Show("Failed to download the update file. Please install the update " +
                                        "manually from http://markdownmonster.west-wind.com/.\r\n\r\n" +
                                        updater.ErrorMessage,
                                        "Update Failed",
                                        MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        ShellUtils.GoUrl("http://markdownmonster.west-wind.com/download.aspx");

                        ShowStatus("Update failed...", 4000);
                        return(false);
                    }

                    ShowStatus("Update download completed...");

                    if (closeForm)
                    {
                        Close();
                    }
                }
            }
            mmApp.Configuration.ApplicationUpdates.LastUpdateCheck = DateTime.UtcNow.Date;

            return(isNewVersion);
        }
        public void CreateGistTest()
        {
            var json     = @"{
  ""description"": ""the description for this gist"",
  ""public"": true,
  ""files"": {
		""file1.txt"": {
			""content"": ""String file contents""
	    }
	}
}";
            var settings = new HttpRequestSettings
            {
                Url         = "https://api.github.com/gists",
                HttpVerb    = "POST",
                Content     = json,
                ContentType = "application/json; charset=utf-8;",
            };

            settings.Headers.Add("User-agent", "Markdown Monster Markdown Editor Gist Add-in");
            settings.Headers.Add("Accept", "application/json");

            var result = HttpUtils.HttpRequestString(settings);



            dynamic jsn = JValue.Parse(result);

            string htmlUrl = jsn.html_url;

            Console.WriteLine(htmlUrl);

            string id = jsn.id;

            Console.WriteLine(id);

            JObject files = jsn.files;

            JProperty fileProp = files.First as JProperty;
            dynamic   fileObj  = fileProp.Value as JObject;

            string rawUrl   = fileObj.raw_url;
            string filename = fileObj.filename;


            Console.WriteLine(rawUrl);
            Console.WriteLine(filename);

            ShellUtils.GoUrl(htmlUrl);
        }
示例#29
0
        void Help()
        {
            HelpCommand = new CommandBase((topicId, command) =>
            {
                string url = mmApp.Urls.DocumentationBaseUrl;

                if (topicId != null)
                {
                    url = mmApp.GetDocumentionUrl(topicId as string);
                }

                ShellUtils.GoUrl(url);
            }, (p, c) => true);
        }
        private void ButtonOpenRemote_Click(object sender, RoutedEventArgs e)
        {
            using (var repo = CommitModel.GitHelper.OpenRepository(CommitModel.Filename))
            {
                var remoteUrl = repo?.Network.Remotes.FirstOrDefault()?.Url;
                if (remoteUrl == null)
                {
                    return;
                }

                StatusBar.ShowStatusSuccess("Opening Url: " + remoteUrl);
                ShellUtils.GoUrl(remoteUrl.Replace(".git", ""));
            }
        }