예제 #1
0
 private void HandleSeenParameter(
     ref MinishellParameterBinderController.MinishellParameters seen,
     MinishellParameterBinderController.MinishellParameters parameter,
     string parameterName)
 {
     using (MinishellParameterBinderController.tracer.TraceMethod())
     {
         if ((seen & parameter) == parameter)
         {
             throw this.NewParameterBindingException((Exception)null, ErrorCategory.InvalidArgument, parameterName, (Type)null, (Type)null, "ParameterSpecifiedAlready", (object)parameterName);
         }
         seen |= parameter;
     }
 }
예제 #2
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);
     }
 }