private bool ProcessPrematureResponse() { // Means scanning has not completed yet, and the user has pressed Send // We gonna scrap discovery stuff, and apply pre-set actions m_threadKiller.Abort(); m_skipDiscovery = true; InitializeEngine(); if (m_encryptionManager == null) { m_encryptionManager = new ContentEncryptionManager(_msgExpander, _msgPacker); } if (!m_encryptionManager.DecryptRequestAttachments(m_request, m_encryptionUi)) { m_processResult = ProcessResult.CANCELLED; return false; } m_response = CallContentScanner(); m_uiResponse = ResponseAdapter.UIResponseFromResponse(m_request, m_response); m_policyClientDialog.SetResponse(m_uiResponse); // Check for violations if (m_uiResponse != null && !m_uiResponse.ContainsViolations()) { m_processResult = ProcessResult.NO_VIOLATIONS; return false; } // Check for Actions in uiResponse if (m_uiResponse != null && m_uiResponse.Actions.Count <= 0) { m_processResult = ProcessResult.NO_ACTIONS; return false; } m_processResult = ProcessResult.UNDEFINED; CreateOfficeApplicationsUsingUroAttachments(); return true; }
private void PrepareProtectSimpleResponse(string profileLocation) { InitializeEngine(); AddProtectSimpleProfile(profileLocation); // A profile is a policy, but we chose to call it a Profile :) if (m_encryptionManager == null) { m_encryptionManager = new ContentEncryptionManager(_msgExpander, _msgPacker); } if (m_encryptionUi != null) { m_encryptionUi.OnShowDialog += new ShowDialogEvent(m_encryptionUi_OnShowDialog); } if (!m_encryptionManager.DecryptRequestAttachments(m_request, m_encryptionUi)) { if (!string.IsNullOrEmpty(m_encryptionManager.LastErrorText)) { m_errors.Add(ErrorAsDialogTextKey + m_encryptionManager.LastErrorText);// prepend ErrorAsDialogTextKey constant so that we DO display the message to the user m_encryptionManager.LastErrorText = string.Empty; m_processResult = ProcessResult.ERRORS; m_bUpdateProcessResult = false; } else { m_processResult = ProcessResult.CANCELLED; } return; } m_response = CallContentScanner(); ResponseAnalyser.CollectAndSendEvents(m_response, ResponseAnalyser.EventType.PolicySet); m_uiResponse = ResponseAdapter.UIResponseFromResponse(m_request, m_response); // hey, you know what - something might have gone wrong in that content scanning. Let's check object[] errors = m_uiResponse.GetErrors(); if (errors.Length > 0) { // wow! something bad did happen. Better report it back to the user RecordDiscoveryErrors(errors); return; } string reason = string.Empty; if (!m_uiResponse.Synchronize(out reason)) { Logger.LogError("Unable to synchronize responses. Reason = " + reason); m_processResult = ClientManager.ProcessResult.ERRORS; return; } // Check for violations if (m_uiResponse != null && !m_uiResponse.ContainsViolations()) { m_processResult = ProcessResult.NO_VIOLATIONS; return; } // Check for Actions in uiResponse if (m_uiResponse != null && m_uiResponse.Actions.Count <= 0) { m_processResult = ProcessResult.NO_ACTIONS; return; } m_processResult = ProcessResult.UNDEFINED; CreateOfficeApplicationsUsingUroAttachments(); return; }
public ProcessResponseActionsArgs(UIResponse uiResponse) { m_uiResponse = uiResponse; }
private bool GetResponse() { object[] errors = null; try { m_response = CallContentScanner(); ResponseAnalyser.CollectAndSendEvents(m_response, ResponseAnalyser.EventType.PolicySet); if (m_response == null) { Logger.LogError("RequestManager.GetResponse(): ContentScanner returned null"); m_processResult = ProcessResult.ERROR_SCAN_FAILURE;// Indicate total scanning failure. return false; } m_uiResponse = ResponseAdapter.UIResponseFromResponse(m_request, m_response); errors = m_uiResponse.GetErrors(); if (errors.Length == 0) { return true; } } catch (Exception ex) { Logger.LogError(ex); } RecordDiscoveryErrors(errors); return false; }
/// <summary> /// Validates and returns the <see cref="Workshare.PolicyContent.Response"/> object within the <see cref="Workshare.Policy.ClientManager.Object.UIResponse"/> /// </summary> /// <param name="uiResponse">A prepared <see cref="Workshare.Policy.ClientManager.Object.UIResponse"/></param> /// <returns>The internal <see cref="Workshare.PolicyContent.Response"/> if it was able to be validated, otherwise null</returns> public static Response ResponseFromUIResponse(UIResponse uiResponse) { if (uiResponse == null) { throw new ArgumentNullException("uiResponse"); } if (uiResponse.Response == null) { throw new InvalidOperationException("uiResponse does not contain a Response"); } string reason = string.Empty; if (!uiResponse.Synchronize(out reason)) { return null; } // Now we have to reconcile the return uiResponse.Response; }
/// <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; }
public PreviewResponseActionArgs(UIResponse uiResponse, string docID, SortedList<string, bool> actions) { m_uiResponse = uiResponse; m_docID = docID; m_actions = actions; }
/// <summary> /// Fiddles with the response before setting the internal reference. /// </summary> /// <remarks> /// In here we are taking a peek at the operation flags and fiddling with the response /// action content items based on the presence or absence of particular values. /// So; if the PDF value is absent then we will disable the PDF action for all the content. /// If it is present then we will fiddle with some values. /// The test will then compare the actionproperties for the policy actions for the content item /// in the real response versus those in the uiresponse to ensure that things have synchronized properly. /// </remarks> /// <param name="response"></param> public void SetResponse(Workshare.Policy.ClientManager.ObjectModel.UIResponse response) { #region LightSpeed Clean if ((m_ops & TestPolicyClientDialogOperationsEnum.LightSpeedClean) != 0) { } else { UIAction action = response.Actions.ContainsKey("LightSpeed Clean") ? response.Actions["LightSpeed Clean"] : null; foreach (string contentItemName in m_contentItems) { if (action != null) { UIContentItem contentItem = action.GetContentItemByName(contentItemName); if (contentItem != null) { SetExecute(contentItem, false); } } } } #endregion #region PDF if ((m_ops & TestPolicyClientDialogOperationsEnum.PDF) != 0) { // Play with PDF a bit UIAction action = response.Actions.ContainsKey("PDF") ? response.Actions["PDF"] : null; foreach (string contentItemName in m_contentItems) { if (action != null) { UIContentItem contentItem = action.GetContentItemByName(contentItemName); if (contentItem != null) { contentItem.ActionPropertySet[Workshare.Policy.Actions.PdfActionStringTable.ProhibitComments].Value = bool.TrueString; contentItem.ActionPropertySet[Workshare.Policy.Actions.PdfActionStringTable.ProhibitCopy].Value = bool.TrueString; contentItem.ActionPropertySet[Workshare.Policy.Actions.PdfActionStringTable.PasswordRequired].Value = bool.TrueString; contentItem.ActionPropertySet[Workshare.Policy.Actions.PdfActionStringTable.Password].Value = "Password01"; } } } } else // If the PDF action is there disable it { UIAction action = response.Actions.ContainsKey("PDF Action") ? response.Actions["PDF Action"] : null; foreach (string contentItemName in m_contentItems) { if (action != null) { UIContentItem contentItem = action.GetContentItemByName(contentItemName); if (contentItem != null) { contentItem.Execute = false; } } } } #endregion #region ZIP if ((m_ops & TestPolicyClientDialogOperationsEnum.ZIP) != 0) { } else { UIAction action = response.Actions.ContainsKey("ZIP") ? response.Actions["ZIP"] : null; foreach (string contentItemName in m_contentItems) { if (action != null) { UIContentItem contentItem = action.GetContentItemByName(contentItemName); if (contentItem != null) { contentItem.Execute = false; } } } } #endregion #region SmartTag if ((m_ops & TestPolicyClientDialogOperationsEnum.SmartTag) != 0) { } else { UIAction action = response.Actions.ContainsKey("SmartTag") ? response.Actions["SmartTag"] : null; foreach (string contentItemName in m_contentItems) { if (action != null) { UIContentItem contentItem = action.GetContentItemByName(contentItemName); if (contentItem != null) { IActionProperty iProperty; contentItem.ActionPropertySet.TryGetValue(PropertyNames.Execute, out iProperty); Workshare.PolicyContent.ActionProperty property = iProperty as Workshare.PolicyContent.ActionProperty; if (property != null) { property.Value = bool.FalseString; } } } } } #endregion foreach (UIAction action in response.Actions.Values) { foreach (UIContentItem contenItem in action.ContentItems.Values) { HandleContentItems(action, contenItem); } } if (!MockContenItemControl.ApplyToAllFired) { if ((m_ops & TestPolicyClientDialogOperationsEnum.ApplyToAll) != 0) { foreach (UIAction action in response.Actions.Values) { foreach (UIContentItem contentItem in action.ContentItems.Values) { if (HandleApplyToAllClick(contentItem)) break; } } } } m_response = response; }
public static bool CompareResponseAndUIResponse(Response response, UIResponse uiResponse) { Assert.IsNotNull(uiResponse, "ResponseAdapter failed to convert Response to UIResponse"); Assert.IsTrue(uiResponse.PolicyType == (Workshare.Policy.PolicyType)Enum.Parse(typeof(Workshare.Policy.PolicyType), response.PolicyType), string.Format("PolicyType should be {0}", response.PolicyType)); int resolvedActionCount = response.ResolvedActions != null ? response.ResolvedActions.Length : 0; Assert.IsTrue(uiResponse.Actions.Count == resolvedActionCount, "response.ResolvedActions.Length count should be equal to uiResponse.Actions.Count"); ResolvedAction[] resolvedActions = response.ResolvedActions == null ? new ResolvedAction[0] : response.ResolvedActions; foreach (ResolvedAction resolvedAction in resolvedActions) { foreach (Workshare.PolicyContent.ContentItem contentItem in resolvedAction.Contents) { foreach (PolicySet policySet in contentItem.PolicySets) { foreach (Workshare.PolicyContent.Policy policy in policySet.Policies) { foreach (Workshare.PolicyContent.Action action in policy.Actions) { UIAction uiAction = uiResponse.Actions.ContainsKey(action.Type) ? uiResponse.Actions[action.Type] : null; Assert.IsNotNull(uiAction, string.Format("Action [{0}] missing from uiResponse", action.Type)); if (uiAction != null) { UIContentItem uiContentItem = uiAction.GetContentItemById(contentItem.Id); Assert.IsNotNull(uiContentItem, string.Format("UIContentItem [{0}] not found", contentItem.Name)); if (uiContentItem != null) { UIPolicy uiPolicy = uiContentItem.Policies.ContainsKey(policy.Name) ? uiContentItem.Policies[policy.Name] : null; Assert.IsNotNull(uiPolicy, string.Format("UIContentItem [{0}] missing UIPolicy [{1}]", uiContentItem.Name, policy.Name)); if (uiPolicy != null) { UICondition condition = uiPolicy.Conditions.ContainsKey(response.Routing != null ? policy.Routing.Name : string.Empty) ? uiPolicy.Conditions[policy.Routing.Name] : null; if (response.Routing != null) { Assert.IsNotNull(condition, string.Format("UICondition [{0}] not found in UIPolicy [{1}]", policy.Routing.Name, uiPolicy.Name)); } foreach (Expression expression in policy.Expressions) { if (expression.Triggered) { condition = uiPolicy.Conditions.ContainsKey(expression.Name) ? uiPolicy.Conditions[expression.Name] : null; Assert.IsNotNull(condition, string.Format("UICondition [{0}] not found for policy [{1}]", expression.Name, uiPolicy.Name)); } } } } } } } } } } return true; }