private void createNRules(RuleMSX rmsx, RuleContainer rc, RuleAction reached, Accumulator acm, int min, int max) { if (min == max) { // leaf node, so add rule with action Rule newRule = new Rule("intBetween" + min.ToString() + "and" + max.ToString(), new IsIntBetween(min, max, acm), rmsx.createAction("ShowValue", new ShowValue(min))); newRule.AddAction(reached); rc.AddRule(newRule); } else { Rule newRule = new Rule("intBetween" + min.ToString() + "and" + max.ToString(), new IsIntBetween(min, max, acm)); rc.AddRule(newRule); if (max - min < 2) { createNRules(rmsx, newRule, reached, acm, min, min); createNRules(rmsx, newRule, reached, acm, max, max); } else { int mid = ((max - min) / 2) + min; createNRules(rmsx, newRule, reached, acm, min, mid); createNRules(rmsx, newRule, reached, acm, mid + 1, max); } } }
public void SetUp() { containingObject = new GameObject(); container = new RuleContainer(); subject = containingObject.AddComponent <ListContainsRule>(); container.Interface = subject; }
public void SetUp() { containingObject = new GameObject(); container = new RuleContainer(); subject = containingObject.AddComponent <ActiveInHierarchyRule>(); container.Interface = subject; }
public IActionResult Update(string org, string service, int id) { List <RuleContainer> rules = _repository.GetRules(org, service); RuleContainer rule = rules.FirstOrDefault(r => r.Id == id); return(View(rule)); }
public void SetUp() { containingObject = new GameObject(); container = new RuleContainer(); subject = containingObject.AddComponent <AnyBehaviourEnabledRule>(); container.Interface = subject; }
protected virtual RuleContainer CreateRule(GameObject element) { RuleContainer container = new RuleContainer(); ListContainsRule rule = containingObject.AddComponent <ListContainsRule>(); rule.objects.Add(element); container.Interface = rule; return(container); }
private string CreateRulesRecursive( RuleContainer ruleContainer, Dictionary <string, Iterator> existingIterators, Dictionary <string, string> existingMethods, ServiceMetadata serviceMetadata, List <char> reservedIndexNames) { Dictionary <string, Iterator> iterators = new Dictionary <string, Iterator>(); CreateIterators(ruleContainer, iterators, serviceMetadata, reservedIndexNames); StringBuilder bodyBuilder = new StringBuilder(); StringBuilder iteratorBuilder = new StringBuilder(); Dictionary <string, Iterator> newIterators = new Dictionary <string, Iterator>(); foreach (KeyValuePair <string, Iterator> iterator in iterators.Where(x => !existingIterators.ContainsKey(x.Key))) { existingIterators.Add(iterator.Key, iterator.Value); newIterators.Add(iterator.Key, iterator.Value); } string condition = CreateConditionRecursive(ruleContainer.Id, ruleContainer.Conditions, existingIterators, existingMethods, serviceMetadata); if (ruleContainer.Rules != null) { foreach (Rule rule in ruleContainer.Rules) { bodyBuilder.AppendLine(CreateRule(ruleContainer.Id, rule, existingIterators, serviceMetadata)); } } if (ruleContainer.ChildContainers != null) { foreach (RuleContainer childContainer in ruleContainer.ChildContainers) { bodyBuilder.AppendLine(CreateRulesRecursive(childContainer, existingIterators, existingMethods, serviceMetadata, reservedIndexNames)); } } string body = bodyBuilder.ToString(); string finalBody = string.Format( "if ({0}) {{ {1} }}", condition, body); // TODO: Check which iterators has been added to this specific rule container if (newIterators.Any()) { string iteratorCode = CreateIteratorCode(newIterators.Values.ToList()); return(string.Format(iteratorCode.Replace("{", "{{").Replace("}", "}}").Replace("{{0}}", "{0}"), finalBody)); } else { return(finalBody); } }
public void SetUp() { containingObject = new GameObject { tag = validTag }; container = new RuleContainer(); subject = containingObject.AddComponent <AnyTagRule>(); container.Interface = subject; }
public void SetUp() { containingObject = new GameObject { layer = LayerMask.NameToLayer("UI") }; container = new RuleContainer(); subject = containingObject.AddComponent <AnyLayerRule>(); container.Interface = subject; }
protected virtual void DrawDisallowedInteractorsList(RuleContainer rule, string undoRedoWarningPropertyPath) { if (rule.Interface == null) { return; } ListContainsRule listRule = (ListContainsRule)rule.Interface; SerializedObject listObject = new SerializedObject(listRule.Objects); DrawPropertyFieldWithChangeHandlers(listObject, "elements", undoRedoWarningPropertyPath); }
public IActionResult GetById(string org, string service, int id) { RuleContainer rule = _repository.GetRules(org, service)?.FirstOrDefault(r => r.Id == id); if (rule != null) { return(Json(rule)); } else { return(NotFound()); } }
private Dictionary <string, Iterator> CreateIterators(RuleContainer ruleContainer, Dictionary <string, Iterator> iterators, ServiceMetadata serviceMetadata, List <char> reservedIndexNames) { foreach (Condition condition in ruleContainer.Conditions) { foreach (Parameter parameter in condition.Parameters.Where(x => !String.IsNullOrEmpty(x.Value))) { string elementId = parameter.Value; if (serviceMetadata.Elements.ContainsKey(elementId)) { iterators = CreateIterator(ruleContainer.Id, elementId, serviceMetadata, reservedIndexNames, iterators); } } } return(iterators); }
/// <summary> /// Create the collection of RuleContainers to configure ResourceStaticAnalysis Engine with. /// </summary> /// <param name="folders">Collection of folders to look for rules or configuration file to create the RuleContainers for.</param> /// <returns>Collection of RuleContainers.</returns> protected virtual IEnumerable <RuleContainer> CreateRuleContainers(IEnumerable <String> folders) { this.RulesConfiguration = this.LoadRuleConfiguration(folders); // Process all the rule assemblies found, creating the ResourceStaticAnalysis Engine Rule Containers for each entry and return the collection of containers. List <RuleContainer> ruleContainerCollection = new List <RuleContainer>(); if (this.RulesConfiguration != null) { foreach (var entry in this.RulesConfiguration.Where(rc => rc.Value.Enabled)) //Only create RuleContainers for the assemblies where the config is enabled. { RuleContainer ruleContainer = new RuleContainer(entry.Key, RuleContainerType.Module); this.ProcessRuleConfig(entry.Value, ruleContainer); ruleContainerCollection.Add(ruleContainer); } } return(ruleContainerCollection); }
public IActionResult Update(string org, string service, int id, [FromBody] RuleContainer rule) { List <RuleContainer> existingRules = _repository.GetRules(org, service); if (existingRules == null) { existingRules = new List <RuleContainer>(); } existingRules.RemoveAll(r => r.Id == rule.Id); existingRules.Add(rule); ServiceMetadata serviceMetadata = _repository.GetServiceMetaData(org, service); _codeGeneration.CreateCalculationsAndValidationsClass(org, service, existingRules, serviceMetadata); _repository.UpdateRules(org, service, existingRules); return(Ok()); }
public IActionResult Create(string org, string service, [FromBody] RuleContainer rule) { List <RuleContainer> existingRules = _repository.GetRules(org, service); if (existingRules == null) { existingRules = new List <RuleContainer>(); } int id = 1; bool idFound = false; while (!idFound) { if (existingRules.FirstOrDefault(r => r.Id == id) == null) { idFound = true; } else { id++; } } rule.Id = id; existingRules.Add(rule); ServiceMetadata serviceMetadata = _repository.GetServiceMetaData(org, service); string rules = string.Empty; _codeGeneration.CreateCalculationsAndValidationsClass(org, service, existingRules, serviceMetadata); _repository.UpdateRules(org, service, existingRules); return(Json(rule)); }
public void AcceptsOnNullContainer() { subject = null; Assert.IsTrue(subject.Accepts(argument)); }
/// <summary> /// Determines whether an object is accepted. /// </summary> /// <param name="container">The container of the <see cref="IRule"/> to check against.</param> /// <param name="target">The object to check.</param> /// <returns><see langword="true"/> if <paramref name="target"/> is accepted, <see langword="false"/> otherwise.</returns> public static bool Accepts(this RuleContainer container, object target) { return(container?.Interface?.Accepts(target) != false); }
/// <summary> /// Process the ResourceStaticAnalysisRulesConfig to create the required filtering for the RuleContainer. /// </summary> /// <param name="rulesConfig">ResourceStaticAnalysisRulesConfig object to process.</param> /// <param name="ruleContainer">RuleContainer object to update with the filtering.</param> protected void ProcessRuleConfig(ResourceStaticAnalysisRulesConfig rulesConfig, RuleContainer ruleContainer) { if (rulesConfig == null || ruleContainer == null) { return; } ruleContainer.FilteringExpressionMethod = this.CreateFilteringExpression(rulesConfig.Cultures, rulesConfig.Projects, rulesConfig.FilteringExpressions); List <RuleFilteringInfo> ruleFilters = new List <RuleFilteringInfo>(); foreach (ResourceStaticAnalysisRulesConfig.Rule rule in rulesConfig.Rules) { if (rule.Enabled) { RuleFilteringInfo ruleFilteringInfo = this.CreateRuleFiltering(rule); if (ruleFilteringInfo != null) { ruleFilters.Add(ruleFilteringInfo); } } else { ruleContainer.DisabledRules.Add(rule.Type); } } if (ruleFilters.Any()) { ruleContainer.PerRuleFilteringExpressionMethods = ruleFilters; } if (!String.IsNullOrWhiteSpace(rulesConfig.WorkingFolder)) { String workingFolder = Environment.ExpandEnvironmentVariables(rulesConfig.WorkingFolder); if (!Path.IsPathRooted(workingFolder) && !String.IsNullOrWhiteSpace(rulesConfig.PathToConfigFile)) { workingFolder = Path.Combine(Path.GetDirectoryName(rulesConfig.PathToConfigFile), workingFolder); } ruleContainer.WorkingFolder = Path.GetFullPath(workingFolder); } }
/// <summary> /// Applies the provided settings to the Teleporter prefab. /// </summary> /// <param name="playAreaAlias">The PlayArea alias.</param> /// <param name="headsetAlias">The Headset alias.</param> /// <param name="sceneCameras">The scene cameras.</param> /// <param name="targetValidity">The rules to determine validity.</param> protected virtual void ApplySettings(GameObject playAreaAlias, GameObject headsetAlias, CameraList sceneCameras, RuleContainer targetValidity) { foreach (SurfaceLocator currentLocator in surfaceLocatorAliases.EmptyIfNull()) { currentLocator.searchOrigin = headsetAlias; } foreach (SurfaceLocator currentLocator in surfaceLocatorRules.EmptyIfNull()) { currentLocator.targetValidity = targetValidity; } foreach (TransformPropertyApplier currentApplier in transformPropertyApplierAliases.EmptyIfNull()) { currentApplier.target = playAreaAlias; currentApplier.offset = headsetAlias; } foreach (CameraColorOverlay currentOverlay in cameraColorOverlays.EmptyIfNull()) { currentOverlay.validCameras = sceneCameras; } }
static void Main(string[] args) { var r1 = new EqualRule(); r1.AttributeName = "a1"; r1.TargetValue.Add("test1"); var r2 = new EqualRule(); r2.AttributeName = "b2"; r2.TargetValue.Add("test2"); r2.TargetValue.Add("test2bis"); var r3 = new EqualRule(); r3.AttributeName = "c3"; r3.TargetValue.Add("test3"); var r4 = new NotEqualRule(); r4.AttributeName = "c4"; r4.TargetValue.Add("test4"); var r5 = new EqualRule(); r5.AttributeName = "or5"; r5.TargetValue.Add("test5"); var r6 = new EqualRule(); r6.AttributeName = "or6"; r6.TargetValue.Add("test6"); var orRule = new OrRule(); orRule.ChildRules.Add(r5); orRule.ChildRules.Add(r6); var andRule = new AndRule(); andRule.ChildRules.Add(r1); andRule.ChildRules.Add(r2); andRule.ChildRules.Add(r3); andRule.ChildRules.Add(r4); andRule.ChildRules.Add(orRule); var rc = new RuleContainer(); rc.MetadataInputs.Add(new MetadataEntity() { AttributeName = "a1", AttributeType = typeof(string) }); rc.MetadataInputs.Add(new MetadataEntity() { AttributeName = "b2", AttributeType = typeof(string) }); rc.MetadataInputs.Add(new MetadataEntity() { AttributeName = "c3", AttributeType = typeof(string) }); rc.MetadataInputs.Add(new MetadataEntity() { AttributeName = "c4", AttributeType = typeof(string) }); rc.MetadataInputs.Add(new MetadataEntity() { AttributeName = "or5", AttributeType = typeof(string) }); rc.MetadataInputs.Add(new MetadataEntity() { AttributeName = "or6", AttributeType = typeof(string) }); rc.Rules.Add(andRule); rc.ReturnValue = "false"; rc.CompileExpression(); var res1 = rc.CompiledFunction(new string[] { "test1", "test2", "test3", "test4444", "test5fdsfsd", "test6" }); }
/// <summary> /// Determines whether the <see cref="RaycastHit"/> data contains a valid collision against the given rule. /// </summary> /// <param name="collisionData">The <see cref="RaycastHit"/> data to check for validity on.</param> /// <param name="rule">The <see cref="RuleContainer"/> to check the validity against.</param> /// <returns>Whether the <see cref="RaycastHit"/> data contains a valid collision.</returns> protected virtual bool CollisionMatchesRule(RaycastHit collisionData, RuleContainer rule) { return(collisionData.transform != null && rule.Accepts(collisionData.transform.gameObject)); }
/// <summary> /// Loads rules from a container: either a module (.dll) or source file (.cs). /// Also compiles a filtering expression, if provided for a rule /// </summary> /// <param name="containerDef">Container definition: provides path to container (.dll or .cs) and an optional filtering expression /// to be applied to all the rules /// </param> public void LoadRulesFromContainer(RuleContainer containerDef) { Exception containerException = null; string exceptionMessage = null; if (containerDef.EnabledRules.Count > 0 && containerDef.DisabledRules.Count > 0) { throw new RuleContainerException("EnabledRules and DisabledRules should not co-exist in a RuleContainer"); } var pathToContainer = containerDef.PathToFile; if (!Path.IsPathRooted(pathToContainer)) { pathToContainer = Path.Combine(Path.GetDirectoryName(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase), pathToContainer); } //if the file doesn't exists try looking in the GAC if (!File.Exists(pathToContainer)) { pathToContainer = Assembly.Load(containerDef.PathToFile).CodeBase; } // if the container does not specify a filtering expression, we look for the default one in engine config if (containerDef.FilteringExpressionMethod == null && String.IsNullOrEmpty(containerDef.FilteringExpression)) { containerDef.FilteringExpression = _owningEngine._engineConfiguration.DefaultFilteringExpression; } try { Assembly ruleModule = null; switch (containerDef.ContainerType) { case RuleContainerType.Source: // Need to compile source file ruleModule = CompileRuleSourceFile(pathToContainer); break; case RuleContainerType.Module: ruleModule = Assembly.LoadFrom(pathToContainer); break; } if (containerDef.FilteringExpressionMethod != null) { AddRulesFromAssembly(ruleModule, containerDef.FilteringExpressionMethod, containerDef.DisabledRules, containerDef.WorkingFolder, containerDef.EnabledRules); } else { AddRulesFromAssembly(ruleModule, containerDef.FilteringExpression, containerDef.DisabledRules, containerDef.WorkingFolder, containerDef.EnabledRules); } //If there is any Rule filtering specified set that here. if (containerDef.PerRuleFilteringExpressionMethods != null) { foreach (var ruleFilter in containerDef.PerRuleFilteringExpressionMethods) { var rule = this._rules.FirstOrDefault(r => r.GetType().FullName == ruleFilter.RuleName); if (rule != null) { if (ruleFilter.ReplaceExisting) { rule.SetFilteringExpression(ruleFilter.FilteringExpressionMethod); } else { rule.AddFilteringExpression(ruleFilter.FilteringExpressionMethod); } } } } } catch (TypeInitializationException e) { exceptionMessage = String.Format(CultureInfo.CurrentCulture, "An error occurred while trying to initialize rule objects from {0}", pathToContainer); containerException = e; } catch (FileNotFoundException e) { exceptionMessage = String.Format(CultureInfo.CurrentCulture, "Engine configuration error. File '{0}' could not be found.", pathToContainer); containerException = e; } catch (MissingFieldException e) { exceptionMessage = "Could not load rules from rule container correctly, please check that required fields exist."; containerException = e; } catch (Exception e) { exceptionMessage = String.Format(CultureInfo.CurrentCulture, "Could not load rules from rule container {0}.", pathToContainer); containerException = e; } finally { if (containerException != null) { throw new RuleContainerException(exceptionMessage, containerException); } } }
protected override void AddSupportType() { RuleContainer.GetInstance().AddSupportType(GetType(), Utility.NumericTypes); }
public void SetUp() { subject = new RuleContainer(); }