internal void Serialize(object o, string streamName) { Serialization.DataFormat dataFormat = this.format; switch (dataFormat) { case Serialization.DataFormat.Text: { this.textWriter.Write(o.ToString()); return; } case Serialization.DataFormat.XML: { if (this.firstCall) { this.firstCall = false; this.textWriter.WriteLine(Serialization.XmlCliTag); } this.xmlSerializer.Serialize(o, streamName); return; } case Serialization.DataFormat.None: { return; } default: { this.textWriter.Write(o.ToString()); return; } } }
private void ParseFormat(string[] args, ref int i, ref Serialization.DataFormat format, string resourceStr) { StringBuilder sb = new StringBuilder(); foreach (string s in Enum.GetNames(typeof(Serialization.DataFormat))) { sb.Append(s); sb.Append(Environment.NewLine); } ++i; if (i >= args.Length) { SetCommandLineError( StringUtil.Format( resourceStr, sb.ToString()), showHelp: true); return; } try { format = (Serialization.DataFormat)Enum.Parse(typeof(Serialization.DataFormat), args[i], true); } catch (ArgumentException) { SetCommandLineError( StringUtil.Format( CommandLineParameterParserStrings.BadFormatParameterValue, args[i], sb.ToString()), showHelp: true); } }
internal WrappedSerializer(Serialization.DataFormat dataFormat, string streamName, TextWriter output) : base(dataFormat, streamName) { this.firstCall = true; this.textWriter = output; Serialization.DataFormat dataFormat1 = this.format; switch (dataFormat1) { case Serialization.DataFormat.Text: { return; } case Serialization.DataFormat.XML: { XmlWriterSettings xmlWriterSetting = new XmlWriterSettings(); xmlWriterSetting.CheckCharacters = false; xmlWriterSetting.OmitXmlDeclaration = true; this.xmlWriter = XmlWriter.Create(this.textWriter, xmlWriterSetting); this.xmlSerializer = new Serializer(this.xmlWriter); return; } default: { return; } } }
internal void End() { Serialization.DataFormat dataFormat = this.format; switch (dataFormat) { default: { return; } } }
internal object Deserialize() { object obj; string str = null; Serialization.DataFormat dataFormat = this.format; if (dataFormat == Serialization.DataFormat.Text) { } else if (dataFormat == Serialization.DataFormat.XML) { obj = this.xmlDeserializer.Deserialize(out str); return(obj); } else if (dataFormat == Serialization.DataFormat.None) { this.atEnd = true; return(null); } if (!this.atEnd) { if (this.firstLine == null) { obj = this.textReader.ReadLine(); if (obj == null) { this.atEnd = true; } } else { obj = this.firstLine; this.firstLine = null; } } else { return(null); } return(obj); }
private void ParseFormat(string[] args, ref int i, ref Serialization.DataFormat format, string resourceStr) { StringBuilder sb = new StringBuilder(); foreach (string s in Enum.GetNames(typeof(Serialization.DataFormat))) { sb.Append(s); sb.Append(ConsoleHostUserInterface.Crlf); } ++i; if (i >= args.Length) { _hostUI.WriteErrorLine( StringUtil.Format( resourceStr, sb.ToString())); _showHelp = true; _abortStartup = true; _exitCode = ConsoleHost.ExitCodeBadCommandLineParameter; return; } try { format = (Serialization.DataFormat)Enum.Parse(typeof(Serialization.DataFormat), args[i], true); } catch (ArgumentException) { _hostUI.WriteErrorLine( StringUtil.Format( CommandLineParameterParserStrings.BadFormatParameterValue, args[i], sb.ToString())); _showHelp = true; _abortStartup = true; _exitCode = ConsoleHost.ExitCodeBadCommandLineParameter; } }
internal void End() { Serialization.DataFormat dataFormat = this.format; switch (dataFormat) { case Serialization.DataFormat.Text: case Serialization.DataFormat.None: { return; } case Serialization.DataFormat.XML: { this.xmlSerializer.Done(); this.xmlSerializer = null; return; } default: { return; } } }
internal WrappedDeserializer(Serialization.DataFormat dataFormat, string streamName, TextReader input) : base(dataFormat, streamName) { if (dataFormat != Serialization.DataFormat.None) { this.textReader = input; this.firstLine = this.textReader.ReadLine(); if (string.Compare(this.firstLine, Serialization.XmlCliTag, StringComparison.OrdinalIgnoreCase) == 0) { dataFormat = Serialization.DataFormat.XML; } Serialization.DataFormat dataFormat1 = this.format; switch (dataFormat1) { case Serialization.DataFormat.Text: { return; } case Serialization.DataFormat.XML: { this.xmlReader = XmlReader.Create(this.textReader); this.xmlDeserializer = new Deserializer(this.xmlReader); return; } default: { return; } } } else { return; } }
private void ParseFormat(string[] args, ref int i, ref Serialization.DataFormat format, string resourceStr) { StringBuilder stringBuilder = new StringBuilder(); string[] names = Enum.GetNames(typeof(Serialization.DataFormat)); for (int num = 0; num < (int)names.Length; num++) { string str = names[num]; stringBuilder.Append(str); stringBuilder.Append("\r\n"); } i = i + 1; if (i < (int)args.Length) { try { format = (Serialization.DataFormat)Enum.Parse(typeof(Serialization.DataFormat), args[i], true); } catch (ArgumentException argumentException) { this.ui.WriteErrorLine(StringUtil.Format(CommandLineParameterParserStrings.BadFormatParameterValue, args[i], stringBuilder.ToString())); this.showHelp = true; this.abortStartup = true; this.exitCode = -196608; } return; } else { this.ui.WriteErrorLine(StringUtil.Format(resourceStr, stringBuilder.ToString())); this.showHelp = true; this.abortStartup = true; this.exitCode = -196608; return; } }
protected Serialization(Serialization.DataFormat dataFormat, string streamName) { this.format = dataFormat; this.streamName = streamName; }
private int Run(CommandLineParameterParser cpp, bool isPrestartWarned) { int exitCode; ConsoleHost.runspaceInitTracer.WriteLine("starting parse of command line parameters", new object[0]); if (string.IsNullOrEmpty(cpp.InitialCommand) || !isPrestartWarned) { if (!cpp.AbortStartup) { this.outputFormat = cpp.OutputFormat; this.inputFormat = cpp.InputFormat; this.wasInitialCommandEncoded = cpp.WasInitialCommandEncoded; this.ui.ReadFromStdin = cpp.ReadFromStdin; this.ui.NoPrompt = cpp.NoPrompt; this.ui.ThrowOnReadAndPrompt = cpp.ThrowOnReadAndPrompt; this.noExit = cpp.NoExit; if (!string.IsNullOrEmpty(cpp.ExecutionPolicy)) { ExecutionPolicy executionPolicy = SecuritySupport.ParseExecutionPolicy(cpp.ExecutionPolicy); SecuritySupport.SetExecutionPolicy(ExecutionPolicyScope.Process, executionPolicy, null); } exitCode = this.DoRunspaceLoop(cpp.InitialCommand, cpp.SkipProfiles, cpp.Args, cpp.StaMode, cpp.ImportSystemModules, cpp.ShowInitialPrompt); } else { ConsoleHost.tracer.WriteLine("processing of cmdline args failed, exiting", new object[0]); exitCode = cpp.ExitCode; } } else { object[] initialCommand = new object[1]; initialCommand[0] = cpp.InitialCommand; ConsoleHost.tracer.TraceError("Start up warnings made command \"{0}\" not executed", initialCommand); string str = StringUtil.Format(ConsoleHostStrings.InitialCommandNotExecuted, cpp.InitialCommand); this.ui.WriteErrorLine(str); exitCode = -65536; } return exitCode; }