/// <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); }
/// <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); }