Beispiel #1
0
        public string Validate(string oid,
                               string xmlReferencedStandard,
                               string xmlValidationContext,
                               string xmlObjectMetaData,
                               byte[] binaryObjectData)
        {
            // check if oid is defined
            if (oid == String.Empty)
            {
                oid = "DVTK-DICOM-EVS-" + Guid.NewGuid().ToString();
            }

            // set up the results overview to return
            DvtkResultsOverview resultsOverview = new DvtkResultsOverview();

            resultsOverview.Oid = oid;
            resultsOverview.ValidationServiceName    = "DVTK DICOM EVS";
            resultsOverview.ValidationServiceVersion = "1.0.1";
            resultsOverview.ValidationDate           = System.DateTime.Now.ToString("yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture);
            resultsOverview.ValidationTime           = System.DateTime.Now.ToString("HHmmss", System.Globalization.CultureInfo.InvariantCulture);
            resultsOverview.ValidationTestId         = oid;
            resultsOverview.ValidationTestResult     = "FAILED";

            try
            {
                _evsServiceLogger.LogDebug("DVTK-DICOM-EVS Validate:");
                _evsServiceLogger.LogDebug("oid = {0}", oid);
                _evsServiceLogger.LogDebug("xmlReferencedStandard = {0}", xmlReferencedStandard);
                _evsServiceLogger.LogDebug("xmlValidationContext = {0}", xmlValidationContext);
                _evsServiceLogger.LogDebug("xmlObjectMetaData = {0}", xmlObjectMetaData);
                _evsServiceLogger.LogDebug("binaryObjectData length = {0}", binaryObjectData.Length);

                // parse the referenced standard xml
                _dvtkReferencedStandard         = new DvtkReferencedStandard(xmlReferencedStandard);
                resultsOverview.StandardName    = _dvtkReferencedStandard.Name;
                resultsOverview.StandardVersion = _dvtkReferencedStandard.Version;

                // not sure what to do with the referenced standard properties yet

                // parse the validation context xml
                _dvtkValidationContext = new DvtkValidationContext(xmlValidationContext);

                // set the results files to be generated
                _mediaSession.DetailedValidationResults = _dvtkValidationContext.GenerateDetailedResults;
                _mediaSession.SummaryValidationResults  = _dvtkValidationContext.GenerateSummaryResults;

                // parse the object meta data xml
                _dvtkObjectMetaData = new DvtkObjectMetaData(xmlObjectMetaData);

                // create the binary data file extension
                String fileExtension = String.Empty;
                switch (_dvtkObjectMetaData.DicomBinaryObjectDataType)
                {
                case DicomBinaryObjectDataType.MediaFile:
                    fileExtension = ".dcm";
                    break;

                case DicomBinaryObjectDataType.CommandSet:
                case DicomBinaryObjectDataType.DataSet:
                    fileExtension = ".raw";
                    break;

                default:
                    break;
                }

                // ensure that the message directory is present
                String        messageDirectory = _dvtkDicomEvsConfig.BaseCacheDirectory + @"\" + _dvtkDicomEvsConfig.MessageSubDirectory;
                DirectoryInfo dirInfo          = new DirectoryInfo(messageDirectory);
                if (dirInfo.Exists != true)
                {
                    dirInfo.Create();
                }

                // create the oid storage directory for the message to be validated and the corresponding results
                String oidDirectory = _dvtkDicomEvsConfig.BaseCacheDirectory + @"\" + _dvtkDicomEvsConfig.MessageSubDirectory + @"\" + oid;
                dirInfo = new DirectoryInfo(oidDirectory);
                if (dirInfo.Exists == true)
                {
                    // delete the directory and any contents if it already exists - this is the case when the same OID is used to
                    // validate files without cleaning the cache in between
                    dirInfo.Delete(true);
                }
                // create the directory
                dirInfo.Create();

                // save the binary data to a file in the message directory
                String binaryDataFilename = oidDirectory + @"\" + BinaryDataFilename + fileExtension;
                _evsServiceLogger.LogDebug("Cached Binary Data Filename = \"{0}\"", binaryDataFilename);
                FileStream   stream = new FileStream(binaryDataFilename, FileMode.CreateNew);
                BinaryWriter writer = new BinaryWriter(stream);
                writer.Write(binaryObjectData);
                writer.Flush();
                writer.Close();
                stream.Close();

                // create the results directory
                String resultsDirectory = _dvtkDicomEvsConfig.BaseCacheDirectory + @"\" + _dvtkDicomEvsConfig.MessageSubDirectory + @"\" + oid + @"\results";
                dirInfo = new DirectoryInfo(resultsDirectory);
                if (dirInfo.Exists != true)
                {
                    dirInfo.Create();
                }

                // use the DVTK core to validate the binary data file
                _mediaSession.ResultsRootDirectory = resultsDirectory;
                _mediaSession.StartResultsGathering(ResultFilename);
                String[] list = new String[1];
                list[0] = binaryDataFilename;
                _mediaSession.ValidateMediaFiles(list);
                _mediaSession.EndResultsGathering();

                // validation result is PASSED when no errors and warnings are present
                resultsOverview.ValidationTestResult = ((_mediaSession.NrOfErrors == 0) && (_mediaSession.NrOfWarnings == 0)) ? "PASSED" : "FAILED";
            }
            catch (System.Exception e)
            {
                _dvtkValidationServiceStatus.Status = "Error";
                _dvtkValidationServiceStatus.AdditionalStatusInfo = e.Message;
                _evsServiceLogger.LogError(e.Message);
            }

            resultsOverview.ValidationServiceStatus = _dvtkValidationServiceStatus.Status;
            resultsOverview.ValidationServiceAdditionalStatusInfo = _dvtkValidationServiceStatus.AdditionalStatusInfo;

            // convert the results files
            if ((_dvtkDicomEvsConfig.DefaultDvtkXmlResultsFormat == false) &&
                (_dvtkValidationContext.GenerateSummaryResults == true))
            {
                ConvertSummaryResults(resultsOverview);
            }
            if ((_dvtkDicomEvsConfig.DefaultDvtkXmlResultsFormat == false) &&
                (_dvtkValidationContext.GenerateDetailedResults == true))
            {
                ConvertDetailedResults(resultsOverview);
            }

            return(resultsOverview.ToXml());
        }
Beispiel #2
0
        public string Validate(string oid,
            string xmlReferencedStandard,
            string xmlValidationContext,
            string xmlObjectMetaData,
            byte[] binaryObjectData)
        {
            // check if oid is defined
            if (oid == String.Empty)
            {
                oid = "DVTK-DICOM-EVS-" + Guid.NewGuid().ToString();
            }

            // set up the results overview to return
            DvtkResultsOverview resultsOverview = new DvtkResultsOverview();
            resultsOverview.Oid = oid;
            resultsOverview.ValidationServiceName = "DVTK DICOM EVS";
            resultsOverview.ValidationServiceVersion = "1.0.1";
            resultsOverview.ValidationDate = System.DateTime.Now.ToString("yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture);
            resultsOverview.ValidationTime = System.DateTime.Now.ToString("HHmmss", System.Globalization.CultureInfo.InvariantCulture);
            resultsOverview.ValidationTestId = oid;
            resultsOverview.ValidationTestResult = "FAILED";

            try
            {
                _evsServiceLogger.LogDebug("DVTK-DICOM-EVS Validate:");
                _evsServiceLogger.LogDebug("oid = {0}", oid);
                _evsServiceLogger.LogDebug("xmlReferencedStandard = {0}", xmlReferencedStandard);
                _evsServiceLogger.LogDebug("xmlValidationContext = {0}", xmlValidationContext);
                _evsServiceLogger.LogDebug("xmlObjectMetaData = {0}", xmlObjectMetaData);
                _evsServiceLogger.LogDebug("binaryObjectData length = {0}", binaryObjectData.Length);

                // parse the referenced standard xml
                _dvtkReferencedStandard = new DvtkReferencedStandard(xmlReferencedStandard);
                resultsOverview.StandardName = _dvtkReferencedStandard.Name;
                resultsOverview.StandardVersion = _dvtkReferencedStandard.Version;

                // not sure what to do with the referenced standard properties yet

                // parse the validation context xml
                _dvtkValidationContext = new DvtkValidationContext(xmlValidationContext);

                // set the results files to be generated
                _mediaSession.DetailedValidationResults = _dvtkValidationContext.GenerateDetailedResults;
                _mediaSession.SummaryValidationResults = _dvtkValidationContext.GenerateSummaryResults;

                // parse the object meta data xml
                _dvtkObjectMetaData = new DvtkObjectMetaData(xmlObjectMetaData);

                // create the binary data file extension
                String fileExtension = String.Empty;
                switch (_dvtkObjectMetaData.DicomBinaryObjectDataType)
                {
                    case DicomBinaryObjectDataType.MediaFile:
                        fileExtension = ".dcm";
                        break;
                    case DicomBinaryObjectDataType.CommandSet:
                    case DicomBinaryObjectDataType.DataSet:
                        fileExtension = ".raw";
                        break;
                    default:
                        break;
                }

                // ensure that the message directory is present
                String messageDirectory = _dvtkDicomEvsConfig.BaseCacheDirectory + @"\" + _dvtkDicomEvsConfig.MessageSubDirectory;
                DirectoryInfo dirInfo = new DirectoryInfo(messageDirectory);
                if (dirInfo.Exists != true)
                {
                    dirInfo.Create();
                }

                // create the oid storage directory for the message to be validated and the corresponding results
                String oidDirectory = _dvtkDicomEvsConfig.BaseCacheDirectory + @"\" + _dvtkDicomEvsConfig.MessageSubDirectory + @"\" + oid;
                dirInfo = new DirectoryInfo(oidDirectory);
                if (dirInfo.Exists == true)
                {
                    // delete the directory and any contents if it already exists - this is the case when the same OID is used to
                    // validate files without cleaning the cache in between
                    dirInfo.Delete(true);
                }
                // create the directory
                dirInfo.Create();

                // save the binary data to a file in the message directory
                String binaryDataFilename = oidDirectory + @"\" + BinaryDataFilename + fileExtension;
                _evsServiceLogger.LogDebug("Cached Binary Data Filename = \"{0}\"", binaryDataFilename);
                FileStream stream = new FileStream(binaryDataFilename, FileMode.CreateNew);
                BinaryWriter writer = new BinaryWriter(stream);
                writer.Write(binaryObjectData);
                writer.Flush();
                writer.Close();
                stream.Close();

                // create the results directory
                String resultsDirectory = _dvtkDicomEvsConfig.BaseCacheDirectory + @"\" + _dvtkDicomEvsConfig.MessageSubDirectory + @"\" + oid + @"\results";
                dirInfo = new DirectoryInfo(resultsDirectory);
                if (dirInfo.Exists != true)
                {
                    dirInfo.Create();
                }

                // use the DVTK core to validate the binary data file
                _mediaSession.ResultsRootDirectory = resultsDirectory;
                _mediaSession.StartResultsGathering(ResultFilename);
                String[] list = new String[1];
                list[0] = binaryDataFilename;
                _mediaSession.ValidateMediaFiles(list);
                _mediaSession.EndResultsGathering();

                // validation result is PASSED when no errors and warnings are present
                resultsOverview.ValidationTestResult = ((_mediaSession.NrOfErrors == 0) && (_mediaSession.NrOfWarnings == 0)) ? "PASSED" : "FAILED";
            }
            catch (System.Exception e)
            {
                _dvtkValidationServiceStatus.Status = "Error";
                _dvtkValidationServiceStatus.AdditionalStatusInfo = e.Message;
                _evsServiceLogger.LogError(e.Message);
            }

            resultsOverview.ValidationServiceStatus = _dvtkValidationServiceStatus.Status;
            resultsOverview.ValidationServiceAdditionalStatusInfo = _dvtkValidationServiceStatus.AdditionalStatusInfo;

            // convert the results files
            if ((_dvtkDicomEvsConfig.DefaultDvtkXmlResultsFormat == false) &&
                (_dvtkValidationContext.GenerateSummaryResults == true))
            {
                ConvertSummaryResults(resultsOverview);
            }
            if ((_dvtkDicomEvsConfig.DefaultDvtkXmlResultsFormat == false) &&
                (_dvtkValidationContext.GenerateDetailedResults == true))
            {
                ConvertDetailedResults(resultsOverview);
            }

            return resultsOverview.ToXml();
        }