Example #1
0
 public void WriteValue(string name, IBinaryXmlElement ob)
 {
     if (ob == null)
     {
         WriteValueHeader(name, TypeCode.Empty);
     }
     else
     {
         WriteValueHeader(name, TypeCode.Object);
         WriteObject(ob);
     }
 }
Example #2
0
 void WriteObject(object ob)
 {
     if (ob == null)
     {
         writer.Write(BinaryXmlReader.TagObjectNull);
     }
     else
     {
         IBinaryXmlElement elem = ob as IBinaryXmlElement;
         if (elem != null)
         {
             writer.Write(BinaryXmlReader.TagObject);
             WriteString(typeMap.GetTypeName(elem));
             elem.Write(this);
             WriteEndElement();
         }
         else if (ob is IDictionary)
         {
             IDictionary dict = (IDictionary)ob;
             writer.Write(BinaryXmlReader.TagObjectDictionary);
             writer.Write(dict.Count);
             foreach (DictionaryEntry e in dict)
             {
                 WriteValue(e.Key);
                 WriteValue(e.Value);
             }
         }
         else if (ob is ICollection)
         {
             ICollection col = (ICollection)ob;
             writer.Write(BinaryXmlReader.TagObjectArray);
             if (ob is Array)
             {
                 writer.Write((byte)Type.GetTypeCode(ob.GetType().GetElementType()));
             }
             else
             {
                 writer.Write((byte)TypeCode.Object);
             }
             writer.Write(col.Count);
             foreach (object e in col)
             {
                 WriteValue(e);
             }
         }
         else
         {
             throw new InvalidOperationException("Invalid object type: " + ob.GetType());
         }
     }
 }
Example #3
0
		public void WriteValue (string name, IBinaryXmlElement ob)
		{
			if (ob == null)
				WriteValueHeader (name, TypeCode.Empty);
			else {
				WriteValueHeader (name, TypeCode.Object);
				WriteObject (ob);
			}
		}
Example #4
0
        public string WriteSharedObject(string directory, string sharedFileName, string extension, string objectId, string readFileName, BinaryXmlTypeMap typeMap, IBinaryXmlElement obj)
        {
            string file = readFileName;

            if (file == null)
            {
                int    count = 1;
                string name  = sharedFileName + "_" + Util.GetStringHashCode(objectId).ToString("x");
                file = Path.Combine(directory, name + extension);

                while (Exists(file))
                {
                    count++;
                    file = Path.Combine(directory, name + "_" + count + extension);
                }
            }

            using (Stream s = Create(file)) {
                BinaryXmlWriter writer = new BinaryXmlWriter(s, typeMap);
                writer.WriteBeginElement("File");
                writer.WriteValue("id", objectId);
                writer.WriteValue("data", obj);
                writer.WriteEndElement();
            }
            return(file);
        }
Example #5
0
 public void WriteSharedObject(string objectId, string targetFile, BinaryXmlTypeMap typeMap, IBinaryXmlElement obj)
 {
     WriteSharedObject(null, null, null, objectId, targetFile, typeMap, obj);
 }
		public string WriteSharedObject (string directory, string sharedFileName, string extension, string objectId, string readFileName, BinaryXmlTypeMap typeMap, IBinaryXmlElement obj)
		{
			string file = readFileName;
			
			if (file == null) {
				int count = 1;
				string name = sharedFileName + "_" + Util.GetStringHashCode (objectId).ToString ("x");
				file = Path.Combine (directory, name + extension);
				
				while (Exists (file)) {
					count++;
					file = Path.Combine (directory, name + "_" + count + extension);
				}
			}
			
			using (Stream s = Create (file)) {
				BinaryXmlWriter writer = new BinaryXmlWriter (s, typeMap);
				writer.WriteBeginElement ("File");
				writer.WriteValue ("id", objectId);
				writer.WriteValue ("data", obj);
				writer.WriteEndElement ();
			}
			return file;
		}
		public void WriteSharedObject (string objectId, string targetFile, BinaryXmlTypeMap typeMap, IBinaryXmlElement obj)
		{
			WriteSharedObject (null, null, null, objectId, targetFile, typeMap, obj);
		}