Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class EhrServerSystemDiscoveryService : IEhrSystemDiscoveryService
- {
- private EHRServerInfo _selectedServer;
- public void Probe(CancellationToken cancelToken, Action<IEnumerable<EHRServerInfo>> onEndpointDiscovered)
- {
- var explorer = new DiscoveryClient(new UdpDiscoveryEndpoint());
- var task = new Task(() =>
- {
- while (!cancelToken.IsCancellationRequested)
- {
- var authEndpoints = explorer.Find(new FindCriteria(typeof(IAuthenticationService))
- {
- MaxResults = 10,
- Duration = TimeSpan.FromMilliseconds(500)
- }).Endpoints;
- var initEndpoints = explorer.Find(new FindCriteria(typeof(IEhrInitializationService))
- {
- MaxResults = 10,
- Duration = TimeSpan.FromMilliseconds(500)
- }).Endpoints;
- onEndpointDiscovered(authEndpoints.Concat(initEndpoints).Select(metadata => EHRServerInfo.Create(metadata)));
- }
- }, cancelToken);
- task.ContinueWith(t => explorer.Close());
- task.Start();
- }
- public void Select(EHRServerInfo info)
- {
- _selectedServer = info;
- }
- public bool CanSearch
- {
- get { return true; }
- }
- public bool InitializationRequired
- {
- get
- {
- return _selectedServer != null && !_selectedServer.IsInitialized;
- }
- }
- public IEhrInitializationService CreateInitializationService()
- {
- if (!InitializationRequired)
- throw new InvalidOperationException();
- return new WcfEhrInitializationServiceClient(_selectedServer.Address);
- }
- public IUserAuthenticator CreateUserAuthenticator()
- {
- if (_selectedServer == null)
- throw new InvalidOperationException("Server is not selected");
- if (InitializationRequired)
- throw new InvalidOperationException("Server is not initialized");
- return new WcfAuthenticationServiceClient(_selectedServer.Address);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement