using System; using System.Collections.Generic; using System.IO; using System.Threading.Tasks; using Microsoft.InformationProtection; using Microsoft.InformationProtection.File; using Microsoft.InformationProtection.Protection; using System.Diagnostics; using Serilog; using Serilog.Core; namespace AipGateway.AIP { public class FileManager : AbstractManager { private readonly ILogger _log; private IFileProfile _profile = null; private IFileEngine _engine = null; public FileManager(Logger logger, string clientId) : base(logger, clientId) { _log = logger.ForContext(); } ~FileManager() => this.Dispose(false); public override void Dispose() { this.Dispose(true); GC.SuppressFinalize((object)this); } protected virtual void Dispose(bool disposing) { lock (this) { if (_profile != null & _engine != null) { //_profile.UnloadEngineAsync(_engine.Settings.EngineId).Wait(); } _engine = null; _profile = null; } } public override bool CreateProfile(ref MipContext mipContext) { try { var profileSettings = new FileProfileSettings(mipContext, //CacheStorageType.OnDiskEncrypted, CacheStorageType.InMemory, new ConsentDelegateImplementation()); // IFileProfile은 특정 애플리케이션에 대한 모든 SDK 작업의 루트입니다. _profile = Task.Run(async () => await MIP.LoadFileProfileAsync(profileSettings)).Result; } catch (Exception e) { SetError(1, "FileManager::CreateProfile Failed.", e.Message); return false; } return _profile != null; } public override bool CreateEngine(ref Identity identity, ref AuthDelegateImplementation authDelegate) { try { authDelegate.ResetError(); //CultureInfo.CurrentCulture.Name; // 보호 엔진 설정 개체를 만듭니다. 첫 번째 매개변수인 엔진 ID에 빈 문자열을 전달하면 SDK가 GUID를 생성합니다. // 이메일 주소나 기타 고유한 값을 전달하면 동일한 사용자에 대해 캐시된 엔진이 매번 로드되도록 하는 데 도움이 됩니다. // 로캘 설정은 지원되며 특히 클라이언트 응용 프로그램의 경우 컴퓨터 로캘을 기반으로 제공되어야 합니다. //_log.Information("Engine ClientID: {0}", _clientId); //_log.Information("Engine UserID: {0}", identity.Email); var engineSettings = new FileEngineSettings(_clientId, authDelegate, string.Empty, "en-US") { // Provide the identity for service discovery. Identity = identity, // Set ProtectionOnlyEngine to true for AD RMS as labeling isn't supported //ProtectionOnlyEngine = true }; _engine = Task.Run(async () => await _profile.AddEngineAsync(engineSettings)).Result; } catch (Exception e) { if (authDelegate.LastErrNo != 0) { SetError(authDelegate.LastErrNo, "FileManager::CreateEngine Failed.", authDelegate.LastErrMsg); } else { SetError(2, "FileManager::CreateEngine Failed.", e.Message); } return false; } return _engine != null; } public IEnumerable