public T GetService <T>(CmdletBase CmdletBase, object parameters = null) where T : IService { var serviceType = typeof(T); if (!_factories.ContainsKey(serviceType)) { throw new ArgumentException($"Invalid service {serviceType.FullName}. Are you missing an [Exports] attribute?"); } return((T)_factories[serviceType](this, CmdletBase, parameters)); }
public IDataService <TObj> GetDataService <TObj>(CmdletBase CmdletBase, object overriddenParameters) where TObj : class { var serviceType = typeof(TObj); if (!_factories.ContainsKey(serviceType)) { throw new ArgumentException($"Invalid service {serviceType.FullName}. Are you missing an [Exports] attribute?"); } var dataService = ((IDataService <TObj>)_factories[serviceType](this, CmdletBase, overriddenParameters)); return(dataService); }
// internal static void Log(this CmdletBase cmdlet, string message, string commandName = null, bool force = false) // { // if (!IsVerbose(cmdlet, force)) return; // if (string.IsNullOrEmpty(commandName)) // { // commandName = cmdlet.CommandName; // } // cmdlet.WriteVerbose($"[{DateTime.Now:HH:mm:ss.ffff}] [{commandName}] {message}"); // } // internal static void LogParameters(this CmdletBase cmdlet) // { // if (!IsVerbose(cmdlet)) return; // var parms = new ParameterDictionary(cmdlet); // if (parms.ContainsKey("Password") && parms["Password"] != null) // { // parms["Password"] = "******"; // } // Log(cmdlet, "ARGS: " + JObject.FromObject(parms) // .ToString(Formatting.None) // .Replace("\":", "\" = ") // .Replace(",\"", "; \"") // .Trim('{', '}') // ); // } //private static string GetLogSiteName(CmdletBase cmdlet) //{ //var cs = new Stack(); //var callStack = cmdlet.InvokeCommand.InvokeScript("Get-PSCallStack").Select(o => o.BaseObject as CallStackFrame).Skip(1); //foreach (var frame in callStack) //{ // var cmd = GetCommandName(frame); // cs.Push(cmd.Trim('_')); // //if (cmd.Contains("-")) // //{ // // break; // //} //} // return cmdlet.MyInvocation.InvocationName; //} //private static string GetCommandName(CallStackFrame frame) //{ // if (frame.InvocationInfo == null) // { // return frame.FunctionName; // } // var commandInfo = frame.InvocationInfo.MyCommand; // if (commandInfo == null) // { // return !string.IsNullOrEmpty(frame.InvocationInfo.InvocationName) ? // frame.InvocationInfo.InvocationName : // frame.Position.Text; // } // return !string.IsNullOrEmpty(commandInfo.Name) ? commandInfo.Name : frame.FunctionName; //} private static bool IsVerbose(CmdletBase cmdlet, bool force = false) { if (force) { return(true); } var containsVerbose = cmdlet.MyInvocation.BoundParameters.ContainsKey("Verbose"); if (containsVerbose) { return(((SwitchParameter)cmdlet.MyInvocation.BoundParameters["Verbose"]).ToBool()); } return((ActionPreference)cmdlet.GetVariableValue("VerbosePreference") != ActionPreference.SilentlyContinue); }
public Models.Connection GetCollection(CmdletBase cmdlet, ParameterDictionary parameters = null) { var pd = new ParameterDictionary(parameters) { ["ConnectionType"] = ClientScope.Collection }; var tpc = GetDataService <Models.Connection>(cmdlet, pd).GetItem(); if (tpc == null) { throw new ArgumentException("No TFS connection information available. Either supply a valid -Collection argument or use Connect-TfsTeamProjectCollection prior to invoking this cmdlet."); } return(tpc); }
public Models.Connection GetServer(CmdletBase cmdlet, ParameterDictionary parameters = null) { var pd = new ParameterDictionary(parameters) { ["ConnectionType"] = ClientScope.Server }; var srv = GetDataService <Models.Connection>(cmdlet, pd).GetItem(); if (srv == null) { throw new ArgumentException("No TFS connection information available. Either supply a valid -Server argument or use Connect-TfsConfigurationServer prior to invoking this cmdlet."); } return(srv); }
public (Models.Connection, WebApiTeamProject) GetCollectionAndProject(CmdletBase cmdlet, ParameterDictionary parameters = null) { var tpc = GetCollection(cmdlet, parameters); var pd = new ParameterDictionary(parameters) { ["Collection"] = tpc }; var tp = GetDataService <WebApiTeamProject>(cmdlet, pd).GetItem(); if (tp == null) { throw new ArgumentException("No TFS team project information available. Either supply a valid -Project argument or use Connect-TfsTeamProject prior to invoking this cmdlet."); } return(tpc, tp); }
internal LoggerImpl(CmdletBase cmdlet) { Cmdlet = cmdlet; }
public (Models.Connection, WebApiTeamProject, WebApiTeam) GetCollectionProjectAndTeam(CmdletBase cmdlet, ParameterDictionary parameters = null) { var parms = new ParameterDictionary(cmdlet, parameters); if (parms.Get <object>("Team") is WebApiTeam t) { parms["Project"] = t.ProjectId; } var(tpc, tp) = GetCollectionAndProject(cmdlet, parms); parms["Collection"] = tpc; parms["Project"] = tp; var team = GetDataService <Models.Team>(cmdlet, parms).GetItem(); if (team == null) { throw new ArgumentException("No TFS team information available. Either supply a valid -Team argument or use Connect-TfsTeam prior to invoking this cmdlet."); } return(tpc, tp, team); }