| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- //
- // CustomPeerResolverService.cs
- //
- // Author:
- // Marcos Cobena ([email protected])
- //
- // Copyright 2007 Marcos Cobena (http://www.youcannoteatbits.org/)
- //
- using System.Collections.Generic;
- using System.Transactions;
- namespace System.ServiceModel.PeerResolvers
- {
- // FIXME: TransactionTimeout must be null by-default.
- [ServiceBehavior (AutomaticSessionShutdown = true, ConcurrencyMode = ConcurrencyMode.Multiple,
- InstanceContextMode = InstanceContextMode.Single, ReleaseServiceInstanceOnTransactionComplete = true,
- TransactionIsolationLevel = IsolationLevel.Unspecified, /*TransactionTimeout = null, */
- UseSynchronizationContext = false, ValidateMustUnderstand = true)]
- public class CustomPeerResolverService : IPeerResolverContract
- {
- TimeSpan cleanup_interval;
- bool control_shape;
- bool opened;
- // Maybe it's worth to change List<T> for a better distributed and faster collection.
- List<Node> mesh = new List<Node> ();
- object mesh_lock = new object ();
- TimeSpan refresh_interval;
- public CustomPeerResolverService ()
- {
- cleanup_interval = new TimeSpan (0, 1, 0);
- control_shape = false;
- opened = false;
- refresh_interval = new TimeSpan (0, 10, 0);
- }
- [MonoTODO ("To check for InvalidOperationException")]
- public TimeSpan CleanupInterval {
- get { return cleanup_interval; }
- set {
- if ((value < TimeSpan.Zero) || (value > TimeSpan.MaxValue))
- throw new ArgumentOutOfRangeException (
- "The interval is either zero or greater than max value.");
- cleanup_interval = value;
- }
- }
- public bool ControlShape {
- get { return control_shape; }
- set { control_shape = value; }
- }
- [MonoTODO ("To check for InvalidOperationException")]
- public TimeSpan RefreshInterval {
- get { return refresh_interval; }
- set {
- if ((value < TimeSpan.Zero) || (value > TimeSpan.MaxValue))
- throw new ArgumentOutOfRangeException (
- "The interval is either zero or greater than max value.");
- refresh_interval = value;
- }
- }
- [MonoTODO]
- public virtual void Close ()
- {
- if (! opened)
- throw new InvalidOperationException ("The service has never been opened or it was closed by a previous call to this method.");
- }
- [MonoTODO]
- public virtual ServiceSettingsResponseInfo GetServiceSettings ()
- {
- if (! opened)
- throw new InvalidOperationException ("The service has never been opened or it was closed previously.");
-
- // return new ServiceSettingsResponseInfo ();
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public virtual void Open ()
- {
- if ((cleanup_interval == TimeSpan.Zero) || (refresh_interval == TimeSpan.Zero))
- throw new ArgumentException ("Cleanup interval or refresh interval are set to a time span interval of zero.");
- if (opened)
- throw new InvalidOperationException ("The service has been started by a previous call to this method.");
-
- opened = true;
- }
- [MonoTODO]
- public virtual RefreshResponseInfo Refresh (RefreshInfo refreshInfo)
- {
- if (refreshInfo == null)
- throw new ArgumentException ("Refresh info cannot be null.");
-
- if (! opened)
- throw new InvalidOperationException ("The service has never been opened or it was closed previously.");
-
- // return new RefreshResponseInfo ();
- throw new NotImplementedException ();
- }
- public virtual RegisterResponseInfo Register (RegisterInfo registerInfo)
- {
- if (registerInfo == null)
- throw new ArgumentException ("Register info cannot be null.");
-
- if (! opened)
- throw new InvalidOperationException ("The service has never been opened or it was closed previously.");
-
- return Register (registerInfo.ClientId, registerInfo.MeshId, registerInfo.NodeAddress);
- }
- [MonoTODO]
- public virtual RegisterResponseInfo Register (Guid clientId,
- string meshId,
- PeerNodeAddress address)
- {
- Node n = new Node ();
- RegisterResponseInfo rri = new RegisterResponseInfo ();
-
- if (ControlShape) {
- // FIXME: To update mesh node here.
- lock (mesh_lock)
- {
- mesh.Add (n);
- // Console.WriteLine ("{0}, {1}, {2}", clientId, meshId, address);
- }
- }
-
- return rri;
- }
- [MonoTODO]
- public virtual ResolveResponseInfo Resolve (ResolveInfo resolveInfo)
- {
- ResolveResponseInfo rri = new ResolveResponseInfo ();
-
- if (resolveInfo == null)
- throw new ArgumentException ("Resolve info cannot be null.");
-
- if (! opened)
- throw new InvalidOperationException ("The service has never been opened or it was closed previously.");
-
- if (ControlShape)
- {
- // FIXME: To resolve address here.
- }
-
- return rri;
- }
- [MonoTODO]
- public virtual void Unregister (UnregisterInfo unregisterInfo)
- {
- if (unregisterInfo == null)
- throw new ArgumentException ("Unregister info cannot be null.");
-
- if (! opened)
- throw new InvalidOperationException ("The service has never been opened or it was closed previously.");
-
- if (ControlShape)
- {
- // FIXME: To remove node from mesh here.
- }
- }
- [MonoTODO]
- public virtual RegisterResponseInfo Update (UpdateInfo updateInfo)
- {
- if (updateInfo == null)
- throw new ArgumentException ("Update info cannot be null.");
-
- if (! opened)
- throw new InvalidOperationException ("The service has never been opened or it was closed previously.");
-
- // return new RegisterResponseInfo ();
- throw new NotImplementedException ();
- }
- }
-
- internal class Node
- {
-
- }
- }
|