/// <summary> /// Method creates a file handler and returns to the caller. /// IFileHandler implements all labeling and protection operations in the File API. /// </summary> /// <param name="options">Struct provided to set various options for the handler.</param> /// <returns></returns> private IPolicyHandler CreatePolicyHandler(ExecutionStateOptions options) { // Create the handler using options from FileOptions. Assumes that the engine was previously created and stored in private engine object. // There's probably a better way to pass/store the engine, but this is a sample ;) var handler = engine.CreatePolicyHandler(options.generateAuditEvent); return(handler); }
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 }; string newLabelId = string.Empty; string currentLabelId = string.Empty; // 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)); } } } Console.Write("Enter a label ID: "); currentLabelId = Console.ReadLine(); Console.Write("Enter a new label ID: "); newLabelId = Console.ReadLine(); ExecutionStateOptions options = new ExecutionStateOptions(); options.newLabel = action.GetLabelById(currentLabelId); options.actionSource = ActionSource.Manual; options.assignmentMethod = AssignmentMethod.Standard; options.contentFormat = Microsoft.InformationProtection.Policy.ContentFormat.Default; options.contentIdentifier = "MyTestFile.pptx"; options.dataState = DataState.Use; options.isDowngradeJustified = false; options.generateAuditEvent = true; options.metadata = new Dictionary <string, string>(); var initialActions = action.ComputeActions(options); // If you need addition actions, modify GetSupportedActions in ExecutionStateImplementation.cs // Then, iterate through teh actions for the one you care about, say, apply header, footer, or watermark. // From those derived actions, you'll be able to get the content marking information. foreach (var item in initialActions) { switch (item.ActionType) { case ActionType.Metadata: options.metadata.Clear(); foreach (var data in ((MetadataAction)item).MetadataToAdd) { options.metadata.Add(data.Key, data.Value); } break; case ActionType.ProtectByTemplate: options.templateId = ((ProtectByTemplateAction)item).TemplateId; break; default: break; } } options.newLabel = action.GetLabelById(newLabelId); var result = action.ComputeActionLoop(options); Console.WriteLine("Press a key to quit."); Console.ReadKey(); }
public ExecutionStateImplementation(ExecutionStateOptions executionStateOptions) { _executionStateOptions = executionStateOptions; }
public bool ComputeActionLoop(ExecutionStateOptions options) { ExecutionStateImplementation state = new ExecutionStateImplementation(options); var handler = CreatePolicyHandler(options); var actions = handler.ComputeActions(state); while (actions.Count > 0) { Console.WriteLine("Action Count: {0}", actions.Count); foreach (var action in actions) { switch (action.ActionType) { case ActionType.Metadata: var derivedMetadataAction = (MetadataAction)action; if (derivedMetadataAction.MetadataToRemove.Count > 0) { Console.WriteLine("*** Action: Remove Metadata."); //Rather than iterate, in the same we just remove it all. options.metadata.Clear(); } if (derivedMetadataAction.MetadataToAdd.Count > 0) { Console.WriteLine("*** Action: Apply Metadata."); //Iterate through metadata and add to options foreach (var item in derivedMetadataAction.MetadataToAdd) { options.metadata.Add(item.Key, item.Value); Console.WriteLine("*** Added: {0} - {1}", item.Key, item.Value); } } break; case ActionType.ProtectByTemplate: var derivedProtectbyTemplateAction = (ProtectByTemplateAction)action; options.templateId = derivedProtectbyTemplateAction.TemplateId; Console.WriteLine("*** Action: Protect by Template: {0}", derivedProtectbyTemplateAction.TemplateId); break; case ActionType.RemoveProtection: var derivedRemoveProtectionAction = (RemoveProtectionAction)action; options.templateId = string.Empty; Console.Write("*** Action: Remove Protection."); break; case ActionType.Justify: var derivedJustificationAction = (JustifyAction)action; Console.WriteLine("*** Justification Required!"); Console.Write("Provide Justification: "); string justificationMessage = Console.ReadLine(); options.isDowngradeJustified = true; options.downgradeJustification = justificationMessage; break; case ActionType.AddContentFooter: // Any other actions must be explicitly defined after this. default: break; } } state = new ExecutionStateImplementation(options); actions = handler.ComputeActions(state); Console.WriteLine("*** Remaining Action Count: {0}", actions.Count); } if (options.generateAuditEvent && actions.Count == 0) { handler.NotifyCommittedActions(state); } return(true); }
public ReadOnlyCollection <Microsoft.InformationProtection.Policy.Actions.Action> ComputeActions(ExecutionStateOptions options) { var handler = CreatePolicyHandler(options); ExecutionStateImplementation state = new ExecutionStateImplementation(options); var actions = handler.ComputeActions(state); if (actions.Count == 0 && options.generateAuditEvent) { handler.NotifyCommittedActions(state); } return(actions); }