public ReturnOutcome Process(IDictionary <string, object> headers, byte[] body)
        {
            try
            {
                Guid fileId = Guid.Empty;
                if (!headers.ContainsKey("file-id"))
                {
                    throw NewAdaptationServiceException("Missing File Id");
                }

                var fileIdString = Encoding.UTF8.GetString((byte[])headers["file-id"]);
                if (fileIdString == null || !Guid.TryParse(fileIdString, out fileId))
                {
                    _logger.LogError($"Error in FileID: {fileIdString ?? "-"}");
                    return(ReturnOutcome.GW_ERROR);
                }

                if (!headers.ContainsKey("file-outcome"))
                {
                    throw NewAdaptationServiceException($"Missing outcome for File Id {fileId}");
                }

                var outcomeString         = Encoding.UTF8.GetString((byte[])headers["file-outcome"]);
                AdaptationOutcome outcome = (AdaptationOutcome)Enum.Parse(typeof(AdaptationOutcome), outcomeString, ignoreCase: true);
                if (!OutcomeMap.ContainsKey(outcome))
                {
                    _logger.LogError($"Returning outcome unmapped: {outcomeString} for File Id {fileId}");
                    return(ReturnOutcome.GW_ERROR);
                }
                return(OutcomeMap[outcome]);
            }
            catch (ArgumentException aex)
            {
                _logger.LogError($"Unrecognised enumeration processing adaptation outcome {aex.Message}");
                return(ReturnOutcome.GW_ERROR);
            }
            catch (JsonReaderException jre)
            {
                _logger.LogError($"Poorly formated adaptation outcome : {jre.Message}");
                return(ReturnOutcome.GW_ERROR);
            }
            catch (AdaptationServiceClientException asce)
            {
                _logger.LogError($"Poorly formated adaptation outcome : {asce.Message}");
                return(ReturnOutcome.GW_ERROR);
            }
        }
            public void Outcome_And_FileId_Is_Returned_When_Message_Is_Valid(AdaptationOutcome expectedOutcome)
            {
                // Arrange
                var expectedFileId = Guid.NewGuid();

                var headers = new Dictionary <string, object>()
                {
                    { "file-id", Encoding.UTF8.GetBytes(expectedFileId.ToString()) },
                    { "file-outcome", Encoding.UTF8.GetBytes(expectedOutcome.ToString()) }
                };

                // Act
                var outcome = _adaptationOutcomeProcessor.Process(headers);

                // Assert
                Assert.That(outcome.Key, Is.EqualTo(expectedFileId));
                Assert.That(outcome.Value, Is.EqualTo(expectedOutcome));
            }
Пример #3
0
        public KeyValuePair <Guid, AdaptationOutcome> Process(IDictionary <string, object> headers)
        {
            try
            {
                if (!headers.ContainsKey("file-id"))
                {
                    throw new AdaptationServiceClientException("Missing File Id");
                }

                var fileIdString = Encoding.UTF8.GetString((byte[])headers["file-id"]);

                Guid fileId = Guid.Empty;

                if (fileIdString == null || !Guid.TryParse(fileIdString, out fileId))
                {
                    throw new AdaptationServiceClientException($"Error in FileID: { fileIdString ?? "-" }");
                }

                if (!headers.ContainsKey("file-outcome"))
                {
                    throw new AdaptationServiceClientException($"Missing outcome for File Id {fileId}");
                }

                var outcomeString         = Encoding.UTF8.GetString((byte[])headers["file-outcome"]);
                AdaptationOutcome outcome = (AdaptationOutcome)Enum.Parse(typeof(AdaptationOutcome), outcomeString, ignoreCase: true);

                return(new KeyValuePair <Guid, AdaptationOutcome>(fileId, outcome));
            }
            catch (ArgumentException aex)
            {
                _logger.LogError($"Unrecognised enumeration processing adaptation outcome {aex.Message}");
                return(new KeyValuePair <Guid, AdaptationOutcome>(Guid.Empty, AdaptationOutcome.Error));
            }
            catch (JsonReaderException jre)
            {
                _logger.LogError($"Poorly formated adaptation outcome : {jre.Message}");
                return(new KeyValuePair <Guid, AdaptationOutcome>(Guid.Empty, AdaptationOutcome.Error));
            }
            catch (AdaptationServiceClientException asce)
            {
                _logger.LogError($"Poorly formated adaptation outcome : {asce.Message}");
                return(new KeyValuePair <Guid, AdaptationOutcome>(Guid.Empty, AdaptationOutcome.Error));
            }
        }
Пример #4
0
        private IAdaptationServiceResponse ProcessHeader(IDictionary <string, object> headers)
        {
            IAdaptationServiceResponse adaptationServiceResponse = new AdaptationServiceResponse();

            if (!headers.ContainsKey(Constants.Header.ICAP_FILE_ID))
            {
                throw NewAdaptationServiceException("Missing File Id");
            }

            string fileIdString = Encoding.UTF8.GetString((byte[])headers[Constants.Header.ICAP_FILE_ID]);

            if (fileIdString == null || !Guid.TryParse(fileIdString, out Guid fileId))
            {
                _logger.LogError($"Error in FileID: {fileIdString ?? "-"}");
                adaptationServiceResponse.FileOutcome = ReturnOutcome.GW_ERROR;
                return(adaptationServiceResponse);
            }

            adaptationServiceResponse.FileId = fileId;
            if (!headers.ContainsKey(Constants.Header.ICAP_FILE_OUTCOME))
            {
                throw NewAdaptationServiceException($"Missing outcome for File Id {fileId}");
            }

            string            outcomeString = Encoding.UTF8.GetString((byte[])headers[Constants.Header.ICAP_FILE_OUTCOME]);
            AdaptationOutcome outcome       = (AdaptationOutcome)Enum.Parse(typeof(AdaptationOutcome), outcomeString, ignoreCase: true);

            if (!OutcomeMap.ContainsKey(outcome))
            {
                _logger.LogError($"Returning outcome unmapped: {outcomeString} for File Id {fileId}");
                adaptationServiceResponse.FileOutcome = ReturnOutcome.GW_ERROR;
                return(adaptationServiceResponse);
            }

            adaptationServiceResponse.FileOutcome = OutcomeMap[outcome];
            if (headers.ContainsKey(Constants.Header.ICAP_CLEAN_PRESIGNED_URL))
            {
                adaptationServiceResponse.CleanPresignedUrl = Encoding.UTF8.GetString((byte[])headers[Constants.Header.ICAP_CLEAN_PRESIGNED_URL]);
            }

            if (headers.ContainsKey(Constants.Header.ICAP_REBUILT_FILE_LOCATION))
            {
                adaptationServiceResponse.RebuiltFileLocation = Encoding.UTF8.GetString((byte[])headers[Constants.Header.ICAP_REBUILT_FILE_LOCATION]);
            }

            if (headers.ContainsKey(Constants.Header.ICAP_REPORT_PRESIGNED_URL))
            {
                adaptationServiceResponse.ReportPresignedUrl = Encoding.UTF8.GetString((byte[])headers[Constants.Header.ICAP_REPORT_PRESIGNED_URL]);
            }

            if (headers.ContainsKey(Constants.Header.ICAP_SOURCE_FILE_LOCATION))
            {
                adaptationServiceResponse.SourceFileLocation = Encoding.UTF8.GetString((byte[])headers[Constants.Header.ICAP_SOURCE_FILE_LOCATION]);
            }

            if (headers.ContainsKey(Constants.Header.ICAP_SOURCE_PRESIGNED_URL))
            {
                adaptationServiceResponse.SourcePresignedUrl = Encoding.UTF8.GetString((byte[])headers[Constants.Header.ICAP_SOURCE_PRESIGNED_URL]);
            }

            if (headers.ContainsKey(Constants.Header.ICAP_SDK_ENGINE_VERSION))
            {
                adaptationServiceResponse.SDKEngineVersion = Encoding.UTF8.GetString((byte[])headers[Constants.Header.ICAP_SDK_ENGINE_VERSION]);
            }

            if (headers.ContainsKey(Constants.Header.ICAP_REBUILD_PROCESSING_STATUS))
            {
                string rebuildProcessingStatus = Encoding.UTF8.GetString((byte[])headers[Constants.Header.ICAP_REBUILD_PROCESSING_STATUS]);
                if (!string.IsNullOrWhiteSpace(rebuildProcessingStatus))
                {
                    adaptationServiceResponse.RebuildProcessingStatus = (RebuildProcessingStatus)Enum.Parse(typeof(RebuildProcessingStatus), rebuildProcessingStatus.Trim().Replace(" ", "_"), ignoreCase: true);
                }
            }

            if (headers.ContainsKey(Constants.Header.ICAP_GWLOG_PRESIGNED_URL))
            {
                adaptationServiceResponse.GwLogPresignedUrl = Encoding.UTF8.GetString((byte[])headers[Constants.Header.ICAP_GWLOG_PRESIGNED_URL]);
            }

            if (headers.ContainsKey(Constants.Header.ICAP_LOG_PRESIGNED_URL))
            {
                adaptationServiceResponse.LogPresignedUrl = Encoding.UTF8.GetString((byte[])headers[Constants.Header.ICAP_LOG_PRESIGNED_URL]);
            }

            if (headers.ContainsKey(Constants.Header.ICAP_METADATA_PRESIGNED_URL))
            {
                adaptationServiceResponse.MetaDataPresignedUrl = Encoding.UTF8.GetString((byte[])headers[Constants.Header.ICAP_METADATA_PRESIGNED_URL]);
            }
            return(adaptationServiceResponse);
        }