protected EntityDA(IConfig config, ISqlStatementDA sqlStatementDA) : base(config) { if (!ServerCache.Exists(CacheKey.SqlStatement)) { ServerCache.Add(CacheKey.SqlStatement, () => GetSqlStatementCallback(sqlStatementDA)); } }
private bool DeviceIsBusy(Device device) { bool busy = false; if (device.ThrottleMaxConnections != UNLIMITED) { if (_tempBlackoutDevices.ContainsKey(device.Key)) { busy = true; } else { List <Model.WorkQueue> currentMoves; using (IReadContext context = PersistentStoreRegistry.GetDefaultStore().OpenReadContext()) { currentMoves = device.GetAllCurrentMoveEntries(context); } if (currentMoves != null && currentMoves.Count > device.ThrottleMaxConnections) { Platform.Log(LogLevel.Warn, "Connection limit on device {0} has been reached. Max = {1}.", device.AeTitle, device.ThrottleMaxConnections); // blackout for 5 seconds _tempBlackoutDevices.Add(device.Key, device); busy = true; } } } return(busy); }
public static void Configure() { ServerCache.Add(CacheKey.UserAccess, () => new UserDataCollection()); ServerCache.Add(CacheKey.BranchConfig, BranchConfigCallback); ServerCache.Add(CacheKey.Message, MessageCallback); ServerCache.Add(CacheKey.Branding, BrandingCallback); ServerCache.Add(CacheKey.SystemInformation, SystemInformationCallback); }
public void TestAdd_Get_Class_Success() { var tokenID = Guid.NewGuid(); ServerCache.Add(key, () => new UserDataCollection { new UserData { TokenID = tokenID } }); var result = ServerCache.Get <UserDataCollection>(key); Assert.AreEqual(1, result.Count); Assert.AreEqual(tokenID, result[0].TokenID); }
private bool DeviceIsBusy(Device device) { bool busy = false; if (device.ThrottleMaxConnections != UNLIMITED) { if (_tempBlackoutDevices.ContainsKey(device.Key)) { busy = true; } else { List <Model.WorkQueue> currentMoves; using (IReadContext context = PersistentStoreRegistry.GetDefaultStore().OpenReadContext()) { currentMoves = device.GetAllCurrentMoveEntries(context); } if (currentMoves != null && currentMoves.Count > device.ThrottleMaxConnections) { // sort the list to see where this entry is // and postpone it if its position is greater than the ThrottleMaxConnections currentMoves.Sort(delegate(Model.WorkQueue item1, Model.WorkQueue item2) { return(item1.ScheduledTime.CompareTo(item2.ScheduledTime)); }); int index = currentMoves.FindIndex(delegate(Model.WorkQueue item) { return(item.Key.Equals(WorkQueueItem.Key)); }); if (index >= device.ThrottleMaxConnections) { Platform.Log(LogLevel.Warn, "Connection limit on device {0} has been reached. Max = {1}.", device.AeTitle, device.ThrottleMaxConnections); // blackout for 5 seconds _tempBlackoutDevices.Add(device.Key, device); busy = true; } } } } return(busy); }
/// <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); }
private AutoReconcilerResult MergeImage(StudyReconcileAction action, DicomFile file, StudyHistory lastHistory) { string originalSeriesUid = file.DataSet[DicomTags.SeriesInstanceUid].ToString(); string originalSopUid = file.DataSet[DicomTags.SopInstanceUid].ToString(); AutoReconcilerResult preProcessingResult = null; StudyStorageLocation destStudy; UidMapper uidMapper = null; if (lastHistory.DestStudyStorageKey != null) { StudyStorage destinationStudy = StudyStorage.Load(lastHistory.DestStudyStorageKey); //Load the destination. An exception will be thrown if any issues are encountered. FilesystemMonitor.Instance.GetWritableStudyStorageLocation(destinationStudy.ServerPartitionKey, destinationStudy.StudyInstanceUid, StudyRestore.True, StudyCache.True, out destStudy); EnsureStudyCanBeUpdated(destStudy); bool belongsToAnotherStudy = !destStudy.Equals(StorageLocation); ImageUpdateCommandBuilder commandBuilder = new ImageUpdateCommandBuilder(); IList <BaseImageLevelUpdateCommand> commands = commandBuilder.BuildCommands <StudyMatchingMap>(destStudy); if (belongsToAnotherStudy) { Platform.Log(LogLevel.Info, "AUTO-RECONCILE: Move SOP {0} to Study {1}, A#: {2}, Patient {3}", originalSopUid, destStudy.StudyInstanceUid, destStudy.Study.AccessionNumber, destStudy.Study.PatientsName); // Load the Uid Map, either from cache or from disk if (!_uidMapCache.TryGetValue(destStudy.Key, out uidMapper)) { UidMapXml mapXml = new UidMapXml(); mapXml.Load(destStudy); uidMapper = new UidMapper(mapXml); _uidMapCache.Add(destStudy.Key, uidMapper); } try { commands.Add(GetUidMappingCommand(StorageLocation, destStudy, uidMapper, originalSopUid, originalSeriesUid)); } catch (InstanceAlreadyExistsException ex) { Platform.Log(LogLevel.Info, "An instance already exists with the SOP Instance Uid {0}", ex.SopInstanceUid); preProcessingResult = new AutoReconcilerResult(StudyReconcileAction.Discard) { DiscardImage = true }; return(preProcessingResult); } } preProcessingResult = new AutoReconcilerResult(action) { Changes = GetUpdateList(file, commands) }; UpdateImage(file, commands); // First, must update the map if (uidMapper != null && uidMapper.Dirty) { UpdateUidMap(destStudy, uidMapper); } if (belongsToAnotherStudy) { SopInstanceImporterContext importContext = new SopInstanceImporterContext(_contextID, file.SourceApplicationEntityTitle, destStudy.ServerPartition); SopInstanceImporter importer = new SopInstanceImporter(importContext); DicomProcessingResult result = importer.Import(file); if (!result.Successful) { throw new ApplicationException(result.ErrorMessage); } } } return(preProcessingResult); }
public void TestAdd_Get_SimpleType_Success() { ServerCache.Add(key, () => "result"); Assert.AreEqual("result", ServerCache.Get <string>(key)); }