public static string MakeInvocationExpression(string filename, string function, IList <string> proc_params, IList <string> extra_params, IList <IXenObject> objs, bool debug) { filename = Placeholders.Substitute(filename, objs); var expression = $"Invoke-Expression $(Get-Content -Path \"{filename}\" -Raw)"; if (!string.IsNullOrEmpty(function)) { function = Placeholders.Substitute(function, objs); } if (!string.IsNullOrEmpty(function)) { expression = $"{expression}; {function}"; } if (debug) { expression = string.Format(DebugFunction, expression); } string xenArrayStatement = XenArrayStatement(proc_params); string extraArrayStatement = ExtraArrayStatement(extra_params, objs); return($"cd \"{Program.AssemblyDir}\"; {xenArrayStatement} {extraArrayStatement} {expression};"); }
public virtual Process CreateProcess(List <string> procParams, IList <IXenObject> targets) { Process proc = new Process(); proc.StartInfo.FileName = Filename; // Targets can be null if the XenCenter node is being targetted, placeholders can cope with this proc.StartInfo.FileName = Placeholders.Substitute(Filename, targets); // 'Params' are defined in the plugin xml and may require substitution List <string> allParams = new List <string>(Params); for (int i = 0; i < allParams.Count; i++) { // sub in null, multi_target, or object properties depending on how many targets there are allParams[i] = Placeholders.Substitute(allParams[i], targets); } // 'procParams' come from ExternalPluginAction, and are tuples about each target (require no substitution) allParams.AddRange(procParams); proc.StartInfo.Arguments = string.Join(" ", allParams.ToArray()); proc.StartInfo.UseShellExecute = !LogOutput; proc.StartInfo.CreateNoWindow = !Window; proc.StartInfo.WindowStyle = !Window ? ProcessWindowStyle.Hidden : ProcessWindowStyle.Normal; proc.StartInfo.RedirectStandardOutput = LogOutput; proc.StartInfo.RedirectStandardError = LogOutput; return(proc); }
public void SetUrl() { // Never update XenCenter node tabs once loaded if (Browser.Url != null && Browser.Url.AbsoluteUri != "about:blank" && XenCenterOnly) { return; } BrowserState state; if (SelectedXenObject == null) { // XenCenter node is selected, the placeholder code will sub in "null" for all placeholders // After this point we will never update this url again for this node, so there is no need to store a browser state state = new BrowserState(Placeholders.SubstituteUri(Url, SelectedXenObject), SelectedXenObject, Browser); } else if (BrowserStates.ContainsKey(SelectedXenObject)) { state = BrowserStates[SelectedXenObject]; state.Uris = Placeholders.SubstituteUri(Url, SelectedXenObject); } else { state = new BrowserState(Placeholders.SubstituteUri(Url, SelectedXenObject), SelectedXenObject, Browser); BrowserStates[SelectedXenObject] = state; } try { if (state.ObjectForScripting != null) { if (Credentials) { state.ObjectForScripting.LoginSession(); } Browser.ObjectForScripting = state.ObjectForScripting; } lastBrowserState = state; Browser.DocumentText = string.Empty; Application.DoEvents(); lastBrowserState.IsError = false; ShowStatus(string.Format(Messages.WEB_BROWSER_WAITING, ShortUri(state.Uris[0]))); Browser.Navigate(state.Uris[0]); } catch (Exception e) { log.Error(string.Format("Failed to set TabPage url to '{0}' for plugin '{1}'", string.Join(",", state.Uris.ConvertAll(u => u.ToString()).ToArray()), PluginDescriptor.Name), e); } }
public static string MakeInvocationExpression(string filename, string function, IList <string> proc_params, IList <string> extra_params, IList <IXenObject> objs, bool debug) { string expression = string.Format(InvokeExpression, Placeholders.Substitute(filename, objs), Placeholders.Substitute(function ?? "", objs)); string xenArrayStatement = XenArrayStatement(proc_params); string extraArrayStatement = ExtraArrayStatement(extra_params, objs); return(string.Format("cd \"{0}\"; {1} {2} {3};", Program.AssemblyDir, xenArrayStatement, extraArrayStatement, debug ? string.Format(DebugFunction, expression) : expression)); }
private void SetUrl() { if (UrlIsLoaded && XenCenterOnly) // Never update XenCenter node tabs. { return; } BrowserState state; if (selectedXenObject == null) { // XenCenter node is selected, the placeholder code will sub in "null" for all placeholders // After this point we will never update this url again for this node, so there is no need to store a browser state state = new BrowserState(Placeholders.SubstituteUri(Url, selectedXenObject), selectedXenObject, Browser); } else if (BrowserStates.ContainsKey(selectedXenObject) && !BrowserStates[selectedXenObject].IsError) { // if there wasn't an error with navigation then use the stored browser-state. Otherwise try again. state = BrowserStates[selectedXenObject]; } else { state = new BrowserState(Placeholders.SubstituteUri(Url, selectedXenObject), selectedXenObject, Browser); BrowserStates[selectedXenObject] = state; } if (lastBrowserState == state) { return; } try { if (state.ObjectForScripting != null) { if (Credentials) { state.ObjectForScripting.LoginSession(); } Browser.ObjectForScripting = state.ObjectForScripting; } Browser.Navigate(state.Urls); lastBrowserState = state; } catch (Exception e) { log.Error(string.Format("Failed to set TabPage url to '{0}' for plugin '{1}'", string.Join(",", state.Urls.ConvertAll(u => u.ToString()).ToArray()), PluginDescriptor.Name), e); } }
private static string ExtraArrayStatement(IList <string> extraParams, IList <IXenObject> objs) { // now we form a statement that will initialise a powershell array in the format (a,b,c,d,e,f,g) StringBuilder sb = new StringBuilder(); sb.Append(string.Format("${0}=@(", USER_PARAM_ARRAY_VAR_NAME)); for (int i = 0; i < extraParams.Count; i++) { if (i > 0) { sb.Append(','); } sb.Append('"'); sb.Append(EscapeQuotes(EscapeBackSlashes(Placeholders.Substitute(extraParams[i], objs)))); sb.Append('"'); } sb.Append(");"); return(sb.ToString()); }