Пример #1
0
 private string ProcessFormatParameterValue(string parameterName, object value)
 {
     using (MinishellParameterBinderController.tracer.TraceMethod())
     {
         string str1;
         try
         {
             str1 = (string)LanguagePrimitives.ConvertTo(value, typeof(string), (IFormatProvider)CultureInfo.InvariantCulture);
         }
         catch (PSInvalidCastException ex)
         {
             MinishellParameterBinderController.tracer.TraceException((Exception)ex);
             throw this.NewParameterBindingException((Exception)ex, ErrorCategory.InvalidArgument, parameterName, typeof(string), value.GetType(), "StringValueExpectedForFormatParameter", (object)parameterName);
         }
         string str2;
         if (MinishellParameterBinderController.StartsWith("xml", (object)str1))
         {
             str2 = "xml";
         }
         else if (MinishellParameterBinderController.StartsWith("text", (object)str1))
         {
             str2 = "text";
         }
         else
         {
             throw this.NewParameterBindingException((Exception)null, ErrorCategory.InvalidArgument, parameterName, typeof(string), value.GetType(), "IncorrectValueForFormatParameter", (object)str1, (object)parameterName);
         }
         return(str2);
     }
 }
Пример #2
0
 private static string ConvertArgsValueToEncodedString(object value)
 {
     using (MinishellParameterBinderController.tracer.TraceMethod())
     {
         ArrayList     arrayList     = MinishellParameterBinderController.ConvertArgsValueToArrayList(value);
         StringWriter  stringWriter  = new StringWriter((IFormatProvider)CultureInfo.InvariantCulture);
         XmlTextWriter xmlTextWriter = new XmlTextWriter((TextWriter)stringWriter);
         Serializer    serializer    = new Serializer((XmlWriter)xmlTextWriter);
         serializer.Serialize((object)arrayList);
         serializer.Done();
         xmlTextWriter.Flush();
         string input = stringWriter.ToString();
         MinishellParameterBinderController.tracer.WriteLine("serialized args: {0}", (object)input);
         return(StringToBase64Converter.StringToBase64String(input));
     }
 }
        private ProcessStartInfo GetProcessStartInfo(
            bool redirectOutput,
            bool redirectError,
            bool redirectInput,
            bool soloCommand)
        {
            ProcessStartInfo processStartInfo = new ProcessStartInfo();

            processStartInfo.FileName = this.Path;
            if (this.validateExtension(this.Path))
            {
                processStartInfo.UseShellExecute = false;
                if (redirectInput)
                {
                    processStartInfo.RedirectStandardInput = true;
                }
                if (redirectOutput)
                {
                    processStartInfo.RedirectStandardOutput = true;
                }
                if (redirectError)
                {
                    processStartInfo.RedirectStandardError = true;
                }
            }
            else
            {
                if (!soloCommand)
                {
                    throw InterpreterError.NewInterpreterException((object)this.Path, typeof(RuntimeException), this.Command.CallingToken, "CantActivateDocumentInPipeline", (object)this.Path);
                }
                processStartInfo.UseShellExecute = true;
            }
            if (this.isMiniShell)
            {
                MinishellParameterBinderController binderController = (MinishellParameterBinderController)this.NativeParameterBinderController;
                binderController.BindParameters(this.arguments, redirectOutput, this.Command.Context.EngineHostInterface.Name);
                processStartInfo.CreateNoWindow = binderController.NonInteractive;
            }
            processStartInfo.Arguments = this.NativeParameterBinderController.Arguments;
            ExecutionContext context      = this.Command.Context;
            string           providerPath = context.EngineSessionState.GetNamespaceCurrentLocation(context.ProviderNames.FileSystem).ProviderPath;

            processStartInfo.WorkingDirectory = WildcardPattern.Unescape(providerPath);
            return(processStartInfo);
        }
Пример #4
0
 private static ArrayList ConvertArgsValueToArrayList(object value)
 {
     using (MinishellParameterBinderController.tracer.TraceMethod())
     {
         ArrayList   arrayList  = new ArrayList();
         IEnumerator enumerator = LanguagePrimitives.GetEnumerator(value);
         if (enumerator == null)
         {
             arrayList.Add(MinishellParameterBinderController.DecodeArgValue(value));
         }
         else
         {
             while (enumerator.MoveNext())
             {
                 arrayList.Add(MinishellParameterBinderController.DecodeArgValue(enumerator.Current));
             }
         }
         return(arrayList);
     }
 }
Пример #5
0
 private ArrayList ProcessMinishellParameters(
     ArrayList args,
     bool outputRedirected,
     string hostName)
 {
     using (MinishellParameterBinderController.tracer.TraceMethod())
     {
         ArrayList arrayList = new ArrayList();
         string    lhs1      = (string)null;
         string    lhs2      = (string)null;
         MinishellParameterBinderController.MinishellParameters seen = (MinishellParameterBinderController.MinishellParameters) 0;
         for (int index = 0; index < args.Count; ++index)
         {
             object obj = args[index];
             if (MinishellParameterBinderController.StartsWith("-command", obj))
             {
                 this.HandleSeenParameter(ref seen, MinishellParameterBinderController.MinishellParameters.Command, "-command");
                 arrayList.Add((object)"-encodedCommand");
                 if (index + 1 >= args.Count)
                 {
                     throw this.NewParameterBindingException((Exception)null, ErrorCategory.InvalidArgument, "-command", typeof(ScriptBlock), (Type)null, "NoValueForCommandParameter");
                 }
                 if (!(args[index + 1] is ScriptBlock scriptBlock))
                 {
                     throw this.NewParameterBindingException((Exception)null, ErrorCategory.InvalidArgument, "-command", typeof(ScriptBlock), args[index + 1].GetType(), "IncorrectValueForCommandParameter");
                 }
                 string base64String = StringToBase64Converter.StringToBase64String(scriptBlock.ToString());
                 arrayList.Add((object)base64String);
                 ++index;
             }
             else if (obj is ScriptBlock)
             {
                 this.HandleSeenParameter(ref seen, MinishellParameterBinderController.MinishellParameters.Command, "-command");
                 arrayList.Add((object)"-encodedCommand");
                 string base64String = StringToBase64Converter.StringToBase64String(obj.ToString());
                 arrayList.Add((object)base64String);
             }
             else if (MinishellParameterBinderController.StartsWith("-inputFormat", obj))
             {
                 this.HandleSeenParameter(ref seen, MinishellParameterBinderController.MinishellParameters.InputFormat, "-inputFormat");
                 arrayList.Add((object)"-inputFormat");
                 if (index + 1 >= args.Count)
                 {
                     throw this.NewParameterBindingException((Exception)null, ErrorCategory.InvalidArgument, "-inputFormat", typeof(string), (Type)null, "NoValueForInputFormatParameter");
                 }
                 lhs1 = this.ProcessFormatParameterValue("-inputFormat", args[index + 1]);
                 ++index;
                 arrayList.Add((object)lhs1);
             }
             else if (MinishellParameterBinderController.StartsWith("-outputFormat", obj))
             {
                 this.HandleSeenParameter(ref seen, MinishellParameterBinderController.MinishellParameters.OutputFormat, "-outputFormat");
                 arrayList.Add((object)"-outputFormat");
                 if (index + 1 >= args.Count)
                 {
                     throw this.NewParameterBindingException((Exception)null, ErrorCategory.InvalidArgument, "-outputFormat", typeof(string), (Type)null, "NoValueForOutputFormatParameter");
                 }
                 lhs2 = this.ProcessFormatParameterValue("-outputFormat", args[index + 1]);
                 ++index;
                 arrayList.Add((object)lhs2);
             }
             else if (MinishellParameterBinderController.StartsWith("-args", obj))
             {
                 this.HandleSeenParameter(ref seen, MinishellParameterBinderController.MinishellParameters.Arguments, "-args");
                 arrayList.Add((object)"-encodedarguments");
                 if (index + 1 >= args.Count)
                 {
                     throw this.NewParameterBindingException((Exception)null, ErrorCategory.InvalidArgument, "-args", typeof(string), (Type)null, "NoValuesSpecifiedForArgs");
                 }
                 string encodedString = MinishellParameterBinderController.ConvertArgsValueToEncodedString(args[index + 1]);
                 ++index;
                 arrayList.Add((object)encodedString);
             }
             else
             {
                 arrayList.Add(obj);
             }
         }
         if (lhs1 == null)
         {
             arrayList.Add((object)"-inputFormat");
             arrayList.Add((object)"xml");
             lhs1 = "xml";
         }
         if (lhs2 == null)
         {
             arrayList.Add((object)"-outputFormat");
             if (outputRedirected)
             {
                 arrayList.Add((object)"xml");
                 lhs2 = "xml";
             }
             else
             {
                 arrayList.Add((object)"text");
                 lhs2 = "text";
             }
         }
         this.inputFormatValue  = !MinishellParameterBinderController.StartsWith(lhs1, (object)"xml") ? NativeCommandIOFormat.Text : NativeCommandIOFormat.Xml;
         this.outputFormatValue = !MinishellParameterBinderController.StartsWith(lhs2, (object)"xml") ? NativeCommandIOFormat.Text : NativeCommandIOFormat.Xml;
         if (string.IsNullOrEmpty(hostName) || !hostName.Equals("ConsoleHost", StringComparison.OrdinalIgnoreCase))
         {
             this.nonInteractive = true;
             arrayList.Insert(0, (object)"-noninteractive");
         }
         return(arrayList);
     }
 }