Example #1
0
		public void PrepareDependenciesDump ()
		{
			System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings();
			settings.Indent = true;
			settings.IndentChars = "\t";
			var depsFile = File.OpenWrite ("linker-dependencies.xml.gz");
			zipStream = new GZipStream (depsFile, CompressionMode.Compress);

			writer = System.Xml.XmlWriter.Create (zipStream, settings);
			writer.WriteStartDocument ();
			writer.WriteStartElement ("dependencies");
			writer.WriteStartAttribute ("version");
			writer.WriteString ("1.0");
			writer.WriteEndAttribute ();
		}
Example #2
0
		public void PrepareDependenciesDump ()
		{
			dependency_stack = new Stack<object> ();
			System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings();
			settings.Indent = true;
			settings.IndentChars = "\t";
			var depsFile = File.OpenWrite (string.Format ("linker-dependencies-{0}.xml.gz", DateTime.Now.Ticks));
			zipStream = new GZipStream (depsFile, CompressionMode.Compress);

			writer = System.Xml.XmlWriter.Create (zipStream, settings);
			writer.WriteStartDocument ();
			writer.WriteStartElement ("dependencies");
			writer.WriteStartAttribute ("version");
			writer.WriteString ("1.0");
			writer.WriteEndAttribute ();
		}
Example #3
0
		public void PrepareDependenciesDump (string filename)
		{
			dependency_stack = new Stack<object> ();
			System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings();
			settings.Indent = true;
			settings.IndentChars = "\t";
			var depsFile = File.OpenWrite (filename);
			zipStream = new GZipStream (depsFile, CompressionMode.Compress);

			writer = System.Xml.XmlWriter.Create (zipStream, settings);
			writer.WriteStartDocument ();
			writer.WriteStartElement ("dependencies");
			writer.WriteStartAttribute ("version");
			writer.WriteString ("1.0");
			writer.WriteEndAttribute ();
		}
Example #4
0
 private static void WriteStartTime(System.Xml.XmlWriter writer, HistoryEntry entry)
 {
     writer.WriteStartAttribute("start");
     writer.WriteValue(entry.VersionStartTime.ToUniversalTime().ToString("R"));
     writer.WriteEndAttribute();
 }
Example #5
0
    static void Main(string[] args)
    {
        string testpath = System.IO.Path.Combine(
            Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "TestFile");

        // Method 1: Automatic XML serialization
        // Requires that the type being serialized and all its serializable members are public
        System.Xml.Serialization.XmlSerializer xs =
            new System.Xml.Serialization.XmlSerializer(typeof(MyPublicData));
        MyPublicData o1 = new MyPublicData()
        {
            id = 3141, value = "a test object"
        };
        MyEncapsulatedData o2 = new MyEncapsulatedData(7);

        using (System.IO.StreamWriter w = new System.IO.StreamWriter(testpath + ".xml"))
        {
            xs.Serialize(w, o1);
        }
        // Method 2: Manual XML serialization
        System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(testpath + "1.xml");
        xw.WriteStartElement("MyPublicData");
        xw.WriteStartAttribute("id");
        xw.WriteValue(o1.id);
        xw.WriteEndAttribute();
        xw.WriteAttributeString("value", o1.value);
        xw.WriteEndElement();
        xw.Close();
        // Method 3: Automatic binary serialization
        // Requires that the type being serialized be marked with the "Serializable" attribute
        using (System.IO.FileStream f = new System.IO.FileStream(testpath + ".bin", System.IO.FileMode.Create))
        {
            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf =
                new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            bf.Serialize(f, o2);
        }
        // Demonstrate how automatic binary deserialization works
        // and prove that it handles objects with private members
        using (System.IO.FileStream f = new System.IO.FileStream(testpath + ".bin", System.IO.FileMode.Open))
        {
            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf =
                new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            MyEncapsulatedData o3 = (MyEncapsulatedData)bf.Deserialize(f);
            Console.WriteLine(o3.ExpirationDate.ToString());
        }
        // Method 4: Manual binary serialization
        using (System.IO.FileStream f = new System.IO.FileStream(testpath + "1.bin", System.IO.FileMode.Create))
        {
            using (System.IO.BinaryWriter w = new System.IO.BinaryWriter(f))
            {
                w.Write(o1.id);
                w.Write(o1.value);
            }
        }
        // Demonstrate how manual binary deserialization works
        using (System.IO.FileStream f = new System.IO.FileStream(testpath + "1.bin", System.IO.FileMode.Open))
        {
            using (System.IO.BinaryReader r = new System.IO.BinaryReader(f))
            {
                MyPublicData o4 = new MyPublicData()
                {
                    id = r.ReadInt32(), value = r.ReadString()
                };
                Console.WriteLine("{0}: {1}", o4.id, o4.value);
            }
        }
    }
Example #6
0
        public void Write(System.IO.TextWriter output)
        {
            System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create(output);

            writer.WriteStartDocument();

            writer.WriteStartElement("sc");

            writer.WriteStartElement("context");
            writer.WriteStartAttribute("timeContext");
            writer.WriteValue(this.timeContext);
            writer.WriteEndAttribute();

            if (this.Scope != null)
            {
                writer.WriteStartAttribute("scope");
                writer.WriteValue(this.Scope);
                writer.WriteEndAttribute();
            }

            writer.WriteEndElement();
            if (this.HasObjects)
            {
                writer.WriteStartElement("objects");

                foreach (var obj in this.objects)
                {
                    writer.WriteRaw(obj.ToString());
                }

                writer.WriteEndElement();
            }

            if (this.HasRelations)
            {
                writer.WriteStartElement("relations");

                foreach (var obj in this.relations)
                {
                    writer.WriteRaw(obj.ToString());
                }

                writer.WriteEndElement();
            }

            if (this.HasMembership)
            {
                writer.WriteStartElement("membership");

                foreach (var obj in this.membership)
                {
                    writer.WriteRaw(obj.ToString());
                }

                writer.WriteEndElement();
            }

            if (this.HasConditions)
            {
                writer.WriteStartElement("conditions");

                foreach (var obj in this.conditions)
                {
                    this.WriteCondition(writer, obj);
                }

                writer.WriteEndElement();
            }

            if (this.HasAcls)
            {
                writer.WriteStartElement("acls");

                foreach (var acl in this.acls)
                {
                    this.WriteAcls(writer, acl);
                }

                writer.WriteEndElement();
            }

            writer.WriteEndElement();
            writer.Close();
        }