public ImportSopResponse ImportSop(ImportSopRequest request) { try { var theFile = new DicomFile(string.Format("{0}{1}", request.SopInstanceUid, ServerPlatform.DicomFileExtension)); using (var stream = new LargeMemoryStream(request.SopInstance)) { theFile.Load(stream); } var partition = ServerPartitionMonitor.Instance.GetPartition(request.CalledAETitle); string aeTitle = theFile.SourceApplicationEntityTitle; if (_importerContext == null) _importerContext = new SopInstanceImporterContext( String.Format("{0}_{1}", aeTitle, DateTime.Now.ToString("yyyyMMddhhmmss")), partition.AeTitle, partition); var utility = new SopInstanceImporter(_importerContext); var importResult = utility.Import(theFile); if (!importResult.Successful) Platform.Log(LogLevel.Error, "Failure importing file file from Web Service: {0}, SOP Instance UID: {1}", importResult.ErrorMessage, request.SopInstanceUid); else Platform.Log(LogLevel.Info, "Processed import for SOP through Web Service: {0}.", request.SopInstanceUid); var result = new ImportSopResponse { DicomStatusCode = importResult.DicomStatus.Code, FailureMessage = importResult.ErrorMessage, Successful = importResult.Successful }; return result; } catch (Exception ex) { var message = string.Format("Failed to import files: {0}, SOP Instance UID: {1}", ex.Message, request.SopInstanceUid); Platform.Log(LogLevel.Error, message); throw new FaultException(message); } }
public static void WriteXmlAndGzip(StudyXmlMemento theMemento, Stream theXmlStream, Stream theGzipStream) { // Write to a memory stream, then flush to disk and to gzip file var ms = new LargeMemoryStream(); Write(theMemento, ms); using (var compressedZipStream = new GZipStream(theGzipStream, CompressionMode.Compress, true)) { ms.Seek(0, SeekOrigin.Begin); ms.WriteTo(compressedZipStream); // Close the stream. compressedZipStream.Flush(); compressedZipStream.Close(); } ms.Seek(0, SeekOrigin.Begin); ms.WriteTo(theXmlStream); // Force a flush. theXmlStream.Flush(); theGzipStream.Flush(); }