Skip to content

Instantly share code, notes, and snippets.

@CJHarmath
Last active February 25, 2019 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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> {"administrator@adrms.lab.local"}, 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