Beispiel #1
0
        /// <summary>
        /// Start the service
        /// </summary>
        public bool Start()
        {
            this.Starting?.Invoke(this, EventArgs.Empty);

            // Get configuration
            this.m_configuration      = ApplicationContext.Current.Configuration.GetSection <SynchronizationConfigurationSection>();
            this.m_threadPool         = ApplicationContext.Current.GetService <IThreadPoolService>();
            this.m_integrationService = ApplicationContext.Current.GetService <IClinicalIntegrationService>();
            this.m_networkInfoService = ApplicationContext.Current.GetService <INetworkInformationService>();

            this.m_networkInfoService.NetworkStatusChanged += (o, e) => this.Pull(SynchronizationPullTriggerType.OnNetworkChange);

            this.m_tracer.TraceInfo("Performing OnStart trigger pull...");
            this.Pull(SynchronizationPullTriggerType.OnStart);

            // Polling
            if (this.m_configuration.SynchronizationResources.Any(o => (o.Triggers & SynchronizationPullTriggerType.PeriodicPoll) != 0) &&
                this.m_configuration.PollInterval != default(TimeSpan))
            {
                Action <Object> pollFn = null;
                pollFn = _ =>
                {
                    this.Pull(SynchronizationPullTriggerType.PeriodicPoll);
                    ApplicationContext.Current.GetService <IThreadPoolService>().QueueUserWorkItem(this.m_configuration.PollInterval, pollFn, null);
                };
                ApplicationContext.Current.GetService <IThreadPoolService>().QueueUserWorkItem(this.m_configuration.PollInterval, pollFn, null);
            }
            this.Started?.Invoke(this, EventArgs.Empty);

            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Data policy filter service with DI
        /// </summary>
        public DataPolicyFilterService(IConfigurationManager configurationManager, IPasswordHashingService passwordService, IPolicyDecisionService pdpService, IThreadPoolService threadPoolService,
                                       IDataCachingService dataCachingService, ISubscriptionExecutor subscriptionExecutor = null, IAdhocCacheService adhocCache = null)
        {
            this.m_hasher               = passwordService;
            this.m_adhocCache           = adhocCache;
            this.m_pdpService           = pdpService;
            this.m_subscriptionExecutor = subscriptionExecutor;
            this.m_dataCachingService   = dataCachingService;
            this.m_threadPool           = threadPoolService;

            // Configuration load
            this.m_configuration = configurationManager.GetSection <DataPolicyFilterConfigurationSection>();

            if (this.m_configuration == null)
            {
                this.m_tracer.TraceWarning("No data policy configuration exists. Setting all to HIDE");
                this.m_configuration = new DataPolicyFilterConfigurationSection()
                {
                    DefaultAction = ResourceDataPolicyActionType.Hide, Resources = new List <ResourceDataPolicyFilter>()
                };
            }

            if (this.m_configuration.Resources != null)
            {
                foreach (var t in this.m_configuration.Resources)
                {
                    if (typeof(Act).IsAssignableFrom(t.ResourceType.Type) || typeof(Entity).IsAssignableFrom(t.ResourceType.Type) || typeof(AssigningAuthority).IsAssignableFrom(t.ResourceType.Type))
                    {
                        this.m_tracer.TraceInfo("Binding privacy action {0} to {1}", t.Action, t.ResourceType.Type);
                        this.m_actions.TryAdd(t.ResourceType.Type, t);
                    }
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// Create a new job manager service
 /// </summary>
 public DefaultJobManagerService(IThreadPoolService threadPool, IServiceManager serviceManager, IJobStateManagerService jobStateManager = null, IJobScheduleManager cronTabManager = null)
 {
     this.m_threadPool         = threadPool;
     this.m_jobScheduleManager = cronTabManager ?? new XmlFileJobScheduleManager();
     this.m_jobStateManager    = jobStateManager ?? new XmlFileJobStateManager();
     this.m_serviceManager     = serviceManager;
 }
 /// <summary>
 /// Thread pool performance probe
 /// </summary>
 public ThreadPoolPerformanceProbe(IThreadPoolService threadPoolService)
 {
     this.m_performanceCounters = new IDiagnosticsProbe[]
     {
         new PoolConcurrencyProbe(threadPoolService),
         new PooledWorkersProbe(threadPoolService),
         new QueueDepthProbe(threadPoolService)
     };
 }
Beispiel #5
0
 /// <summary>
 /// Creates a new entity merger service
 /// </summary>
 public MdmEntityMerger(IDataPersistenceService <Bundle> batchService, IThreadPoolService threadPool, IPolicyEnforcementService policyEnforcement, IStoredQueryDataPersistenceService <TEntity> persistenceService, IFastQueryDataPersistenceService <EntityRelationship> relationshipPersistence)
 {
     this.m_dataManager             = MdmDataManagerFactory.GetDataManager <TEntity>();
     this.m_batchPersistence        = batchService;
     this.m_pepService              = policyEnforcement;
     this.m_entityPersistence       = persistenceService;
     this.m_relationshipPersistence = relationshipPersistence;
     this.m_threadPool              = threadPool;
     if (this.m_relationshipPersistence is IReportProgressChanged irpc)
     {
         irpc.ProgressChanged += (o, e) => this.ProgressChanged?.Invoke(o, e); // pass through progress reports
     }
 }
Beispiel #6
0
        /// <summary>
        /// Start the service
        /// </summary>
        public bool Start()
        {
            this.Starting?.Invoke(this, EventArgs.Empty);

            // Get configuration
            this.m_configuration      = ApplicationContext.Current.Configuration.GetSection <SynchronizationConfigurationSection>();
            this.m_threadPool         = ApplicationContext.Current.GetService <IThreadPoolService>();
            this.m_integrationService = ApplicationContext.Current.GetService <IClinicalIntegrationService>();
            this.m_networkInfoService = ApplicationContext.Current.GetService <INetworkInformationService>();

            this.m_networkInfoService.NetworkStatusChanged += (o, e) => this.Pull(SynchronizationPullTriggerType.OnNetworkChange);

            // Notification for tickles when the pull is completed
            this.PullCompleted += (o, e) =>
            {
                if (e.Type == null) // general pull complete
                {
                    ApplicationContext.Current.SetProgress(Strings.locale_idle, 1.0f);
                    var tickleService = ApplicationContext.Current.GetService <ITickleService>();
                    if (e.IsInitial)
                    {
                        tickleService.SendTickle(
                            new Tickler.Tickle(Guid.Empty, Tickler.TickleType.Task | Tickler.TickleType.Toast, Strings.locale_sync_initial, DateTime.Now.Add(this.m_configuration.PollInterval))
                            );
                    }
                    else
                    {
                        tickleService.SendTickle(
                            new Tickler.Tickle(Guid.Empty, Tickler.TickleType.Task | Tickler.TickleType.Toast, Strings.locale_sync_complete, DateTime.Now.Add(this.m_configuration.PollInterval))
                            );
                    }
                }
            };

            ApplicationServiceContext.Current.Started += (xo, xe) =>
            {
                try
                {
                    this.m_tracer.TraceInfo("Performing OnStart trigger pull...");
                    this.Pull(SynchronizationPullTriggerType.OnStart);

                    // Polling
                    if (this.m_configuration.SynchronizationResources.Any(o => (o.Triggers & SynchronizationPullTriggerType.PeriodicPoll) != 0) &&
                        this.m_configuration.PollInterval != default(TimeSpan))
                    {
                        var jms  = ApplicationServiceContext.Current.GetService <IJobManagerService>();
                        var jsms = ApplicationServiceContext.Current.GetService <IJobStateManagerService>();
                        var job  = new RemoteSynchronizationJob(this, jsms);
                        jms.AddJob(job, JobStartType.DelayStart);
                        jms.SetJobSchedule(job, this.m_configuration.PollInterval);
                    }
                }
                catch (Exception)
                {
                    this.m_tracer.TraceError("Error starting remote sync service: {0}");
                }
            };

            this.Started?.Invoke(this, EventArgs.Empty);

            return(true);
        }
        /// <summary>
        /// ADO freetext constructor
        /// </summary>
        public AdoFreetextSearchService(IJobManagerService jobManager, IServiceManager serviceManager, IConfigurationManager configurationManager, IThreadPoolService threadPoolService)
        {
            this.m_configuration = configurationManager.GetSection <AdoPersistenceConfigurationSection>();

            this.m_ftiRefreshThread = new Thread(this.MonitorFreetextJob)
            {
                Name         = "ADO.NET FullText Realtime Refresh",
                IsBackground = true,
                Priority     = ThreadPriority.Lowest
            };
            this.m_ftiRefreshThread.Start();

            if (this.m_configuration.Provider.GetFilterFunction("freetext") == null)
            {
                return;                                                                      // Freetext not supported
            }
            var job = serviceManager.CreateInjected <AdoRebuildFreetextIndexJob>();

            jobManager.AddJob(job, JobStartType.TimerOnly);
            if (jobManager.GetJobSchedules(job)?.Any() != true)
            {
                jobManager.SetJobSchedule(job, new DayOfWeek[] { DayOfWeek.Saturday }, new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0));
            }

            // Subscribe to common types and events
            var appServiceProvider = ApplicationServiceContext.Current;

            appServiceProvider.GetService <IDataPersistenceService <Bundle> >().Inserted               += (o, e) => e.Data.Item.ForEach(i => this.ReIndex(i));
            appServiceProvider.GetService <IDataPersistenceService <Patient> >().Inserted              += (o, e) => this.ReIndex(e.Data);
            appServiceProvider.GetService <IDataPersistenceService <Provider> >().Inserted             += (o, e) => this.ReIndex(e.Data);
            appServiceProvider.GetService <IDataPersistenceService <Material> >().Inserted             += (o, e) => this.ReIndex(e.Data);
            appServiceProvider.GetService <IDataPersistenceService <ManufacturedMaterial> >().Inserted += (o, e) => this.ReIndex(e.Data);
            appServiceProvider.GetService <IDataPersistenceService <Entity> >().Inserted               += (o, e) => this.ReIndex(e.Data);
            appServiceProvider.GetService <IDataPersistenceService <Place> >().Inserted               += (o, e) => this.ReIndex(e.Data);
            appServiceProvider.GetService <IDataPersistenceService <Organization> >().Inserted        += (o, e) => this.ReIndex(e.Data);
            appServiceProvider.GetService <IDataPersistenceService <Person> >().Inserted              += (o, e) => this.ReIndex(e.Data);
            appServiceProvider.GetService <IDataPersistenceService <Patient> >().Updated              += (o, e) => this.ReIndex(e.Data);
            appServiceProvider.GetService <IDataPersistenceService <Provider> >().Updated             += (o, e) => this.ReIndex(e.Data);
            appServiceProvider.GetService <IDataPersistenceService <Material> >().Updated             += (o, e) => this.ReIndex(e.Data);
            appServiceProvider.GetService <IDataPersistenceService <ManufacturedMaterial> >().Updated += (o, e) => this.ReIndex(e.Data);
            appServiceProvider.GetService <IDataPersistenceService <Entity> >().Updated               += (o, e) => this.ReIndex(e.Data);
            appServiceProvider.GetService <IDataPersistenceService <Place> >().Updated        += (o, e) => this.ReIndex(e.Data);
            appServiceProvider.GetService <IDataPersistenceService <Organization> >().Updated += (o, e) => this.ReIndex(e.Data);
            appServiceProvider.GetService <IDataPersistenceService <Person> >().Updated       += (o, e) => this.ReIndex(e.Data);
            appServiceProvider.Stopping += (o, e) => this.m_shutdown = true;
        }
 /// <summary>
 /// Creates a new instance with DI
 /// </summary>
 public ExemptablePolicyFilterService(IConfigurationManager configManager, IPasswordHashingService passwordService, IPolicyDecisionService pdpService, IThreadPoolService threadPoolService, IDataCachingService dataCachingService, IAdhocCacheService adhocCache = null, ISubscriptionExecutor subscriptionExecutor = null)
     : base(configManager, passwordService, pdpService, threadPoolService, dataCachingService, subscriptionExecutor, adhocCache)
 {
 }
Beispiel #9
0
        /// <summary>
        /// Starts the queue manager service.
        /// </summary>
        /// <returns>Returns true if the service started successfully.</returns>
        public bool Start()
        {
            this.Starting?.Invoke(this, EventArgs.Empty);

            this.m_threadPool = ApplicationContext.Current.GetService <IThreadPoolService>();

            // Bind to the inbound queue
            SynchronizationQueue.Inbound.Enqueued += (o, e) =>
            {
                // Someone already got this!
                if (Monitor.IsEntered(this.m_inboundLock))
                {
                    return;
                }
                Action <Object> async = (itm) =>
                {
                    this.ExhaustInboundQueue();
                };
                this.m_threadPool.QueueUserWorkItem(async);
            };

            // Bind to outbound queue
            SynchronizationQueue.Outbound.Enqueued += (o, e) =>
            {
                // Trigger sync?
                if (e.Data.Type.StartsWith(typeof(Patch).FullName) ||
                    e.Data.Type.StartsWith(typeof(Bundle).FullName) ||
                    ApplicationContext.Current.Configuration.GetSection <SynchronizationConfigurationSection>().SynchronizationResources.
                    Exists(r => r.ResourceType == Type.GetType(e.Data.Type) &&
                           (r.Triggers & SynchronizationPullTriggerType.OnCommit) != 0))
                {
                    Action <Object> async = (itm) =>
                    {
                        this.ExhaustOutboundQueue();
                    };
                    this.m_threadPool.QueueUserWorkItem(async);
                }
            };

            // Bind to administration queue
            SynchronizationQueue.Admin.Enqueued += (o, e) =>
            {
                // Admin is always pushed
                this.m_threadPool.QueueUserWorkItem(a => this.ExhaustAdminQueue());
            };

            ApplicationContext.Current.Started += (o, e) =>
            {
                // startup
                Action <Object> startup = (iar) =>
                {
                    try
                    {
                        this.ExhaustOutboundQueue();
                        this.ExhaustInboundQueue();
                        this.ExhaustAdminQueue();
                    }
                    catch (Exception ex)
                    {
                        this.m_tracer.TraceError("Error executing initial queues: {0}", ex);
                    }
                };

                ApplicationContext.Current.GetService <IThreadPoolService>().QueueNonPooledWorkItem(startup, null);
            };


            this.Started?.Invoke(this, EventArgs.Empty);

            return(true);
        }
Beispiel #10
0
        public bool Start()
        {
            try
            {
                this.Starting?.Invoke(this, EventArgs.Empty);

                this.m_tracer.TraceInfo("Starting internal IMS services...");
                this.m_threadPool = ApplicationContext.Current.GetService <IThreadPoolService>();

                XamarinApplicationContext.Current.SetProgress("IMS Service Bus", 0);

                this.m_bypassMagic      = XamarinApplicationContext.Current.GetType().Name == "MiniApplicationContext";
                this.m_listener         = new HttpListener();
                this.m_defaultViewModel = ViewModelDescription.Load(typeof(MiniImsServer).Assembly.GetManifestResourceStream("OpenIZ.Mobile.Core.Xamarin.Resources.ViewModel.xml"));

                // Scan for services
                try
                {
                    foreach (var t in typeof(MiniImsServer).Assembly.DefinedTypes.Where(o => o.GetCustomAttribute <RestServiceAttribute>() != null))
                    {
                        var    serviceAtt = t.GetCustomAttribute <RestServiceAttribute>();
                        object instance   = Activator.CreateInstance(t);
                        foreach (var mi in t.GetRuntimeMethods().Where(o => o.GetCustomAttribute <RestOperationAttribute>() != null))
                        {
                            var operationAtt = mi.GetCustomAttribute <RestOperationAttribute>();
                            var faultMethod  = operationAtt.FaultProvider != null?t.GetRuntimeMethod(operationAtt.FaultProvider, new Type[] { typeof(Exception) }) : null;

                            String pathMatch = String.Format("{0}:{1}{2}", operationAtt.Method, serviceAtt.BaseAddress, operationAtt.UriPath);
                            if (!this.m_services.ContainsKey(pathMatch))
                            {
                                lock (this.m_lockObject)
                                    this.m_services.Add(pathMatch, new InvokationInformation()
                                    {
                                        BindObject    = instance,
                                        Method        = mi,
                                        FaultProvider = faultMethod,
                                        Demand        = (mi.GetCustomAttributes <DemandAttribute>().Union(t.GetCustomAttributes <DemandAttribute>())).Select(o => o.PolicyId).ToList(),
                                        Anonymous     = (mi.GetCustomAttribute <AnonymousAttribute>() ?? t.GetCustomAttribute <AnonymousAttribute>()) != null,
                                        Parameters    = mi.GetParameters()
                                    });
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    this.m_tracer.TraceWarning("Could scan for handlers : {1}", e);
                }

                // Get loopback
                var loopback = GetLocalIpAddress();

                // Core always on 9200
                this.m_listener.Prefixes.Add(String.Format("http://{0}:9200/", loopback));

                this.m_acceptThread = new Thread(() =>
                {
                    // Process the request
                    while (this.m_listener != null)
                    {
                        try
                        {
                            //var iAsyncResult = this.m_listener.BeginGetContext(null, null);
                            //iAsyncResult.AsyncWaitHandle.WaitOne();
                            var context = this.m_listener.GetContext(); //this.m_listener.EndGetContext(iAsyncResult);
                            this.m_threadPool.QueueUserWorkItem(TimeSpan.MinValue, this.HandleRequest, context);
                        }
                        catch (Exception e)
                        {
                            this.m_tracer.TraceError("Listener Error: {0}", e);
                        }
                    }
                });

                this.m_listener.Start();
                this.m_acceptThread.IsBackground = true;
                this.m_acceptThread.Start();
                this.m_acceptThread.Name = "MiniIMS";
                this.m_tracer.TraceInfo("Started internal IMS services...");

                // We have to wait for the IAppletManager service to come up or else it is pretty useless
                this.Started?.Invoke(this, EventArgs.Empty);

                this.m_startFinished = true;
                return(true);
            }
            catch (Exception ex)
            {
                this.m_tracer.TraceError("Error starting IMS : {0}", ex);
                ApplicationContext.Current.Alert(Strings.err_moreThanOneApplication);
                return(false);
            }
        }
Beispiel #11
0
        /// <summary>
        /// Starts the queue manager service.
        /// </summary>
        /// <returns>Returns true if the service started successfully.</returns>
        public bool Start()
        {
            this.Starting?.Invoke(this, EventArgs.Empty);

            this.m_threadPool = ApplicationContext.Current.GetService <IThreadPoolService>();

            // Bind to the inbound queue
            SynchronizationQueue.Inbound.Enqueued += (o, e) =>
            {
                // Someone already got this!
                if (Monitor.IsEntered(this.m_inboundLock))
                {
                    return;
                }
                Action <Object> async = (itm) =>
                {
                    this.ExhaustInboundQueue();
                };
                this.m_threadPool.QueueUserWorkItem(async);
            };

            // Bind to outbound queue
            SynchronizationQueue.Outbound.Enqueued += (o, e) =>
            {
                // Trigger sync?
                if (e.Data.Type.StartsWith(typeof(Patch).FullName) ||
                    e.Data.Type.StartsWith(typeof(Bundle).FullName) ||
                    ApplicationContext.Current.Configuration.GetSection <SynchronizationConfigurationSection>().SynchronizationResources.
                    Exists(r => r.ResourceType == Type.GetType(e.Data.Type) &&
                           (r.Triggers & SynchronizationPullTriggerType.OnCommit) != 0))
                {
                    Action <Object> async = (itm) =>
                    {
                        this.ExhaustOutboundQueue();
                    };
                    this.m_threadPool.QueueUserWorkItem(async);
                }
            };

            // Bind to administration queue
            SynchronizationQueue.Admin.Enqueued += (o, e) =>
            {
                // Admin is always pushed
                this.m_threadPool.QueueUserWorkItem(a => this.ExhaustAdminQueue());
            };

            ApplicationContext.Current.Started += (o, e) =>
            {
                // startup
                Action <Object> startup = (iar) =>
                {
                    try
                    {
                        this.ExhaustOutboundQueue();
                        this.ExhaustInboundQueue();
                        this.ExhaustAdminQueue();
                    }
                    catch (Exception ex)
                    {
                        this.m_tracer.TraceError("Error executing initial queues: {0}", ex);
                    }
                };

                ApplicationContext.Current.GetService <IThreadPoolService>().QueueNonPooledWorkItem(startup, null);
            };

            // Does the outbound queue have data?
            int dlc = SynchronizationQueue.DeadLetter.Count();

            if (dlc > 0 &&
                ApplicationContext.Current.Confirm(Strings.locale_retry))
            {
                try
                {
                    int i = 0;
                    while (SynchronizationQueue.DeadLetter.Count() > 0)
                    {
                        ApplicationContext.Current.SetProgress(Strings.locale_requeueing, ((float)i++) / (float)dlc);

                        var itm = SynchronizationQueue.DeadLetter.PeekRaw();
                        switch (itm.OriginalQueue)
                        {
                        case "inbound":
                        case "inbound_queue":
                            SynchronizationQueue.Inbound.EnqueueRaw(new InboundQueueEntry(itm));
                            break;

                        case "outbound":
                        case "outbound_queue":
                            SynchronizationQueue.Outbound.EnqueueRaw(new OutboundQueueEntry(itm));
                            break;

                        case "admin":
                        case "admin_queue":
                            SynchronizationQueue.Admin.EnqueueRaw(new OutboundAdminQueueEntry(itm));
                            break;
                        }
                        SynchronizationQueue.DeadLetter.Delete(itm.Id);
                    }
                }
                catch (Exception e)
                {
                    this.m_tracer.TraceInfo("Could not re-queue items: {0}", e.Message);
                }
            }

            this.Started?.Invoke(this, EventArgs.Empty);

            return(true);
        }
        /// <summary>
        /// Synchronized dispatch service
        /// </summary>
        public SynchronizedAuditDispatchService(IConfigurationManager configurationManager, IJobStateManagerService jobStateManager, IJobManagerService scheduleManager, IThreadPoolService threadPool, IQueueManagerService queueManagerService)
        {
            this.m_securityConfiguration = configurationManager.GetSection <SecurityConfigurationSection>();
            this.m_jobStateManager       = jobStateManager;
            this.m_queueManagerService   = queueManagerService;

            if (!scheduleManager.GetJobSchedules(this).Any())
            {
                scheduleManager.SetJobSchedule(this, new TimeSpan(0, 5, 0));
            }

            threadPool.QueueUserWorkItem(_ =>
            {
                try
                {
                    AuditData securityAlertData = new AuditData(DateTime.Now, ActionType.Execute, OutcomeIndicator.Success, EventIdentifierType.SecurityAlert, AuditUtil.CreateAuditActionCode(EventTypeCodes.AuditLoggingStarted));
                    AuditUtil.AddLocalDeviceActor(securityAlertData);
                    AuditUtil.SendAudit(securityAlertData);
                }
                catch (Exception ex)
                {
                    this.m_tracer.TraceError("Error starting up audit repository service: {0}", ex);
                }
            });
        }
 /// <summary>
 /// Non pooled workers counter
 /// </summary>
 public PooledWorkersProbe(IThreadPoolService threadPool) : base("Pool Use", "Shows the number of busy worker threads")
 {
     this.m_threadPool = threadPool;
 }
 /// <summary>
 /// Non pooled workers counter
 /// </summary>
 public QueueDepthProbe(IThreadPoolService threadPool) : base("Queue Depth", "Shows the number of tasks waiting to be executed")
 {
     this.m_threadPool = threadPool;
 }
 /// <summary>
 /// Non pooled workers counter
 /// </summary>
 public PoolConcurrencyProbe(IThreadPoolService threadPool) : base("Thread pool size", "Shows the total number of threads which are allocated to the thread pool")
 {
     this.m_threadPool = threadPool;
 }
 /// <summary>
 /// Creates a new local job manager
 /// </summary>
 public LocalJobManagerService(IThreadPoolService threadPool, IServiceManager serviceManager, IJobStateManagerService jobStateManager = null, IJobScheduleManager cronTabManager = null) : base(threadPool, serviceManager, jobStateManager, cronTabManager)
 {
 }