Ejemplo n.º 1
1
		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;
				}
			}
		}
Ejemplo n.º 2
0
 protected override void EndProcessing()
 {
     if (this._serializer != null)
     {
         this._serializer.Done();
         this._serializer = null;
     }
     this.CleanUp();
 }
 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());
 }
Ejemplo n.º 4
0
 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();
 }
Ejemplo n.º 5
0
		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;
				}
			}
		}
Ejemplo n.º 6
0
 private void CreateFileStream()
 {
     if (base.ShouldProcess(this.Path))
     {
         StreamWriter writer;
         PathUtils.MasterStreamOpen(this, this.Path, this.Encoding, false, false, (bool) this.Force, (bool) this.NoClobber, out this._fs, out writer, out this.readOnlyFileInfo, this.isLiteralPath);
         XmlWriterSettings settings = new XmlWriterSettings {
             CloseOutput = true,
             Encoding = writer.Encoding,
             Indent = true,
             OmitXmlDeclaration = true
         };
         this._xw = XmlWriter.Create(writer, settings);
         if (this._depth == 0)
         {
             this._serializer = new Serializer(this._xw);
         }
         else
         {
             this._serializer = new Serializer(this._xw, this._depth, true);
         }
     }
 }
Ejemplo n.º 7
0
        WrappedSerializer(DataFormat dataFormat, string streamName, TextWriter output)
            :
            base(dataFormat, streamName)
        {
            Dbg.Assert(output != null, "output should have a value");

            textWriter = output;
            switch (format)
            {
                case DataFormat.XML:
                    XmlWriterSettings settings = new XmlWriterSettings();
                    settings.CheckCharacters = false;
                    settings.OmitXmlDeclaration = true;
                    _xmlWriter = XmlWriter.Create(textWriter, settings);
                    _xmlSerializer = new Serializer(_xmlWriter);
                    break;
                case DataFormat.Text:
                default:
                    // do nothing; we'll just write to the TextWriter
                    // or discard it.

                    break;
            }
        }
Ejemplo n.º 8
0
        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();
            }
        }
Ejemplo n.º 9
0
        private void CreateFileStream()
        {
            Dbg.Assert(Path != null, "FileName is mandatory parameter");

            if (!ShouldProcess(Path)) return;

            StreamWriter sw;
            PathUtils.MasterStreamOpen(
                this,
                this.Path,
                this.Encoding,
                false, // default encoding
                false, // append
                this.Force,
                this.NoClobber,
                out _fs,
                out sw,
                out _readOnlyFileInfo,
                _isLiteralPath
                );

            // create xml writer
            XmlWriterSettings xmlSettings = new XmlWriterSettings();
            xmlSettings.CloseOutput = true;
            xmlSettings.Encoding = sw.Encoding;
            xmlSettings.Indent = true;
            xmlSettings.OmitXmlDeclaration = true;
            _xw = XmlWriter.Create(sw, xmlSettings);
            if (Depth == 0)
            {
                _serializer = new Serializer(_xw);
            }
            else
            {
                _serializer = new Serializer(_xw, Depth, true);
            }
        }
        /// <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);
        }
Ejemplo n.º 11
0
 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;
 }
Ejemplo n.º 12
0
 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();
     }
 }