Skip to content

Instantly share code, notes, and snippets.

@CJHarmath
Last active February 25, 2019 19:27
Show Gist options
  • Save CJHarmath/295cf4d26d6d1158342b3d66d58d4085 to your computer and use it in GitHub Desktop.
Save CJHarmath/295cf4d26d6d1158342b3d66d58d4085 to your computer and use it in GitHub Desktop.
Sample attempt to protect a document with RMS
// method was added to the Action.cs in the sample
// https://github.com/Azure-Samples/MipSdk-Dotnet-File-Quickstart/blob/master/mip-sdk-dotnet-quickstart/Action.cs
public bool SetProtection(FileOptions options)
{
try
{
var handler = CreateFileHandler(options);
var newRights = new List<UserRights>
{
new UserRights(new List<string> {"[email protected]"}, new List<string> {"owner"})
};
ProtectionDescriptor protectionDescriptor = new ProtectionDescriptor(newRights);
handler.SetProtection(protectionDescriptor);
// The change isn't committed to the file referenced by the handler until CommitAsync() is called.
// Pass the desired output file name in to the CommitAsync() function.
var result = Task.Run(async() => await handler.CommitAsync(options.OutputName)).Result;
// If the commit was successful and GenerateChangeAuditEvents is true, call NotifyCommitSuccessful()
if(result && options.GenerateChangeAuditEvent)
{
// This doesn't work with on-prem
// Submits and audit event about the labeling action to Azure Information Protection Analytics
// handler.NotifyCommitSuccessful(options.FileName);
Console.WriteLine("Commit successful!");
}
return result;
}
catch(Exception ex)
{
Console.WriteLine(ex);
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment