/// <summary> /// Locates a policy by object and id. Object is Global, Product, File, Event or Cab. /// </summary> /// <param name="collectionObject">Object type to look for.</param> /// <param name="id">Id of the object.</param> /// <param name="conditionObject">Condition object.</param> /// <param name="objectToCollect">Object to collect.</param> /// <returns>Found policy or null.</returns> public StackHashCollectionPolicy FindPolicy(StackHashCollectionObject rootObject, int id, StackHashCollectionObject conditionObject, StackHashCollectionObject objectToCollect) { Monitor.Enter(this); try { foreach (StackHashCollectionPolicy policy in this) { if ((policy.RootObject == rootObject) && (policy.ConditionObject == conditionObject) && (policy.ObjectToCollect == objectToCollect) && (policy.RootId == id)) { return(policy); } } return(null); } finally { Monitor.Exit(this); } }
/// <summary> /// Locates a policy for the specified cab knowing its product, file and event. /// The policy used will be the cab policy if present, otherwise the next highest level /// object policy in that order. /// </summary> /// <param name="productId">Owning product.</param> /// <param name="fileId">Owning file.</param> /// <param name="eventId">Owning event.</param> /// <param name="cabId">The cab to make a decision on.</param> /// <param name="objectToCollect">Type of the object to collect.</param> /// <param name="conditionObject">Object being compared.</param> /// <returns>One prioritized matching policy.</returns> public StackHashCollectionPolicy FindPrioritizedPolicy(int productId, int fileId, int eventId, int cabId, StackHashCollectionObject objectToCollect, StackHashCollectionObject conditionObject) { if (objectToCollect == StackHashCollectionObject.Any) { throw new ArgumentException("Must specify an object to collect", "objectToCollect"); } if (conditionObject == StackHashCollectionObject.Any) { throw new ArgumentException("Must specify a condition object", "conditionObject"); } Monitor.Enter(this); try { StackHashCollectionPolicy globalPolicy = null; StackHashCollectionPolicy productPolicy = null; StackHashCollectionPolicy eventPolicy = null; StackHashCollectionPolicy filePolicy = null; StackHashCollectionPolicy cabPolicy = null; foreach (StackHashCollectionPolicy policy in this) { if ((objectToCollect != StackHashCollectionObject.Any) && (objectToCollect != policy.ObjectToCollect)) { continue; } if ((conditionObject != StackHashCollectionObject.Any) && (conditionObject != policy.ConditionObject)) { continue; } switch (policy.RootObject) { case StackHashCollectionObject.Global: globalPolicy = policy; break; case StackHashCollectionObject.Product: if (productId == policy.RootId) { productPolicy = policy; } break; case StackHashCollectionObject.File: if (fileId == policy.RootId) { filePolicy = policy; } break; case StackHashCollectionObject.Event: if (eventId == policy.RootId) { eventPolicy = policy; } break; case StackHashCollectionObject.Cab: if (cabId == policy.RootId) { cabPolicy = policy; } break; default: throw new InvalidOperationException("Data collection option not known"); } } // Prioritize from cab up. if (cabPolicy != null) { return(cabPolicy); } else if (eventPolicy != null) { return(eventPolicy); } else if (filePolicy != null) { return(filePolicy); } else if (productPolicy != null) { return(productPolicy); } else if (globalPolicy != null) { return(globalPolicy); } else { return(null); } } finally { Monitor.Exit(this); } }
/// <summary> /// Sets the policies used by the control /// </summary> /// <param name="cabPolicy">Cab collection policy</param> /// <param name="eventPolicy">Event collection policy (optional)</param> /// <param name="level">The actual level of this CollectionPolicyControl</param> /// <param name="overrideId">The Id of the object that will apply to any possible override</param> public void SetPolicies(StackHashCollectionPolicy cabPolicy, StackHashCollectionPolicy eventPolicy, StackHashCollectionObject level, int overrideId) { if (cabPolicy == null) { throw new ArgumentNullException("cabPolicy"); } // OK for eventPolicy to be null _cabPolicy = cabPolicy; _level = level; _rootIdForOverride = overrideId; int hitThreshold = 0; // use labels / checkboxes depending on level if (level == StackHashCollectionObject.Global) { textCabCollectionPolicy.Visibility = Visibility.Visible; textEventPolicy.Visibility = Visibility.Visible; checkBoxCabCollectionPolicy.Visibility = Visibility.Collapsed; checkBoxEventCollectionPolicy.Visibility = Visibility.Collapsed; } else { textCabCollectionPolicy.Visibility = Visibility.Collapsed; textEventPolicy.Visibility = Visibility.Collapsed; checkBoxCabCollectionPolicy.Visibility = Visibility.Visible; checkBoxEventCollectionPolicy.Visibility = Visibility.Visible; } // hide event policy if not specified if (eventPolicy == null) { _eventPolicy = null; textEventPolicy.Visibility = Visibility.Collapsed; labelHitThreshold.Visibility = Visibility.Collapsed; textBoxEventHitThreshold.Visibility = Visibility.Collapsed; checkBoxEventCollectionPolicy.Visibility = Visibility.Collapsed; } else { _eventPolicy = eventPolicy; hitThreshold = _eventPolicy.Minimum; labelHitThreshold.Visibility = Visibility.Visible; textBoxEventHitThreshold.Visibility = Visibility.Visible; } _contextValidation = new ContextValidation(_cabPolicy.Percentage, _cabPolicy.Maximum, hitThreshold, _cabPolicy.CollectLarger, _cabPolicy.CollectionOrder); this.DataContext = _contextValidation; switch (_cabPolicy.CollectionType) { case StackHashCollectionType.All: default: radioButtonAll.IsChecked = true; break; case StackHashCollectionType.Count: radioButtonCount.IsChecked = true; break; case StackHashCollectionType.Percentage: radioButtonPercentage.IsChecked = true; break; case StackHashCollectionType.None: radioButtonNone.IsChecked = true; break; } // determine if the policies are set at this level or inherited if (_cabPolicy.RootObject == _level) { checkBoxCabCollectionPolicy.IsChecked = true; _providedCabPolicyIsAtThisLevel = true; } if ((_eventPolicy != null) && (_eventPolicy.RootObject == _level)) { checkBoxEventCollectionPolicy.IsChecked = true; _providedEventPolicyIsAtThislevel = true; } }
} // Required for serialization. /// <summary> /// Locates all the top priority policies for a partcular collection object. /// Note this may be more than 1. e.g. there may be a cab condition and an event condition for collecting cabs. /// e.g. collect 2 cabs for the top 20 events. /// </summary> /// <param name="productId">Owning product.</param> /// <param name="fileId">Owning file.</param> /// <param name="eventId">Owning event.</param> /// <param name="cabId">The cab to make a decision on.</param> /// <param name="objectToCollect">Type of the object to collect.</param> /// <returns>One prioritized matching policy.</returns> public StackHashCollectionPolicyCollection FindAllPoliciesForObjectBeingCollected(int productId, int fileId, int eventId, int cabId, StackHashCollectionObject objectToCollect) { StackHashCollectionPolicyCollection allPolicies = new StackHashCollectionPolicyCollection(); if (objectToCollect == StackHashCollectionObject.Any) { throw new ArgumentException("Must specify an object to collect", "objectToCollect"); } Monitor.Enter(this); try { foreach (StackHashCollectionObject conditionObject in Enum.GetValues(typeof(StackHashCollectionObject))) { // Only check specific ones. if (conditionObject == StackHashCollectionObject.Any) { continue; } StackHashCollectionPolicy policy = FindPrioritizedPolicy(productId, fileId, eventId, cabId, objectToCollect, conditionObject); if (policy != null) { allPolicies.Add(policy); } } return(allPolicies); } finally { Monitor.Exit(this); } }
public static DisplayCollectionPolicy FindPolicy(List <StackHashCollectionPolicy> policies, int productId, int fileId, int eventId, int cabId, StackHashCollectionObject objectToCollect, StackHashCollectionObject conditionObject) { if (policies == null) { throw new ArgumentNullException("policies"); } if (objectToCollect == StackHashCollectionObject.Any) { throw new ArgumentException("Must specify an object to collect", "objectToCollect"); } if (conditionObject == StackHashCollectionObject.Any) { throw new ArgumentException("Must specify a condition object", "conditionObject"); } DisplayCollectionPolicy displayPolicy = null; StackHashCollectionPolicy globalPolicy = null; StackHashCollectionPolicy productPolicy = null; StackHashCollectionPolicy eventPolicy = null; StackHashCollectionPolicy filePolicy = null; StackHashCollectionPolicy cabPolicy = null; foreach (StackHashCollectionPolicy policy in policies) { if ((objectToCollect != StackHashCollectionObject.Any) && (objectToCollect != policy.ObjectToCollect)) { continue; } if ((conditionObject != StackHashCollectionObject.Any) && (conditionObject != policy.ConditionObject)) { continue; } switch (policy.RootObject) { case StackHashCollectionObject.Global: globalPolicy = policy; break; case StackHashCollectionObject.Product: if (productId == policy.RootId) { productPolicy = policy; } break; case StackHashCollectionObject.File: if (fileId == policy.RootId) { filePolicy = policy; } break; case StackHashCollectionObject.Event: if (eventId == policy.RootId) { eventPolicy = policy; } break; case StackHashCollectionObject.Cab: if (cabId == policy.RootId) { cabPolicy = policy; } break; default: throw new InvalidOperationException("Data collection option not known"); } } // Prioritize from cab up. if (cabPolicy != null) { displayPolicy = new DisplayCollectionPolicy(cabPolicy); } else if (eventPolicy != null) { displayPolicy = new DisplayCollectionPolicy(eventPolicy); } else if (filePolicy != null) { displayPolicy = new DisplayCollectionPolicy(filePolicy); } else if (productPolicy != null) { displayPolicy = new DisplayCollectionPolicy(productPolicy); } else if (globalPolicy != null) { displayPolicy = new DisplayCollectionPolicy(globalPolicy); } else { throw new InvalidOperationException("Failed to find matching data collection policy"); } return(displayPolicy); }