Esempio n. 1
0
        private void listener_StoreRequest(DICOMConnection conn, DICOMData data)
        {
            try
            {
                if (!this._settings.StoreMetadataOnlyFiles && !data.Elements.ContainsKey(DICOMTags.PixelData))
                {
                    this._logger.Log(LogLevel.Info, "Data set has no image data (only metadata). Metadata storing is disabled, so image will not be persisted.");
                    conn.SendCSTORERSP(CommandStatus.Error_MissingAttribute);
                    return;
                }

                if (this._settings.AutoDecompress && data.TransferSyntax.Compression != DICOMSharp.Data.Compression.CompressionInfo.None)
                {
                    this._logger.Log(LogLevel.Info, "Image is compressed, decompressing before storage!");
                    if (!data.Uncompress())
                    {
                        this._logger.Log(LogLevel.Warning, "Image decompression failed! Storing compressed image.");
                    }
                }

                string postName = FileUtil.GenerateFilenameFromImage(data, this._logger);

                //form full file path
                string diskPath = _db.FixImagePath(this._settings.ImageStoragePath);
                if (!diskPath.EndsWith("\\"))
                {
                    diskPath += "\\";
                }
                diskPath += postName;

                data.WriteFile(diskPath, this._logger);

                // Db path can save a ~ path, so recalc without MapPath
                string dbPath = this._settings.ImageStoragePath;
                if (!dbPath.EndsWith("\\"))
                {
                    dbPath += "\\";
                }
                dbPath += postName;

                this._db.PersistImage(data, diskPath, dbPath);

                conn.SendCSTORERSP(CommandStatus.Success);
            }
            catch (Exception e)
            {
                this._logger.Log(LogLevel.Error, "Error in StoreRequest: " + e.ToString());
                conn.SendCSTORERSP(CommandStatus.Error_UnrecognizedOperation);
            }
        }
Esempio n. 2
0
        private void conn_CommandReceived(DICOMConnection conn, PDATACommands command, DICOMData cmdDICOM, DICOMData dataDICOM)
        {
            switch (command)
            {
            case PDATACommands.CECHORQ:
                conn.LogLine(LogLevel.Info, "Received C-ECHO-RQ");
                conn.SendCECHORSP();
                break;

            case PDATACommands.CSTORERQ:
                conn.LogLine(LogLevel.Info, "Received C-STORE-RQ");

                //Add source AE title to image
                dataDICOM[DICOMTags.SourceApplicationEntityTitle].Data = conn.CallingAE;

                if (StoreRequest != null)
                {
                    StoreRequest(conn, dataDICOM);
                }
                else
                {
                    conn.SendCSTORERSP(CommandStatus.Success);
                }
                break;

            case PDATACommands.CSTORERSP:
                conn.LogLine(LogLevel.Info, "Received C-STORE-RSP");

                break;

            case PDATACommands.CFINDRQ:
                conn.LogLine(LogLevel.Info, "Received C-FIND-RQ");
                if (FindRequest != null)
                {
                    QRResponseData response = FindRequest(conn, new QRRequestData(cmdDICOM, dataDICOM));
                    conn.SendCFINDRSP(response);
                }
                else
                {
                    conn.SendCFINDRSP(null, CommandStatus.Success);
                }
                break;

            case PDATACommands.CGETRQ:
                conn.LogLine(LogLevel.Info, "Received C-GET-RQ");
                if (GetRequest != null)
                {
                    QRResponseData response = GetRequest(conn, new QRRequestData(cmdDICOM, dataDICOM));
                    conn.StartGetResponse(response);
                }
                else
                {
                    conn.SendCGETRSP((ushort)cmdDICOM[DICOMTags.MessageID].Data, CommandStatus.Success, 0, 0, 0, 0);
                }
                break;

            case PDATACommands.CMOVERQ:
                conn.LogLine(LogLevel.Info, "Received C-MOVE-RQ");
                if (MoveRequest != null)
                {
                    string            newAE  = cmdDICOM[DICOMTags.MoveDestination].Display.Trim();
                    ApplicationEntity entity = null;
                    if (EntityLookup != null)
                    {
                        entity = EntityLookup(newAE);
                    }

                    if (entity != null)
                    {
                        QRResponseData response = MoveRequest(conn, new QRRequestData(cmdDICOM, dataDICOM));
                        conn.StartMoveResponse(entity, response);
                    }
                    else
                    {
                        conn.LogLine(LogLevel.Warning, "No entity found for the MOVE request: " + newAE);
                        conn.SendCMOVERSP(CommandStatus.Error_ProcessingFailure, 0, 0, 0, 0);
                    }
                }
                else
                {
                    conn.SendCMOVERSP(CommandStatus.Error_ProcessingFailure, 0, 0, 0, 0);
                }
                break;

            case PDATACommands.NGETRQ:
                conn.LogLine(LogLevel.Info, "Received N-GET-RQ");

                // No idea what we're supposed to do with these yet
                conn.SendNGETRSP(CommandStatus.Refused_SOPClassNotSupported, null);
                break;

            default:
                conn.LogLine(LogLevel.Warning, "Unhandled P-DATA Command Type: " + command + "...");
                break;
            }
        }