private void _WriteGroupByGroupHeader(object newResult, bool isDefaultGroupBy) { PsContext headerCtx; bool preserveHeaderContext; ScriptBlock customHeaderScript = GetCustomWriteGroupByGroupHeaderScript(out headerCtx, out preserveHeaderContext); if (null != customHeaderScript) { // ISSUE: Or maybe the group-by evaluation functions should return a // PSObject instead. PSObject pso = newResult as PSObject; if ((null == pso) && (null != newResult)) { pso = new PSObject(newResult); // you can't pass null to the PSObject constructor. } using (var pch = new PsContextHelper(customHeaderScript, headerCtx, preserveHeaderContext)) { string val = RenderScriptValue(pso, pch.AdjustedScriptBlock, true, pch.WithContext); m_groupByHeaderCtx = pch.SavedContext; if (null != val) { WriteObject(val); } } } else if (isDefaultGroupBy) { // If something makes sense to be the default group by, it's probably clear what it is from context without a special label // And we probably don't want indentation & blank lines surrounding something that is printed all the time WriteObject(ObjectToMarkedUpString(newResult).ToString()); } else { WriteObject(String.Empty); WriteObject(new ColorString(" ") //.AppendPushFgBg( ConsoleColor.Black, ConsoleColor.Cyan ) //.AppendPushFg( ConsoleColor.Cyan ) .AppendPushFgBg(ConsoleColor.Black, ConsoleColor.White) .Append(m_groupByLabel) .AppendPop() .Append(": ") .Append(ObjectToMarkedUpString(newResult).ToString()) .ToString(DbgProvider.HostSupportsColor)); WriteObject(String.Empty); } } // end _WriteGroupByGroupHeader()
private void _WriteGroupByGroupHeader(object newResult) { PsContext headerCtx; bool preserveHeaderContext; ScriptBlock customHeaderScript = GetCustomWriteGroupByGroupHeaderScript(out headerCtx, out preserveHeaderContext); if (null != customHeaderScript) { // ISSUE: Or maybe the group-by evaluation functions should return a // PSObject instead. PSObject pso = newResult as PSObject; if ((null == pso) && (null != newResult)) { pso = new PSObject(newResult); // you can't pass null to the PSObject constructor. } using (var pch = new PsContextHelper(customHeaderScript, headerCtx, preserveHeaderContext)) { string val = RenderScriptValue(pso, pch.AdjustedScriptBlock, true, pch.WithContext); m_groupByHeaderCtx = pch.SavedContext; if (null != val) { WriteObject(val); } } } else { WriteObject(String.Empty); WriteObject(new ColorString(" ") //.AppendPushFgBg( ConsoleColor.Black, ConsoleColor.Cyan ) //.AppendPushFg( ConsoleColor.Cyan ) .AppendPushFgBg(ConsoleColor.Black, ConsoleColor.White) .Append(m_groupByLabel) .AppendPop() .Append(": ") .Append(ObjectToMarkedUpString(newResult).ToString()) .ToString(DbgProvider.HostSupportsColor)); WriteObject(String.Empty); } } // end _WriteGroupByGroupHeader()
protected override void ApplyViewToInputObject() { string val; using (var pch = new PsContextHelper(m_view.Script, m_view.Context + m_preservedScriptContext, m_view.PreserveScriptContext)) { val = RenderScriptValue(InputObject, pch.AdjustedScriptBlock, true, pch.WithContext); if (m_view.PreserveScriptContext) { m_preservedScriptContext += pch.SavedContext; } } if (null != val) { WriteObject(val); } } // end ProcessRecord()
} // end InvokeScript internal static Collection <PSObject> InvokeWithContext(ScriptBlock scriptBlock, PsContext withContext, PSReference saveContext) { if (null == withContext) { withContext = new PsContext(); // TODO: share a single, readonly Empty context } using (var ctxHelper = new PsContextHelper(scriptBlock, withContext, null != saveContext)) { // TODO: Should I switch to using shell.AddScript, like in FormatBaseCommand.cs? var results = ctxHelper.AdjustedScriptBlock.InvokeWithContext(ctxHelper.WithContext.Funcs, ctxHelper.WithContext.VarList); if (null != saveContext) { saveContext.Value = ctxHelper.SavedContext; } return(results); } // end using( ctxHelper ) } // end InvokeWithContext