private static Device FindServer(string retrieveAeTitle)
        {
            var webUser = Thread.CurrentPrincipal as CustomPrincipal;

            if (webUser != null)
            {
                foreach (var partition in ServerPartitionMonitor.Instance)
                {
                    if (partition.AeTitle.Equals(retrieveAeTitle, StringComparison.InvariantCulture))
                    {
                        if (!partition.IsUserAccessAllowed(webUser))
                        {
                            throw new PermissionDeniedException(string.Format("User does not have permission to access partition {0}", partition.AeTitle));
                        }
                    }
                }
            }

            using (IReadContext ctx = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
            {
                var broker   = ctx.GetBroker <IDeviceEntityBroker>();
                var criteria = new DeviceSelectCriteria();
                criteria.AeTitle.EqualTo(retrieveAeTitle);
                IList <Device> list = broker.Find(criteria);
                foreach (Device theDevice in list)
                {
                    if (string.Compare(theDevice.AeTitle, retrieveAeTitle, false, CultureInfo.InvariantCulture) == 0)
                    {
                        return(theDevice);
                    }
                }
            }

            return(null);
        }
Beispiel #2
0
        protected override bool OnServerSideEvaluate()
        {
            String deviceAE = GetControlValidationValue(ControlToValidate);

            if (String.IsNullOrEmpty(deviceAE))
            {
                ErrorMessage = ValidationErrors.AETitleCannotBeEmpty;
                return(false);
            }

            if (OriginalAeTitle.Equals(deviceAE))
            {
                return(true);
            }

            var controller = new DeviceConfigurationController();
            var criteria   = new DeviceSelectCriteria();

            criteria.AeTitle.EqualTo(deviceAE);
            criteria.ServerPartitionKey.EqualTo(Partition);

            IList <Device> list = controller.GetDevices(criteria);

            foreach (var d in list)
            {
                if (string.Compare(d.AeTitle, deviceAE, false, CultureInfo.InvariantCulture) == 0)
                {
                    ErrorMessage = String.Format(ValidationErrors.AETitleIsInUse, deviceAE);
                    return(false);
                }
            }

            return(true);
        }
        /// <summary>
        /// Do the insertion of the AutoRoute.
        /// </summary>
        protected override void OnExecute(CommandProcessor theProcessor, IUpdateContext updateContext)
        {
            DeviceSelectCriteria deviceSelectCriteria = new DeviceSelectCriteria();

            deviceSelectCriteria.AeTitle.EqualTo(_deviceAe);
            deviceSelectCriteria.ServerPartitionKey.EqualTo(_context.ServerPartitionKey);

            IDeviceEntityBroker selectDevice = updateContext.GetBroker <IDeviceEntityBroker>();

            Device dev = selectDevice.FindOne(deviceSelectCriteria);

            if (dev == null)
            {
                Platform.Log(LogLevel.Warn,
                             "Device '{0}' on partition {1} not in database for autoroute request!  Ignoring request.", _deviceAe,
                             _context.ServerPartition.AeTitle);

                ServerPlatform.Alert(
                    AlertCategory.Application, AlertLevel.Warning,
                    SR.AlertComponentAutorouteRule, AlertTypeCodes.UnableToProcess, null, TimeSpan.FromMinutes(5),
                    SR.AlertAutoRouteUnknownDestination, _deviceAe, _context.ServerPartition.AeTitle);

                return;
            }
            if (!dev.AllowAutoRoute)
            {
                Platform.Log(LogLevel.Warn,
                             "Auto-route attempted to device {0} on partition {1} with autoroute support disabled.  Ignoring request.",
                             dev.AeTitle, _context.ServerPartition.AeTitle);

                ServerPlatform.Alert(AlertCategory.Application, AlertLevel.Warning, SR.AlertComponentAutorouteRule, AlertTypeCodes.UnableToProcess, null, TimeSpan.FromMinutes(5),
                                     SR.AlertAutoRouteDestinationAEDisabled, dev.AeTitle, _context.ServerPartition.AeTitle);

                return;
            }

            InsertWorkQueueParameters parms = new InsertWorkQueueParameters
            {
                WorkQueueTypeEnum = WorkQueueTypeEnum.AutoRoute,
                ScheduledTime     = _scheduledTime.HasValue
                                                                                                ? _scheduledTime.Value
                                                                                                : Platform.Time.AddSeconds(10),
                StudyStorageKey    = _context.StudyLocationKey,
                ServerPartitionKey = _context.ServerPartitionKey,
                DeviceKey          = dev.GetKey(),
                SeriesInstanceUid  =
                    _context.Message.DataSet[DicomTags.SeriesInstanceUid].GetString(0, string.Empty),
                SopInstanceUid =
                    _context.Message.DataSet[DicomTags.SopInstanceUid].GetString(0, string.Empty)
            };
            IInsertWorkQueue broker = updateContext.GetBroker <IInsertWorkQueue>();

            if (broker.FindOne(parms) == null)
            {
                throw new ApplicationException("InsertAutoRouteCommand failed");
            }
        }
Beispiel #4
0
        /// <summary>
        /// Load the devices for the partition based on the filters specified in the filter panel.
        /// </summary>
        /// <remarks>
        /// This method only reloads and binds the list bind to the internal grid. <seealso cref="Refresh"/> should be called
        /// to explicit update the list in the grid.
        /// <para>
        /// This is intentionally so that the list can be reloaded so that it is available to other controls during postback.  In
        /// some cases we may not want to refresh the list if there's no change. Calling <seealso cref="Refresh"/> will
        /// give performance hit as the data will be transfered back to the browser.
        ///
        /// </para>
        /// </remarks>
        public void LoadDevices()
        {
            if (ServerPartition == null)
            {
                return;
            }

            var criteria = new DeviceSelectCriteria();

            // only query for device in this partition
            criteria.ServerPartitionKey.EqualTo(ServerPartition.GetKey());

            if (!String.IsNullOrEmpty(AETitleFilter.TrimText))
            {
                QueryHelper.SetGuiStringCondition(criteria.AeTitle,
                                                  SearchHelper.LeadingAndTrailingWildCard(AETitleFilter.TrimText));
            }

            if (!String.IsNullOrEmpty(DescriptionFilter.TrimText))
            {
                QueryHelper.SetGuiStringCondition(criteria.Description,
                                                  SearchHelper.LeadingAndTrailingWildCard(DescriptionFilter.TrimText));
            }

            if (!String.IsNullOrEmpty(IPAddressFilter.TrimText))
            {
                QueryHelper.SetGuiStringCondition(criteria.IpAddress,
                                                  SearchHelper.TrailingWildCard(IPAddressFilter.TrimText));
            }

            if (StatusFilter.SelectedIndex != 0)
            {
                criteria.Enabled.EqualTo(StatusFilter.SelectedIndex == 1);
            }

            if (DHCPFilter.SelectedIndex != 0)
            {
                criteria.Dhcp.EqualTo(DHCPFilter.SelectedIndex == 1);
            }

            if (DeviceTypeFilter.SelectedIndex > -1)
            {
                var types = new List <DeviceTypeEnum>();
                foreach (ListItem item in DeviceTypeFilter.Items)
                {
                    if (item.Selected)
                    {
                        types.Add(DeviceTypeEnum.GetEnum(item.Value));
                    }
                }
                criteria.DeviceTypeEnum.In(types);
            }

            DeviceGridViewControl1.Devices = _theController.GetDevices(criteria);
            DeviceGridViewControl1.RefreshCurrentPage();
        }
Beispiel #5
0
        public ImageServerData()
        {
            using (IReadContext context = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
            {
                TotalStudiesCount = 0;

                IServerPartitionEntityBroker partitionBroker = context.GetBroker <IServerPartitionEntityBroker>();
                var partitions = partitionBroker.Find(new ServerPartitionSelectCriteria());
                foreach (ServerPartition partition in partitions)
                {
                    TotalStudiesCount += partition.StudyCount;
                }

                IDeviceEntityBroker  deviceBroker = context.GetBroker <IDeviceEntityBroker>();
                DeviceSelectCriteria criteria     = new DeviceSelectCriteria();
                criteria.Enabled.EqualTo(true);
                ActiveDeviceCount += deviceBroker.Count(criteria);
            }
        }
        private static Device FindServer(string retrieveAeTitle)
        {
            using (IReadContext ctx = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
            {
                var broker   = ctx.GetBroker <IDeviceEntityBroker>();
                var criteria = new DeviceSelectCriteria();
                criteria.AeTitle.EqualTo(retrieveAeTitle);
                IList <Device> list = broker.Find(criteria);
                foreach (Device theDevice in list)
                {
                    if (string.Compare(theDevice.AeTitle, retrieveAeTitle, false, CultureInfo.InvariantCulture) == 0)
                    {
                        return(theDevice);
                    }
                }
            }

            return(null);
        }
Beispiel #7
0
        /// <summary>
        /// Load <see cref="Device"/> information for a Move destination.
        /// </summary>
        /// <param name="read"></param>
        /// <param name="partition"></param>
        /// <param name="remoteAe"></param>
        /// <returns></returns>
        private static Device LoadRemoteHost(IPersistenceContext read, ServerPartition partition, string remoteAe)
        {
            var select = read.GetBroker <IDeviceEntityBroker>();

            // Setup the select parameters.
            var selectParms = new DeviceSelectCriteria();

            selectParms.AeTitle.EqualTo(remoteAe);
            selectParms.ServerPartitionKey.EqualTo(partition.GetKey());
            var devices = select.Find(selectParms);

            foreach (var d in devices)
            {
                if (string.Compare(d.AeTitle, remoteAe, false, CultureInfo.InvariantCulture) == 0)
                {
                    return(d);
                }
            }
            return(null);
        }
Beispiel #8
0
        /// <summary>
        /// Load the devices for the partition based on the filters specified in the filter panel.
        /// </summary>
        /// <remarks>
        /// This method only reloads and binds the list bind to the internal grid. <seealso cref="UpdateUI()"/> should be called
        /// to explicit update the list in the grid.
        /// <para>
        /// This is intentionally so that the list can be reloaded so that it is available to other controls during postback.  In
        /// some cases we may not want to refresh the list if there's no change. Calling <seealso cref="UpdateUI()"/> will
        /// give performance hit as the data will be transfered back to the browser.
        ///
        /// </para>
        /// </remarks>
        public void LoadDevices()
        {
            DeviceSelectCriteria criteria = new DeviceSelectCriteria();

            // only query for device in this partition
            criteria.ServerPartitionKey.EqualTo(Partition.GetKey());

            if (!String.IsNullOrEmpty(AETitleFilter.TrimText))
            {
                string key = AETitleFilter.TrimText + "%";
                key = key.Replace("*", "%");
                key = key.Replace("?", "_");
                criteria.AeTitle.Like(key);
            }

            if (!String.IsNullOrEmpty(DescriptionFilter.TrimText))
            {
                string key = DescriptionFilter.TrimText + "%";
                key = key.Replace("*", "%");
                key = key.Replace("?", "_");
                criteria.Description.Like(key);
            }

            if (!String.IsNullOrEmpty(IPAddressFilter.TrimText))
            {
                string key = IPAddressFilter.TrimText + "%";
                key = key.Replace("*", "%");
                key = key.Replace("?", "_");
                criteria.IpAddress.Like(key);
            }

            if (DHCPFilter.SelectedIndex != 0)
            {
                if (DHCPFilter.SelectedIndex == 1)
                {
                    criteria.Dhcp.EqualTo(true);
                }
                else
                {
                    criteria.Dhcp.EqualTo(false);
                }
            }

            if (DeviceTypeFilter.SelectedIndex > -1)
            {
                List <DeviceTypeEnum> types = new List <DeviceTypeEnum>();
                foreach (ListItem item in DeviceTypeFilter.Items)
                {
                    if (item.Selected)
                    {
                        types.Add(DeviceTypeEnum.GetEnum(item.Value));
                    }
                }
                criteria.DeviceTypeEnum.In(types);
            }

            // only enabled devices and devices that allow retrieves.
            criteria.Enabled.EqualTo(true);
            criteria.AllowRetrieve.EqualTo(true);

            DeviceGridPanel.Devices = _theController.GetDevices(criteria);
            DeviceGridPanel.RefreshCurrentPage();
        }
Beispiel #9
0
        /// <summary>
        /// Lookup the device entity in the database corresponding to the remote AE of the association.
        /// </summary>
        /// <param name="partition">The partition to look up the devices</param>
        /// <param name="association">The association</param>
        /// <param name="isNew">Indicates whether the device returned is created by the call.</param>
        /// <returns>The device record corresponding to the called AE of the association</returns>
        public static Device LookupDevice(ServerPartition partition, AssociationParameters association, out bool isNew)
        {
            isNew = false;

            Device device;

            if (DeviceCache.TryGetValue(association.CallingAE + partition.Key, out device))
            {
                return(device);
            }

            using (
                IUpdateContext updateContext =
                    PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
            {
                var deviceEntityBroker = updateContext.GetBroker <IDeviceEntityBroker>();

                // Setup the select parameters.
                var queryParameters = new DeviceSelectCriteria();
                queryParameters.AeTitle.EqualTo(association.CallingAE);
                queryParameters.ServerPartitionKey.EqualTo(partition.GetKey());
                var devices = deviceEntityBroker.Find(queryParameters);
                foreach (var d in devices)
                {
                    if (string.Compare(d.AeTitle, association.CallingAE, false, CultureInfo.InvariantCulture) == 0)
                    {
                        device = d;
                        break;
                    }
                }

                if (device == null)
                {
                    if (!partition.AcceptAnyDevice)
                    {
                        return(null);
                    }

                    if (partition.AutoInsertDevice)
                    {
                        // Auto-insert a new entry in the table.
                        var updateColumns = new DeviceUpdateColumns
                        {
                            AeTitle                = association.CallingAE,
                            Enabled                = true,
                            Description            = String.Format("AE: {0}", association.CallingAE),
                            Dhcp                   = false,
                            IpAddress              = association.RemoteEndPoint.Address.ToString(),
                            ServerPartitionKey     = partition.GetKey(),
                            Port                   = partition.DefaultRemotePort,
                            AllowQuery             = true,
                            AllowRetrieve          = true,
                            AllowStorage           = true,
                            ThrottleMaxConnections = ImageServerCommonConfiguration.Device.MaxConnections,
                            DeviceTypeEnum         = DeviceTypeEnum.Workstation
                        };

                        var insert = updateContext.GetBroker <IDeviceEntityBroker>();

                        device = insert.Insert(updateColumns);

                        updateContext.Commit();

                        isNew = true;
                    }
                }

                if (device != null)
                {
                    // For DHCP devices, we always update the remote ip address, if its changed from what is in the DB.
                    if (device.Dhcp && !association.RemoteEndPoint.Address.ToString().Equals(device.IpAddress))
                    {
                        var updateColumns = new DeviceUpdateColumns
                        {
                            IpAddress        = association.RemoteEndPoint.Address.ToString(),
                            LastAccessedTime = Platform.Time
                        };

                        if (!deviceEntityBroker.Update(device.GetKey(), updateColumns))
                        {
                            Platform.Log(LogLevel.Error,
                                         "Unable to update IP Address for DHCP device {0} on partition '{1}'",
                                         device.AeTitle, partition.Description);
                        }
                        else
                        {
                            updateContext.Commit();
                        }
                    }
                    else if (!isNew)
                    {
                        var updateColumns = new DeviceUpdateColumns {
                            LastAccessedTime = Platform.Time
                        };

                        if (!deviceEntityBroker.Update(device.GetKey(), updateColumns))
                        {
                            Platform.Log(LogLevel.Error,
                                         "Unable to update LastAccessedTime device {0} on partition '{1}'",
                                         device.AeTitle, partition.Description);
                        }
                        else
                        {
                            updateContext.Commit();
                        }
                    }

                    DeviceCache.Add(device.AeTitle + partition.Key, device);
                }
            }

            return(device);
        }
Beispiel #10
0
        /// <summary>
        /// Do the insertion of the AutoRoute.
        /// </summary>
        protected override void OnExecute(CommandProcessor theProcessor, IUpdateContext updateContext)
        {
            var deviceSelectCriteria = new DeviceSelectCriteria();

            deviceSelectCriteria.AeTitle.EqualTo(_deviceAe);
            deviceSelectCriteria.ServerPartitionKey.EqualTo(_context.ServerPartitionKey);

            var selectDevice = updateContext.GetBroker <IDeviceEntityBroker>();

            var dev = selectDevice.FindOne(deviceSelectCriteria);

            if (dev == null)
            {
                Platform.Log(LogLevel.Warn,
                             "Device '{0}' on partition {1} not in database for autoroute request!  Ignoring request.", _deviceAe,
                             _context.ServerPartition.AeTitle);

                ServerPlatform.Alert(
                    AlertCategory.Application, AlertLevel.Warning,
                    SR.AlertComponentAutorouteRule, AlertTypeCodes.UnableToProcess, null, TimeSpan.FromMinutes(5),
                    SR.AlertAutoRouteUnknownDestination, _deviceAe, _context.ServerPartition.AeTitle);

                return;
            }

            if (!dev.AllowAutoRoute)
            {
                Platform.Log(LogLevel.Warn,
                             "Study Auto-route attempted to device {0} on partition {1} with autoroute support disabled.  Ignoring request.",
                             dev.AeTitle, _context.ServerPartition.AeTitle);

                ServerPlatform.Alert(AlertCategory.Application, AlertLevel.Warning, SR.AlertComponentAutorouteRule,
                                     AlertTypeCodes.UnableToProcess, null, TimeSpan.FromMinutes(5),
                                     SR.AlertAutoRouteDestinationAEDisabled, dev.AeTitle, _context.ServerPartition.AeTitle);

                return;
            }

            if (_qcStatus != null)
            {
                var studyBroker = updateContext.GetBroker <IStudyEntityBroker>();
                var studySelect = new StudySelectCriteria();
                studySelect.StudyStorageKey.EqualTo(_context.StudyLocationKey);
                studySelect.ServerPartitionKey.EqualTo(_context.ServerPartitionKey);
                var study = studyBroker.FindOne(studySelect);
                if (!study.QCStatusEnum.Equals(_qcStatus))
                {
                    Platform.Log(LogLevel.Debug,
                                 "Ignoring Auto-route where the QCStatusEnum status must be {0}, but database has {1} for study {2}",
                                 _qcStatus.Description, study.QCStatusEnum.Description, study.StudyInstanceUid);
                    return;
                }
            }

            var parms = new InsertWorkQueueParameters
            {
                WorkQueueTypeEnum = WorkQueueTypeEnum.StudyAutoRoute,
                ScheduledTime     = _scheduledTime.HasValue
                                                                        ? _scheduledTime.Value
                                                                        : Platform.Time.AddSeconds(30),
                StudyStorageKey    = _context.StudyLocationKey,
                ServerPartitionKey = _context.ServerPartitionKey,
                DeviceKey          = dev.GetKey()
            };
            var broker = updateContext.GetBroker <IInsertWorkQueue>();

            if (broker.FindOne(parms) == null)
            {
                throw new ApplicationException("InsertWorkQueue for Study Auto-Route failed");
            }
        }
Beispiel #11
0
 /// <summary>
 /// Retrieve list of devices.
 /// </summary>
 /// <param name="criteria"/>
 /// <returns>List of <see cref="Device"/> matches <paramref name="criteria"/></returns>
 public IList <Device> GetDevices(DeviceSelectCriteria criteria)
 {
     return(_adapter.GetDevices(criteria));
 }
        public override PriorStudyFinderResult FindPriorStudies()
        {
            _cancel = false;

            var priorsServerQueries = new List <IStudyRootQuery>();

            foreach (ServerPartition partition in ServerPartitionMonitor.Instance)
            {
                using (IReadContext ctx = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
                {
                    IDeviceEntityBroker  broker   = ctx.GetBroker <IDeviceEntityBroker>();
                    DeviceSelectCriteria criteria = new DeviceSelectCriteria();
                    criteria.DeviceTypeEnum.EqualTo(DeviceTypeEnum.PriorsServer);
                    criteria.ServerPartitionKey.EqualTo(partition.Key);
                    IList <Device> list = broker.Find(criteria);
                    foreach (Device theDevice in list)
                    {
                        // Check the settings and log for debug purposes
                        if (!theDevice.Enabled)
                        {
                            Platform.Log(LogLevel.Debug, "Prior Server '{0}' on partition '{1}' is disabled in the device setting",
                                         theDevice.AeTitle, partition.AeTitle);
                            continue;
                        }

                        DicomStudyRootQuery remoteQuery = new DicomStudyRootQuery(partition.AeTitle, theDevice.AeTitle,
                                                                                  theDevice.IpAddress, theDevice.Port);
                        priorsServerQueries.Add(remoteQuery);
                    }
                }
            }

            // Log the prior servers for debug purpose
            if (Platform.IsLogLevelEnabled(LogLevel.Debug) && priorsServerQueries.Count > 0)
            {
                StringBuilder log = new StringBuilder();
                log.Append("Searching for priors on the following servers:");

                StringBuilder serverList = new StringBuilder();
                foreach (DicomStudyRootQuery server in priorsServerQueries)
                {
                    if (serverList.Length > 0)
                    {
                        serverList.Append(",");
                    }
                    serverList.AppendFormat("{0}", server);
                }

                log.Append(serverList.ToString());
                Platform.Log(LogLevel.Debug, log.ToString());
            }

            StudyItemList results = new StudyItemList();

            DefaultPatientReconciliationStrategy reconciliationStrategy = new DefaultPatientReconciliationStrategy();
            List <string> patientIds = new List <string>();

            foreach (Patient patient in Viewer.StudyTree.Patients)
            {
                if (_cancel)
                {
                    break;
                }

                IPatientData reconciled = reconciliationStrategy.ReconcileSearchCriteria(patient);
                if (!patientIds.Contains(reconciled.PatientId))
                {
                    patientIds.Add(reconciled.PatientId);
                }
            }

            //Note: we don't catch the exception for this one because it's just querying the other
            //partitions, so if it fails we want an outright failure to occur.  Besides, it should never happen
            //if the server is functioning correctly.
            using (StudyRootQueryBridge bridge = new StudyRootQueryBridge(Platform.GetService <IStudyRootQuery>()))
            {
                foreach (string patientId in patientIds)
                {
                    StudyRootStudyIdentifier identifier = new StudyRootStudyIdentifier {
                        PatientId = patientId
                    };

                    IList <StudyRootStudyIdentifier> studies = bridge.StudyQuery(identifier);
                    foreach (StudyRootStudyIdentifier study in studies)
                    {
                        if (_cancel)
                        {
                            break;
                        }

                        StudyItem studyItem = ConvertToStudyItem(study);
                        if (studyItem != null)
                        {
                            results.Add(studyItem);
                        }
                    }
                }
            }

            bool complete = true;

            foreach (IStudyRootQuery query in priorsServerQueries)
            {
                foreach (string patientId in patientIds)
                {
                    try
                    {
                        var identifier = new StudyRootStudyIdentifier
                        {
                            PatientId = patientId
                        };

                        IList <StudyRootStudyIdentifier> list = query.StudyQuery(identifier);
                        foreach (StudyRootStudyIdentifier i in list)
                        {
                            if (_cancel)
                            {
                                break;
                            }

                            StudyItem studyItem = ConvertToStudyItem(i);
                            if (studyItem != null)
                            {
                                results.Add(studyItem);
                            }
                        }
                    }
                    catch (FaultException <DataValidationFault> ex)
                    {
                        complete = false;
                        Platform.Log(LogLevel.Error, ex, "An error has occurred when searching for prior studies on server '{0}'", query.ToString());
                    }
                    catch (FaultException <QueryFailedFault> ex)
                    {
                        complete = false;
                        Platform.Log(LogLevel.Error, ex, "An error has occurred when searching for prior studies on server '{0}'", query.ToString());
                    }
                }
            }

            return(new PriorStudyFinderResult(results, complete));
        }