public void TestRegisterResourceHandler() { FhirResourceHandlerUtil.RegisterResourceHandler(new DummyResourceHandler()); Assert.NotNull(FhirResourceHandlerUtil.GetResourceHandler(ResourceType.DomainResource)); Assert.IsInstanceOf <DummyResourceHandler>(FhirResourceHandlerUtil.GetResourceHandler(ResourceType.DomainResource)); Assert.IsTrue(FhirResourceHandlerUtil.ResourceHandlers.Any(c => c.GetType() == typeof(DummyResourceHandler))); }
public void TestUnRegisterResourceHandler() { FhirResourceHandlerUtil.RegisterResourceHandler(new DummyResourceHandler()); Assert.NotNull(FhirResourceHandlerUtil.GetResourceHandler(ResourceType.DomainResource)); Assert.IsInstanceOf <DummyResourceHandler>(FhirResourceHandlerUtil.GetResourceHandler(ResourceType.DomainResource)); FhirResourceHandlerUtil.UnRegisterResourceHandler(new DummyResourceHandler()); Assert.IsFalse(FhirResourceHandlerUtil.ResourceHandlers.Any(c => c.GetType() == typeof(DummyResourceHandler))); Assert.Throws <NotSupportedException>(() => FhirResourceHandlerUtil.GetResourceHandler(ResourceType.DomainResource)); }
/// <summary> /// Start the FHIR message handler /// </summary> public bool Start() { try { this.Starting?.Invoke(this, EventArgs.Empty); this.m_webHost = new WebServiceHost(typeof(FhirServiceBehavior)); this.m_webHost.Description.ConfigurationName = this.m_configuration.WcfEndpoint; foreach (var endpoint in this.m_webHost.Description.Endpoints) { this.m_traceSource.TraceInformation("Starting FHIR on {0}...", endpoint.Address); (endpoint.Binding as WebHttpBinding).ContentTypeMapper = new FhirContentTypeHandler(); endpoint.EndpointBehaviors.Add(new FhirRestEndpointBehavior()); endpoint.EndpointBehaviors.Add(new FhirErrorEndpointBehavior()); } // Configuration foreach (Type t in this.m_configuration.ResourceHandlers) { ConstructorInfo ci = t.GetConstructor(Type.EmptyTypes); if (ci == null) { this.m_traceSource.TraceEvent(TraceEventType.Warning, 0, "Type {0} has no default constructor", t.FullName); continue; } FhirResourceHandlerUtil.RegisterResourceHandler(ci.Invoke(null) as IFhirResourceHandler); } // Start the web host this.m_webHost.Open(); this.Started?.Invoke(this, EventArgs.Empty); return(true); } catch (Exception e) { this.m_traceSource.TraceEvent(TraceEventType.Error, e.HResult, e.ToString()); return(false); } }
/// <summary> /// Start the FHIR message handler /// </summary> public bool Start() { try { this.Starting?.Invoke(this, EventArgs.Empty); this.m_webHost = ApplicationServiceContext.Current.GetService <IRestServiceFactory>().CreateService(typeof(FhirServiceBehavior)); this.m_webHost.AddServiceBehavior(new FhirErrorEndpointBehavior()); foreach (var endpoint in this.m_webHost.Endpoints) { endpoint.AddEndpointBehavior(new FhirMessageDispatchFormatterEndpointBehavior()); this.m_traceSource.TraceInfo("Starting FHIR on {0}...", endpoint.Description.ListenUri); } // Configuration foreach (Type t in this.m_configuration.ResourceHandlers.Select(o => o.Type)) { ConstructorInfo ci = t.GetConstructor(Type.EmptyTypes); if (ci == null || t.IsAbstract) { this.m_traceSource.TraceEvent(EventLevel.Warning, "Type {0} has no default constructor", t.FullName); continue; } FhirResourceHandlerUtil.RegisterResourceHandler(ci.Invoke(null) as IFhirResourceHandler); } // Start the web host this.m_webHost.Start(); this.Started?.Invoke(this, EventArgs.Empty); return(true); } catch (Exception e) { this.m_traceSource.TraceEvent(EventLevel.Error, e.ToString()); return(false); } }
public void TestRegisterResourceHandlerNull() { Assert.Throws <ArgumentNullException>(() => FhirResourceHandlerUtil.RegisterResourceHandler(null)); }