public string ConvertMarkdownToHTML(string markdown) { if (!NetworkUtilities.IsNetworkAvailable()) { return("<strong>" + LocalizationProvider.GetLocalizedString("Error_NoNetworkConnection", false, "MarkdownPadStrings") + "</strong>"); } IAuthenticator authenticator = null; if (!this._settings.Markdown_GFM_AnonymousMode) { authenticator = new HttpBasicAuthenticator(this._settings.Markdown_GFM_Username, SettingsProvider.DecryptString(this._settings.Markdown_GFM_Password).ToInsecureString()); } RestClient restClient = new RestClient { BaseUrl = "https://api.github.com", Authenticator = authenticator, Proxy = WebRequest.DefaultWebProxy }; RestRequest restRequest = new RestRequest { Resource = "markdown", RequestFormat = RestSharp.DataFormat.Json, Method = Method.POST }; restRequest.AddBody(new { text = markdown, mode = "gfm" }); IRestResponse restResponse = restClient.Execute(restRequest); try { this.CheckResponse(restResponse); } catch (RestResponseException ex) { GitHubFlavoredMarkdownProcessor._logger.ErrorException("GFM RestResponseException", ex); string text = string.Empty; if (ex.Response == null) { GitHubFlavoredMarkdownProcessor._logger.ErrorException("GFM RestResponseException: Response was null", ex); text = ex.Message; } else { if (ex.Response.ErrorException != null) { GitHubFlavoredMarkdownProcessor._logger.ErrorException("GFM RestResponseException: Response was not null, and an Response ErrorException was present.", ex.Response.ErrorException); text = ex.Response.ErrorMessage; } else { GitHubFlavoredMarkdownProcessor._logger.ErrorException("GFM RestResponseException: Error message received from GFM API, deserializing JSON...\n" + ex.Response, ex); try { JsonDeserializer jsonDeserializer = new JsonDeserializer(); System.Collections.Generic.Dictionary <string, string> dictionary = jsonDeserializer.Deserialize <System.Collections.Generic.Dictionary <string, string> >(ex.Response); if (dictionary.ContainsKey("message")) { HttpStatusCode statusCode = ex.Response.StatusCode; string statusDescription = ex.Response.StatusDescription; string arg = dictionary["message"]; text = string.Format("{0} ({1}): {2}", statusCode, statusDescription, arg); string text2 = text; text = string.Concat(new string[] { text2, "<br /><br />", LocalizationProvider.GetLocalizedString("Error_GitHubFlavoredMarkdownMessage2", false, "MarkdownPadStrings"), "<br /><h4>Technical Details</h4><pre><code>", ex.Response.Content, "</code></pre>" }); } } catch (System.Runtime.Serialization.SerializationException ex2) { GitHubFlavoredMarkdownProcessor._logger.ErrorException("GFM: Error deserializing error", ex2); text = string.Concat(new object[] { LocalizationProvider.GetLocalizedString("Gfm_Error_UnexpectedErrorResponse", false, "MarkdownPadStrings"), "<br /><br /><h4>Technical Details</h4><pre><code>", ex, "</code></pre><br /><pre><code>", ex.Response.Content, "</code></pre><br /><pre><code>", ex2, "</code></pre>" }); } } } return(string.Concat(new string[] { "<p>", LocalizationProvider.GetLocalizedString("Error_GitHubFlavoredMarkdownMessage1", false, "MarkdownPadStrings"), "</p><p><strong>", text, "</strong></p><p>", LocalizationProvider.GetLocalizedString("IfBugPersists", false, "MarkdownPadStrings"), "</p>" })); } return(restResponse.Content); }
public static void SendStats() { if (!NetworkUtilities.IsNetworkAvailable()) { return; } string text = System.Environment.OSVersion.ToString(); string text2 = System.Environment.Is64BitOperatingSystem ? "x64" : "x86"; string version = AssemblyUtilities.Version; string text3 = string.Empty; RegistryView view = RegistryView.Registry32; if (System.Environment.Is64BitOperatingSystem) { view = RegistryView.Registry64; } try { Microsoft.Win32.RegistryKey registryKey = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, view); registryKey = registryKey.OpenSubKey("SOFTWARE\\Microsoft\\Cryptography"); if (registryKey != null) { text3 = registryKey.GetValue("MachineGuid", "keyNotFound").ToString(); } } catch (System.Exception exception) { Stats._logger.ErrorException("Error getting machine GUID", exception); } string input = string.Concat(new object[] { text3, ":", text, ":", System.Environment.MachineName, ":", System.Environment.UserName, ":", System.Environment.UserDomainName, ":", text2, ":", System.Environment.ProcessorCount }); string str = Stats.ComputeHash(input, new System.Security.Cryptography.SHA1CryptoServiceProvider()); System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); stringBuilder.Append("anonHostId=" + HttpUtility.UrlEncode(str)); stringBuilder.Append("&os=" + HttpUtility.UrlEncode(text)); stringBuilder.Append("&cpu=" + HttpUtility.UrlEncode(text2)); stringBuilder.Append("&version=" + HttpUtility.UrlEncode(version)); byte[] bytes = System.Text.Encoding.ASCII.GetBytes(stringBuilder.ToString()); string uri = Stats.useSsl ? Urls.MarkdownPad_StatsSsl : Urls.MarkdownPad_StatsNoSsl; bool flag = false; try { flag = Stats.CreateAndSendWebRequest(uri, bytes); } catch (WebException ex) { Stats._logger.Warn <WebException>("WebException statistics error, retrying once", ex); System.Exception baseException = ex.GetBaseException(); if (baseException.GetType() == typeof(AuthenticationException) && Stats.useSsl) { Stats.useSsl = false; Stats.SendStats(); return; } } catch (System.Exception exception2) { Stats._logger.WarnException("Statistics error", exception2); } Stats._logger.Trace("Statistics success: " + flag); }