Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.34 KB | None | 0 0
  1. public class EhrServerSystemDiscoveryService : IEhrSystemDiscoveryService
  2.     {
  3.         private EHRServerInfo _selectedServer;
  4.  
  5.         public void Probe(CancellationToken cancelToken, Action<IEnumerable<EHRServerInfo>> onEndpointDiscovered)
  6.         {
  7.             var explorer = new DiscoveryClient(new UdpDiscoveryEndpoint());
  8.  
  9.             var task = new Task(() =>
  10.             {
  11.                 while (!cancelToken.IsCancellationRequested)
  12.                 {
  13.                     var authEndpoints = explorer.Find(new FindCriteria(typeof(IAuthenticationService))
  14.                     {
  15.                         MaxResults = 10,
  16.                         Duration = TimeSpan.FromMilliseconds(500)
  17.                     }).Endpoints;
  18.  
  19.                     var initEndpoints = explorer.Find(new FindCriteria(typeof(IEhrInitializationService))
  20.                     {
  21.                         MaxResults = 10,
  22.                         Duration = TimeSpan.FromMilliseconds(500)
  23.                     }).Endpoints;
  24.  
  25.                     onEndpointDiscovered(authEndpoints.Concat(initEndpoints).Select(metadata => EHRServerInfo.Create(metadata)));
  26.                 }
  27.             }, cancelToken);
  28.  
  29.             task.ContinueWith(t => explorer.Close());
  30.             task.Start();
  31.         }
  32.  
  33.         public void Select(EHRServerInfo info)
  34.         {
  35.             _selectedServer = info;
  36.         }
  37.  
  38.         public bool CanSearch
  39.         {
  40.             get { return true; }
  41.         }
  42.  
  43.  
  44.         public bool InitializationRequired
  45.         {
  46.             get
  47.             {
  48.                 return _selectedServer != null && !_selectedServer.IsInitialized;
  49.             }
  50.         }
  51.  
  52.         public IEhrInitializationService CreateInitializationService()
  53.         {
  54.             if (!InitializationRequired)
  55.                 throw new InvalidOperationException();
  56.  
  57.             return new WcfEhrInitializationServiceClient(_selectedServer.Address);
  58.         }
  59.  
  60.         public IUserAuthenticator CreateUserAuthenticator()
  61.         {
  62.             if (_selectedServer == null)
  63.                 throw new InvalidOperationException("Server is not selected");
  64.  
  65.             if (InitializationRequired)
  66.                 throw new InvalidOperationException("Server is not initialized");
  67.  
  68.             return new WcfAuthenticationServiceClient(_selectedServer.Address);
  69.         }
  70.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement