static void Main(string[] args) { // Create ApplicationInfo, setting the clientID from Azure AD App Registration as the ApplicationId // If any of these values are not set API throws BadInputException. ApplicationInfo appInfo = new ApplicationInfo() { // ApplicationId should ideally be set to the same ClientId found in the Azure AD App Registration. // This ensures that the clientID in AAD matches the AppId reported in AIP Analytics. ApplicationId = clientId, ApplicationName = appName, ApplicationVersion = appVersion }; // Initialize Action class, passing in AppInfo. Action action = new Action(appInfo); // To Do: List Templates when Protection API is available //IEnumerable<Label> labels = action.ListLabels(); // Prompt for path inputs Console.Write("Enter an input file path: "); string inputFilePath = Console.ReadLine(); Console.Write("Enter an output file path: "); string outputFilePath = Console.ReadLine(); var result = MenuOptions.ShowRightsRolesMenu(); // Set file options from FileOptions struct. Used to set various parameters for FileHandler Action.FileOptions options = new Action.FileOptions { FileName = inputFilePath, OutputName = outputFilePath, GenerateChangeAuditEvent = false, IsAuditDiscoveryEnabled = false }; if (result == MenuOptions.DescriptorMethod.Template) { Console.WriteLine("Enter a template ID: "); options.TemplatelId = Console.ReadLine(); } else { options.UserRoles = MenuOptions.BuildUserRoles(); } //Set the label on the file handler object Console.WriteLine(string.Format("Setting protection on {0}", inputFilePath)); // Set label, commit change to outputfile, and send audit event if enabled. var fileResult = action.SetProtection(options); // Create a new handler to read the labeled file metadata. Console.WriteLine(string.Format("Getting the protection details committed to file: {0}", outputFilePath)); // Update options to read the previously generated file output. options.FileName = options.OutputName; // Read label from the previously labeled file. var protectionHandler = action.GetProtectionHandler(options); if (protectionHandler != null) { Console.WriteLine("Owner: {0}", protectionHandler.Owner); Console.WriteLine("IssuedTo: {0}", protectionHandler.IssuedTo); foreach (var right in protectionHandler.Rights) { Console.WriteLine("Right: {0}", right); } Console.WriteLine("Content ID: {0}", protectionHandler.ContentId); Console.WriteLine("Encrypted Data:"); foreach (var kvp in protectionHandler.ProtectionDescriptor.EncryptedAppData) { Console.WriteLine(kvp); } Console.WriteLine("Signed Data:"); foreach (var kvp in protectionHandler.ProtectionDescriptor.SignedAppData) { Console.WriteLine(kvp); } } Console.WriteLine("Press a key to quit."); Console.ReadKey(); }
static void Main(string[] args) { try { // Create ApplicationInfo, setting the clientID from Azure AD App Registration as the ApplicationId // If any of these values are not set API throws BadInputException. ApplicationInfo appInfo = new ApplicationInfo() { // ApplicationId should ideally be set to the same ClientId found in the Azure AD App Registration. // This ensures that the clientID in AAD matches the AppId reported in AIP Analytics. ApplicationId = clientId, ApplicationName = appName, ApplicationVersion = appVersion }; // Initialize Action class, passing in AppInfo. Action action = new Action(appInfo); // List all labels available to the engine created in Action IEnumerable <Label> labels = action.ListLabels(); // Enumerate parent and child labels and print name/ID. foreach (var label in labels) { Console.WriteLine(string.Format("{0} - {1}", label.Name, label.Id)); if (label.Children.Count > 0) { foreach (Label child in label.Children) { Console.WriteLine(string.Format("\t{0} - {1}", child.Name, child.Id)); } } } // Prompt user to enter a label ID from above Console.Write("Enter a label identifier from above: "); var labelId = Console.ReadLine(); // Prompt for path inputs Console.Write("Enter an input file path: "); string inputFilePath = Console.ReadLine(); Console.Write("Enter an output file path: "); string outputFilePath = Console.ReadLine(); // Set file options from FileOptions struct. Used to set various parameters for FileHandler Action.FileOptions options = new Action.FileOptions { FileName = inputFilePath, OutputName = outputFilePath, ActionSource = ActionSource.Manual, AssignmentMethod = AssignmentMethod.Standard, ContentState = ContentState.Rest, GenerateChangeAuditEvent = true, IsAuditDiscoveryEnabled = true, LabelId = labelId }; //Set the label on the file handler object Console.WriteLine(string.Format("Set label ID {0} on {1}", labelId, inputFilePath)); // Set label, commit change to outputfile, and send audit event if enabled. var result = action.SetLabel(options); Console.WriteLine(string.Format("Committed label ID {0} to {1}", labelId, outputFilePath)); // Create a new handler to read the labeled file metadata. Console.WriteLine(string.Format("Getting the label committed to file: {0}", outputFilePath)); // Update options to read the previously generated file output. options.FileName = options.OutputName; // Read label from the previously labeled file. var contentLabel = action.GetLabel(options); // Display the label with protection information. Console.WriteLine(string.Format("File Label: {0} \r\nIsProtected: {1}", contentLabel.Label.Name, contentLabel.IsProtectionAppliedFromLabel.ToString())); Console.WriteLine("Press a key to quit."); Console.ReadKey(); } catch (Exception ex) { Console.WriteLine("****** Error!"); Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } }