Exemplo n.º 1
0
        private void ConvertDetailedResults(DvtkResultsOverview resultsOverview)
        {
            // parse the dvtk detailed results
            DvtkDetailedResults dvtkDetailedResults = new DvtkDetailedResults();
            String dvtkDetailedResultsFilename      = GetDvtkDetailedResultsFilename(resultsOverview.Oid);

            dvtkDetailedResults.FromXml(dvtkDetailedResultsFilename);

            // set up the evs detailed results
            EvsDetailedResults evsDetailedResults = new EvsDetailedResults();

            evsDetailedResults.ValidationResultsOverview = resultsOverview;
            evsDetailedResults.XmlFmiValidationResults   = dvtkDetailedResults.XmlFmiValidationResults;
            evsDetailedResults.XmlDatasetResults         = dvtkDetailedResults.XmlDatasetResults;
            evsDetailedResults.ValidationErrorCount      = dvtkDetailedResults.ValidationErrorCount;
            evsDetailedResults.ValidationWarningCount    = dvtkDetailedResults.ValidationWarningCount;
            evsDetailedResults.ValidationConditionCount  = dvtkDetailedResults.ValidationConditionCount;
            evsDetailedResults.ValidationResult          = dvtkDetailedResults.ValidationResult;

            // save the evs detailed results file
            String evsDetailedResultsFilename = GetEvsDetailedResultsFilename(resultsOverview.Oid);

            evsDetailedResults.Save(evsDetailedResultsFilename);

            // delete the dvtk detailed results file
            try
            {
                FileInfo dvtkDetailedResultsFileInfo = new FileInfo(dvtkDetailedResultsFilename);
                dvtkDetailedResultsFileInfo.Delete();
            }
            catch (System.Exception)
            {
                // exception thrown if the file is currently being accessed by another process - this will be picked up on the next RemoveCachedData() call.
            }
        }
Exemplo n.º 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());
        }
Exemplo n.º 3
0
        private void ConvertSummaryResults(DvtkResultsOverview resultsOverview)
        {
            // parse the dvtk summary results
            DvtkSummaryResults dvtkSummaryResults = new DvtkSummaryResults();
            String dvtkSummaryResultsFilename = GetDvtkSummaryResultsFilename(resultsOverview.Oid);
            dvtkSummaryResults.FromXml(dvtkSummaryResultsFilename);

            // set up the evs summary results
            EvsSummaryResults evsSummaryResults = new EvsSummaryResults();
            evsSummaryResults.ValidationResultsOverview = resultsOverview;
            evsSummaryResults.XmlFmiValidationResults = dvtkSummaryResults.XmlFmiValidationResults;
            evsSummaryResults.XmlDatasetResults = dvtkSummaryResults.XmlDatasetResults;
            evsSummaryResults.ValidationErrorCount = dvtkSummaryResults.ValidationErrorCount;
            evsSummaryResults.ValidationWarningCount = dvtkSummaryResults.ValidationWarningCount;
            evsSummaryResults.ValidationConditionCount = dvtkSummaryResults.ValidationConditionCount;
            evsSummaryResults.ValidationResult = dvtkSummaryResults.ValidationResult;

            // save the evs summary results file
            String evsSummaryResultsFilename = GetEvsSummaryResultsFilename(resultsOverview.Oid);
            evsSummaryResults.Save(evsSummaryResultsFilename);

            // delete the dvtk summary results file
            try
            {
                FileInfo dvtkSummaryResultsFileInfo = new FileInfo(dvtkSummaryResultsFilename);
                dvtkSummaryResultsFileInfo.Delete();
            }
            catch (System.Exception)
            {
                // exception thrown if the file is currently being accessed by another process - this will be picked up on the next RemoveCachedData() call.
            }
        }
Exemplo n.º 4
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();
        }