GetJsonContent() public static method

public static GetJsonContent ( string configPath, string file, string json = null ) : Newtonsoft.Json.Linq.JObject
configPath string
file string
json string
return Newtonsoft.Json.Linq.JObject
Ejemplo n.º 1
0
        private void AddCommandToFile(object sender, EventArgs e)
        {
            OleMenuCommand button = (OleMenuCommand)sender;
            var            item   = ProjectHelpers.GetSelectedItems().FirstOrDefault();

            if (item == null || item.FileCount == 0)
            {
                return;
            }

            string file = item.FileNames[1];
            bool   isSolution;
            string configPath  = GetConfigPath(item, out isSolution);
            bool   configExist = File.Exists(configPath);

            JObject json = CommandHelpers.GetJsonContent(configPath, file);

            ProjectHelpers.CheckFileOutOfSourceControl(configPath);
            File.WriteAllText(configPath, json.ToString(), new UTF8Encoding(false));

            if (!configExist)
            {
                AddFileToProject(item, isSolution, configPath);
                _dte.ItemOperations.OpenFile(configPath);
                _dte.ExecuteCommand("SolutionExplorer.SyncWithActiveDocument");
                _dte.ExecuteCommand("SolutionExplorer.SyncWithActiveDocument");
            }

            OpenTaskRunnerExplorer();
            _dte.StatusBar.Text = $"File successfully added to {Constants.FILENAME}";
        }
Ejemplo n.º 2
0
        public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo)
        {
            ITextDocument document;

            if (!_documentFactory.TryGetTextDocument(_view.TextDataModel.DocumentBuffer, out document))
            {
                return(DragDropPointerEffects.None);
            }

            var    snapshot      = _view.TextBuffer.CurrentSnapshot;
            string bufferContent = snapshot.GetText();
            var    json          = CommandHelpers.GetJsonContent(document.FilePath, _fileName, bufferContent);

            using (var edit = _view.TextBuffer.CreateEdit())
            {
                edit.Replace(0, snapshot.Length, json.ToString());
                edit.Apply();
            }

            return(DragDropPointerEffects.Link);
        }