private static string RunConverter(string converter, string convertArguments, string text) { var args = convertArguments ?? ""; var program = StartInfo(converter, args, text != null); using (var process = Process.Start(program)) { if (process == null) { Notify.Alert($"Error starting {converter}"); return(text); } if (text != null) { var utf8 = new StreamWriter(process.StandardInput.BaseStream, Encoding.UTF8); utf8.Write(text); utf8.Close(); } var result = process.StandardOutput.ReadToEnd(); process.WaitForExit(); if (process.ExitCode != 0) { var msg = process.StandardError.ReadToEnd(); result = string.IsNullOrWhiteSpace(msg) ? "empty error response" : msg; } return(result); } }
private void SetLanguage(string language) { try { ClearLanguage(); var speller = new Hunspell(); var path = SpellCheckFolder(); var aff = Path.Combine(path, language + ".aff"); var dic = Path.Combine(path, language + ".dic"); if (File.Exists(aff) && File.Exists(dic)) { speller.Load(aff, dic); LoadCustomDictonary(speller); _speller = speller; _language = language; } else { Notify.Alert(language + " dictionary not found"); } } catch (Exception ex) { Notify.Alert($"{ex.Message} in {language ?? "null"} file"); } }
private void SetupSyntaxHighlighting() { var colorizer = new MarkdownHighlightingColorizer(); var blockBackgroundRenderer = new BlockBackgroundRenderer(); TextChanged += (s, e) => { try { AbstractSyntaxTree = GenerateAbstractSyntaxTree(Text); colorizer.UpdateAbstractSyntaxTree(AbstractSyntaxTree); blockBackgroundRenderer.UpdateAbstractSyntaxTree(AbstractSyntaxTree); // The block nature of markdown causes edge cases in the syntax hightlighting. // This is the nuclear option but it doesn't seem to cause issues. EditBox.TextArea.TextView.Redraw(); } catch (Exception ex) { // See #159 Notify.Alert($"Abstract Syntax Tree generation failed: {ex.ToString()}"); } }; ThemeChanged += (s, e) => { colorizer.OnThemeChanged(e.Theme); blockBackgroundRenderer.OnThemeChanged(e.Theme); }; EditBox.TextArea.TextView.LineTransformers.Add(colorizer); EditBox.TextArea.TextView.BackgroundRenderers.Add(blockBackgroundRenderer); }
private static string RunConverter(string converter, string text) { var separator = converter.StartsWith("\"") ? new[] { '"' } : null; var split = converter.Split(separator, 2); var fileName = split[0]; var args = split[1]; var program = StartInfo(fileName, args, text != null); using (var process = Process.Start(program)) { if (process == null) { Notify.Alert($"Error starting {fileName}"); return(text); } if (text != null) { var utf8 = new StreamWriter(process.StandardInput.BaseStream, Encoding.UTF8); utf8.Write(text); utf8.Close(); } var result = process.StandardOutput.ReadToEnd(); process.WaitForExit(); if (process.ExitCode != 0) { var msg = process.StandardError.ReadToEnd(); result = string.IsNullOrWhiteSpace(msg) ? "empty error response" : msg; } return(result); } }
private static void InitializeSettings() { try { if (Settings.Default.UpgradeSettings) { Settings.Default.Upgrade(); Settings.Default.UpgradeSettings = false; Settings.Default.Save(); // Adds new settings from this version UserSettings.Load()?.Save(); } } catch (ConfigurationErrorsException e) { var ex = e.InnerException as ConfigurationErrorsException; if (string.IsNullOrWhiteSpace(ex?.Filename)) { Notify.Alert("Settings file corrupted, can't delete."); throw; } File.Delete(ex.Filename); Process.Start(ResourceAssembly.Location); Current.Shutdown(); } UserSettings = UserSettings.Load(); }
private async void Update(string markdown) { if (markdown == null) { return; } try { UpdateBaseTag(); var div = GetContentsDiv(); if (div == null) { return; } await Task.Run(() => { var html = Markdown.ToHtml(markdown); div.innerHTML = ScrubHtml(html); }); UpdateDocumentStatistics(div.innerText ?? string.Empty); EmitFirePreviewUpdatedEvent(); } catch (Exception ex) { Notify.Alert(ex.ToString()); } }
private void TryIt(Action <string> action) { try { if (_vm.UseClipboardImage) { action(null); } else { foreach (var droppedFile in DroppedFiles().Where(Images.IsImageUrl)) { action(droppedFile); } } } catch (Exception ex) { Notify.Alert(ex.Message); } finally { ActivateClose(); } }
private void ReadSnippetFile() { try { var file = SnippetFile(); if (File.Exists(file) == false) { Directory.CreateDirectory(UserSettings.SettingsFolder); File.WriteAllText(file, Resources.Snippets); } var key = default(string); var value = default(string); _snippets = new Dictionary <string, string>(); foreach (var line in File.ReadAllLines(file)) { if (key != null) { // Keep reading until terminator sequence if (line.TrimEnd() != "::") { value += line + Environment.NewLine; } else { _snippets.Add(key, value); key = null; value = null; } continue; } if (string.IsNullOrWhiteSpace(line)) { continue; } var pair = line.Split(null, 2); if (pair.Length == 2) { _snippets.Add(pair[0], pair[1]); } else if (pair[0].EndsWith("::") && pair[0][0] != ':') { // begin multiline sequence key = pair[0].TrimEnd(':'); value = string.Empty; } } } catch (Exception ex) { Notify.Alert($"{ex.Message} in {SnippetFile()}"); } }
private static Theme LoadTheme(string file) { try { return(JsonConvert.DeserializeObject <Theme>(file.ReadAllTextRetry())); } catch (Exception ex) { Notify.Alert($"{ex.Message} in {file ?? "null"}"); return(null); } }
private void UpdateCustomDictionary(string word) { try { var file = CustomDictionaryFile(); File.AppendAllLines(file, new[] { word }); } catch (Exception ex) { Notify.Alert($"{ex.Message} while updating custom dictionary"); } }
private void LoadCustomDictonary(Hunspell speller) { try { var file = CustomDictionaryFile(); foreach (var word in File.ReadAllLines(file)) { speller.Add(word); } } catch (Exception ex) { Notify.Alert($"{ex.Message} while loading custom dictionary"); } }
private void OpenFile() { var file = FilesListBox.SelectedItem as RecentFile; if (file == null) { return; } if (File.Exists(file.FileName.StripOffsetFromFileName()) == false) { Notify.Alert((string)TranslationProvider.Translate("recent-file-not-found"), this); return; } ApplicationCommands.Open.Execute(file.FileName, Application.Current.MainWindow); ApplicationCommands.Close.Execute(null, this); }
private static void Execute(object sender, ExecutedRoutedEventArgs e) { try { var filename = GetFileName(); if (filename == null) { return; } var theme = JsonConvert.SerializeObject(App.UserSettings.Theme); // ReSharper disable once AssignNullToNotNullAttribute Directory.CreateDirectory(Path.GetDirectoryName(filename)); File.WriteAllText(filename, theme); } catch (Exception ex) { Notify.Alert(ex.Message); } }
private void Guard(Func <string, string> action) { try { var text = _vm.UseClipboardImage ? action(null) : DroppedFiles().Where(Images.IsImageUrl).Select(action).Aggregate((a, c) => a + c); InsertText(TextEditor, DragEventArgs, text); } catch (Exception ex) { Notify.Alert(ex.Message); } finally { ActivateClose(); } }
public async Task SetPedVehicleDensityToZeroEveryFrame() { var position = Game.PlayerPed.Position; var rxr = Radius1 * Radius1; if (position.DistanceToSquared2D(Pos1) <= rxr || position.DistanceToSquared2D(Pos2) <= rxr || position.DistanceToSquared2D(Pos3) <= rxr || position.DistanceToSquared2D(Pos4) <= rxr) { SetPedDensityMultiplierThisFrame(0); SetVehicleDensityMultiplierThisFrame(0); if (Game.Player.WantedLevel > 0) { Game.PlayerPed.Health = -100; Notify.Alert("被通缉的时候禁止进入秋名山区域!"); } } await Task.FromResult(0); }
private void Update(string markdown) { if (markdown == null) { return; } try { var html = Markdown.ToHtml(markdown); UpdateBaseTag(); var div = GetContentsDiv(); if (div == null) { return; } div.innerHTML = ScrubHtml(html); WordCount = div.innerText.WordCount(); EmitFirePreviewUpdatedEvent(); } catch (CommonMarkException ex) { Notify.Alert(ex.ToString()); } }
private async void OnUploadToImgur(object sender, RoutedEventArgs e) { try { UploadProgressChangedEventHandler progress = (o, args) => TextEditor.Dispatcher.InvokeAsync(() => { if (_canceled) { ((WebClient)o).CancelAsync(); } var progressPercentage = (int)(args.BytesSent / (double)args.TotalBytesToSend * 100); ProgressBar.Value = progressPercentage; if (progressPercentage == 100) { ProgressBar.IsIndeterminate = true; } }); UploadValuesCompletedEventHandler completed = (o, args) => { if (_canceled) { ((WebClient)o).CancelAsync(); } }; string name; byte[] image; if (_vm.UseClipboardImage) { name = "clipboard"; image = Images.ClipboardDibToBitmapSource().ToPngArray(); } else { var files = DroppedFiles(); if (files.Length > 1) { throw new Exception("Upload only 1 file at a time"); } var path = files[0]; name = Path.GetFileNameWithoutExtension(path); image = File.ReadAllBytes(path); } _vm.Uploading = true; ContextMenu.IsOpen = false; var link = await new ImageUploadImgur().UploadBytesAsync(image, progress, completed); ActivateClose(); if (Uri.IsWellFormedUriString(link, UriKind.Absolute)) { InsertText(TextEditor, DragEventArgs, CreateImageTag(link, name)); } else { Notify.Alert(link); } } catch (Exception ex) { ActivateClose(); Notify.Alert(ex.Message); } }