/** * Execute a shortcut in an xml shorcuts file from the given parameters */ public static bool ExecuteShortcut(ShortcutParams parameters) { JArgumentNullException.Check(parameters, "parameters"); try { var profile = parameters.Profile; var xmlFile = new XmlShortcutFile(parameters.File); var shortcut = xmlFile.GetShortcut(parameters.Profile, parameters.Shortcut); if (shortcut != null) { shortcut.Params += " " + parameters.Args; return shortcut.Execute(); } return false; } catch (JRunXmlException ex) { throw CreateXmlException(ex); } catch (JRunException) { throw; } catch (Exception ex) { throw new JException(ex, "Could not execute shortcut \"{0}\" for profile \"{1}\" in xml file \"{2}\"", parameters.Shortcut, parameters.Profile, parameters.File); } }
static void Main(string[] args) { DateTime appStart = DateTime.Now; string filePath = "Shortcuts.xml"; string profile = ""; string exportPath = null; string cmd = null; bool bReportTime = false; var options = new NDesk.Options.OptionSet() { { "cmd:|shortcut", "The name of the shortcut to execute.", s => cmd = s }, { "f:|file:", "File to load shortcuts from. Default is 'Shortcuts.xml'.", s => filePath = s }, { "p:|profile:", "Profile to execute the shortcut in. Default is the first profile.", s => profile = s }, //{ "e:|export:", "The SlickRun (.qrs) file to export all of the profile's shortcuts to.", s => exportPath = s }, { "timed", "Prints how long it takes to find and execute the shortcut.", s => bReportTime = s != null }, }; options.Parse(args); if (cmd == null) { if (args.Length > 0 && args[0].Length > 0 && args[0][0] != '-') { cmd = args[0]; } } if (cmd != null) { try { DateTime executeStart = DateTime.Now; var jparams = new ShortcutParams().SetFile(filePath).SetProfile(profile).SetShortcut(cmd); var bSuccess = ShortcutExecutor.ExecuteShortcut(jparams); if (!bSuccess) { Console.WriteLine("Could not find shortcut \"{0}\" for profile \"{1}\" in xml file \"{2}\"", cmd, profile, filePath); } if (bReportTime) { DateTime End = DateTime.Now; TimeSpan appTime = End - appStart; TimeSpan executeTime = End - executeStart; Console.WriteLine("App Time: {0}, Execute Time: {1}", appTime.TotalMilliseconds, executeTime.TotalMilliseconds); Console.ReadKey(); } } catch (Exception ex) { for (var innerEx = ex; innerEx != null; innerEx = innerEx.InnerException) { Console.WriteLine(innerEx.Message); } Console.ReadKey(); } } else if (exportPath != null) { // TODO support exporting shortcuts to other formats } }
/** * Enumerates the names of all shortcuts (explicit and virtual) in the xml shortcuts file. * Useful for auto-complete. */ public static IEnumerable<string> GetAllShortcutNames(ShortcutParams parameters) { try { var xmlFile = new XmlShortcutFile(parameters.File); return xmlFile.GetAllShortcutNames(parameters.Profile); } catch (JRunXmlException ex) { throw CreateXmlException(ex); } catch (Exception ex) { throw new JException(ex, "Could not get all shortcut names for profile \"{0}\" in xml file \"{1}\"", parameters.Profile, parameters.File); } }
/** * Populate the parameters to pass to JRun */ public ShortcutParams InstanceParams() { var parms = new ShortcutParams(); if (!String.IsNullOrEmpty(App.Current.Settings.XmlFile)) { parms.SetFile(App.Current.Settings.XmlFile); } if (!String.IsNullOrEmpty(App.Current.Settings.ProfileSelector)) { parms.SetProfile(ShortcutExecutor.SelectProfile(App.Current.Settings.ProfileSelector)); } else if (!String.IsNullOrEmpty(App.Current.Settings.ProfileName)) { parms.SetProfile(App.Current.Settings.ProfileName); } return parms; }