Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }