Implement DiscoveryMessageSequence* types serialization.
authorAtsushi Eno <atsushi@ximian.com>
Fri, 6 Aug 2010 10:47:22 +0000 (19:47 +0900)
committerAtsushi Eno <atsushi@ximian.com>
Fri, 6 Aug 2010 10:47:22 +0000 (19:47 +0900)
mcs/class/System.ServiceModel.Discovery/System.ServiceModel.Discovery.Version11/DiscoveryMessageSequence11.cs
mcs/class/System.ServiceModel.Discovery/System.ServiceModel.Discovery.VersionApril2005/DiscoveryMessageSequenceApril2005.cs
mcs/class/System.ServiceModel.Discovery/System.ServiceModel.Discovery.VersionCD1/DiscoveryMessageSequenceCD1.cs
mcs/class/System.ServiceModel.Discovery/System.ServiceModel.Discovery/DiscoveryMessageSequence.cs

index efcfb8ad94898ff07c4ce312b31c5d054b45baf0..9a80814845a1d11a4a3fb5659430d4d4a675ae72 100755 (executable)
@@ -1,7 +1,7 @@
 //
 // Author: Atsushi Enomoto <atsushi@ximian.com>
 //
-// Copyright (C) 2009 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2009,2010 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -35,41 +35,63 @@ using System.Xml.Serialization;
 
 namespace System.ServiceModel.Discovery.Version11
 {
+       [XmlSchemaProvider ("GetSchema")]
        public class DiscoveryMessageSequence11 : IXmlSerializable
        {
                public static DiscoveryMessageSequence11 FromDiscoveryMessageSequence (DiscoveryMessageSequence discoveryMessageSequence)
                {
-                       throw new NotImplementedException ();
+                       return new DiscoveryMessageSequence11 (discoveryMessageSequence);
+               }
+
+               static readonly DiscoveryVersion version = DiscoveryVersion.WSDiscovery11;
+               static XmlSchema schema;
+               
+               static XmlSchema Schema {
+                       get {
+                               if (schema == null)
+                                       schema = DiscoveryMessageSequence.BuildSchema (version);
+                               return schema;
+                       }
                }
 
                public static XmlQualifiedName GetSchema (XmlSchemaSet schemaSet)
                {
-                       throw new NotImplementedException ();
+                       schemaSet.Add (Schema);
+                       return new XmlQualifiedName ("AppSequenceType", version.Namespace);
+               }
+
+               // for deserialization
+               DiscoveryMessageSequence11 ()
+               {
                }
 
-               internal DiscoveryMessageSequence11 ()
+               internal DiscoveryMessageSequence11 (DiscoveryMessageSequence source)
                {
-                       throw new NotImplementedException ();
+                       this.source = source;
                }
 
+               DiscoveryMessageSequence source;
+
                public XmlSchema GetSchema ()
                {
-                       throw new NotImplementedException ();
+                       return Schema;
                }
 
                public void ReadXml (XmlReader reader)
                {
-                       throw new NotImplementedException ();
+                       source = DiscoveryMessageSequence.ReadXml (reader, version);
                }
 
                public DiscoveryMessageSequence ToDiscoveryMessageSequence ()
                {
-                       throw new NotImplementedException ();
+                       if (source == null)
+                               throw new InvalidOperationException ("Call ReadXml method first to fill its contents");
+                       return source;
                }
 
                public void WriteXml (XmlWriter writer)
                {
-                       throw new NotImplementedException ();
+                       source.WriteXml (writer);
                }
        }
 }
index ea4791f12f486e315b48b3aaa9536caa95a405a2..8783f1de40fc2f9eaa11fa85974144b31faa15ed 100755 (executable)
@@ -1,7 +1,7 @@
 //
 // Author: Atsushi Enomoto <atsushi@ximian.com>
 //
-// Copyright (C) 2009 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2009,2010 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -35,41 +35,58 @@ using System.Xml.Serialization;
 
 namespace System.ServiceModel.Discovery.VersionApril2005
 {
+       [XmlSchemaProvider ("GetSchema")]
        public class DiscoveryMessageSequenceApril2005 : IXmlSerializable
        {
                public static DiscoveryMessageSequenceApril2005 FromDiscoveryMessageSequence (DiscoveryMessageSequence discoveryMessageSequence)
                {
-                       throw new NotImplementedException ();
+                       return new DiscoveryMessageSequenceApril2005 (discoveryMessageSequence);
+               }
+
+               static readonly DiscoveryVersion version = DiscoveryVersion.WSDiscoveryApril2005;
+               static XmlSchema schema;
+               
+               static XmlSchema Schema {
+                       get {
+                               if (schema == null)
+                                       schema = DiscoveryMessageSequence.BuildSchema (version);
+                               return schema;
+                       }
                }
 
                public static XmlQualifiedName GetSchema (XmlSchemaSet schemaSet)
                {
-                       throw new NotImplementedException ();
+                       schemaSet.Add (Schema);
+                       return new XmlQualifiedName ("AppSequenceType", version.Namespace);
                }
 
-               internal DiscoveryMessageSequenceApril2005 ()
+               internal DiscoveryMessageSequenceApril2005 (DiscoveryMessageSequence source)
                {
-                       throw new NotImplementedException ();
+                       this.source = source;
                }
 
+               DiscoveryMessageSequence source;
+
                public XmlSchema GetSchema ()
                {
-                       throw new NotImplementedException ();
+                       return Schema;
                }
 
                public void ReadXml (XmlReader reader)
                {
-                       throw new NotImplementedException ();
+                       source = DiscoveryMessageSequence.ReadXml (reader, version);
                }
 
                public DiscoveryMessageSequence ToDiscoveryMessageSequence ()
                {
-                       throw new NotImplementedException ();
+                       if (source == null)
+                               throw new InvalidOperationException ("Call ReadXml method first to fill its contents");
+                       return source;
                }
 
                public void WriteXml (XmlWriter writer)
                {
-                       throw new NotImplementedException ();
+                       source.WriteXml (writer);
                }
        }
 }
index d17db0afa895c2a42fa8fc69a386c325fa0aa54e..840f5c73aa4e48c85a725b2f7f6dc7aa65b5756e 100755 (executable)
@@ -1,7 +1,7 @@
 //
 // Author: Atsushi Enomoto <atsushi@ximian.com>
 //
-// Copyright (C) 2009 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2009,2010 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -35,41 +35,63 @@ using System.Xml.Serialization;
 
 namespace System.ServiceModel.Discovery.VersionCD1
 {
+       [XmlSchemaProvider ("GetSchema")]
        public class DiscoveryMessageSequenceCD1 : IXmlSerializable
        {
                public static DiscoveryMessageSequenceCD1 FromDiscoveryMessageSequence (DiscoveryMessageSequence discoveryMessageSequence)
                {
-                       throw new NotImplementedException ();
+                       return new DiscoveryMessageSequenceCD1 (discoveryMessageSequence);
+               }
+
+               static readonly DiscoveryVersion version = DiscoveryVersion.WSDiscoveryCD1;
+               static XmlSchema schema;
+               
+               static XmlSchema Schema {
+                       get {
+                               if (schema == null)
+                                       schema = DiscoveryMessageSequence.BuildSchema (version);
+                               return schema;
+                       }
                }
 
                public static XmlQualifiedName GetSchema (XmlSchemaSet schemaSet)
                {
-                       throw new NotImplementedException ();
+                       schemaSet.Add (Schema);
+                       return new XmlQualifiedName ("AppSequenceType", version.Namespace);
+               }
+
+               // for deserialization
+               DiscoveryMessageSequenceCD1 ()
+               {
                }
 
-               internal DiscoveryMessageSequenceCD1 ()
+               internal DiscoveryMessageSequenceCD1 (DiscoveryMessageSequence source)
                {
-                       throw new NotImplementedException ();
+                       this.source = source;
                }
 
+               DiscoveryMessageSequence source;
+
                public XmlSchema GetSchema ()
                {
-                       throw new NotImplementedException ();
+                       return Schema;
                }
 
                public void ReadXml (XmlReader reader)
                {
-                       throw new NotImplementedException ();
+                       source = DiscoveryMessageSequence.ReadXml (reader, version);
                }
 
                public DiscoveryMessageSequence ToDiscoveryMessageSequence ()
                {
-                       throw new NotImplementedException ();
+                       if (source == null)
+                               throw new InvalidOperationException ("Call ReadXml method first to fill its contents");
+                       return source;
                }
 
                public void WriteXml (XmlWriter writer)
                {
-                       throw new NotImplementedException ();
+                       source.WriteXml (writer);
                }
        }
 }
index bfe51e871ed181d5fe17558d7eb380a94cda681d..2a04e3cf19e126efe4bece22f12d704746c71935 100755 (executable)
@@ -29,6 +29,8 @@ using System.ServiceModel;
 using System.ServiceModel.Channels;
 using System.ServiceModel.Description;
 using System.ServiceModel.Dispatcher;
+using System.Xml;
+using System.Xml.Schema;
 
 namespace System.ServiceModel.Discovery
 {
@@ -89,5 +91,42 @@ namespace System.ServiceModel.Discovery
                {
                        return messageSequence1 == null ? messageSequence2 != null : !messageSequence1.Equals (messageSequence2);
                }
+
+               internal static DiscoveryMessageSequence ReadXml (XmlReader reader, DiscoveryVersion version)
+               {
+                       if (reader == null)
+                               throw new ArgumentNullException ("reader");
+                       if (reader.LocalName != "AppSequenceType" || reader.NamespaceURI != version.Namespace)
+                               throw new ArgumentException (String.Format ("AppSequenceType element in namespace '{0}' was expected. Got '{1}' element in '{2}' namespace", version.Namespace, reader.LocalName, reader.NamespaceURI));
+
+                       var instId = reader.GetAttribute ("InstanceId");
+                       var seqId = reader.GetAttribute ("SequenceId");
+                       var msgno = reader.GetAttribute ("MessageNumber");
+                       var source = new DiscoveryMessageSequence (instId != null ? XmlConvert.ToInt64 (instId) : 0, seqId != null ? new Uri (seqId, UriKind.RelativeOrAbsolute) : null, msgno != null ? XmlConvert.ToInt64 (msgno) : 0);
+                       
+                       reader.Skip ();
+                       return source;
+               }
+
+               internal void WriteXml (XmlWriter writer)
+               {
+                       writer.WriteAttributeString ("InstanceId", XmlConvert.ToString (InstanceId));
+                       if (SequenceId != null)
+                               writer.WriteAttributeString ("SequenceId", SequenceId.ToString ());
+                       writer.WriteAttributeString ("MessageNumber", XmlConvert.ToString (MessageNumber));
+               }
+
+               internal static XmlSchema BuildSchema (DiscoveryVersion version)
+               {
+                       var schema = new XmlSchema () { TargetNamespace = version.Namespace };
+                       var ccr = new XmlSchemaComplexContentRestriction ();
+                       ccr.Attributes.Add (new XmlSchemaAttribute () { Name = "InstanceId", SchemaTypeName = new XmlQualifiedName ("unsignedInt", XmlSchema.Namespace), Use = XmlSchemaUse.Required });
+                       ccr.Attributes.Add (new XmlSchemaAttribute () { Name = "SequenceId", SchemaTypeName = new XmlQualifiedName ("anyURI", XmlSchema.Namespace), Use = XmlSchemaUse.Optional });
+                       ccr.Attributes.Add (new XmlSchemaAttribute () { Name = "MessageNumber", SchemaTypeName = new XmlQualifiedName ("unsignedInt", XmlSchema.Namespace), Use = XmlSchemaUse.Required });
+                       var ct = new XmlSchemaComplexType () { Name = "AppSequenceType", ContentModel = new XmlSchemaComplexContent () { Content = ccr } };
+                       schema.Items.Add (ct);
+
+                       return schema;
+               }
        }
 }