public IFileProtectResponse GetProtectedFile(ContentManagementFlags contentManagementFlags, string fileType, byte[] fileBytes)
        {
            var response = new FileProtectResponse {
                ProtectedFile = Enumerable.Empty <byte>().ToArray()
            };

            var glasswallConfiguration = _glasswallConfigurationAdaptor.Adapt(contentManagementFlags);
            var configurationOutcome   = _glasswallFileOperations.SetConfiguration(glasswallConfiguration);

            if (configurationOutcome != EngineOutcome.Success)
            {
                _logger.Log(LogLevel.Error, "Error processing configuration");
                response.Outcome = configurationOutcome;
                return(response);
            }

            var version = _glasswallFileOperations.GetLibraryVersion();

            _logger.LogInformation($"Engine version: {version}");

            var engineOutcome = _glasswallFileOperations.ProtectFile(fileBytes, fileType, out var protectedFile);

            response.Outcome       = engineOutcome;
            response.ProtectedFile = protectedFile;

            if (engineOutcome != EngineOutcome.Success)
            {
                _logger.Log(LogLevel.Error, $"Unable to protect file, reason: {engineOutcome}.");
            }

            return(response);
        }
Esempio n. 2
0
        public IFileProtectResponse GetProtectedFile(ContentManagementFlags contentManagementFlags, string fileType, byte[] fileBytes)
        {
            var response = new FileProtectResponse {
                ProtectedFile = Enumerable.Empty <byte>().ToArray()
            };

            var glasswallConfiguration = _glasswallConfigurationAdaptor.Adapt(contentManagementFlags);
            var configurationOutcome   = _glasswallFileOperations.SetConfiguration(glasswallConfiguration);

            if (configurationOutcome != EngineOutcome.Success)
            {
                response.Outcome = configurationOutcome;
                return(response);
            }

            var version = _glasswallFileOperations.GetLibraryVersion();

            var engineOutcome = _glasswallFileOperations.ProtectFile(fileBytes, fileType, out var protectedFile);

            response.Outcome       = engineOutcome;
            response.ProtectedFile = protectedFile;

            if (engineOutcome != EngineOutcome.Success)
            {
                response.ErrorMessage = _glasswallFileOperations.GetEngineError();
            }

            return(response);
        }
        public EngineOutcome SetConfiguration(string configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            return(_glasswallFileOperations.SetConfiguration(configuration));
        }
        public string GetReport(ContentManagementFlags flags, string fileType, byte[] fileBytes)
        {
            var analysisReport = string.Empty;

            var glasswallConfiguration = _glasswallConfigurationAdaptor.Adapt(flags);

            if (glasswallConfiguration == null)
            {
                return(analysisReport);
            }

            var setConfigurationEngineOutcome = _glasswallFileOperations.SetConfiguration(glasswallConfiguration);

            if (setConfigurationEngineOutcome != EngineOutcome.Success)
            {
                return(analysisReport);
            }

            _glasswallFileOperations.AnalyseFile(fileBytes, fileType, out analysisReport);


            return(analysisReport);
        }