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 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) { response.ErrorMessage = _glasswallFileOperations.GetEngineError(); _logger.Log(LogLevel.Error, $"Unable to protect file, reason: {engineOutcome}. Error Message: {response.ErrorMessage}"); } return(response); }