Merge branch 'master' of github.com:mono/mono
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Channels / PeerCustomResolverBindingElement.cs
index 6382e428e4a63dbdd633cf40ee418bfcb19f277a..19cf3eaa6fecc1d64639197dded3d543e697aeea 100755 (executable)
@@ -44,8 +44,7 @@ namespace System.ServiceModel.Channels
                        settings = new PeerCustomResolverSettings ();
                }
 
-               private PeerCustomResolverBindingElement (
-                       PeerCustomResolverBindingElement other)
+               public PeerCustomResolverBindingElement (PeerCustomResolverBindingElement other)
                        : base (other)
                {
                        ReferralPolicy = other.ReferralPolicy;
@@ -66,8 +65,24 @@ namespace System.ServiceModel.Channels
                BindingContext context;
                PeerCustomResolverSettings settings;
 
+               public EndpointAddress Address {
+                       get { return settings.Address; }
+                       set { settings.Address = value; }
+               }
+
+               public Binding Binding {
+                       get { return settings.Binding; }
+                       set { settings.Binding = value; }
+               }
+
+               [MonoTODO]
                public override PeerReferralPolicy ReferralPolicy { get; set; }
 
+               public override bool CanBuildChannelFactory<TChannel> (BindingContext context)
+               {
+                       return context.CanBuildInnerChannelFactory<TChannel> ();
+               }
+
                public override IChannelFactory<TChannel> BuildChannelFactory<TChannel> (
                        BindingContext context)
                {
@@ -78,6 +93,11 @@ namespace System.ServiceModel.Channels
                        return cf;
                }
 
+               public override bool CanBuildChannelListener<TChannel> (BindingContext context)
+               {
+                       return context.CanBuildInnerChannelListener<TChannel> ();
+               }
+
                public override IChannelListener<TChannel>
                        BuildChannelListener<TChannel> (
                        BindingContext context)
@@ -122,7 +142,9 @@ namespace System.ServiceModel.Channels
 
                public PeerCustomResolver (ServiceEndpoint endpoint)
                {
-                       var client = new ChannelFactory<ICustomPeerResolverClient> (endpoint).CreateChannel ();
+                       if (endpoint == null)
+                               throw new ArgumentNullException ("endpoint");
+                       client = new ChannelFactory<ICustomPeerResolverClient> (endpoint).CreateChannel ();
                }
 
                public override bool CanShareReferrals {
@@ -132,6 +154,13 @@ namespace System.ServiceModel.Channels
                public override object Register (string meshId,
                        PeerNodeAddress nodeAddress, TimeSpan timeout)
                {
+                       if (String.IsNullOrEmpty (meshId))
+                               throw new ArgumentNullException ("meshId");
+                       if (nodeAddress == null)
+                               throw new ArgumentNullException ("nodeAddress");
+                       if (timeout <= TimeSpan.Zero)
+                               throw new ArgumentException (String.Format ("Timeout value must be positive value. It was {0}", timeout));
+
                        client.OperationTimeout = timeout;
                        preserved_mesh_id = meshId;
                        return client.Register (new RegisterInfo (client_id, meshId, nodeAddress)).RegistrationId;
@@ -140,13 +169,23 @@ namespace System.ServiceModel.Channels
                public override ReadOnlyCollection<PeerNodeAddress> Resolve (
                        string meshId, int maxAddresses, TimeSpan timeout)
                {
+                       if (String.IsNullOrEmpty (meshId))
+                               throw new ArgumentNullException ("meshId");
+                       if (maxAddresses <= 0)
+                               throw new ArgumentOutOfRangeException ("maxAddresses must be positive integer");
+                       if (timeout <= TimeSpan.Zero)
+                               throw new ArgumentException (String.Format ("Timeout value must be positive value. It was {0}", timeout));
+
                        client.OperationTimeout = timeout;
-                       return new ReadOnlyCollection<PeerNodeAddress> (client.Resolve (new ResolveInfo (client_id, meshId, maxAddresses)).Addresses);
+                       return new ReadOnlyCollection<PeerNodeAddress> (client.Resolve (new ResolveInfo (client_id, meshId, maxAddresses)).Addresses ?? new PeerNodeAddress [0]);
                }
 
                public override void Unregister (object registrationId,
                        TimeSpan timeout)
                {
+                       if (timeout <= TimeSpan.Zero)
+                               throw new ArgumentException (String.Format ("Timeout value must be positive value. It was {0}", timeout));
+
                        client.OperationTimeout = timeout;
                        preserved_mesh_id = null;
                        client.Unregister (new UnregisterInfo (preserved_mesh_id, (Guid) registrationId));
@@ -155,6 +194,9 @@ namespace System.ServiceModel.Channels
                public override void Update (object registrationId,
                        PeerNodeAddress updatedNodeAddress, TimeSpan timeout)
                {
+                       if (timeout <= TimeSpan.Zero)
+                               throw new ArgumentException (String.Format ("Timeout value must be positive value. It was {0}", timeout));
+
                        client.OperationTimeout = timeout;
                        client.Update (new UpdateInfo ((Guid) registrationId, client_id, preserved_mesh_id, updatedNodeAddress));
                }