Example #1
0
        private void HandleDestinationAeTitleEvents(WatchEventType eventType, DestinationApplicationEntityCustomResource item)
        {
            lock (SyncRoot)
            {
                switch (eventType)
                {
                case WatchEventType.Added:
                    if (!_configurationValidator.IsDestinationValid(item.Spec))
                    {
                        _logger.Log(LogLevel.Error, $"The configured DICOM Destination is invalid: {item.Spec.Name} with AE Title {item.Spec.AeTitle}");
                        return;
                    }

                    _configuration.Value.Dicom.Scu.Destinations.Add(item.Spec);
                    _logger.Log(LogLevel.Information, $"Destination AE Title added: {item.Spec.AeTitle}");
                    break;

                case WatchEventType.Deleted:
                    var deleted = _configuration.Value.Dicom.Scu.Destinations.FirstOrDefault(
                        p => p.Name.Equals(item.Spec.Name, StringComparison.OrdinalIgnoreCase));
                    if (deleted != null)
                    {
                        _configuration.Value.Dicom.Scu.Destinations.Remove(deleted);
                    }

                    _logger.Log(LogLevel.Information, $"Destination AE Title deleted: {item.Spec.Name}");
                    break;

                default:
                    _logger.Log(LogLevel.Warning, $"Unsupported watch event type {eventType} detected for {item.Metadata.Name}");
                    break;
                }

                if (DestinationAeTitlesChanged != null)
                {
                    DestinationAeTitlesChanged(item.Spec, new AeTitleUpdatedEventArgs(eventType));
                }
            }
        }
Example #2
0
        private object CreateCrdFromType(T item)
        {
            if (item is ClaraApplicationEntity claraAe)
            {
                if (!_configurationValidator.IsClaraAeTitleValid(_dicomAdapterConfiguration.Value.Dicom.Scp.AeTitles, "dicom>scp>ae-title", claraAe, true))
                {
                    throw new Exception("Invalid Clara (local) AE Title specs provided or AE Title already exits");
                }

                claraAe.SetDefaultValues();

                return(new ClaraApplicationEntityCustomResource
                {
                    Kind = _customResourceDefinition.Kind,
                    ApiVersion = _customResourceDefinition.ApiVersion,
                    Metadata = new k8s.Models.V1ObjectMeta
                    {
                        Name = claraAe.Name.ToLowerInvariant()
                    },
                    Spec = claraAe,
                    Status = AeTitleStatus.Default
                });
            }
            else if (item is SourceApplicationEntity sourceAe)
            {
                if (!_dicomAdapterConfiguration.Value.ReadAeTitlesFromCrd)
                {
                    throw new CrdNotEnabledException("dicom>scp>read-sources-from-crd is disabled");
                }

                if (!_configurationValidator.IsSourceValid(sourceAe))
                {
                    throw new Exception("Invalid source AE Title specs provided");
                }

                return(new SourceApplicationEntityCustomResource
                {
                    Kind = _customResourceDefinition.Kind,
                    ApiVersion = _customResourceDefinition.ApiVersion,
                    Metadata = new k8s.Models.V1ObjectMeta
                    {
                        Name = sourceAe.AeTitle.ToLowerInvariant()
                    },
                    Spec = sourceAe,
                    Status = AeTitleStatus.Default
                });
            }
            else if (item is DestinationApplicationEntity destAe)
            {
                if (!_dicomAdapterConfiguration.Value.ReadAeTitlesFromCrd)
                {
                    throw new CrdNotEnabledException("dicom>scu>read-destinations-from-crd is disabled");
                }

                if (!_configurationValidator.IsDestinationValid(destAe))
                {
                    throw new Exception("Invalid destination specs provided");
                }

                return(new DestinationApplicationEntityCustomResource
                {
                    Kind = _customResourceDefinition.Kind,
                    ApiVersion = _customResourceDefinition.ApiVersion,
                    Metadata = new k8s.Models.V1ObjectMeta
                    {
                        Name = destAe.Name.ToLowerInvariant()
                    },
                    Spec = destAe,
                    Status = AeTitleStatus.Default
                });
            }
            throw new ApplicationException($"Unsupported data type: {item.GetType()}");
        }