Exemplo n.º 1
0
 public void RegisterAllExternalStoreAddins()
 {
     foreach (ExternalStoreItem item in _items)
     {
         DataAccessServiceLocator.Register <ICrud>(item.ExternalStoreAddinConfig.GetCrudInterface(), item.ExternalStoreAddinConfig.Guid);
     }
 }
Exemplo n.º 2
0
        // Called when the external store addin is loaded by the PACSFramework
        // Registers the ICrud interface used by this external store add-in
        // If this external store add-in is currently active, this method starts the JobManager for this addin
        public override void Load(string serviceDirectory, string displayName)
        {
            // Open 'advanced.config' which contains all settings for CSStorageServerManger.exe addins (including this ExternalStore SampleAddin)
            AdvancedSettings settings = AdvancedSettings.Open(serviceDirectory);

            _serviceDirectory = serviceDirectory;

            try
            {
                Type[] extraTypes = new[] { typeof(SampleConfiguration) };
                Options = settings.GetAddInCustomData <ExternalStoreOptions>(ExternalStorePresenter._Name, "ExternalStoreOptions", extraTypes);
                if (Options == null)
                {
                    Options = new ExternalStoreOptions();
                }
                ICrud thisCrud = Options.GetCrud(SampleGuid);
                if (thisCrud != null)
                {
                    DataAccessServiceLocator.Register(thisCrud, thisCrud.ExternalStoreGuid);
                }
            }
            catch (Exception e)
            {
                if (Options == null)
                {
                    Options = new ExternalStoreOptions();
                }

                Logger.Global.Error(Source, e.Message);
            }

            ExternalStore.Addin.Module.StartExternalStoreJobs(SampleExternalStoreAddinConfig, "Sample");
        }
Exemplo n.º 3
0
        public static void RegisterInterfaces()
        {
#if TUTORIAL_CUSTOM_DATABASE
            // The 'RegisterInterfaces' method is implemented as part of the "Changing the LEAD HTML5 Medical Viewer to use a different database schema" tutorial.
            // For the tutorial, 'RegisterInterfaces' is used to register custom classes that you define to interact with a custom database.
            // For the shipping version, the 'RegisterInterfaces' does nothing
            //
            // Since the WCF services are stateless (below), this method is called before using any of the services.
            // The AddinsFactory class is used to generate the addins required by each of the services.
            // So the AddinsFactory constructor calls 'RegisterInterfaces' if it has not already been called.
            //
            // WCF Services:
            // * AuthenticationService
            // * ObjectRetrieveService
            // * PacsQueryService
            // * PACSRetrieveService
            // * StoreService
            //
            // The MyPatientInfo, MyStudyInfo, MySeriesInfo, and MyInstanceInfo classes are used for extracting DICOM data from a System.Data.DataRow.
            // The MyStorageSqlDbDataAccessAgent and MyStorageDataAccessConfigurationView classes are used for accessing your custom database
            // The MyPatient, MyStudy, MySeries, and MyInstance classes are used to generate the WHERE statement of the database query
            // For more details, see the "Changing the LEAD HTML5 Medical Viewer to use a different database schema" tutorial.

            if (!DataAccessServiceLocator.IsRegistered <IPatientInfo>())
            {
                DataAccessServiceLocator.Register <IPatientInfo>(new MyPatientInfo());
            }

            if (!DataAccessServiceLocator.IsRegistered <IStudyInfo>())
            {
                DataAccessServiceLocator.Register <IStudyInfo>(new MyStudyInfo());
            }

            if (!DataAccessServiceLocator.IsRegistered <ISeriesInfo>())
            {
                DataAccessServiceLocator.Register <ISeriesInfo>(new MySeriesInfo());
            }

            if (!DataAccessServiceLocator.IsRegistered <IInstanceInfo>())
            {
                DataAccessServiceLocator.Register <IInstanceInfo>(new MyInstanceInfo());
            }

            if (!DataAccessServices.IsDataAccessServiceRegistered <IStorageDataAccessAgent3>())
            {
                System.Configuration.Configuration configuration     = ServiceUtils.GetGlobalPacsConfig();
                IStorageDataAccessAgent3           storageDataAccess = DataAccessFactory.GetInstance(new MyStorageDataAccessConfigurationView(configuration, ServiceUtils.ProductNameStorageServer, null)).CreateDataAccessAgent <IStorageDataAccessAgent3>();
                DataAccessServices.RegisterDataAccessService <IStorageDataAccessAgent3>(storageDataAccess);
            }

            RegisteredEntities.AddItem(RegisteredEntities.PatientEntityName, typeof(MyPatient));
            RegisteredEntities.AddItem(RegisteredEntities.StudyEntityName, typeof(MyStudy));
            RegisteredEntities.AddItem(RegisteredEntities.SeriesEntityName, typeof(MySeries));
            RegisteredEntities.AddItem(RegisteredEntities.InstanceEntityName, typeof(MyInstance));
#endif
        }
Exemplo n.º 4
0
        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();
                }
            }
        }
Exemplo n.º 5
0
        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());
                }
            }
        }
Exemplo n.º 6
0
        static void RegisterInterfaces()
        {
            DataAccessServiceLocator.Register <IPatientInfo>(new MyPatientInfo());
            DataAccessServiceLocator.Register <IStudyInfo>(new MyStudyInfo());
            DataAccessServiceLocator.Register <ISeriesInfo>(new MySeriesInfo());
            DataAccessServiceLocator.Register <IInstanceInfo>(new MyInstanceInfo());

            RegisteredEntities.Items.Add(RegisteredEntities.PatientEntityName, typeof(MyPatient));
            RegisteredEntities.Items.Add(RegisteredEntities.StudyEntityName, typeof(MyStudy));
            RegisteredEntities.Items.Add(RegisteredEntities.SeriesEntityName, typeof(MySeries));
            RegisteredEntities.Items.Add(RegisteredEntities.InstanceEntityName, typeof(MyInstance));
        }
Exemplo n.º 7
0
        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");
        }
Exemplo n.º 8
0
        public static void StopExternalStoreJobs()
        {
            if (JobManager != null)
            {
                string sDebug = string.Format("Module.StopExternalStoreJobs  -- JobManager.Stop");
                DicomUtilities.DebugString(DebugStringOptions.ShowCounter, sDebug);
                JobManager.Stop();
            }

            // No cloud storage
            Settings.RefreshSettings();
            Options = Settings.GetAddInCustomData <ExternalStoreOptions>(ExternalStorePresenter._Name, "ExternalStoreOptions", null);

            string s = string.Format("{0}: Module.StopExternalStoreJobs()", ExternalStorePresenter._Name);

            ExternalStorePresenter.MyDumpExternalStoreOptions(s, Options);
            if (Options.ExternalStoreIndex == -1)
            {
                DataAccessServiceLocator.Register <ICrud>(new DefaultCrud());
            }
        }
Exemplo n.º 9
0
        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);
                    }
                }
            }
        }
Exemplo n.º 10
0
        public void Run( )
        {
            try
            {
                StorageServerContainerView      containerPanel     = new StorageServerContainerView( );
                StorageServerContainerPresenter containerPresenter = new StorageServerContainerPresenter();

                RegisterDataAccessLayers( );

                _Form                       = new MainForm( );
                _Form.Text                  = Shell.storageServerName;
                containerPanel.Dock         = DockStyle.Fill;
                containerPanel.GradientMode = LinearGradientMode.Vertical;

                _Form.Controls.Add(containerPanel);

                using (ServiceAdministrator serverAdmin = new ServiceAdministrator(Application.StartupPath))
                {
                    DicomService service = null;


                    string serviceName = InitializeServiceAdmin(serverAdmin);

                    if (serverAdmin.Services.Count > 0)
                    {
                        service = serverAdmin.Services [serviceName];
                    }

                    CreateConfigurationServices(service);


#if TUTORIAL_CUSTOM_DATABASE
                    // To use a custom database schema, you must create and register your CatalogEntity classes (MyPatient, MyStudy, MySeries, MyInstance).
                    // Also, you must register your classes to extract DICOM data from a System.Data.DataRow (MyPatientInfo, MyStudyInfo, MySeriesInfo, MyInstanceInfo
                    // For more details, see the "Changing the LEAD Medical Storage Server to use a different database schema" tutorial.

                    DataAccessServiceLocator.Register <IPatientInfo>(new MyPatientInfo());
                    DataAccessServiceLocator.Register <IStudyInfo>(new MyStudyInfo());
                    DataAccessServiceLocator.Register <ISeriesInfo>(new MySeriesInfo());
                    DataAccessServiceLocator.Register <IInstanceInfo>(new MyInstanceInfo());

                    RegisteredEntities.Items.Add(RegisteredEntities.PatientEntityName, typeof(MyPatient));
                    RegisteredEntities.Items.Add(RegisteredEntities.StudyEntityName, typeof(MyStudy));
                    RegisteredEntities.Items.Add(RegisteredEntities.SeriesEntityName, typeof(MySeries));
                    RegisteredEntities.Items.Add(RegisteredEntities.InstanceEntityName, typeof(MyInstance));
#endif


                    ServerState.Instance.ServerService = service;
#if (LEADTOOLS_V19_OR_LATER_MEDICAL_VERIFY_ADDINS) || (LEADTOOLS_V19_OR_LATER)
                    if (ServerState.Instance.ServerService != null)
                    {
                        ServerState.Instance.ServerService.Message += new EventHandler <MessageEventArgs>(ServerService_Message);
                    }
#endif
                    ServerState.Instance.ServiceAdmin  = serverAdmin;
                    ServerState.Instance.BaseDirectory = Application.StartupPath;
                    ServerState.Instance.ServiceName   = serviceName;

                    ConfigureDataAccessLayers( );

                    LoadLoggingState(service);
                    InitializeLogger( );
#if LEADTOOLS_V18_OR_LATER
                    CheckLicenseFile();
#endif // #if LEADTOOLS_V18_OR_LATER

                    string csPathLogDump = ServerState.Instance.LoggingState.AutoSaveDirectory;

                    containerPresenter.PathLogDump = csPathLogDump;

                    containerPresenter.RunView(containerPanel);

                    SubscribeToEvents( );

                    new AuditLogSubscriber( ).Start( );

                    new CStoreAddIn().Start();

                    LogAudit(string.Format(AuditMessages.UserLogIn.Message, UserManager.User.FriendlyName));

                    Start(_Form);

                    if (UserManager.User != null)
                    {
                        LogAudit(string.Format(AuditMessages.UserLogOff.Message, UserManager.User.FriendlyName));
                    }
                    else
                    {
                        LogAudit("Canceled idle timer re-login");
                    }
                }
            }
            catch (Exception)
            {
                // Console.WriteLine ( ex.Message ) ;
                throw;
            }
        }