コード例 #1
0
ファイル: ScriptTests.cs プロジェクト: lzinga/ScriptJunkie
        public void PowershellScript_ResultFail()
        {
            Script script = new Script();

            script.Name = "Powershell test script.";

            // The powershell script.
            script.Executable = new Executable()
            {
                Path = Utilities.GetIncludedFile("Scripts/PowershellTest_ScriptFail.ps1")
            };

            // Exit Codes
            ExitCodeCollection exitCollection = new ExitCodeCollection();

            exitCollection.Add(new ExitCode()
            {
                Value = 0, Message = "Success", IsSuccess = true
            });
            exitCollection.Add(new ExitCode()
            {
                Value = 1, Message = "Failure"
            });

            // Add all elements into the single script file.
            script.ExitCodes = exitCollection;

            // Add the single script above into a collection of scripts.
            ScriptCollection scriptCollection = new ScriptCollection();

            scriptCollection.Add(script);

            // No Downloads.
            DownloadCollection downloadCollection = new DownloadCollection();

            // Add the 2 main elements, the scripts to run and the downloads to download.
            Setup setup = new Setup();

            setup.Scripts   = scriptCollection;
            setup.Downloads = downloadCollection;


            int exitCode = -1;

            if (setup.Initalize())
            {
                exitCode = setup.Execute();
            }

            // The exit code should be 1, since the script did not match IsSuccess ExitCode.
            Assert.IsTrue(exitCode == 1);
        }
コード例 #2
0
ファイル: ScriptTests.cs プロジェクト: lzinga/ScriptJunkie
        public void PowershellScript_Both()
        {
            #region Script 1
            Script script1 = new Script();
            script1.Name       = "Powershell test script 1.";
            script1.Executable = new Executable()
            {
                Path = Utilities.GetIncludedFile("Scripts/PowershellTest_ScriptPass.ps1")
            };

            // Exit Codes
            ExitCodeCollection exitCollection1 = new ExitCodeCollection();
            exitCollection1.Add(new ExitCode()
            {
                Value = 0, Message = "Success", IsSuccess = true
            });
            exitCollection1.Add(new ExitCode()
            {
                Value = 1, Message = "Failure"
            });

            // Add all elements into the script1
            script1.ExitCodes = exitCollection1;
            #endregion

            #region Script 2
            Script script2 = new Script();
            script2.Name       = "Powershell test script 2.";
            script2.Executable = new Executable()
            {
                Path = Utilities.GetIncludedFile("Scripts/PowershellTest_ScriptFail.ps1")
            };

            // Exit Codes
            ExitCodeCollection exitCollection2 = new ExitCodeCollection();
            exitCollection2.Add(new ExitCode()
            {
                Value = 0, Message = "Success", IsSuccess = true
            });
            exitCollection2.Add(new ExitCode()
            {
                Value = 1, Message = "Failure"
            });

            // Add all elements into the script1
            script2.ExitCodes = exitCollection2;
            #endregion

            // Add the single script above into a collection of scripts.
            ScriptCollection scriptCollection = new ScriptCollection();
            scriptCollection.Add(script1);
            scriptCollection.Add(script2);

            // No Downloads.
            DownloadCollection downloadCollection = new DownloadCollection();

            // Add the 2 main elements, the scripts to run and the downloads to download.
            Setup setup = new Setup();
            setup.Scripts   = scriptCollection;
            setup.Downloads = downloadCollection;


            int exitCode = -1;
            if (setup.Initalize())
            {
                exitCode = setup.Execute();
            }

            // Exit code should be 1 as 1 of the 2 scripts didn't have the expected result.
            Assert.IsTrue(exitCode == 1);
        }
コード例 #3
0
        /// <summary>
        /// Generates a template xml to base custom scripts off of.
        /// </summary>
        /// <param name="savePath">The location the template will be saved.</param>
        public void GenerateXmlTemplate(string savePath)
        {
            ServiceManager.Services.LogService.WriteHeader("Generating Xml Template...");

            #region Script 1
            Script script = new Script();
            script.Name        = "Script 1";
            script.Description = "Does nothing";

            Executable executable = new Executable();
            executable.Path = "C:/Temp/nothing.ps1";

            ArgumentCollection argCollection = new ArgumentCollection();
            argCollection.Add(new Argument()
            {
                Key = "-i", Value = "C:/Temp/something.bin"
            });
            argCollection.Add(new Argument()
            {
                Key = "-x", Value = ""
            });

            ExitCodeCollection exitCollection = new ExitCodeCollection();
            exitCollection.Add(new ExitCode()
            {
                Value = 0, Message = "Files deleted", IsSuccess = true
            });
            exitCollection.Add(new ExitCode()
            {
                Value = 1, Message = "Files failed to delete"
            });
            exitCollection.Add(new ExitCode()
            {
                Value = 2, Message = "Couldn't find any files"
            });

            // Add all elements into the single script file.
            script.Arguments  = argCollection;
            script.ExitCodes  = exitCollection;
            script.Executable = executable;
            #endregion

            #region Script 2
            Script script2 = new Script();
            script2.Name        = "Script 2";
            script2.Description = "Does nothing";

            Executable executable2 = new Executable();
            executable2.Path = "C:/Temp/Downloads/Extracted/SomethingThatWasInAZip.exe";

            ArgumentCollection argCollection2 = new ArgumentCollection();
            argCollection2.Add(new Argument()
            {
                Key = "-install"
            });
            argCollection2.Add(new Argument()
            {
                Key = "-silent"
            });

            ExitCodeCollection exitCollection2 = new ExitCodeCollection();
            exitCollection2.Add(new ExitCode()
            {
                Value = 0, Message = "Script 2 has installed", IsSuccess = true
            });
            exitCollection2.Add(new ExitCode()
            {
                Value = 1, Message = "Failed to install."
            });
            exitCollection2.Add(new ExitCode()
            {
                Value = 2, Message = "Installed but limited."
            });

            // Add all elements into the single script file.
            script2.Arguments  = argCollection;
            script2.ExitCodes  = exitCollection;
            script2.Executable = executable;

            // Add the single script above into a collection of scripts.
            ScriptCollection scriptCollection = new ScriptCollection();
            scriptCollection.Add(script);
            scriptCollection.Add(script2);
            #endregion

            ServiceManager.Services.LogService.WriteLine("Generating Download Collection...");
            DownloadCollection downloadCollection = new DownloadCollection();
            downloadCollection.TimeOut     = 60;
            downloadCollection.RefreshRate = 10;
            downloadCollection.Add(new Download()
            {
                Name = "Nothing Powershell Script", Description = "This script does nothing", DownloadUrl = "www.blank.com/nothing.ps1", DestinationPath = "C:/Temp/Downloads/nothing.ps1"
            });
            downloadCollection.Add(new Download()
            {
                Name = "Test Zip File", Description = "This zip has nothing", DownloadUrl = "www.blank.com/nothing.zip", DestinationPath = "C:/Temp/Downloads", ExtractionPath = "C:/Temp/Downloads/Extracted"
            });

            // Add the 2 main elements, the scripts to run and the downloads to download.
            Setup setup = new Setup();
            setup.Scripts   = scriptCollection;
            setup.Downloads = downloadCollection;

            ServiceManager.Services.LogService.WriteLine("Saving file to: \"{0}\"", savePath);
            setup.Serialize(savePath);
        }