public override void Load(string serviceDirectory, string displayName) { string msg = string.Format("serviceDirectory:{0} displayName:{1}", serviceDirectory, displayName); DicomUtilities.DebugString(DebugStringOptions.ShowCounter, "Module.Load() -- JobManager.Start" + msg); AdvancedSettings settings = AdvancedSettings.Open(serviceDirectory); _serviceDirectory = serviceDirectory; DicomServer server = ServiceLocator.Retrieve <DicomServer>(); ServiceName = server.Name; try { Type[] extraTypes = new Type[] { typeof(AzureConfiguration) }; Options = settings.GetAddInCustomData <ExternalStoreOptions>(ExternalStorePresenter._Name, "ExternalStoreOptions", extraTypes); ExternalStorePresenter.MyDumpExternalStoreOptions("Module.Load() -- settings.GetAddInCustomData()", Options); if (Options == null) { Options = new ExternalStoreOptions(); } ICrud thisCrud = Options.GetCrud(AzureGuid); if (thisCrud != null) { DataAccessServiceLocator.Register <ICrud>(thisCrud, thisCrud.ExternalStoreGuid); } } catch (Exception e) { DicomUtilities.DebugString(DebugStringOptions.ShowCounter, "*** Exception: Module.Load() settings.GetAddInCustomData" + e.Message); if (Options == null) { Options = new ExternalStoreOptions(); } Logger.Global.Error(Source, e.Message); } ExternalStore.Addin.Module.StartExternalStoreJobs(AzureExternalStoreAddinConfig, "Azure"); }
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); } } } }