public TestContenItemControl(UIContentItem contentItem) { m_contentItem = contentItem; m_contentItem.StateChanged += new UIObjectStateChangedDelegate(m_contentItem_StateChanged); m_clientActionControl = m_contentItem.ClientActionControl; m_clientActionControl.ApplyToAllClicked += new EventHandler<EventArgs>(ctrl_ApplyToAllClicked); m_clientActionControl.ActionProperties = m_contentItem.ActionPropertySet; }
/// <summary> /// Returns whether the content item and all its children are to be processed transparently /// </summary> /// <param name="name"></param> /// <returns></returns> private static bool ProcessTransparently(UIContentItem parent) { if (parent == null || !parent.Transparent) { return false; } foreach (UIContentItem child in parent.ChildContentItems.Values) { if (!ProcessTransparently(child)) { return false; } } return true; }
/// <summary> /// Doctors the "ApplyToAll" ActionProperty value. /// </summary> /// <param name="contentItem"></param> /// <param name="applyToAll"></param> private static void SetApplyToAll(UIContentItem contentItem, bool applyToAll) { if (contentItem == null) { throw new ArgumentNullException("contentItem"); } IActionProperty applyToAllProperty = contentItem.GetClientActionProperty(PropertyNames.ApplyToAll); if (applyToAllProperty != null) { applyToAllProperty.Value = applyToAll; } }
/// <summary> /// For each of the given UIContentItem and its children, adds a SummaryContentControl row /// to the list, or updates the row to Completed state if it's already there /// </summary> /// <param name="action"></param> /// <param name="parent"></param> private void IterateContentItems(UIAction action, UIContentItem item) { if (item.ContainsPolicyViolation()) { SummaryContentControl control = m_summaryContentControlList.Find(c => c.ContentId == item.Id); if (control == null && item.ContentType == ContentTypeEnum.Email.ToString()) { // This could be the item for the email subject/body itself (not an attachment). // Look for a placeholder item added earlier (when we didn't have the Id available). control = m_summaryContentControlList.Find(c => c.TitleText == item.Name); } if (control == null) { // The control wasn't created before scanning: add it now control = AddNewContentControl(item.Id, item.DisplayName, item.ContentType, true); } // Either the control was just created, or it was a placeholder // created during dynamic-discovery scanning. // Make sure it has the outcome of the scan for each action type string actionType = Dialogs.Utilities.MapActionToActionType(action); if (!control.ContentItems.ContainsKey(actionType)) { control.ContentItems.Add(actionType, item); } string parentActionType = Dialogs.Utilities.MapActionToActionType(item.Action); if (!control.ContentItems.ContainsKey(parentActionType)) { control.ContentItems.Add(parentActionType, item); } bool execute = true; { IActionProperty actionProperty; item.ActionPropertySet.TryGetValue(PropertyNames.Execute, out actionProperty); ActionPropertyFacade executeProperty = actionProperty as ActionPropertyFacade; if (executeProperty != null) { execute = Convert.ToBoolean(executeProperty.Value, CultureInfo.InvariantCulture); } } foreach (UIPolicy policy in item.Policies.Values) { if (!policy.Triggered) { continue; } control.AddPolicy(policy.Name); control.AddRisk(policy.HighestRating); control.AddAction(actionType, execute); if (!control.SelectionContexts.ContainsKey(actionType)) { control.SelectionContexts.Add(actionType, true); } control.ScanCompleted = true; } } foreach (UIContentItem child in item.ChildContentItems.Values) { IterateContentItems(action, child); } }
protected bool HandleApplyToAllClick(UIContentItem parent) { Control[] controls = parent.ClientActionControl.Controls.Find("cbApplyToAll", true); if (controls.Length > 0) { CheckBox checkBox = null; int i = 0; while (checkBox == null) { checkBox = controls[i++] as CheckBox; } if (checkBox != null) { checkBox.Checked = true; return true; } } foreach (UIContentItem contentItem in parent.ChildContentItems.Values) { if (HandleApplyToAllClick(contentItem)) return true; } return false; }
public SelectedContentItemsChangedArgs(UIContentItem[] selectedContentItems, bool allSelected) { m_allSelected = allSelected; m_selectContentItems = (selectedContentItems ?? new UIContentItem[0]); }
public MockTransparentContentItemControl(UIContentItem contentItem) : base(contentItem) { ContentItem.ActionPropertySet[PropertyNames.Transparent].Value = bool.TrueString; }
/// <summary> /// Returns whether the content item or any of its children contain the specified content type /// </summary> /// <remarks> /// The comparison of the content type is not case-sensitive. /// Only leaf (non-container) nodes are tested. /// </remarks> /// <returns></returns> private static bool ContainsContentType(UIContentItem parent, string contentType) { if (parent == null) { return false; } if (!parent.Container && string.Compare(parent.ContentType, contentType, StringComparison.InvariantCultureIgnoreCase) == 0) { return true; } foreach (UIContentItem child in parent.ChildContentItems.Values) { if (ContainsContentType(child, contentType)) { return true; } } return false; }
/// <summary>| /// We need this to handle the recursive parenting. /// </summary> /// <param name="response">The <see cref="Workshare.PolicyContent.Response"/></param> /// <param name="uiAction">The <see cref="UIAction"/> object for the content item</param> /// <param name="action">The <see cref="Workshare.PolicyContent.Action"/> object for the content item</param> /// <param name="contentItem"></param> /// <returns></returns> private static UIContentItem HandleParentContentItems(Response response, UIAction uiAction, PolicyContent.Action action, ContentItem contentItem) { UIContentItem parent = uiAction.GetContentItemById(contentItem.ParentId); if (parent == null) { CustomProperty parentIndex = Array.Find(contentItem.Properties, p => p.Name == "ParentIndex"); int index = (parentIndex == null ? -1 : Int32.Parse(parentIndex.Value)); if (index > -1) { parent = new UIContentItem(response.Contents[index], action, true); } if (parent != null) { if (parent.ParentId == null) { uiAction.ContentItems[parent.Id] = parent; } else { UIContentItem grandparent = HandleParentContentItems(response, uiAction, action, parent.ContentItem); grandparent.ChildContentItems[parent.Id] = parent; } } } return parent; }
/// <summary> /// Returns the UIContentItem in the given tree that has the specified name /// </summary> /// <param name="contentItem">The root of the tree to search</param> /// <param name="name">The name to look for</param> /// <returns>The matching UIContentItem if found, otherwise null</returns> public static UIContentItem GetContentItemByName(UIContentItem contentItem, string name) { if (contentItem == null) { return null; } if (contentItem.Name == name) { return contentItem; } foreach (UIContentItem child in contentItem.ChildContentItems.Values) { UIContentItem result = GetContentItemByName(child, name); if (result != null) { return result; } } return null; }
/// <summary> /// Returns the UIContentItem in the given tree that has the specified id /// </summary> /// <param name="contentItem">The root of the tree to search</param> /// <param name="id">The id to look for</param> /// <returns>The matching UIContentItem if found, otherwise null</returns> public static UIContentItem GetContentItemById(UIContentItem contentItem, string id) { if (contentItem == null) { return null; } if (contentItem.Id == id) { return contentItem; } foreach (UIContentItem child in contentItem.ChildContentItems.Values) { UIContentItem result = GetContentItemById(child, id); if (result != null) { return result; } } return null; }
public ExecuteActionPropertyChangedArgs(UIContentItem contentItem, bool execute) { m_contenItem = contentItem; m_execute = execute; }
protected void HandleContentItems(UIAction action, UIContentItem parent) { bool allowExecuteOverride = parent.AllowOverride(PropertyNames.Execute); bool isContainerContentItem = parent.IsContainerContentItem(); MockContenItemControl ctrl = m_transparent ? new MockTransparentContentItemControl(parent) : new MockContenItemControl(parent); ctrl.ApplyToAll += new ApplyToAllDelegate(action.HandleApplyToAll); m_controls.Add(ctrl); foreach (UIContentItem child in parent.ChildContentItems.Values) { HandleContentItems(action, child); } }
protected static void SetExecute(UIContentItem parent, bool value) { parent.Execute = value; foreach (UIContentItem child in parent.ChildContentItems.Values) { SetExecute(child, value); } }
/// <summary> /// Returns whether the content item or any of its children require an application controller /// </summary> /// <param name="name"></param> /// <returns></returns> private static bool RequiresApplicationController(UIContentItem parent) { if (parent == null) { return false; } if (parent.RequiresApplicationController) { return true; } foreach (UIContentItem child in parent.ChildContentItems.Values) { if (RequiresApplicationController(child)) { return true; } } return false; }
/// <summary> /// Prepares a <see cref="Workshare.Policy.ClientManager.ObjectModel.UIResponse"/> object based on the supplied <see cref="Response"/> /// </summary> /// <param name="request">A <see cref="Workshare.PolicyContent.Request"/> the request that the content scanner recieved when it generate the response</param> /// <param name="response">A <see cref="Workshare.PolicyContent.Response"/> object to parse</param> /// <returns>A fully populated <see cref="Workshare.Policy.ClientManager.ObjectModel.UIResponse"/> object</returns> public static UIResponse UIResponseFromResponse(Request request, Response response) { if (response == null) { throw new ArgumentNullException("response"); } UIResponse uiResponse = new UIResponse(request, response); uiResponse.Initialize(); ResolvedAction[] resolvedActions = response.ResolvedActions ?? new ResolvedAction[0]; #region The loops foreach (ResolvedAction resolvedAction in resolvedActions) { foreach (ContentItem contentItem in resolvedAction.Contents) { foreach (PolicySet policySet in contentItem.PolicySets) { foreach (Workshare.PolicyContent.Policy policy in policySet.Policies) { if (!policy.Triggered) continue; foreach (Workshare.PolicyContent.Action action in policy.Actions) { #region Is Action valid if (action.Type != resolvedAction.Action.Type) { continue; } if (!Array.Exists(action.Properties, c => c.Name == "ExceptionAction")) { continue; } #endregion #region Create UIAction UIAction uiAction; uiResponse.Actions.TryGetValue(action.Type, out uiAction); if (uiAction == null) { uiAction = new UIAction(resolvedAction); uiResponse.Actions[action.Type] = uiAction; } #endregion #region Create UIContent & add to UIAction // First try and find the parent. UIContentItem uiParentContentItem = HandleParentContentItems(response, uiAction, action, contentItem); UIContentItem uiContentItem = null; if (uiParentContentItem == null) { uiContentItem = uiAction.GetContentItemById(contentItem.Id); if (uiContentItem == null) { uiContentItem = new UIContentItem(contentItem, action); } uiAction.ContentItems[uiContentItem.Name] = uiContentItem; } else { uiContentItem = UIContentItem.GetContentItemById(uiParentContentItem, contentItem.Id); if (uiContentItem == null) { uiContentItem = new UIContentItem(contentItem, action); } uiParentContentItem.ChildContentItems[uiContentItem.Id] = uiContentItem; } uiContentItem.Container = false; #endregion #region Create UIPolicy & add to UIContentItem UIPolicy uiPolicy; uiContentItem.Policies.TryGetValue(policy.Name, out uiPolicy); if (uiPolicy == null) { uiPolicy = new UIPolicy(policySet, policy); uiContentItem.Policies[policy.Name] = uiPolicy; } uiPolicy.Actions.Add(uiAction); #endregion #region Is this UIAction a blocking action? if (uiAction.IsBlockingAction() && !uiResponse.BlockingActions.Contains(uiAction)) { uiResponse.BlockingActions.Add(uiAction); } #endregion } } } } } #endregion try { // The initialization will call Initialize on all contained objects. uiResponse.Initialize(); } catch { uiResponse = null; } return uiResponse; }
/// <summary> /// Returns whether the content item or any of its children contain policy violations /// </summary> /// <returns></returns> private static bool ContainsViolations(UIContentItem parent) { if (parent == null) { return false; } if (parent.ContainsPolicyViolation()) { return true; } foreach (UIContentItem child in parent.ChildContentItems.Values) { if (ContainsViolations(child)) { return true; } } return false; }
private void IterateContentItems(UIAction action, UIContentItem parent) { switch (Dialogs.Utilities.MapActionToActionType(action)) { case "CLEAN": RemoveCommentsEnabled = true; RemoveTrackChangesEnabled = true; SkipOfficeCleaningEnabled = true; break; case "PDFCLEAN": SkipPdfCleaningEnabled = true; break; case "PDF": PDFOptionsEnabled = true; break; } foreach (UIPolicy policy in parent.Policies.Values) { if (!policy.Triggered) { continue; } if (!policy.Actions.Exists(item => item.Name == action.Name)) { continue; } SortedList<string, List<UICondition>> conditions; m_triggeredPolicies.TryGetValue(parent.Id, out conditions); if (conditions == null) { conditions = new SortedList<string, List<UICondition>>(); m_triggeredPolicies[parent.Id] = conditions; } if (conditions.ContainsKey(policy.Name)) { continue; } List<UICondition> expressions = new List<UICondition>(); foreach (UICondition condition in policy.Conditions.Values) { UIExpression expression = condition as UIExpression; if (expression != null) { expressions.Add(expression); } } conditions[policy.Name] = expressions; if (m_totalRiskRating < policy.HighestRating) { m_totalRiskRating = policy.HighestRating; } } foreach (UIContentItem contentItem in parent.ChildContentItems.Values) { IterateContentItems(action, contentItem); } }
/// <summary> /// For all content items in the given tree that are of the same ContentType as the master, /// copies the values of all properties defined in both items (except EXECUTE) /// from the master item to the item in the tree /// </summary> /// <param name="parent"></param> /// <param name="master"></param> private void ApplyToAll(UIContentItem parent, UIContentItem master) { if (parent == null || master == null) { return; } if (parent != master && parent.ContentType == master.ContentType) { foreach (var masterProp in master.ActionPropertySet) { if (masterProp.Key == PropertyNames.Execute) { continue; } Workshare.Policy.Action.IActionProperty prop; if (parent.ActionPropertySet.TryGetValue(masterProp.Key, out prop)) { prop.Value = masterProp.Value; } } parent.OnStateChanged(new UIObjectStateChangedArgs(parent)); } foreach (UIContentItem child in parent.ChildContentItems.Values) { ApplyToAll(child, master); } }
private void ConfigureOfficeCleanOptions(UIContentItem contentItem, ref TriState tsWord, ref TriState tsExcel, ref TriState tsPpt, ref TriState tsDefault, ref bool firstClean) { IActionProperty executeProperty = contentItem.GetClientActionProperty(PropertyNames.Execute); if (executeProperty == null) { return; } bool execute = Convert.ToBoolean(executeProperty.Value, CultureInfo.InvariantCulture); // Remove Comments IActionProperty removeCommentsProperty = contentItem.GetClientActionProperty(PropertyNames.Comments); bool removeComments = (removeCommentsProperty != null && Convert.ToBoolean(removeCommentsProperty.Value, CultureInfo.InvariantCulture)); SetCheckBoxCheckState(removeCommentsCheckBox, removeComments, firstClean); // Remove Track changes IActionProperty removeTrackChangesProperty = contentItem.GetClientActionProperty(PropertyNames.TrackChanges); bool removeTrackChanges = (!skipOfficeCleaningCheckBox.Checked && removeTrackChangesProperty != null && Convert.ToBoolean(removeTrackChangesProperty.Value, CultureInfo.InvariantCulture)); SetCheckBoxCheckState(removeTrackChangesCheckBox, removeTrackChanges, firstClean); // Skip cleaning MasterSkipCleaningEnabled = SkipOfficeCleaningEnabled = executeProperty.Override; SetCheckBoxCheckState(skipOfficeCleaningCheckBox, !execute, firstClean); RemoveCommentsEnabled = (execute && !skipOfficeCleaningCheckBox.Checked && removeCommentsProperty != null && removeCommentsProperty.Override && removeCommentsProperty.Visible); ContentTypeEnum contentType = ContentTypeEnum.Unknown; if (!string.IsNullOrEmpty(contentItem.ContentType)) { try { contentType = (ContentTypeEnum) Enum.Parse(typeof(ContentTypeEnum), contentItem.ContentType); } catch { } } FindRemoveTrackChangesState(contentType, removeTrackChangesProperty, execute, ref tsWord, ref tsExcel, ref tsPpt, ref tsDefault); firstClean = false; officeHiddenDataOptionsLinkLabel.Enabled = true; }
public SelectedContentItemsChangedArgs(UIContentItem[] selectedContentItems) : this(selectedContentItems, false) { }
private void ConfigurePdfCleanOptions(UIContentItem contentItem, ref bool firstClean) { IActionProperty executeProperty = contentItem.GetClientActionProperty(PropertyNames.Execute); if (executeProperty == null) { return; } bool execute = Convert.ToBoolean(executeProperty.Value, CultureInfo.InvariantCulture); // Skip cleaning MasterSkipCleaningEnabled = SkipPdfCleaningEnabled = executeProperty.Override; SetCheckBoxCheckState(skipPdfCleaningCheckBox, !execute, firstClean); firstClean = false; pdfHiddenDataOptionsLinkLabel.Enabled = true; }
public ApplyToAllArgs(UIContentItem contentItem) { m_contentItem = contentItem; }
public void AddClientActionControl(UIContentItem contentItem) { m_contentItems.Add(contentItem); IActionPropertySet propertySet = contentItem.ActionPropertySet; ClientActionControl clientActionControl = contentItem.ClientActionControl; m_containsApplyToAll = true; // Doctor the action property set to make the "ApplyToAll" property invisible. try { IActionProperty prop; propertySet.TryGetValue("ApplyToAll", out prop); ActionPropertyFacade applyToAllProperty = (ActionPropertyFacade) prop; if (applyToAllProperty == null) { m_containsApplyToAll = false; m_selectAllState = true; m_selectAllOverride = true; } else { applyToAllProperty.Visible = false; m_selectAllOverride = false; if ((applyToAllProperty.Override == false) && ((bool)applyToAllProperty.Value)) { m_selectAllState = true; m_selectAllOverride = true; } } } catch (InvalidCastException ice) { Logger.LogError("Invalid cast: UIContentItem.PropertySet[\"ApplyToAll\"] not ActionPropertyFacade"); Logger.LogError(ice); } // Build the APPLYTOALL ClientActionControl if (m_applyToAllClientActionControl == null) { // HACK: Stops us creating the UIContentItem.ClientActionControl .... m_applyToAllClientActionControl = m_containsApplyToAll ? contentItem.Action.Action2.ClientActionControl : clientActionControl; m_applyToAllClientActionControl.Size = new Size(350, m_applyToAllClientActionControl.Height); m_applyToAllClientActionControl.Dock = DockStyle.Top; clientActionControlContainerPanel.Controls.Add(m_applyToAllClientActionControl); m_applyToAllClientActionControl.ApplyToAllClicked += clientActionControl_ApplyToAllClicked; m_applyToAllClientActionControl.Visible = false; m_controls.Add(m_applyToAllClientActionControl); } if (m_containsApplyToAll) { if (m_applyToAllActionPropertySet == null) { m_applyToAllActionPropertySet = new ActionPropertySet(); } MergePropertySets(propertySet, m_applyToAllActionPropertySet, m_contentItems.Count == 0); } else { m_applyToAllActionPropertySet = propertySet; } // Now we have the final propertySet we can assign it. clientActionControl.ActionProperties = propertySet; // Build the APPLYTOALL Execute Checkbox if (m_applyToAllExecuteCheckBox == null) { m_applyToAllExecuteCheckBox = new CheckBox(); m_applyToAllExecuteCheckBox.Text = Properties.Resources.APPLY_ACTION_TEXT; m_applyToAllExecuteCheckBox.Dock = DockStyle.Left; m_applyToAllExecuteCheckBox.AutoSize = true; m_applyToAllExecuteCheckBox.Name = "APPLYTOALL"; m_applyToAllExecuteCheckBox.Visible = executePanel.Controls.Count == 0; m_applyToAllExecuteCheckBox.CheckedChanged += executeCheckBox_CheckedChanged; // Hook up the execute executePanel.Controls.Add(m_applyToAllExecuteCheckBox); IActionProperty executeProperty; m_applyToAllActionPropertySet.TryGetValue(PropertyNames.Execute, out executeProperty); if (executeProperty != null) { ExecutePropertyController.Hook(executeProperty, m_applyToAllExecuteCheckBox, "CheckedChanged", "Checked"); } m_applyToAllClientActionControl.Tag = m_applyToAllExecuteCheckBox; m_applyToAllExecuteCheckBox.Tag = m_applyToAllClientActionControl; } if (!m_containsApplyToAll) return; // Check to see if the client action control instance already exists as some of the actions // have implemented a singleton for the ClientActionControl. This has consequences when attempting // sync of ActionProperty's. if (m_controls.Contains(clientActionControl)) { m_singleton = true; } CheckBox executeCheckBox = new CheckBox(); executeCheckBox.Text = Properties.Resources.APPLY_ACTION_TEXT; executeCheckBox.Dock = DockStyle.Left; executeCheckBox.AutoSize = true; executeCheckBox.Name = contentItem.Id; executeCheckBox.Visible = executePanel.Controls.Count == 0; executeCheckBox.CheckedChanged += executeCheckBox_CheckedChanged; // Hook up the execute executePanel.Controls.Add(executeCheckBox); IActionProperty execProperty; propertySet.TryGetValue(PropertyNames.Execute, out execProperty); if (execProperty != null) { ExecutePropertyController.Hook(execProperty, executeCheckBox, "CheckedChanged", "Checked"); } // Add client action control to the checkbox TAG executeCheckBox.Tag = clientActionControl; if (m_singleton) return; clientActionControl.Name = contentItem.Id; clientActionControl.Tag = executeCheckBox; clientActionControl.Size = new Size(350, clientActionControl.Height); clientActionControl.Dock = DockStyle.Top; clientActionControlContainerPanel.Controls.Add(clientActionControl); m_controls.Add(clientActionControl); clientActionControl.Visible = false; // We're only doing this here to ensure the control has a stab at setup before the initial display. // For some ClientActionControl implementations this does not work as the Visible property for controls // is linked to Parent.Visisble and makes the control !Visible regardless of any assignment. }