public bool SaveStreamData(DicomMessage message, byte[] data, int offset, int count) { ISopInstanceImporter importer = IoC.Get <ISopInstanceImporter>(); importer.Context = _importContext; var sopInstanceUid = message.DataSet[DicomTags.SopInstanceUid].GetString(0, string.Empty); if (_fileStream == null) { if (!importer.GetStreamedFileStorageFolder(message, out _sourceFolder, out _filesystemStreamingFolder)) { Platform.Log(LogLevel.Warn, "Unable to create a folder to save SOP Instance, rejecting: {0}", sopInstanceUid); return(false); } _sourceFilename = Path.Combine(_sourceFolder, Guid.NewGuid().ToString() + "dcm"); try { _fileStream = FileStreamOpener.OpenForSoleUpdate(_sourceFilename, FileMode.Create); } catch (Exception x) { Platform.Log(LogLevel.Warn, x, "Unable to open file for saving filestream: {0}", _sourceFilename); return(false); } } _fileStream.Write(data, offset, count); return(true); }
public override IList <SupportedSop> GetSupportedSopClasses() { if (_list == null) { ISopInstanceImporter importer = IoC.Get <ISopInstanceImporter>(); _list = importer.GetStroageSupportedSopClasses(); } return(_list); }
public bool CompleteStream(DicomServer server, ServerAssociationParameters assoc, byte presentationId, DicomMessage message) { DicomProcessingResult result; try { if (_fileStream != null) { _fileStream.Flush(true); _fileStream.Close(); _fileStream.Dispose(); _fileStream = null; } ISopInstanceImporter importer = IoC.Get <ISopInstanceImporter>(); importer.Context = _importContext; result = importer.ImportFile(message, _sourceFilename); if (result.Successful) { if (!String.IsNullOrEmpty(result.AccessionNumber)) { Platform.Log(LogLevel.Info, "Received SOP Instance {0} from {1} to {2} (A#:{3} StudyUid:{4})", result.SopInstanceUid, assoc.CallingAE, assoc.CalledAE, result.AccessionNumber, result.StudyInstanceUid); } else { Platform.Log(LogLevel.Info, "Received SOP Instance {0} from {1} to {2} (StudyUid:{3})", result.SopInstanceUid, assoc.CallingAE, assoc.CalledAE, result.StudyInstanceUid); } } } catch (Exception e) { result = new DicomProcessingResult { DicomStatus = DicomStatuses.ProcessingFailure, ErrorMessage = e.Message }; } if (!result.Successful) { Platform.Log(LogLevel.Warn, "Failure importing sop: {0}", result.ErrorMessage); } CleanupDirectory(); server.SendCStoreResponse(presentationId, message.MessageId, message.AffectedSopInstanceUid, result.DicomStatus); return(true); }
public override bool OnReceiveRequest(DicomServer server, ServerAssociationParameters association, byte presentationId, DicomMessage message) { try { SopInstanceImporterContext context = new SopInstanceImporterContext( String.Format("{0}_{1}", association.CallingAE, association.TimeStamp.ToString("yyyyMMddhhmmss")), association.CallingAE, Partition.AeTitle); DicomProcessingResult result = new DicomProcessingResult(); ISopInstanceImporter importer = IoC.Get <ISopInstanceImporter>(); if (importer != null) { importer.Context = context; result = importer.Import(message); } if (result.Successful) { if (!String.IsNullOrEmpty(result.AccessionNumber)) { Log.Logger.Info("Received SOP Instance {0} from {1} to {2} (A#:{3} StudyUid:{4})", result.SopInstanceUid, association.CallingAE, association.CalledAE, result.AccessionNumber, result.StudyInstanceUid); } else { Log.Logger.Info("Received SOP Instance {0} from {1} to {2} (StudyUid:{3})", result.SopInstanceUid, association.CallingAE, association.CalledAE, result.StudyInstanceUid); } } else { Log.Logger.Warn("Failure importing sop: {0}", result.ErrorMessage); } server.SendCStoreResponse(presentationId, message.MessageId, message.AffectedSopInstanceUid, result.DicomStatus); return(true); } catch (DicomDataException ex) { Log.Logger.Error(ex, "Error when import {0}", message.AffectedSopInstanceUid); return(false); // caller will abort the association } catch (Exception ex) { Log.Logger.Error(ex, "Error when import {0}", message.AffectedSopInstanceUid); return(false); // caller will abort the association } }