/// <summary> /// Evaluate the file type expressions within a collection of IPolicyObjects to determine whether they are valid. /// For now, we assume that the collection of IPolicyObjects will consist of IConditionGroups only. If there are /// other IPolicyObject types in the collection, these will not be validated. /// </summary> /// <param name="conditions">The IPolicyObject to evaluate</param> /// <returns>True if all file type expressions with the IPolicyObject collection are valid, otherwise False</returns> public static bool ValidateIntraPolicy(string policyName, IPolicyObject policyObject, PolicySetValidator.AddViolationMessageHandler AddMessage) { if (policyObject is IConditionGroup) { if (!ValidateIntraPolicyConditionGroup((IConditionGroup)policyObject)) { if (null != AddMessage) { AddMessage(policyName, Properties.Resources.VALIDATION_INTRAPOLICY_FILETYPE_CONFLICT, false); } return false; } } else { //the following is for the developer - we are only expecting to find expressions in a //Policy -> ConditionGroup -> Condition structure. You're in this code because presumably //we have now changed the way we structure expressions System.Resources.ResourceManager resourceManager = new System.Resources.ResourceManager("Workshare.Policy.Properties.Resources", typeof(PolicySuites).Assembly); string message = resourceManager.GetString("VALIDATION_INTRAPOLICY_EXPRESSIONS_UNSUPPORTEDSTRUCTURE", System.Globalization.CultureInfo.InvariantCulture); Logger.LogError(message); System.Diagnostics.Debug.Assert(false, message); } return true; }
/// <summary> /// Ensures that the language item of a custom attribute is translatable. If, on a call to this /// method, the type is non translatable, a new translateable language item is created. Subsequent /// calls to this on the same custom attribute will not create new non-translateable language items /// </summary> /// <param name="policyObject">The policy object containing the custom attribute</param> /// <param name="attributeName">Name of the custom attribute</param> private static void EnforceTranslateableLanguageItem(IPolicyObject policyObject, string attributeName) { if (policyObject[attributeName] is NonTranslateableLanguageItem) { policyObject[attributeName] = new TranslateableLanguageItem(Guid.NewGuid(), policyObject[attributeName].Value); } }
public void WriteChildCollection(IPolicySet policySet, IPolicyObject parent, string name, IPolicyObjectCollection<IPolicyObject> collection) { if (parent == null) return; IPolicy policy = parent as IPolicy; if (policy == null) return; string ruleXpath = string.Format(CultureInfo.InvariantCulture, "PolicySet[@id='{0}']/Policies/Policy[@id='{1}']", XmlHelpers.GetPolicyObjectIdString(policySet), XmlHelpers.GetPolicyObjectIdString(parent)); XmlNode xmlRuleNode = m_policieSetsNode.SelectSingleNode(ruleXpath); if (xmlRuleNode == null) { new XmlCataloguePolicyWriter(m_xmlRootNode, policy).Write(); xmlRuleNode = m_xmlRootNode.SelectSingleNode(ruleXpath); } if (collection.Count == 0) return; IPolicyChannel channel = collection[0] as IPolicyChannel; if (channel == null) { new XmlConditionsWriter(xmlRuleNode, collection).Write(); } else { new XmlPolicyChannelsWriter(xmlRuleNode, collection).Write(); } }
public ConditionSummary(IPolicyObject conditionObject, Workshare.Policy.PolicyType type) { m_conditionObject = conditionObject; StringBuilder sb = new StringBuilder(); ProcessConditionOrConditionGroup(m_conditionObject, sb, type); m_desc = sb.ToString(); }
public NxPreRoutingSet(IPolicyChannel channel, IPolicyObject parent, Guid preRoutingId, Guid offlineRoutingId) : base(preRoutingId.ToString()) { m_channel = channel; m_parent = parent; m_ChannelRoutingId = channel.Identifier; m_OfflineRoutingId = offlineRoutingId; CreatePreRoutingSet(); }
/// <summary> /// /// </summary> /// <param name="policyObject"></param> /// <returns></returns> public static ConditionUnitFactory.PreDefinedConditionType GetPreDefinedConditionType(IPolicyObject policyObject) { try { return (ConditionUnitFactory.PreDefinedConditionType)Enum.Parse(typeof(ConditionUnitFactory.PreDefinedConditionType), policyObject[PreDefinedConditionTypeAttribute].Value, true); } catch (ArgumentException) { return ConditionUnitFactory.PreDefinedConditionType.Undefined; } }
/// <summary> /// /// </summary> /// <param name="policyObject"></param> /// <param name="preDefinedConditionType"></param> public static void SetPreDefinedConditionType(IPolicyObject policyObject, ConditionUnitFactory.PreDefinedConditionType preDefinedConditionType) { if (preDefinedConditionType == ConditionUnitFactory.PreDefinedConditionType.Undefined) { Utilities.ErrorMessage errorMessage = new Utilities.ErrorMessage( "CONDITION_INVALID_PREDEFINED", "Workshare.PolicyDesigner.Properties.Resources", System.Reflection.Assembly.GetExecutingAssembly()); Logger.LogError(errorMessage.LogString); throw new ArgumentException(errorMessage.DisplayString); } policyObject[PreDefinedConditionTypeAttribute].Value = Enum.GetName(typeof(ConditionUnitFactory.PreDefinedConditionType), preDefinedConditionType); }
public static string GetConditionSummary(IPolicyObject policyObject) { IEnumerator<KeyValuePair<string, IPolicyLanguageItem>> enumerator = policyObject.GetAttributeEnumerator(); while (enumerator.MoveNext()) { KeyValuePair<string, IPolicyLanguageItem> pair = enumerator.Current; if (string.Compare(pair.Key, "ConditionSummary", true, CultureInfo.InvariantCulture) == 0) { return pair.Value.Value; } } return ""; }
//public NxParameter(string name, Guid id) //{ // m_value = id.ToString(); // m_name = name; // m_IsValueId = true; //} public NxParameter(string name, IPolicyObject po) { m_name = name; if (po.Name.Identifier == Guid.Empty) { m_value = po.Name.Value; m_IsValueId = false; } else { m_value = po.Name.Identifier.ToString(); m_IsValueId = true; } }
/// <summary> /// Checks if a policy object exists in a policy set's master catalogue /// </summary> /// <param name="policySet">The policy set whose master catalogue we will be looking in</param> /// <param name="policyObject">The policy object we are looking up in the catalogue</param> /// <returns>True if the policy object exists in the policy set master catalogue, otherwise false</returns> public static bool IsInMyMasterCatalogue(IPolicySet policySet, IPolicyObject policyObject) { if (policyObject is IActionGroup) { return policySet.MasterCatalogue.ActionGroups.Contains(policyObject); } else if (policyObject is IAction) { return policySet.MasterCatalogue.Actions.Contains(policyObject); } else if (policyObject is IRoutingItem) { return policySet.MasterCatalogue.Locations.Contains(policyObject); } else if (policyObject is IRoutingItemCollections) { return policySet.MasterCatalogue.LocationsCollection.Contains(policyObject); } else if (policyObject is ICataloguePolicy) { return policySet.MasterCatalogue.CataloguePolicies.Contains(policyObject); } else if (policyObject is IChannel) { return policySet.MasterCatalogue.Channels.Contains(policyObject); } else if (policyObject is IConditionGroup) { return policySet.MasterCatalogue.ConditionGroups.Contains(policyObject); } else if (policyObject is ICondition) { return policySet.MasterCatalogue.Conditions.Contains(policyObject); } else if (policyObject is IDataElement) { return policySet.MasterCatalogue.DataElements.Contains(policyObject); } else if (policyObject is IRoutingTable) { return policySet.MasterCatalogue.RoutingTables.Contains(policyObject); } else { Logger.LogError("Unsupported IPolicyObject"); throw new ArgumentException("Unsupported IPolicyObject"); } }
private void ProcessConditionOrConditionGroup(IPolicyObject ipo, StringBuilder sb, Workshare.Policy.PolicyType type) { if (ipo is ICondition) { ConditionDisplayBase disp = ConditionDisplayFactory.CreateConditionDisplay(ipo as ICondition, type); sb.Append(disp.ToString()); } else if (ipo is IConditionGroup) { IConditionGroup group = ipo as IConditionGroup; foreach (ICondition condition in group.Conditions) { ProcessConditionOrConditionGroup(condition, sb, type); } } }
public static void SetConditionSummary(IPolicyObject policyObject, string conditionSummary) { IEnumerator<KeyValuePair<string, IPolicyLanguageItem>> enumerator = policyObject.GetAttributeEnumerator(); bool exists = false; while (enumerator.MoveNext()) { KeyValuePair<string, IPolicyLanguageItem> pair = enumerator.Current; if (string.Compare(pair.Key, "ConditionSummary", true, CultureInfo.InvariantCulture) == 0) { pair.Value.Value = conditionSummary; exists = true; break; } } enumerator.Dispose(); if (!exists) { CustomAttributes.SetConditionSummary(policyObject, conditionSummary); } }
private void AddExpressions(IPolicyObject policyobject, CustomGXNode rulenode) { if (policyobject is ICondition) { ICondition condition = policyobject as ICondition; CustomGXNode cnode = rulenode; CustomGXNode conditionnode = new CustomGXNode(condition["ShortName"], condition); //TreeGxNodeControl control = new TreeGxNodeControl(condition["ShortName"], new ConditionControl(condition), Color.FromArgb(255,231,156)); //conditionnode.HostedControl = control; conditionnode.Style = DevComponents.Tree.NodeStyles.Yellow; rulenode.Nodes.Add(conditionnode); } else if (policyobject is IConditionGroup) { IConditionGroup group = policyobject as IConditionGroup; foreach (IPolicyObject condition in group.Conditions) { AddExpressions(condition, rulenode); } } }
private void AddExpressions(IPolicyObject policyobject, int indent) { string indentstring = GetIndentString(indent); if (policyobject is ICondition) { ICondition condition = policyobject as ICondition; string expression = indentstring + "\"" + condition.DataLeft.Name + "\""; expression = expression + " " + condition.Operator.ToString(); expression = expression + " \"" + condition.DataRight.Name + "\""; this.conditionslb.Items.Add(expression); } else if (policyobject is IConditionGroup) { IConditionGroup group = policyobject as IConditionGroup; if (group.Conditions.Count == 1) { foreach (IPolicyObject condition in group.Conditions) { AddExpressions(condition, indent + 1); } return; } int count = group.Conditions.Count - 1; foreach (IPolicyObject condition in group.Conditions) { AddExpressions(condition, indent + 1); if (count > 0) this.conditionslb.Items.Add(indentstring + group.Logic.ToString()); count--; } } }
private static void SetDefaultLdapContext(IPolicyObject policyObj) { DirectoryAnalyzer analyzer = AddressSearchHelper.Instance.CurrentDirectoryAnalyzer; if (analyzer != null) { LdapInfoToPolicyObject(policyObj, analyzer.CreationInfo); } }
private static void SetPropertyIfNotNullOrEmpty(IPolicyObject obj, string property, string value) { if (!string.IsNullOrEmpty(value)) { obj[property].Value = value; } }
private static string GetProperty(IPolicyObject policyObj, string property) { IPolicyLanguageItem item = PolicyObject.FindAttribute(policyObj, property); return item == null ? "" : item.Value; }
public static LdapServerInformation PolicyObjectToLdapInfo(IPolicyObject policyObj) { string serverName = GetProperty(policyObj, LDAPRouter.SERVERNAMEPROPERTY); string context = GetProperty(policyObj, LDAPRouter.CONTEXTPROPERTY); string port = GetProperty(policyObj, LDAPRouter.PORTPROPERTY); string userName = GetProperty(policyObj, LDAPRouter.USERNAMEPROPERTY); string password = GetProperty(policyObj, LDAPRouter.PASSWORDPROPERTY); int portNum = string.IsNullOrEmpty(port) ? 0 : int.Parse(port, System.Globalization.CultureInfo.CurrentCulture); return new LdapServerInformation(serverName, context, portNum, userName, password); }
public static void DirectoryAnalyzerToPolicyObject(IPolicyObject policyObj, DirectoryAnalyzer analyzer) { LdapInfoToPolicyObject(policyObj, analyzer.CreationInfo); }
public static void LdapInfoToPolicyObject(IPolicyObject policyObj, LdapServerInformation info) { SetPropertyIfNotNullOrEmpty(policyObj, LDAPRouter.SERVERNAMEPROPERTY, info.ServerName); SetPropertyIfNotNullOrEmpty(policyObj, LDAPRouter.CONTEXTPROPERTY, info.Context); SetPropertyIfNotNullOrEmpty(policyObj, LDAPRouter.PORTPROPERTY, info.Port.ToString(CultureInfo.InvariantCulture)); SetPropertyIfNotNullOrEmpty(policyObj, LDAPRouter.USERNAMEPROPERTY, info.UserName); SetPropertyIfNotNullOrEmpty(policyObj, LDAPRouter.PASSWORDPROPERTY, info.Password); }
protected PolicyObject(IPolicyObject rhs, bool readOnly, bool createNewId) { CopyPolicyObject(rhs as PolicyObject, createNewId); m_readOnly = readOnly; }
public static void AddIdAttribute(XmlNode parentNode, IPolicyObject policyObject) { AddAttribute(parentNode, "id", GetPolicyObjectIdString(policyObject)); }
/// <summary> /// Searches the attribute set of an IPolicyObject, returning the first attribute whose key matches the specified name (invariant /// culture comparison) /// </summary> public static IPolicyLanguageItem FindAttribute(IPolicyObject obj, string name, bool ignoreCase) { return FindAttribute(obj, name, ignoreCase, CultureInfo.InvariantCulture); }
/// <summary> /// Removes a policy object from a policy set's master catalogue. This method assumes that there is no sharing of /// objects within the object model; when a policy object is removed from the catalogue, all children of this /// policy object are also removed. /// /// Be careful when using this method; in general, the object model dictates that it is only logical to explicitly /// remove those objects that are stored within a collection. You should also ensure you remove the policy object from /// the parent expression *before* calling this method. /// /// Example 1: a policy, stored in policySet.Policies, is safe to remove from the catalogue explicitly, so long as you /// remove it from policySet.Policies before calling this method. /// /// Example 2: a DataElement, stored in Condition.DataLeft, should not be removed explicitly via this method. Note that if /// you decide to remove the parent Condition from the catalogue, the DataElement will be implicitly removed for you. /// /// Ignoring this advice is not dangerous per se; the only problem you should see is that the policy object will /// reappear in the catalogue the next time you inspect the parent object. /// /// Note: At the time of writing, because of problems with the object model not deleting action matrix cells when an location /// collection is removed, explicit removal of LocationsCollection and Locations has been disabled. These can still be /// removed implicitly if you remove a PolicyChannel (or another object even higher up the object model). /// </summary> /// <param name="policySet">The policy set from whose master catalogue we should remove the policy object</param> /// <param name="policyObject">The policy object to remove</param> public static void RemovePolicyObjectFromCatalogue(IPolicySet policySet, IPolicyObject policyObject) { if (policyObject is IPolicy) { RemovePolicy(policySet, policyObject as IPolicy); return; } if (policyObject is ICondition) { RemoveCondition(policySet, policyObject as ICondition); return; } if (policyObject is IConditionGroup) { RemoveConditionGroup(policySet, policyObject as IConditionGroup); return; } if (policyObject is IDataElement) { //use this with care. If the DataElement is condition.DataLeft or condition.DataRight, //the dataelement will be added back into the catalogue the next time the parent condition is //inspected. Only use this if removing a DataElement from an action or from a parameter in a //method. RemoveDataElement(policySet, policyObject as IDataElement); return; } if (policyObject is IPolicyChannel) { RemoveChannel(policySet, policyObject as IPolicyChannel); return; } if (policyObject is IAction) { RemoveAction(policySet, policyObject as IAction); return; } //for now, don't support removal of individual location collections, as the object model doesn't delete //action matrix cells for us and so the location collection is automatically re-added into the catalogue. //however, location groups can be removed as part of a channel removal. //TODO: refactor object model to correctly remove action matrix cells //if (policyObject is IRoutingItemCollection) //{ // RemoveAddressCollection(policySet, policyObject as IRoutingItemCollection); // return; //} //for now, don't support removal of individual locations, as the object model doesn't delete //action matrix cells for us and so the location is automatically re-added into the catalogue. //however, locations can be removed as part of a channel removal. //TODO: refactor object model to correctly remove action matrix cells //if (policyObject is IRoutingItem) //{ // RemoveAddress(policySet, policyObject as IRoutingItem); // return; //} //It is illogical to attempt to remove the following objects in isolation; these should only //ever be removed from the catalogue because their parent object is being removed // //- remove a routing table only when removing an entire channel //- remove an action group only when removing an action condition group Utilities.ErrorMessage errorMessage = new Utilities.ErrorMessage( "POLICY_UNSUPPORTED_TYPE", "Workshare.PolicyDesigner.Properties.Resources", System.Reflection.Assembly.GetExecutingAssembly(), policyObject.ToString()); Logger.LogError(errorMessage.LogString); throw new ArgumentException(errorMessage.DisplayString); }
/// <summary> /// Searches the attribute set of an IPolicyObject, returning the first attribute whose key matches the specified name /// </summary> public static IPolicyLanguageItem FindAttribute(IPolicyObject obj, string name, bool ignoreCase, CultureInfo culture) { Dictionary<string, IPolicyLanguageItem>.Enumerator pos = obj.GetAttributeEnumerator(); while (pos.MoveNext()) { if (string.Compare(pos.Current.Key,name, ignoreCase, culture) == 0) { return pos.Current.Value; } } return null; }
/// <summary> /// Searches the attribute set of an IPolicyObject, returning the first attribute whose key matches the specified name (case sensitive, /// invariant culture comparison) /// </summary> public static string FindAttributeValue(IPolicyObject obj, string name, string defaultValue) { IPolicyLanguageItem item = FindAttribute(obj, name); return (item == null ? defaultValue : item.Value); }
public MatrixContentCellControl(IPolicyObject policyObject) { InitializeComponent(); m_policyObject = policyObject; }
public static void AddCustomAttributes(XmlNode parentNode, IPolicyObject policyObject) { AddCustomAttributes(parentNode, policyObject.GetAttributeEnumerator()); }
public static string GetPolicyObjectIdString(IPolicyObject policyObject) { return policyObject.Identifier.ToString("B").ToUpper(CultureInfo.InvariantCulture); }
/// <summary> /// Searches the attribute set of an IPolicyObject, returning the first attribute whose key matches the specified name /// </summary> public static string FindAttributeValue(IPolicyObject obj, string name, bool ignoreCase, CultureInfo culture, string defaultValue) { IPolicyLanguageItem item = FindAttribute(obj, name, ignoreCase, culture); return (item == null ? defaultValue : item.Value); }