/// <summary> /// Converts the String representation of a action to a ActionKill object. /// A return value indicates whether the conversion succeded or not. /// <param name="sAction">A string containing the action to convert</param> /// <param name="action">When this method returns, contains the ActionKill equivalent to the action /// contained in the string, if the conversion succeeded, or null if the conversion failed. /// The conversion fails if the node parameter is a null reference (Nothing in Visual Basic) or is not of the correct format. /// This parameter is passed uninitialized</param> /// </summary> /// <returns>true if conversion was successfull, false otherwise</returns> public static bool TryParse(string sAction, out ActionKill action) { Match m; string pName; int timeOut; action = null; m = rxActionKillValidator.Match(sAction); if (!m.Success) { return(false); } pName = m.Result("${pName}"); if (!Int32.TryParse(m.Result("${timeOut}"), out timeOut)) { timeOut = 1000; } action = new ActionKill(pName, timeOut); return(true); }
/// <summary> /// Parses an string and gets the action contained in it /// </summary> /// <param name="sAction">string containing the action to parse</param> /// <param name="action">The action extracted from string</param> /// <returns>true if action parsed successfully, false otherwise</returns> private bool Parse(string sAction, out IAction action) { Match m = rxAction.Match(sAction); string actionName; action = null; if (!m.Success) { return(false); } actionName = m.Result("${action}"); switch (actionName.ToLower()) { case "checkprocess": if (ActionCheck.TryParse(sAction, out action)) { return(true); } break; case "kill": if (ActionKill.TryParse(sAction, out action)) { return(true); } break; case "run": if (ActionRun.TryParse(sAction, out action)) { ((ActionRun)action).UserName = "******"; return(true); } break; } return(false); }