/// <summary> /// Converts the String representation of a action to a ActionCheck 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 ActionCheck 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 ActionCheck action) { Match m; string pName; string programPath; string programArgs; action = null; m = rxActionCheckValidator.Match(sAction); if (!m.Success) { return(false); } pName = m.Result("${pName}"); programPath = m.Result("${programPath}"); programArgs = (m.Result("${programArgs}") == null) ? "" : m.Result("${programArgs}"); action = new ActionCheck(pName, programPath, programArgs); 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); }