Encapsulates a script and all of its parameters.
Exemplo n.º 1
0
Arquivo: Api.cs Projeto: Tirasa/ConnId
 public Object RunScriptOnConnector(ScriptContext request,
     OperationOptions options)
 {
     return ((ScriptOnConnectorApiOp)this
             .GetOperationCheckSupported(SafeType<APIOperation>.Get<ScriptOnConnectorApiOp>()))
             .RunScriptOnConnector(request, options);
 }
Exemplo n.º 2
0
 public Object RunScriptOnResource(ScriptContext request,
     OperationOptions options)
 {
     return ((ScriptOnResourceApiOp)GetOperationCheckSupported(SafeType<APIOperation>.Get<ScriptOnResourceApiOp>()))
             .RunScriptOnResource(request, options);
 }
        public void RunScript(ActiveDirectoryConnector connector, String user,
            string password, string prefix)
        {
            string tempFileName = Path.GetTempFileName();
            String arg0Name = "ARG0";
            String arg1Name = "ARG1";

            string scriptText = String.Format(
                "echo %{0}%:%{1}%:%USERNAME%:%PASSWORD% > \"{2}\"", prefix + arg0Name,
                prefix + arg1Name, tempFileName);

            IDictionary<string, object> arguments = new Dictionary<string, object>();
            string arg0 = "argument_zero";
            string arg1 = "argument one";
            arguments.Add(arg0Name, arg0);
            arguments.Add(arg1Name, arg1);

            OperationOptionsBuilder builder = new OperationOptionsBuilder();
            if (user.Length > 0)
            {
                builder.RunAsUser = user;
            }
            if (password.Length > 0)
            {
                builder.RunWithPassword = GetGuardedString(password);
            }
            builder.Options["variablePrefix"] = prefix;

            ScriptContext context = new ScriptContext("Shell", scriptText, arguments);
            object resultObject = connector.RunScriptOnResource(context, builder.Build());
            Assert.IsNotNull(resultObject);
            Assert.That(resultObject is int);
            Assert.AreEqual(0, resultObject);
            FileStream outputFs = new FileStream(tempFileName, FileMode.Open, FileAccess.Read);
            StreamReader outputReader = new StreamReader(outputFs);
            // read the first line
            string output = outputReader.ReadLine();
            string[] returnedArray = output.Split(':');
            Assert.AreEqual(4, returnedArray.Length);
            Assert.AreEqual((arg0), returnedArray[0]);
            Assert.AreEqual((arg1), returnedArray[1]);
        }