private static string ConvertArgsValueToEncodedString(object value) { ArrayList source = ConvertArgsValueToArrayList(value); StringWriter w = new StringWriter(CultureInfo.InvariantCulture); XmlTextWriter writer = new XmlTextWriter(w); Serializer serializer = new Serializer(writer); serializer.Serialize(source); serializer.Done(); writer.Flush(); return StringToBase64Converter.StringToBase64String(w.ToString()); }
private static string ConvertArgsValueToEncodedString(object value) { ArrayList source = ConvertArgsValueToArrayList(value); StringWriter w = new StringWriter(CultureInfo.InvariantCulture); XmlTextWriter writer = new XmlTextWriter(w); Serializer serializer = new Serializer(writer); serializer.Serialize(source); serializer.Done(); writer.Flush(); return(StringToBase64Converter.StringToBase64String(w.ToString())); }
public static string Serialize(object source, int depth) { StringBuilder output = new StringBuilder(); XmlWriterSettings settings = new XmlWriterSettings { CloseOutput = true, Encoding = Encoding.Unicode, Indent = true, OmitXmlDeclaration = true }; Serializer serializer = new Serializer(XmlWriter.Create(output, settings), depth, true); serializer.Serialize(source); serializer.Done(); serializer = null; return output.ToString(); }
public static string Serialize(object source, int depth) { StringBuilder output = new StringBuilder(); XmlWriterSettings settings = new XmlWriterSettings { CloseOutput = true, Encoding = Encoding.Unicode, Indent = true, OmitXmlDeclaration = true }; Serializer serializer = new Serializer(XmlWriter.Create(output, settings), depth, true); serializer.Serialize(source); serializer.Done(); serializer = null; return(output.ToString()); }
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)); } }
/// <summary> /// Converts value of args parameter in to an encoded string /// </summary> private static string ConvertArgsValueToEncodedString(object value) { ArrayList list = ConvertArgsValueToArrayList(value); //Serialize the list StringWriter stringWriter = new StringWriter(System.Globalization.CultureInfo.InvariantCulture); //When (if) switching to XmlTextWriter.Create remember the OmitXmlDeclaration difference XmlWriter xmlWriter = XmlWriter.Create(stringWriter); Serializer serializer = new Serializer(xmlWriter); serializer.Serialize(list); serializer.Done(); xmlWriter.Flush(); string result = stringWriter.ToString(); //convert result to encoded string return(StringToBase64Converter.StringToBase64String(result)); }
private void WriteXmlInput() { try { this.streamWriter.WriteLine("#< CLIXML"); Serializer serializer = new Serializer((XmlWriter) new XmlTextWriter((TextWriter)this.streamWriter)); foreach (object input in this.inputList) { if (this.stopping) { return; } serializer.Serialize(input); } serializer.Done(); } finally { this.streamWriter.Close(); } }
private void WriteXmlInput() { try { //Write header _streamWriter.WriteLine("#< CLIXML"); // When (if) switching to XmlTextWriter.Create remember the OmitXmlDeclaration difference XmlWriter writer = XmlWriter.Create(_streamWriter); Serializer ser = new Serializer(writer); foreach (object o in _inputList) { if (_stopping) return; ser.Serialize(o); } ser.Done(); } finally { _streamWriter.Dispose(); } }
/// <summary> /// Converts value of args parameter in to an encoded string /// </summary> private static string ConvertArgsValueToEncodedString(object value) { ArrayList list = ConvertArgsValueToArrayList(value); //Serialize the list StringWriter stringWriter = new StringWriter(System.Globalization.CultureInfo.InvariantCulture); //When (if) switching to XmlTextWriter.Create remember the OmitXmlDeclaration difference XmlWriter xmlWriter = XmlWriter.Create(stringWriter); Serializer serializer = new Serializer(xmlWriter); serializer.Serialize(list); serializer.Done(); xmlWriter.Flush(); string result = stringWriter.ToString(); //convert result to encoded string return StringToBase64Converter.StringToBase64String(result); }
internal List<string> GenerateProxyModule(DirectoryInfo moduleRootDirectory, string fileNamePrefix, Encoding encoding, bool force, List<CommandMetadata> listOfCommandMetadata, Dictionary<string, string> alias2resolvedCommandName, List<ExtendedTypeDefinition> listOfFormatData, X509Certificate2 certificate) { List<string> list = new List<string>(); string str = Path.Combine(moduleRootDirectory.FullName, fileNamePrefix); FileMode mode = force ? FileMode.OpenOrCreate : FileMode.CreateNew; list.Add(str + ".psm1"); FileStream stream = new FileStream(str + ".psm1", mode, FileAccess.Write, FileShare.None); using (TextWriter writer = new StreamWriter(stream, encoding)) { if (listOfCommandMetadata == null) { listOfCommandMetadata = new List<CommandMetadata>(); } this.GenerateModuleHeader(writer); this.GenerateHelperFunctions(writer); this.GenerateCommandProxy(writer, listOfCommandMetadata); this.GenerateExportDeclaration(writer, listOfCommandMetadata); this.GenerateAliases(writer, alias2resolvedCommandName); stream.SetLength(stream.Position); } list.Add(str + ".format.ps1xml"); FileStream stream2 = new FileStream(str + ".format.ps1xml", mode, FileAccess.Write, FileShare.None); using (TextWriter writer2 = new StreamWriter(stream2, encoding)) { if (listOfFormatData == null) { listOfFormatData = new List<ExtendedTypeDefinition>(); } this.GenerateFormatFile(writer2, listOfFormatData); stream2.SetLength(stream2.Position); } switch (SecuritySupport.GetExecutionPolicy(Utils.DefaultPowerShellShellID)) { case ExecutionPolicy.Restricted: case ExecutionPolicy.AllSigned: { if (certificate == null) { throw new PSInvalidOperationException(ImplicitRemotingStrings.CertificateNeeded); } string fileName = str + ".psm1"; try { SignatureHelper.SignFile(SigningOption.AddFullCertificateChainExceptRoot, fileName, certificate, string.Empty, null); fileName = str + ".format.ps1xml"; SignatureHelper.SignFile(SigningOption.AddFullCertificateChainExceptRoot, fileName, certificate, string.Empty, null); } catch (Exception exception) { throw new PSInvalidOperationException(StringUtil.Format(ImplicitRemotingStrings.InvalidSigningOperation, fileName), exception); } break; } } list.Add(str + ".psd1"); FileInfo info = new FileInfo(str + ".psd1"); FileStream stream3 = new FileStream(info.FullName, mode, FileAccess.Write, FileShare.None); using (TextWriter writer3 = new StreamWriter(stream3, encoding)) { this.GenerateManifest(writer3, str + ".psm1", str + ".format.ps1xml"); stream3.SetLength(stream3.Position); } PSPrimitiveDictionary applicationArguments = this.GetApplicationArguments(); if (applicationArguments != null) { string item = Path.Combine(moduleRootDirectory.FullName, "ApplicationArguments.xml"); list.Add(item); using (XmlWriter writer4 = XmlWriter.Create(item)) { Serializer serializer = new Serializer(writer4); serializer.Serialize(applicationArguments); serializer.Done(); } } return list; }
private void WriteXmlInput() { try { this.streamWriter.WriteLine("#< CLIXML"); XmlWriter writer = new XmlTextWriter(this.streamWriter); Serializer serializer = new Serializer(writer); foreach (object obj2 in this.inputList) { if (this.stopping) { return; } serializer.Serialize(obj2); } serializer.Done(); } finally { this.streamWriter.Close(); } }