예제 #1
0
        //called once for the lifetime of the app domain
        protected void Application_Start()
        {
            AppDomainException = null;

            GlobalConfiguration.Configure(WebApiConfig.Register);

            //allow xml serialization
            //GlobalConfiguration.Configuration.Formatters.XmlFormatter.UseXmlSerializer = true;

            // ServicePointManager setup
            ServicePointManager.UseNagleAlgorithm      = false;
            ServicePointManager.Expect100Continue      = false;
            ServicePointManager.DefaultConnectionLimit = int.MaxValue;
            ServicePointManager.EnableDnsRoundRobin    = true;
            //ServicePointManager.ReusePort = true;

            try
            {
                //initialize
                SupportLock.SetLicense();
                DicomEngine.Startup();
                DicomNet.Startup();

                //Unity dependency injection container
                var unity = new UnityContainer();

                //register types

                //controllers that should be injectable
                unity.RegisterType <AuthController>();
                unity.RegisterType <AuditController>();
                unity.RegisterType <TemplateController>();
                unity.RegisterType <StoreController>();
                unity.RegisterType <PatientController>();
                unity.RegisterType <PatientAccessRightsController>();
                unity.RegisterType <PACSRetrieveController>();
                unity.RegisterType <PacsQueryController>();
                unity.RegisterType <OptionsController>();
                unity.RegisterType <MonitorCalibrationController>();
                unity.RegisterType <ExportController>();
                unity.RegisterType <RetrieveController>();
                unity.RegisterType <QueryController>();
                unity.RegisterType <ThreeDController>();
                unity.RegisterType <AutoController>();

                //injectable types
                unity.RegisterType <AddinsFactory>();

                //injectable types/base
                unity.RegisterType <IAuthHandler, AuthHandler>();
                unity.RegisterType <IAuditHandler, AuditHandler>();
                unity.RegisterType <ITemplateHandler, TemplateHandler>();
                unity.RegisterType <IStoreHandler, StoreHandler>();
                unity.RegisterType <IPatientHandler, PatientHandler>();
                unity.RegisterType <IPatientAccessRightsHandler, PatientAccessRightsHandler>();

                unity.RegisterType <IOptionsHandler, OptionsHandler>();
                unity.RegisterType <IMonitorCalibrationHandler, MonitorCalibrationHandler>();
                //unity.RegisterType<IStreamExportHandler, StreamExportHandler>();
                unity.RegisterType <IHashingProvider, HashingProvider>();
                unity.RegisterType <IExportHandler, ExportHandler>();

                unity.RegisterType <IRetrieveHandler, RetrieveHandler>("local");
                unity.RegisterType <IRetrieveHandler, WadoRetrieveHandler>("wado");

                unity.RegisterType <IQueryHandler, QueryHandler>("local");
                unity.RegisterType <IQueryHandler, WadoQueryHandler>("wado");
                unity.RegisterType <IThreeDHandler, ThreeDHandler>();

                unity.RegisterType <IPacsQueryHandler, PacsQueryHandler>("pacsquery");
                unity.RegisterType <IPacsQueryHandler, WadoAsPacsQueryHandler>("wadoaspacsquery");

                unity.RegisterType <IPacsRetrieveHandler, PacsRetrieveHandler>("pacsretrieve");
                unity.RegisterType <IPacsRetrieveHandler, WadoAsPacsRetrieveHandler>("wadoaspacsretrieve");

                unity.RegisterType <IAutoHandler, AutoHandler>();

                {
                    //register singletons
                    CreateSingletons();

                    unity.RegisterInstance <Lazy <IMessagesBus> >(_messageBus, new ExternallyControlledLifetimeManager());
                    unity.RegisterInstance <Lazy <IStorageDataAccessAgent3> >(_storageAgent, new ExternallyControlledLifetimeManager());
                    unity.RegisterInstance <Lazy <ILoggingDataAccessAgent> >(_loggingAgent, new ExternallyControlledLifetimeManager());
                    unity.RegisterInstance <Lazy <IUserManagementDataAccessAgent4> >(_userManagementDataAccessAgent, new ExternallyControlledLifetimeManager());
                    unity.RegisterInstance <Lazy <IPermissionManagementDataAccessAgent2> >(_permissionManagementDataAccessAgent, new ExternallyControlledLifetimeManager());
                    unity.RegisterInstance <Lazy <IOptionsDataAccessAgent> >(_optionsDataAccessAgent, new ExternallyControlledLifetimeManager());
                    unity.RegisterInstance <Lazy <IPatientRightsDataAccessAgent> >(_patientRightsDataAccess, new ExternallyControlledLifetimeManager());
                    unity.RegisterInstance <Lazy <IDownloadJobsDataAccessAgent> >(_downloadJobsDataAccessAgent, new ExternallyControlledLifetimeManager());
                    unity.RegisterInstance <Lazy <IAuthorizedStorageDataAccessAgent2> >(_authorizedStorageDataAccessAgent, new ExternallyControlledLifetimeManager());
                    unity.RegisterInstance <Lazy <IMonitorCalibrationDataAccessAgent> >(_monitorCalibrationDataAccessAgent, new ExternallyControlledLifetimeManager());
                    unity.RegisterInstance <Lazy <ITemplateDataAccessAgent> >(_templateDataAccessAgent, new ExternallyControlledLifetimeManager());
                    unity.RegisterInstance <Lazy <IExternalStoreDataAccessAgent> >(_externalStoreAgent, new ExternallyControlledLifetimeManager());
                    unity.RegisterInstance <Lazy <Leadtools.Dicom.Imaging.IDataCacheProvider> >(_dataCache, new ExternallyControlledLifetimeManager());
                    unity.RegisterInstance <Lazy <ConnectionSettings> >(_connectionSettings, new ExternallyControlledLifetimeManager());
                }

                //set default dependency resolver to Unity (with the wrapper)
                GlobalConfiguration.Configuration.DependencyResolver = new IoCContainer(unity);

                //caching workers
                LTCachingCtrl.QeueuWorkers();
            }
            catch (ServiceSetupException ex)
            {
                AppDomainException = ex;
                //handle on first request
            }
            catch (Exception)
            {
                HttpRuntime.UnloadAppDomain();
                throw;
            }
        }
예제 #2
0
        static void Startup()
        {
            try
            {
                SupportLock.Unlock();
                DicomEngine.Startup();
                DicomNet.Startup();

                //chance for any override
                ServiceUtils.RegisterInterfaces();

                LoadTimeStamp();
                //Debug.WriteLine("lt: " + (_timeStamp.HasValue? _timeStamp.ToString():"none"));
                //PACS client settings
                {
                    //the client AE/IP/port used for connecting to remote PACS for query
                    _clientConnection.AETitle = ConfigurationManager.AppSettings.Get("ClientAe");
                    if (string.IsNullOrEmpty(_clientConnection.AETitle))
                    {
                        _clientConnection.AETitle = "LTCLIENT19";
                    }
                    _clientConnection.IPAddress = ConfigurationManager.AppSettings.Get("ClientIP");
                    if (string.IsNullOrEmpty(_clientConnection.IPAddress))
                    {
                        _clientConnection.IPAddress = ServiceUtils.GetLocalIPAddressesV4();
                    }

                    _clientConnection.Port = ServiceUtils.ToInt(ConfigurationManager.AppSettings.Get("ClientPort"), ServiceUtils.GetFreeIPPort());
                }

                //Storage server settings
                {
                    //the path for the local storage server service, used by the store add-in to read the server configuration
                    _storageServerServicePath = ConfigurationManager.AppSettings.Get("storageServerServicePath");
                    _storageServerServicePath = ServiceUtils.MapConfigPath(_storageServerServicePath);

                    _storageServerConnection.AETitle   = ConfigurationManager.AppSettings.Get("ServerAe");
                    _storageServerConnection.IPAddress = ConfigurationManager.AppSettings.Get("ServerIP");
                    _storageServerConnection.Port      = ServiceUtils.ToInt(ConfigurationManager.AppSettings.Get("ServerPort"), -1);

                    //read default storage server dicom connection settings
                    if (!string.IsNullOrEmpty(_storageServerServicePath) &&
                        (string.IsNullOrEmpty(_storageServerConnection.AETitle) ||
                         string.IsNullOrEmpty(_storageServerConnection.IPAddress) ||
                         _storageServerConnection.Port <= 0))
                    {
                        try
                        {
                            var settingsFile = Path.Combine(_storageServerServicePath, "settings.xml");
                            var doc          = XDocument.Load(settingsFile);
                            {
                                _storageServerConnection.Port      = ServiceUtils.ToInt(doc.Descendants("Port").First().Value, -1);
                                _storageServerConnection.IPAddress = doc.Descendants("IpAddress").First().Value;
                                _storageServerConnection.AETitle   = doc.Descendants("AETitle").First().Value;
                            }
                        }
                        catch
                        {
                        }
                    }

                    if (string.IsNullOrEmpty(_storageServerConnection.AETitle))
                    {
                        _storageServerConnection.AETitle = "LTSTORAGESERVER";
                    }
                }

                //read static settings
                {
                    //the path for storing the annotations files (not used anymore)
                    _annotationsPath = ConfigurationManager.AppSettings.Get("AnnotationsPath");

                    if (string.IsNullOrEmpty(_annotationsPath))
                    {
                        _annotationsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Annotations");
                    }
                }

                //initialize external storage
                ExternalStorage.Startup();
            }
            catch (Exception ex)
            {
                ServiceUtils.Log(ex.ToString());
                throw new ServiceException("Failed to startup: " + ex.Message, HttpStatusCode.InternalServerError);
            }

            //caching workers
            LTCachingCtrl.QeueuWorkers();
        }