-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Neil South <neil.south@answerdigital.com>
- Loading branch information
1 parent
c59cbf7
commit 91cfa12
Showing
17 changed files
with
243 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/InformaticsGateway/Services/Common/ScpInputTypeEnum.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2023 MONAI Consortium | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Monai.Deploy.InformaticsGateway.Services.Common | ||
{ | ||
public enum ScpInputTypeEnum | ||
{ | ||
WorkflowTrigger, | ||
ExternalAppReturn | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
src/InformaticsGateway/Services/Scp/ExternalAppScpService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright 2021-2023 MONAI Consortium | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
using Ardalis.GuardClauses; | ||
using FellowOakDicom.Network; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
using Monai.Deploy.InformaticsGateway.Api.Rest; | ||
using Monai.Deploy.InformaticsGateway.Configuration; | ||
using Monai.Deploy.InformaticsGateway.Logging; | ||
|
||
|
||
namespace Monai.Deploy.InformaticsGateway.Services.Scp | ||
{ | ||
internal class ExternalAppScpService : ScpServiceBase | ||
{ | ||
private readonly IServiceScope _serviceScope; | ||
private readonly ILogger<ExternalAppScpService> _logger; | ||
private readonly ILogger<ExternalAppScpServiceInternal> _scpServiceInternalLogger; | ||
private readonly IOptions<InformaticsGatewayConfiguration> _configuration; | ||
private readonly IApplicationEntityManager _associationDataProvider; | ||
|
||
public override string ServiceName => "External App DICOM SCP Service"; | ||
|
||
public ExternalAppScpService(IServiceScopeFactory serviceScopeFactory, | ||
IApplicationEntityManager applicationEntityManager, | ||
IHostApplicationLifetime appLifetime, | ||
IOptions<InformaticsGatewayConfiguration> configuration) : base(serviceScopeFactory, applicationEntityManager, appLifetime, configuration) | ||
{ | ||
Guard.Against.Null(serviceScopeFactory, nameof(serviceScopeFactory)); | ||
Guard.Against.Null(applicationEntityManager, nameof(applicationEntityManager)); | ||
Guard.Against.Null(appLifetime, nameof(appLifetime)); | ||
Guard.Against.Null(configuration, nameof(configuration)); | ||
|
||
_associationDataProvider = applicationEntityManager; | ||
|
||
_serviceScope = serviceScopeFactory.CreateScope(); | ||
var logginFactory = _serviceScope.ServiceProvider.GetService<ILoggerFactory>(); | ||
|
||
_logger = logginFactory!.CreateLogger<ExternalAppScpService>(); | ||
_scpServiceInternalLogger = logginFactory!.CreateLogger<ExternalAppScpServiceInternal>(); | ||
_configuration = configuration; | ||
} | ||
|
||
public override void ServiceStart() | ||
{ | ||
var ScpPort = _configuration.Value.Dicom.Scp.ExternalAppPort; | ||
try | ||
{ | ||
_logger.ServiceStarting(ServiceName); | ||
Server = DicomServerFactory.Create<ExternalAppScpServiceInternal>( | ||
NetworkManager.IPv4Any, | ||
ScpPort, | ||
logger: _scpServiceInternalLogger, | ||
userState: _associationDataProvider); | ||
|
||
Server.Options.IgnoreUnsupportedTransferSyntaxChange = true; | ||
Server.Options.LogDimseDatasets = _configuration.Value.Dicom.Scp.LogDimseDatasets; | ||
Server.Options.MaxClientsAllowed = _configuration.Value.Dicom.Scp.MaximumNumberOfAssociations; | ||
|
||
if (Server.Exception != null) | ||
{ | ||
_logger.ScpListenerInitializationFailure(); | ||
throw Server.Exception; | ||
} | ||
|
||
Status = ServiceStatus.Running; | ||
_logger.ScpListeningOnPort(ServiceName, ScpPort); | ||
} | ||
catch (System.Exception ex) | ||
{ | ||
Status = ServiceStatus.Cancelled; | ||
_logger.ServiceFailedToStart(ServiceName, ex); | ||
AppLifetime.StopApplication(); | ||
} | ||
|
||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/InformaticsGateway/Services/Scp/ExternalAppScpServiceInternal.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright 2021-2023 MONAI Consortium | ||
* Copyright 2019-2021 NVIDIA Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
using System; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using FellowOakDicom.Network; | ||
using Microsoft.Extensions.Logging; | ||
using Monai.Deploy.InformaticsGateway.Api.Models; | ||
using Monai.Deploy.InformaticsGateway.Common; | ||
using Monai.Deploy.InformaticsGateway.Logging; | ||
|
||
|
||
namespace Monai.Deploy.InformaticsGateway.Services.Scp | ||
{ | ||
internal class ExternalAppScpServiceInternal : ScpServiceInternalBase | ||
{ | ||
|
||
private readonly DicomAssociationInfo _associationInfo; | ||
private readonly ILogger _logger; | ||
|
||
public ExternalAppScpServiceInternal(INetworkStream stream, Encoding fallbackEncoding, ILogger logger, DicomServiceDependencies dicomServiceDependencies) | ||
: base(stream, fallbackEncoding, logger, dicomServiceDependencies) | ||
{ | ||
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||
_associationInfo = new DicomAssociationInfo(); | ||
} | ||
public override async Task<DicomCStoreResponse> OnCStoreRequestAsync(DicomCStoreRequest request) | ||
{ | ||
try | ||
{ | ||
_logger?.TransferSyntaxUsed(request.TransferSyntax); | ||
var payloadId = await AssociationDataProvider!.HandleCStoreRequest(request, Association.CalledAE, Association.CallingAE, AssociationId, Common.ScpInputTypeEnum.ExternalAppReturn).ConfigureAwait(false); | ||
_associationInfo.FileReceived(payloadId); | ||
return new DicomCStoreResponse(request, DicomStatus.Success); | ||
} | ||
catch (InsufficientStorageAvailableException ex) | ||
{ | ||
_logger?.CStoreFailedDueToLowStorageSpace(ex); | ||
_associationInfo.Errors = $"Failed to store file due to low disk space: {ex}"; | ||
return new DicomCStoreResponse(request, DicomStatus.ResourceLimitation); | ||
} | ||
catch (System.IO.IOException ex) when ((ex.HResult & 0xFFFF) == Constants.ERROR_HANDLE_DISK_FULL || (ex.HResult & 0xFFFF) == Constants.ERROR_DISK_FULL) | ||
{ | ||
_logger?.CStoreFailedWithNoSpace(ex); | ||
_associationInfo.Errors = $"Failed to store file due to low disk space: {ex}"; | ||
return new DicomCStoreResponse(request, DicomStatus.StorageStorageOutOfResources); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_logger?.CStoreFailed(ex); | ||
_associationInfo.Errors = $"Failed to store file: {ex}"; | ||
return new DicomCStoreResponse(request, DicomStatus.ProcessingFailure); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.