private async Task MakeChanges(string root, string fileName)
        {
            string text      = Element.GetText(Element.InnerRange).Trim();
            string reference = GetReference(Element, fileName, root);

            try
            {
                ProjectHelpers.DTE.UndoContext.Open(DisplayText);
                using (ITextEdit edit = TextBuffer.CreateEdit())
                {
                    edit.Replace(new Span(Element.Start, Element.Length), reference);
                    edit.Apply();
                }

                File.WriteAllText(fileName, text);
                ProjectHelpers.AddFileToActiveProject(fileName);
                ProjectHelpers.DTE.ItemOperations.OpenFile(fileName);

                await Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() =>
                {
                    ProjectHelpers.DTE.ExecuteCommand("Edit.FormatDocument");
                }), DispatcherPriority.ApplicationIdle, null);
            }
            finally
            {
                ProjectHelpers.DTE.UndoContext.Close();
            }
        }
示例#2
0
 public static bool SaveDataUriToFile(string dataUri, string filePath)
 {
     try
     {
         int    index      = dataUri.IndexOf("base64,", StringComparison.Ordinal) + 7;
         byte[] imageBytes = Convert.FromBase64String(dataUri.Substring(index));
         File.WriteAllBytes(filePath, imageBytes);
         ProjectHelpers.AddFileToActiveProject(filePath);
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }