/// <summary> /// Creates a new IFileProfile object and stores in private _fileProfile. /// </summary> private void CreateFileProfile() { try { var profileSettings = new FileProfileSettings(mipPath, false, _authDelegate, new ConsentDelegateImplementation(), _appInfo, LogLevel.Trace); _fileProfile = Task.Run(async() => await new FileProfileFactory().LoadAsync(profileSettings)).Result; } catch (Exception ex) { throw ex; } }
/// <summary> /// Creates an IFileProfile and returns. /// IFileProfile is the root of all MIP SDK File API operations. Typically only one should be created per app. /// </summary> /// <param name="appInfo"></param> /// <param name="authDelegate"></param> /// <returns></returns> private IFileProfile CreateFileProfile(ApplicationInfo appInfo, ref AuthDelegateImplementation authDelegate) { mipContext = MIP.CreateMipContext(appInfo, "mip_data", LogLevel.Trace, null, null); // Initialize file profile settings to create/use local state. var profileSettings = new FileProfileSettings(mipContext, CacheStorageType.OnDiskEncrypted, new ConsentDelegateImplementation()); // Use MIP.LoadFileProfileAsync() providing settings to create IFileProfile. // IFileProfile is the root of all SDK operations for a given application. var profile = Task.Run(async() => await MIP.LoadFileProfileAsync(profileSettings)).Result; return(profile); }
/// <summary> /// Creates a new IFileProfile object and stores in private _fileProfile. /// </summary> private void CreateFileProfile() { try { mipContext = MIP.CreateMipContext(appInfo, mipPath, LogLevel.Error, null, null); var profileSettings = new FileProfileSettings(mipContext, CacheStorageType.OnDisk, new ConsentDelegateImplementation()); fileProfile = Task.Run(async() => await MIP.LoadFileProfileAsync(profileSettings)).Result; } catch (Exception ex) { throw ex; } }
/// <summary> /// Creates an IFileProfile and returns. /// IFileProfile is the root of all MIP SDK File API operations. Typically only one should be created per app. /// </summary> /// <param name="appInfo"></param> /// <param name="authDelegate"></param> /// <returns></returns> private IFileProfile CreateFileProfile(ApplicationInfo appInfo, ref AuthDelegateImplementation authDelegate) { try { // Initialize file profile settings to create/use local state. var profileSettings = new FileProfileSettings("mip_data", false, authDelegate, new ConsentDelegateImplementation(), appInfo, LogLevel.Trace); // Use MIP.LoadFileProfileAsync() providing settings to create IFileProfile. // IFileProfile is the root of all SDK operations for a given application. var profile = Task.Run(async() => await MIP.LoadFileProfileAsync(profileSettings)).Result; return(profile); } catch (Exception ex) { throw ex; } }
public ActionResult InvokeMIP() { string name = User.Identity.Name; ClaimsPrincipal principal = ClaimsPrincipal.Current; var tenantId = principal.FindFirst(c => c.Type == "http://schemas.microsoft.com/identity/claims/tenantid").Value; // Set path to bins folder. var path = Path.Combine( Directory.GetParent(Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath)).FullName, Environment.Is64BitProcess ? "bin\\x64" : "bin\\x86"); //Initialize Wrapper for File API operations MIP.Initialize(MipComponent.File, path); //Create ApplicationInfo, setting the clientID from Azure AD App Registration as the ApplicationId ApplicationInfo appInfo = new ApplicationInfo() { ApplicationId = clientId, ApplicationName = appName, ApplicationVersion = appVersion }; //Instatiate the AuthDelegateImpl object, passing in AppInfo. AuthDelegateImplementation authDelegate = new AuthDelegateImplementation(appInfo, tenantId); //Initialize and instantiate the File Profile //Create the FileProfileSettings object var profileSettings = new FileProfileSettings(mipPath, false, authDelegate, new ConsentDelegateImplementation(), appInfo, LogLevel.Trace); //Load the Profile async and wait for the result var fileProfile = Task.Run(async() => await MIP.LoadFileProfileAsync(profileSettings)).Result; //Create a FileEngineSettings object, then use that to add an engine to the profile var engineSettings = new FileEngineSettings(name, "", "en-US"); engineSettings.Identity = new Identity(name); var fileEngine = Task.Run(async() => await fileProfile.AddEngineAsync(engineSettings)).Result; // Just a test code to check if all the custom labels are populated or not foreach (var label in fileEngine.SensitivityLabels) { string labelName = label.Name; } //Set paths and label ID. You can paas file input stream too string filePath = Server.MapPath(@"~/App_Data/DemoAIPDoc.docx"); string outputFilePath = @"D:\Test2.docx"; var stream = System.IO.File.OpenRead(filePath); //Create a file handler for that file //Note: the 2nd inputFilePath is used to provide a human-readable content identifier for admin auditing. var handler = Task.Run(async() => await fileEngine.CreateFileHandlerAsync(stream, filePath, true)).Result; LabelingOptions labelingOptions = new LabelingOptions() { AssignmentMethod = AssignmentMethod.Privileged, //important as we are removing the label IsDowngradeJustified = true, JustificationMessage = "Lowering label" }; //remove the label handler.DeleteLabel(labelingOptions); // Commit changes, save as outputFilePath. You can also generate output stream var result = Task.Run(async() => await handler.CommitAsync(outputFilePath)).Result; return(RedirectToAction("Index")); }