public void Start() { try { ExternalStoreItem item = null; if (_Options != null) { item = _Options.GetCurrentOption(); } if (item != null) { if (item.ExternalStoreJob != null) { FixUpJob(item.ExternalStoreJob); Scheduler.SubmitJob(item.ExternalStoreJob, new Action <Job>(ExternalStore)); } if (item.CleanJob != null) { FixUpJob(item.CleanJob); Scheduler.SubmitJob(item.CleanJob, new Action <Job>(Clean)); } } } catch (Exception ex) { DicomUtilities.DebugString(DebugStringOptions.ShowCounter, "Exception: JobManager.Start(): " + ex.Message); } }
public static void StartExternalStoreJobs(ExternalStoreAddinConfigAbstract addinExternalStoreAddinConfig, string addinFriendlyName) { ExternalStoreItem item = null; if (Options != null) { item = Options.GetCurrentOption(); } if ((item != null) && (addinExternalStoreAddinConfig != null) && (item.ExternalStoreAddinConfig.Equals(addinExternalStoreAddinConfig))) { ICrud crud = item.ExternalStoreAddinConfig.GetCrudInterface(); crud.Initialize(); DataAccessServiceLocator.Register <ICrud>(crud); DataAccessServiceLocator.Register <ICrud>(crud, crud.ExternalStoreGuid); StorageConfigManager = new StorageModuleConfigurationManager(true); StorageConfigManager.Load(ServiceDirectory); System.Configuration.Configuration configuration = DicomDemoSettingsManager.GetGlobalPacsAddinsConfiguration(_serviceDirectory); IExternalStoreDataAccessAgent externalStoreAgent; if (!DataAccessServices.IsDataAccessServiceRegistered <IExternalStoreDataAccessAgent>()) { externalStoreAgent = DataAccessFactory.GetInstance(new ExternalStoreDataAccessConfigurationView(configuration, null, _displayName)).CreateDataAccessAgent <IExternalStoreDataAccessAgent>(); DataAccessServices.RegisterDataAccessService <IExternalStoreDataAccessAgent>(externalStoreAgent); } else { externalStoreAgent = DataAccessServices.GetDataAccessService <IExternalStoreDataAccessAgent>(); } IStorageDataAccessAgent storageAgent; if (!DataAccessServices.IsDataAccessServiceRegistered <IStorageDataAccessAgent>()) { storageAgent = DataAccessFactory.GetInstance(new StorageDataAccessConfigurationView(configuration, null, _displayName)).CreateDataAccessAgent <IStorageDataAccessAgent>(); DataAccessServices.RegisterDataAccessService <IStorageDataAccessAgent>(storageAgent); } else { storageAgent = DataAccessServices.GetDataAccessService <IStorageDataAccessAgent>(); } string sDebug = string.Format("{0}: Module.StartOrStopAddin() -- new JobManager()", addinFriendlyName); ExternalStorePresenter.MyDumpExternalStoreOptions(sDebug, Options); JobManager = new JobManager(Options, externalStoreAgent, storageAgent, ServiceName, StorageConfigManager.GetStorageAddInsSettings()); JobManager.ExternalStoreGuid = item.ExternalStoreAddinConfig.Guid; if (IsLicenseValid()) { sDebug = string.Format("{0}: Module.StartOrStopAddin() -- JobManager.Start", addinFriendlyName); DicomUtilities.DebugString(DebugStringOptions.ShowCounter, sDebug); JobManager.Start(); } } }
static ExternalStorage() { AdvancedSettings _Settings = null; List <Type> _extraTypeList = new List <Type>(); const string _Name = "ExternalStore"; ExternalStoreOptions _Options = null; if (_Settings == null) { try { string storageServerServicePath = ConfigurationManager.AppSettings.Get("storageServerServicePath"); if (Directory.Exists(storageServerServicePath)) { storageServerServicePath = ServiceUtils.MapConfigPath(storageServerServicePath); _Settings = AdvancedSettings.Open(storageServerServicePath); _Settings.RefreshSettings(); } } catch (System.Configuration.ConfigurationErrorsException) { // This can occur when connection a v19 HTML Medical Web Viewer to a v18 CSStorageServerManager.exe database // The v18 CSStorageServerManager.exe does not have support for external store } catch (Exception e) { throw new ServiceException("Possible invalid storageServerServicePath specified. " + e.Message); } if (_Settings != null) { _Options = _Settings.GetAddInCustomData <ExternalStoreOptions>(_Name, "ExternalStoreOptions", _extraTypeList.ToArray()); } if (_Options == null) { _Options = new ExternalStoreOptions(); } _Options.RegisterAllExternalStoreAddins(); ExternalStoreItem item = _Options.GetCurrentOption(); if (item != null) { ICrud crud = item.ExternalStoreAddinConfig.GetCrudInterface(); DataAccessServiceLocator.Register <ICrud>(crud); DataAccessServiceLocator.Register <ICrud>(crud, crud.ExternalStoreGuid); } else { DataAccessServiceLocator.Register <ICrud>(new DefaultCrud()); } } }
public void RunThread(IExternalStoreDataAccessAgent externalStoreAgent, IStorageDataAccessAgent storageAgent) { DicomUtilities.DebugString(DebugStringOptions.ShowCounter, "ExternalStoreProcess.Run"); string message; ICrud crud = _Options.GetCrud(_externalStoreGuid); if (crud == null) { message = string.Format("ExternalStore ICrud interface not found:ExternalStoreGuid[{0}], FriendlyName[{1}]", _externalStoreGuid, FriendlyName); Logger.Global.SystemMessage(LogType.Error, message, _serviceName); return; } if (!DataAccessServiceLocator.IsRegistered(_externalStoreGuid)) { DataAccessServiceLocator.Register(crud, _externalStoreGuid); } lock (_externalStoreLock) { ExternalStoreInstance[] instances = externalStoreAgent.GetExternalStoreList(); if (instances.Length > 0) { message = string.Format("{0} {1} found to send to external store", instances.Length, "dataset(s)"); Logger.Global.SystemMessage(LogType.Information, message, _serviceName); } ExternalStoreItem item = _Options.GetExternalStoreItem(_externalStoreGuid); if (item == null) { return; } if (instances.Length > 0 && item.Verify) { message = string.Format("{0} {1} will be verified after sending to external store", instances.Length, instances.Length == 1 ? "instance" : "instances"); Logger.Global.SystemMessage(LogType.Information, message, _serviceName); } foreach (ExternalStoreInstance instance in instances) { if (_cancelExternalStore) { _cancelExternalStore = false; Logger.Global.SystemMessage(LogType.Information, string.Format("Cancelling External Store Process", instance.ReferencedFile), _serviceName); break; } try { if (!File.Exists(instance.ReferencedFile)) { message = string.Format("Referenced file doesn't exist. Instance ({0}) will be removed from external store queue. [{1}]", instance.SOPInstanceUID, instance.ReferencedFile); Logger.Global.SystemMessage(LogType.Warning, message, _serviceName); // TODO: fix this up -- assign a valid token externalStoreAgent.SetInstanceExternalStored(instance.SOPInstanceUID, string.Empty, string.Empty, DateTime.Now, null); continue; } string storeToken; string externalStoreGuid; if (ExternalStoreInstance(crud, instance, out storeToken, out externalStoreGuid)) { DateTime?expires = null; DateTime externalStoreDate = DateTime.Now; if (item.ImageHold != null && item.ImageHold != 0) { switch (item.HoldInterval) { case HoldInterval.Days: expires = externalStoreDate.AddDays(item.ImageHold.Value); break; case HoldInterval.Months: expires = externalStoreDate.AddMonths(item.ImageHold.Value); break; default: expires = externalStoreDate.AddYears(item.ImageHold.Value); break; } } if (!item.Verify || VerifyInstance(crud, storeToken)) { if (item.Verify) { message = string.Format("SOP instance successfully verified: {0}", instance.SOPInstanceUID); Logger.Global.SystemMessage(LogType.Information, message, _serviceName); } externalStoreAgent.SetInstanceExternalStored(instance.SOPInstanceUID, externalStoreGuid, storeToken, externalStoreDate, expires); externalStoreAgent.SetToken(instance.SOPInstanceUID, storeToken); externalStoreAgent.SetExternalStoreGuid(instance.SOPInstanceUID, externalStoreGuid); } else { message = string.Format("Failed to verify SOP instance: {0}. Instance not marked as externally stored.", instance.SOPInstanceUID); Logger.Global.SystemMessage(LogType.Error, message, _serviceName); } } } catch (Exception e) { Logger.Global.SystemMessage(LogType.Error, string.Format("{0}", e.Message), _serviceName); } } } }