Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
     }
 }