public IPathNode SetItem(IContext context, string path, object value) { var p = context.DynamicParameters as SetItemDynamicParameters; if (null != p && null != p.Bindings) { _command.Bindings = p.Bindings; } if (null != value) { string functionName = FunctionUtilities.GetFunctionNameFromPath(path); var fpath = "function:" + functionName; string command = String.Format( @"if( test-path ""{0}"" ) {{ remove-item -path ""{0}""; }} new-item -path ""{0}"" -value {{ {1} }} -options Constant,AllScope;", fpath, value ); context.InvokeCommand.InvokeScript(command, false, PipelineResultTypes.None, null); } return(GetNodeValue()); }
void RemoveScriptCommands() { var dte = _applicationObject; if (null == dte) { return; } var keepers = new[] { StudioShellExecuteCommandName, StudioShellRestartCommandName, StudioShellCommandName, StudioShellCancelCommandName }; List <Command> losers = new List <Command>(); foreach (Command cmd in dte.Commands) { if (keepers.Contains(cmd.Name, StringComparer.InvariantCultureIgnoreCase)) { continue; } if (FunctionUtilities.IsPowerShellCommandName(cmd.Name)) { losers.Add(cmd); } } losers.ForEach(cmd => cmd.Delete()); }
/// <summary>Implements the QueryStatus method of the IDTCommandTarget interface. This is called when the command's availability is updated</summary> /// <param term='commandName'>The name of the command to determine state for.</param> /// <param term='neededText'>Text that is needed for the command.</param> /// <param term='status'>The state of the command in the user interface.</param> /// <param term='commandText'>Text requested by the neededText parameter.</param> /// <seealso class='Exec' /> public void QueryStatus(string commandName, vsCommandStatusTextWanted neededText, ref vsCommandStatus status, ref object commandText) { if (neededText == vsCommandStatusTextWanted.vsCommandStatusTextWantedNone) { if (commandName == StudioShellCommandName) { status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled; return; } if (commandName == StudioShellRestartCommandName) { if (null != Shell) { status = (vsCommandStatus)(vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled); } else { status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported; } return; } if (commandName == StudioShellCancelCommandName) { if (null != Shell && Shell.CurrentState == CommandExecutorState.Unavailable) { status = (vsCommandStatus)(vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled); } else { status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported; } return; } if (commandName == StudioShellExecuteCommandName || FunctionUtilities.IsPowerShellCommandName(commandName)) { if (null != Shell && Shell.CurrentState == CommandExecutorState.Unavailable) { status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported; } else { status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled; } return; } if (commandName == StudioShellDoNothingCommandName) { status = vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled; } } }
public void RemoveItem(IContext context, string path, bool recurse) { _command.Delete(); string functionName = FunctionUtilities.GetFunctionNameFromPath(path); string script = "remove-item -path function:" + functionName; context.InvokeCommand.InvokeScript(script, false, PipelineResultTypes.None, null); }
private static async Task <HttpResponseMessage> Run(HttpRequest req, ILogger log, ExecutionContext ec, string version) { return(await SafeExecutor.Execute(async() => { var cnfg = ConfigUtilities.LoadConfiguration(); var graphRequestUrl = UrlUtilities.Combine(cnfg.GraphBaseUrl, req.Path, req.QueryString.ToString()); var authProvider = FunctionUtilities.GetAuthenticationProvider(req, cnfg); var graphClient = GraphUtilities.GetAuthenticatedClient(cnfg.GraphBaseUrl, version, authProvider); var graphResponse = await GraphUtilities.ExecuteGetRequest(graphClient, graphRequestUrl); return await FunctionUtilities.TransformResponse(req.GetHostUrl(), cnfg.GraphBaseUrl, graphResponse); }, req, log)); }
public IPathNode NewItem(IContext context, string path, string itemTypeName, object value) { AddIn addIn = Locator.Get <AddIn>(); if (null == addIn) { throw new ServiceUnavailableException( typeof(AddIn), "Note that the new-item cmdlet is not available for Visual Studio Commands when using the StudioShell standalone provider." ); } var validValueTypes = new[] { typeof(ScriptBlock), typeof(string) }; if (!validValueTypes.Contains(value.GetType())) { var validNames = String.Join(", ", validValueTypes.ToList().ConvertAll(t => t.FullName).ToArray()); throw new ArgumentException("new item values must be one of the following types: " + validNames); } var p = context.DynamicParameters as NewItemDynamicParameters ?? new NewItemDynamicParameters(); object[] contextGuids = new object[] {}; string functionName = FunctionUtilities.GetFunctionNameFromPath(path); var cmd = _commands.AddNamedCommand2( addIn, path, p.Label ?? path, p.Tooltip ?? String.Empty, true, null, ref contextGuids, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton ); if (null != p.Bindings) { cmd.Bindings = p.Bindings; } string command = "new-item -path function:global:" + functionName + " -value {" + value + "} "; context.InvokeCommand.InvokeScript(command, false, PipelineResultTypes.None, null, null); var factory = new CommandNodeFactory(cmd); return(factory.GetNodeValue()); }
/// <summary>Implements the Exec method of the IDTCommandTarget interface. This is called when the command is invoked.</summary> /// <param term='commandName'>The name of the command to execute.</param> /// <param term='executeOption'>Describes how the command should be run.</param> /// <param term='varIn'>Parameters passed from the caller to the command handler.</param> /// <param term='varOut'>Parameters passed from the command handler to the caller.</param> /// <param term='handled'>Informs the caller if the command was handled or not.</param> /// <seealso class='Exec' /> public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled) { handled = false; if (executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault) { if (commandName == StudioShellCommandName) { ExecuteStudioShellCommand(); handled = true; return; } if (commandName == StudioShellRestartCommandName) { RestartShell(); handled = true; return; } if (commandName == StudioShellExecuteCommandName) { varOut = ExecuteStudioShellExecuteCommand(varIn); handled = true; return; } if (commandName == StudioShellCancelCommandName) { ExecuteStudioShellCancelCommand(); handled = true; return; } if (commandName.EndsWith("_1")) { handled = true; return; } if (FunctionUtilities.IsPowerShellCommandName(commandName)) { varOut = null; handled = true; object input = varIn; ThreadPool.QueueUserWorkItem(ctx => ExecuteStudioShellPowerShellCommand(commandName, input)); return; } } }
public static void Run([ServiceBusTrigger("InputQueue", AccessRights.Listen, Connection = "")] BrokeredMessage queueMessage, Microsoft.Azure.WebJobs.ExecutionContext context, CancellationToken cancellationToken) { var utilities = new FunctionUtilities(context.FunctionName, context.InvocationId); var logger = utilities.Logger; logger.TrackTrace($"Started function {nameof(ASBQueueTrigger)}", SeverityLevel.Information); cancellationToken.Register(() => { var exception = new OperationCanceledException("Azure function reached the time limit", cancellationToken); logger.TrackException(exception); throw exception; }); Event eventObject = new Event(); try { eventObject = queueMessage.GetBody <Event>(); } catch (Exception exception) { logger.TrackException(exception); } if (string.IsNullOrWhiteSpace(eventObject.User)) { return; } using (var client = new HttpClient()) { var response = client.PostAsJsonAsync(utilities.ConfigurationManager.ApiUrl, eventObject); } }