Exemplo n.º 1
0
        /// <summary>
        /// Checks input format based on the stored input type.
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        protected bool IsInputOk(string input)
        {
            bool inputOk = false;

            switch (_inputType)
            {
            case "string": inputOk = inputCheck.IsString(input);    break;

            case "int": inputOk = inputCheck.IsInt(input);          break;

            case "bool": inputOk = inputCheck.IsBool(input);        break;

            case "username": inputOk = inputCheck.IsString(input);  break;

            case "password": inputOk = inputCheck.IsString(input);  break;

            case "multiline": inputOk = inputCheck.IsString(input); break;

            case "checkbox": inputOk = inputCheck.IsBool(input);    break;

            case "radiobutton": inputOk = inputCheck.IsBool(input); break;

            default: PsGuiException.WriteErrorToScreen("Script file header error: Unknown variable type '" + _inputType + "'"); break;
            }
            return(inputOk);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Fills the list of categories with the folders found
 /// in the given module path.
 /// @Throws PSGuiException
 /// </summary>
 public void UpdateScriptCategoriesList()
 {
     string[] categoryList;
     try
     {
         categoryList = Directory.GetDirectories(modulePath);
         foreach (string category in categoryList)
         {
             _scriptCategories.Add(new ScriptCategory(category, modulePathLength));
         }
     }
     catch (System.Exception e)
     {
         PsGuiException.WriteErrorToFile(e.ToString());
         PsGuiException.WriteErrorToScreen("No script directory found!");
         PsGuiException.CloseApp();
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Reads the selected powershell script and calls the functions
        /// responsible to parse and store the information. Adds
        /// all the gathered information to the ScriptVariables collection.
        /// </summary>
        /// <param name="script"></param>
        public void ReadSelectedScript(string scriptPath)
        {
            string[] lines = System.IO.File.ReadAllLines(scriptPath);
            string   scriptHeaderEndTag = "#>";
            int      lineNum            = 0;
            int      lastHeaderLine     = 1; // Must match number of meta data lines

            try
            {
                foreach (string line in lines)
                {
                    // If header is completely parsed
                    if (line.Equals(scriptHeaderEndTag))
                    {
                        break;
                    }
                    // If script meta data (description...)
                    if (lineNum <= lastHeaderLine)
                    {
                        ReadScriptHeader(lineNum, line);
                    }
                    // Else if input variables to script
                    else
                    {
                        ReadScriptVariables(line);
                    }
                    lineNum++;
                }
            }
            catch (Exception e)
            {
                PsGuiException.WriteErrorToFile(e.ToString());
                PsGuiException.WriteErrorToScreen("The header in the Powershell-script is improperly formated.\r\n\r\nClosing PsGui.");
                PsGuiException.CloseApp();
            }

            AddScriptArgumentsToMainCollection();
        }