protected override void OnProcess(Model.ServiceLock item) { DirectoryImportSettings settings = DirectoryImportSettings.Default; ServerFilesystemInfo filesystem = EnsureFilesystemIsValid(item); if (filesystem != null) { Platform.Log(LogLevel.Debug, "Start importing dicom files from {0}", filesystem.Filesystem.FilesystemPath); foreach (ServerPartition partition in ServerPartitionMonitor.Instance) { DirectoryImporterParameters parms = new DirectoryImporterParameters(); String incomingFolder = partition.GetIncomingFolder(); // String.Format("{0}_{1}", partition.PartitionFolder, FilesystemMonitor.ImportDirectorySuffix); parms.Directory = new DirectoryInfo(filesystem.Filesystem.GetAbsolutePath(incomingFolder)); parms.PartitionAE = partition.AeTitle; parms.MaxImages = settings.MaxBatchSize; parms.Delay = settings.ImageDelay; parms.Filter = "*.*"; if (!parms.Directory.Exists) { parms.Directory.Create(); } DirectoryImporterBackgroundProcess process = new DirectoryImporterBackgroundProcess(parms); process.SopImported += delegate { _importedSopCounter++; }; process.RestoreTriggered += delegate { _restoreTriggered = true; }; _queue.Enqueue(process); } // start the processes. for (int n = 0; n < settings.MaxConcurrency && n < _queue.Count; n++) { LaunchNextBackgroundProcess(); } _allCompleted.WaitOne(); if (CancelPending) { Platform.Log(LogLevel.Info, "All import processes have completed gracefully."); } } if (_restoreTriggered) { DateTime newScheduledTime = Platform.Time.AddSeconds(Math.Max(settings.RecheckDelaySeconds, 60)); Platform.Log(LogLevel.Info, "Some Study/Studies need to be restored first. File Import will resume until {0}", newScheduledTime); UnlockServiceLock(item, true, newScheduledTime); } else { UnlockServiceLock(item, true, Platform.Time.AddSeconds(_importedSopCounter > 0? 5: settings.RecheckDelaySeconds)); } }
protected override void OnProcess(Model.ServiceLock item) { DirectoryImportSettings settings = DirectoryImportSettings.Default; // #10419: Avoid running multiple instances of Import service - which can lead to race condition on the input files if (CheckMultipleInstances()) { // Instead of disabling duplicate entries automatically, decided it's easier and safer to let user figure out which one should be disabled. Platform.Log(LogLevel.Warn, "Detect multiple active instances of the Import File Service. Go to Service Scheduling configuration and make sure only one of them is active."); DateTime newScheduledTime = Platform.Time.AddSeconds(Math.Max(settings.RecheckDelaySeconds, 60)); UnlockServiceLock(item, true, newScheduledTime); return; } ServerFilesystemInfo filesystem = EnsureFilesystemIsValid(item); if (filesystem != null) { Platform.Log(LogLevel.Debug, "Start importing dicom files from {0}", filesystem.Filesystem.FilesystemPath); foreach (ServerPartition partition in ServerPartitionMonitor.Instance) { if (partition.Enabled) { String incomingFolder = partition.GetIncomingFolder(); if (!string.IsNullOrEmpty(incomingFolder)) { DirectoryImporterParameters parms = new DirectoryImporterParameters { Directory = new DirectoryInfo(incomingFolder), PartitionAE = partition.AeTitle, MaxImages = settings.MaxBatchSize, Delay = settings.ImageDelay, Filter = "*.*" }; if (!parms.Directory.Exists) { parms.Directory.Create(); } DirectoryImporterBackgroundProcess process = new DirectoryImporterBackgroundProcess(parms); process.SopImported += delegate { _importedSopCounter++; }; process.RestoreTriggered += delegate { _restoreTriggered = true; }; _queue.Enqueue(process); } } } // start the processes. for (int n = 0; n < settings.MaxConcurrency && n < _queue.Count; n++) { LaunchNextBackgroundProcess(); } _allCompleted.WaitOne(); if (CancelPending) { Platform.Log(LogLevel.Info, "All import processes have completed gracefully."); } } if (_restoreTriggered) { DateTime newScheduledTime = Platform.Time.AddSeconds(Math.Max(settings.RecheckDelaySeconds, 60)); Platform.Log(LogLevel.Info, "Some Study/Studies need to be restored first. File Import will resume until {0}", newScheduledTime); UnlockServiceLock(item, true, newScheduledTime); } else { UnlockServiceLock(item, true, Platform.Time.AddSeconds(_importedSopCounter > 0 ? 5 : settings.RecheckDelaySeconds)); } }