private async void Execute(object sender, EventArgs e) { try { ThreadHelper.ThrowIfNotOnUIThread(); this.Logger?.RecordFeatureUsage(nameof(InsertGridRowDefinitionCommand)); var dte = await Instance.ServiceProvider.GetServiceAsync(typeof(DTE)) as DTE; var vs = new VisualStudioAbstraction(this.Logger, this.ServiceProvider, dte); var activeDocText = vs.GetActiveDocumentText(); if (activeDocText.IsValidXml()) { var logic = new InsertGridRowDefinitionCommandLogic(this.Logger, vs); var replacements = logic.GetReplacements(); var(start, end, exclusions) = logic.GetGridBoundary(); var(newDefinition, newDefPos) = logic.GetDefinitionAtCursor(); vs.StartSingleUndoOperation(StringRes.Info_UndoContextIndertRowDef); try { vs.ReplaceInActiveDoc(replacements, start, end, exclusions); vs.InsertIntoActiveDocumentOnNextLine(newDefinition, newDefPos); } finally { vs.EndSingleUndoOperation(); } } else { this.Logger.RecordInfo(StringRes.Info_UnableToInsertRowDefinitionInvalidXaml); } } catch (Exception exc) { this.Logger?.RecordException(exc); throw; } }