Beispiel #1
0
 /// <summary>
 /// Static CTOR
 /// </summary>
 static BaseRecordMatchingService()
 {
     foreach (var t in typeof(BaseRecordMatchingService).Assembly.ExportedTypes.Where(t => typeof(IQueryFilterExtension).IsAssignableFrom(t) && !t.IsAbstract))
     {
         QueryFilterExtensions.AddExtendedFilter(Activator.CreateInstance(t) as IQueryFilterExtension);
     }
     ModelSerializationBinder.RegisterModelType(typeof(MatchConfiguration));
 }
Beispiel #2
0
 public void TestCanParseNonStandardBundle()
 {
     ModelSerializationBinder.RegisterModelType(typeof(EntityMaster <Patient>));
     using (var stream = typeof(NonStandardEntityInBundleTest).Assembly.GetManifestResourceStream("SanteDB.Core.Api.Test.Resources.NonStandardBundle.xml"))
     {
         var xsz    = XmlModelSerializerFactory.Current.CreateSerializer(typeof(Bundle));
         var bundle = xsz.Deserialize(stream) as Bundle;
         Assert.AreEqual(4, bundle.Item.Count);
     }
 }
Beispiel #3
0
        // Static ctor
        static AgsDispatchFormatter()
        {
            m_defaultViewModel = ViewModelDescription.Load(Assembly.Load("SanteDB.Rest.Common").GetManifestResourceStream("SanteDB.Rest.Common.Resources.ViewModel.xml"));
            var tracer = Tracer.GetTracer(typeof(AgsDispatchFormatter <TContract>));

            foreach (var t in s_knownTypes)
            {
                ModelSerializationBinder.RegisterModelType(t);
            }
            tracer.TraceInfo("Will generate serializer for {0}", typeof(TContract).FullName);
        }
 /// <summary>
 /// Get all types from core classes of entity and act and create shims in the model serialization binder
 /// </summary>
 static MdmDataManager()
 {
     foreach (var t in typeof(Entity).GetTypeInfo().Assembly.ExportedTypes.Where(o => typeof(Entity).GetTypeInfo().IsAssignableFrom(o.GetTypeInfo())))
     {
         ModelSerializationBinder.RegisterModelType(typeof(EntityMaster <>).MakeGenericType(t));
     }
     foreach (var t in typeof(Act).GetTypeInfo().Assembly.ExportedTypes.Where(o => typeof(Act).GetTypeInfo().IsAssignableFrom(o.GetTypeInfo())))
     {
         ModelSerializationBinder.RegisterModelType(typeof(ActMaster <>).MakeGenericType(t));
     }
 }
Beispiel #5
0
        /// <summary>
        /// Start the service
        /// </summary>
        public bool Start()
        {
            // Don't startup unless in SanteDB
            if (Assembly.GetEntryAssembly().GetName().Name != "SanteDB")
            {
                return(true);
            }

            try
            {
                this.Starting?.Invoke(this, EventArgs.Empty);


                this.m_webHost = ApplicationContext.Current.GetService <IRestServiceFactory>().CreateService(typeof(AmiServiceBehavior));
                this.m_webHost.AddServiceBehavior(new ErrorServiceBehavior());

                // Add service behaviors
                foreach (ServiceEndpoint endpoint in this.m_webHost.Endpoints)
                {
                    this.m_traceSource.TraceInfo("Starting AMI on {0}...", endpoint.Description.ListenUri);
                }

                // Start the webhost
                this.m_webHost.Start();
                ModelSerializationBinder.RegisterModelType(typeof(SecurityPolicyInfo));

                if (this.m_configuration.ResourceHandlers.Count() > 0)
                {
                    AmiMessageHandler.ResourceHandler = new ResourceHandlerTool(this.configuration.ResourceHandlers, typeof(IAmiServiceContract));
                }
                else
                {
                    AmiMessageHandler.ResourceHandler = new ResourceHandlerTool(
                        ApplicationServiceContext.Current.GetService <IServiceManager>().GetAllTypes()
                        .Where(t => !t.IsAbstract && !t.IsInterface && typeof(IApiResourceHandler).IsAssignableFrom(t))
                        .ToList(),
                        typeof(IAmiServiceContract)
                        );
                }

                this.Started?.Invoke(this, EventArgs.Empty);
                return(true);
            }
            catch (Exception e)
            {
                this.m_traceSource.TraceEvent(EventLevel.Error, e.ToString());
                return(false);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Get all types from core classes of entity and act and create shims in the model serialization binder
        /// </summary>
        public RemoteRepositoryFactory(IConfigurationManager configurationManager, IServiceManager serviceManager, ILocalizationService localizationService)
        {
            foreach (var t in typeof(Entity).Assembly.ExportedTypes.Where(o => typeof(Entity).IsAssignableFrom(o)))
            {
                ModelSerializationBinder.RegisterModelType(typeof(EntityMaster <>).MakeGenericType(t));
            }
            foreach (var t in typeof(Act).Assembly.ExportedTypes.Where(o => typeof(Act).IsAssignableFrom(o)))
            {
                ModelSerializationBinder.RegisterModelType(typeof(ActMaster <>).MakeGenericType(t));
            }
            ModelSerializationBinder.RegisterModelType(typeof(EntityRelationshipMaster));

            this.m_localizationService = localizationService;
            this.m_serviceManager      = serviceManager;
            this.m_configuration       = configurationManager.GetSection <ApplicationServiceContextConfigurationSection>();
        }
 /// <summary>
 /// Match configuration
 /// </summary>
 static MatchConfiguration()
 {
     ModelSerializationBinder.RegisterModelType(typeof(MatchConfiguration));
 }
        /// <summary>
        /// Start the daemon
        /// </summary>
        public bool Start()
        {
            this.Starting?.Invoke(this, EventArgs.Empty);

            // Pre-register types for serialization
            foreach (var itm in this.m_configuration.ResourceTypes)
            {
                if (itm.Type == typeof(Entity))
                {
                    throw new InvalidOperationException("Cannot bind MDM control to Entity or Act , only sub-classes");
                }

                var    rt       = itm.Type;
                string typeName = $"{rt.Name}Master";
                if (typeof(Entity).IsAssignableFrom(rt))
                {
                    rt = typeof(EntityMaster <>).MakeGenericType(rt);
                }
                else if (typeof(Act).IsAssignableFrom(rt))
                {
                    rt = typeof(ActMaster <>).MakeGenericType(rt);
                }
                ModelSerializationBinder.RegisterModelType(typeName, rt);
            }

            // Wait until application context is started
            ApplicationServiceContext.Current.Started += (o, e) =>
            {
                if (this.m_matchingService == null)
                {
                    this.m_traceSource.TraceWarning("The MDM Service should be using a record matching service");
                }

                // Replace matching
                var mdmMatcher = this.m_serviceManager.CreateInjected <MdmRecordMatchingService>();
                this.m_serviceManager.AddServiceProvider(mdmMatcher);
                var mdmMatchConfig = this.m_serviceManager.CreateInjected <MdmMatchConfigurationService>();
                this.m_serviceManager.AddServiceProvider(mdmMatchConfig);
                if (this.m_matchingService != null)
                {
                    this.m_serviceManager.RemoveServiceProvider(this.m_matchingService.GetType());
                }
                if (this.m_matchConfigurationService != null)
                {
                    this.m_serviceManager.RemoveServiceProvider(this.m_matchConfigurationService.GetType());
                }

                foreach (var itm in this.m_configuration.ResourceTypes)
                {
                    this.m_traceSource.TraceInfo("Adding MDM listener for {0}...", itm.Type.Name);
                    MdmDataManagerFactory.RegisterDataManager(itm.Type);
                    var idt = typeof(MdmResourceHandler <>).MakeGenericType(itm.Type);
                    var ids = this.m_serviceManager.CreateInjected(idt) as IDisposable;
                    this.m_listeners.Add(ids);
                    this.m_serviceManager.AddServiceProvider(ids);
                    this.m_serviceManager.AddServiceProvider(MdmDataManagerFactory.CreateMerger(itm.Type));

                    // Add job
                    var jobType = typeof(MdmMatchJob <>).MakeGenericType(itm.Type);
                    var job     = this.m_serviceManager.CreateInjected(jobType) as IJob;
                    this.m_jobManager?.AddJob(job, JobStartType.Never);
                }

                // Add an entity relationship and act relationship watcher to the persistence layer for after update
                // this will ensure that appropriate cleanup is performed on successful processing of data
                this.m_entityRelationshipService = ApplicationServiceContext.Current.GetService <IDataPersistenceService <EntityRelationship> >();
                this.m_entityService             = ApplicationServiceContext.Current.GetService <IDataPersistenceService <Entity> >();

                ApplicationServiceContext.Current.GetService <IDataPersistenceService <Bundle> >().Inserted  += RecheckBundleTrigger;
                ApplicationServiceContext.Current.GetService <IDataPersistenceService <Bundle> >().Updated   += RecheckBundleTrigger;
                ApplicationServiceContext.Current.GetService <IDataPersistenceService <Bundle> >().Obsoleted += RecheckBundleTrigger;
                this.m_entityRelationshipService.Inserted  += RecheckRelationshipTrigger;
                this.m_entityRelationshipService.Updated   += RecheckRelationshipTrigger;
                this.m_entityRelationshipService.Obsoleted += RecheckRelationshipTrigger;

                // Add an MDM listener for subscriptions
                if (this.m_subscriptionExecutor != null)
                {
                    m_subscriptionExecutor.Executing += MdmSubscriptionExecuting;
                    m_subscriptionExecutor.Executed  += MdmSubscriptionExecuted;
                }
                this.m_listeners.Add(new BundleResourceInterceptor(this.m_listeners));

                // Slipstream the MdmEntityProvider
                //EntitySource.Current = new EntitySource(new MdmEntityProvider());

                // HACK: Replace any freetext service with our own
                this.m_serviceManager.RemoveServiceProvider(typeof(IFreetextSearchService));
                m_serviceManager.AddServiceProvider(new MdmFreetextSearchService());
            };

            this.Started?.Invoke(this, EventArgs.Empty);
            return(true);
        }