private void loadTarget(PolicyEntity pe, XmlNode node) { pe.Target = new TargetEntity(); pe.Target.IsDirty = true; if (node != null) { XmlNodeList subjects = node.SelectNodes("subject"); foreach (XmlNode subject in subjects) loadSubject(pe.Target, subject); } }
private void loadPolicyBase(int idx, string title,PolicyEntity pe,XmlNode node) { XmlNode attr = node.Attributes.GetNamedItem("combine"); string combine = "deny-overrides"; if (attr != null) combine = attr.Value; CombineModeCollection cmcoll = new CombineModeCollection(); cmcoll.GetMulti((CombineModeFields.Name == combine)); if (cmcoll.Count != 1) throw new Exception(string.Format("unrecognised policy combine mode: {0}", combine)); attr = node.Attributes.GetNamedItem("description"); if (attr != null) pe.Description = attr.Value; else { if (pe.Set) pe.Description = string.Format("{0}-set-{1}", title, idx); else pe.Description = string.Format("{0}-policy-{1}", title, idx); } pe.CombineMode = cmcoll[0]; pe.Uid = Guid.NewGuid(); XmlNode target = node.SelectSingleNode("target"); loadTarget(pe,target); }
private void loadRule(int idx,PolicyEntity pe, XmlNode node) { RuleEntity re = new RuleEntity(); re.Policy = pe; re.Order = idx; string effect = "permit"; XmlNode attr = node.Attributes.GetNamedItem("effect"); if (attr != null) effect = attr.Value; EffectCollection ecoll = new EffectCollection(); ecoll.GetMulti(EffectFields.Name == effect); if (ecoll.Count != 1) throw new Exception(string.Format("unrecognised rule effect {0}", effect)); re.Effect = ecoll[0]; DecisionNodeEntity ce = new DecisionNodeEntity(); re.Condition = ce; ce.Type = constants.conditionType; ce.IsDirty = true; XmlNode condition = node.SelectSingleNode("condition"); if (condition != null) loadCondition(ce, condition); }
private static bool DeletePolicyFromLib(int id) { PredicateExpression pe = new PredicateExpression(PolicyLinkFields.PolicyId == id); PredicateExpression peOr = new PredicateExpression(new FieldCompareSetPredicate(PolicyLinkFields.Id, PolicyDocumentFields.PolicyLinkId, SetOperator.In, null)); peOr.AddWithOr(PolicyLinkFields.ParentId != DBNull.Value); pe.Add(peOr); PolicyLinkCollection plcoll = new PolicyLinkCollection(); if (plcoll.GetMulti(pe) && plcoll.Count == 0) { // Policy isn't referenced in any policy document. PolicyEntity delPolicy = new PolicyEntity(id); delPolicy.PolicyLink.DeleteMulti(); DeletePolicy(delPolicy); return true; } else return false; }
private string GetPolicyAction(PolicyEntity policy) { return policy.Set ? "EditPolicySet" : "EditPolicy"; }
/// <summary> Retrieves the related entity of type 'PolicyEntity', using a relation of type 'n:1'</summary> /// <param name="forceFetch">if true, it will discard any changes currently in the currently loaded related entity and will refetch the entity from the persistent storage</param> /// <returns>A fetched entity of type 'PolicyEntity' which is related to this entity.</returns> public virtual PolicyEntity GetSinglePolicy(bool forceFetch) { if( ( !_alreadyFetchedPolicy || forceFetch || _alwaysFetchPolicy) && !base.IsSerializing && !base.IsDeserializing && !base.InDesignMode) { bool performLazyLoading = base.CheckIfLazyLoadingShouldOccur(RuleEntity.Relations.PolicyEntityUsingPolicyId); PolicyEntity newEntity = new PolicyEntity(); if(base.ParticipatesInTransaction) { base.Transaction.Add(newEntity); } bool fetchResult = false; if(performLazyLoading) { fetchResult = newEntity.FetchUsingPK(this.PolicyId); } if(fetchResult) { if(base.ActiveContext!=null) { newEntity = (PolicyEntity)base.ActiveContext.Get(newEntity); } this.Policy = newEntity; } else { if(_policyReturnsNewIfNotFound) { if(performLazyLoading || (!performLazyLoading && (_policy == null))) { this.Policy = newEntity; } } else { this.Policy = null; } } _alreadyFetchedPolicy = fetchResult; if(base.ParticipatesInTransaction && !fetchResult) { base.Transaction.Remove(newEntity); } } return _policy; }
private static void DeletePolicy(PolicyEntity pe) { // Delete target conditions. foreach (DecisionNodeEntity ce in pe.Target.ConditionCollectionViaTargetCondition) { DeleteDecisionNode(ce); } // Delete rule conditions. foreach (RuleEntity re in pe.Rule) { DeleteDecisionNode(re.Condition); } // Delete the policy. pe.Delete(); // Delete the target. pe.Target.Delete(); }
/// <summary> Initializes the class members</summary> private void InitClassMembers() { _condition = null; _conditionReturnsNewIfNotFound = true; _alwaysFetchCondition = false; _alreadyFetchedCondition = false; _effect = null; _effectReturnsNewIfNotFound = true; _alwaysFetchEffect = false; _alreadyFetchedEffect = false; _policy = null; _policyReturnsNewIfNotFound = true; _alwaysFetchPolicy = false; _alreadyFetchedPolicy = false; PerformDependencyInjection(); // __LLBLGENPRO_USER_CODE_REGION_START InitClassMembers // __LLBLGENPRO_USER_CODE_REGION_END OnInitClassMembersComplete(); }
/// <summary> setups the sync logic for member _policy</summary> /// <param name="relatedEntity">Instance to set as the related entity of type entityType</param> private void SetupSyncPolicy(IEntity relatedEntity) { if(_policy!=relatedEntity) { DesetupSyncPolicy(true, true); _policy = (PolicyEntity)relatedEntity; base.PerformSetupSyncRelatedEntity( _policy, new PropertyChangedEventHandler( OnPolicyPropertyChanged ), "Policy", RuleEntity.Relations.PolicyEntityUsingPolicyId, true, ref _alreadyFetchedPolicy, new string[] { } ); } }
/// <summary> Removes the sync logic for member _policy</summary> /// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param> /// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param> private void DesetupSyncPolicy(bool signalRelatedEntity, bool resetFKFields) { base.PerformDesetupSyncRelatedEntity( _policy, new PropertyChangedEventHandler( OnPolicyPropertyChanged ), "Policy", RuleEntity.Relations.PolicyEntityUsingPolicyId, true, signalRelatedEntity, "Rule", resetFKFields, new int[] { (int)RuleFieldIndex.PolicyId } ); _policy = null; }
/// <summary>Private CTor for deserialization</summary> /// <param name="info"></param> /// <param name="context"></param> protected RuleEntity(SerializationInfo info, StreamingContext context) : base(info, context) { _condition = (DecisionNodeEntity)info.GetValue("_condition", typeof(DecisionNodeEntity)); if(_condition!=null) { _condition.AfterSave+=new EventHandler(OnEntityAfterSave); } _conditionReturnsNewIfNotFound = info.GetBoolean("_conditionReturnsNewIfNotFound"); _alwaysFetchCondition = info.GetBoolean("_alwaysFetchCondition"); _alreadyFetchedCondition = info.GetBoolean("_alreadyFetchedCondition"); _effect = (EffectEntity)info.GetValue("_effect", typeof(EffectEntity)); if(_effect!=null) { _effect.AfterSave+=new EventHandler(OnEntityAfterSave); } _effectReturnsNewIfNotFound = info.GetBoolean("_effectReturnsNewIfNotFound"); _alwaysFetchEffect = info.GetBoolean("_alwaysFetchEffect"); _alreadyFetchedEffect = info.GetBoolean("_alreadyFetchedEffect"); _policy = (PolicyEntity)info.GetValue("_policy", typeof(PolicyEntity)); if(_policy!=null) { _policy.AfterSave+=new EventHandler(OnEntityAfterSave); } _policyReturnsNewIfNotFound = info.GetBoolean("_policyReturnsNewIfNotFound"); _alwaysFetchPolicy = info.GetBoolean("_alwaysFetchPolicy"); _alreadyFetchedPolicy = info.GetBoolean("_alreadyFetchedPolicy"); base.FixupDeserialization(FieldInfoProviderSingleton.GetInstance(), PersistenceInfoProviderSingleton.GetInstance()); // __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor // __LLBLGENPRO_USER_CODE_REGION_END }
/// <summary> Initializes the class members</summary> private void InitClassMembers() { _policyDocument = new policyDB.CollectionClasses.PolicyDocumentCollection(new PolicyDocumentEntityFactory()); _policyDocument.SetContainingEntityInfo(this, "PolicyLink"); _alwaysFetchPolicyDocument = false; _alreadyFetchedPolicyDocument = false; _children = new policyDB.CollectionClasses.PolicyLinkCollection(new PolicyLinkEntityFactory()); _children.SetContainingEntityInfo(this, "Parent"); _alwaysFetchChildren = false; _alreadyFetchedChildren = false; _libraryCollectionViaPolicyDocument = new policyDB.CollectionClasses.LibraryCollection(new LibraryEntityFactory()); _alwaysFetchLibraryCollectionViaPolicyDocument = false; _alreadyFetchedLibraryCollectionViaPolicyDocument = false; _policyCollectionViaPolicyLink = new policyDB.CollectionClasses.PolicyCollection(new PolicyEntityFactory()); _alwaysFetchPolicyCollectionViaPolicyLink = false; _alreadyFetchedPolicyCollectionViaPolicyLink = false; _policy = null; _policyReturnsNewIfNotFound = true; _alwaysFetchPolicy = false; _alreadyFetchedPolicy = false; _parent = null; _parentReturnsNewIfNotFound = true; _alwaysFetchParent = false; _alreadyFetchedParent = false; PerformDependencyInjection(); // __LLBLGENPRO_USER_CODE_REGION_START InitClassMembers // __LLBLGENPRO_USER_CODE_REGION_END OnInitClassMembersComplete(); }
/// <summary>Private CTor for deserialization</summary> /// <param name="info"></param> /// <param name="context"></param> protected PolicyLinkEntity(SerializationInfo info, StreamingContext context) : base(info, context) { _policyDocument = (policyDB.CollectionClasses.PolicyDocumentCollection)info.GetValue("_policyDocument", typeof(policyDB.CollectionClasses.PolicyDocumentCollection)); _alwaysFetchPolicyDocument = info.GetBoolean("_alwaysFetchPolicyDocument"); _alreadyFetchedPolicyDocument = info.GetBoolean("_alreadyFetchedPolicyDocument"); _children = (policyDB.CollectionClasses.PolicyLinkCollection)info.GetValue("_children", typeof(policyDB.CollectionClasses.PolicyLinkCollection)); _alwaysFetchChildren = info.GetBoolean("_alwaysFetchChildren"); _alreadyFetchedChildren = info.GetBoolean("_alreadyFetchedChildren"); _libraryCollectionViaPolicyDocument = (policyDB.CollectionClasses.LibraryCollection)info.GetValue("_libraryCollectionViaPolicyDocument", typeof(policyDB.CollectionClasses.LibraryCollection)); _alwaysFetchLibraryCollectionViaPolicyDocument = info.GetBoolean("_alwaysFetchLibraryCollectionViaPolicyDocument"); _alreadyFetchedLibraryCollectionViaPolicyDocument = info.GetBoolean("_alreadyFetchedLibraryCollectionViaPolicyDocument"); _policyCollectionViaPolicyLink = (policyDB.CollectionClasses.PolicyCollection)info.GetValue("_policyCollectionViaPolicyLink", typeof(policyDB.CollectionClasses.PolicyCollection)); _alwaysFetchPolicyCollectionViaPolicyLink = info.GetBoolean("_alwaysFetchPolicyCollectionViaPolicyLink"); _alreadyFetchedPolicyCollectionViaPolicyLink = info.GetBoolean("_alreadyFetchedPolicyCollectionViaPolicyLink"); _policy = (PolicyEntity)info.GetValue("_policy", typeof(PolicyEntity)); if(_policy!=null) { _policy.AfterSave+=new EventHandler(OnEntityAfterSave); } _policyReturnsNewIfNotFound = info.GetBoolean("_policyReturnsNewIfNotFound"); _alwaysFetchPolicy = info.GetBoolean("_alwaysFetchPolicy"); _alreadyFetchedPolicy = info.GetBoolean("_alreadyFetchedPolicy"); _parent = (PolicyLinkEntity)info.GetValue("_parent", typeof(PolicyLinkEntity)); if(_parent!=null) { _parent.AfterSave+=new EventHandler(OnEntityAfterSave); } _parentReturnsNewIfNotFound = info.GetBoolean("_parentReturnsNewIfNotFound"); _alwaysFetchParent = info.GetBoolean("_alwaysFetchParent"); _alreadyFetchedParent = info.GetBoolean("_alreadyFetchedParent"); base.FixupDeserialization(FieldInfoProviderSingleton.GetInstance(), PersistenceInfoProviderSingleton.GetInstance()); // __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor // __LLBLGENPRO_USER_CODE_REGION_END }
/// <summary>Creates a new, empty PolicyEntity object.</summary> /// <returns>A new, empty PolicyEntity object.</returns> public override IEntity Create() { IEntity toReturn = new PolicyEntity(); // __LLBLGENPRO_USER_CODE_REGION_START CreateNewPolicy // __LLBLGENPRO_USER_CODE_REGION_END return toReturn; }