public void TestHardRuleFailedWithoutFirstComponentString() { // Arrange var symbol1 = 'g'; var symbol2 = 'b'; var rule11 = new SymbolRule(symbol: symbol1); var rule1 = new OneOrManyRule(rule11); var rule22 = new SymbolRule(symbol: symbol2); var rule2 = new ZeroOrManyRule(rule22); var rule = new GroupRule(new List <IRule> { rule1, rule2 }); var stream = new MemoryStream().FromString($"${symbol2}"); // Act var result = rule.Check(stream); // Assert Assert.IsFalse(result, message: "result is false"); }
public static void CheckConfig(hwmAddressablesSystemConfig config) { for (int iGroup = 0; iGroup < config.GroupRules.Length; iGroup++) { GroupRule iterGroupRule = config.GroupRules[iGroup]; if (string.IsNullOrWhiteSpace(iterGroupRule.GroupName)) { Debug.LogError(string.Format("Group-{0}的GroupName为空", iterGroupRule.GroupName)); } for (int iAsset = 0; iAsset < iterGroupRule.AssetRules.Length; iAsset++) { AssetRule iterAssetRule = iterGroupRule.AssetRules[iAsset]; if (!(iterAssetRule.Path.StartsWith("Assets") && iterAssetRule.Path.EndsWith("/"))) { Debug.LogError(string.Format("Group-{0}({1})的AssetRule-{2}的Path不是\"Assets*/\"格式", iGroup, iterGroupRule.GroupName, iAsset)); } for (int iExtension = 0; iExtension < iterAssetRule.ExtensionFilters.Count; iExtension++) { string iterExtension = iterAssetRule.ExtensionFilters[iExtension]; if (!iterExtension.StartsWith(".")) { Debug.LogError(string.Format("Group-{0}({1})的AssetRule-{2}的ExtensionFilters-{3}({4})不是\".*/\"格式", iGroup, iterGroupRule.GroupName, iAsset, iExtension, iterExtension)); } } } } Debug.Log("Check config finish"); }
public void TestManySuccessivelyChekingWithLastFailed() { // Arrange var symbol1 = 'g'; var symbol2 = 'b'; var symbol3 = 'i'; var rule1 = new SymbolRule(symbol: symbol1); var rule2 = new SymbolRule(symbol: symbol2); var rule3 = new SymbolRule(symbol: symbol3); var rule = new GroupRule(new List <IRule> { rule1, rule2, rule3 }); var stream = new MemoryStream().FromString($"{symbol1}{symbol2}/{symbol3}"); // Act var result = rule.Check(stream); // Assert Assert.IsFalse(result, message: "result is false"); }
private void CreatePropertyCondition(XbimQueryBuilder qBuilder, XmlNode propGroupNode) { GroupRule pGrpRule = GetGroupRule(propGroupNode); //apply logical operators according to the "select" XmlNodeList pSets = ((XmlElement)propGroupNode).GetElementsByTagName("propertySet"); foreach (XmlNode pSet in pSets) { string pSetName = GetName(pSet); NameRule pSetNameRule = GetNameRule(pSet); XmlNode propNode = ((XmlElement)pSet).GetElementsByTagName("property").Item(0); string propName = GetName(propNode); NameRule propNameRule = GetNameRule(propNode); if (string.IsNullOrEmpty(propName)) { errLog.WriteLine("Name of the property must be specified. Property set: '" + pSetName + "', element: '" + eName + "'."); continue; } XmlNode valNode = (propNode as XmlElement).GetElementsByTagName("value").Item(0); string value = valNode.InnerText; ValueRule valRule = GetValueRule(valNode); if (string.IsNullOrEmpty(value)) { errLog.WriteLine("Value of the property '" + propName + "' must be specified. Property set: '" + pSetName + "', element: '" + eName + "."); continue; } qBuilder.AddPropertyCondition(pSetName, pSetNameRule, propName, propNameRule, value, valRule, pGrpRule); } }
private GroupRule GetGroupRule(XmlNode node) { XmlAttribute attr = node.Attributes["select"]; string select = "all"; //default value if (attr != null && !String.IsNullOrEmpty(attr.Value)) { select = attr.Value; } GroupRule result = GroupRule.ALL; if (select.ToLower() == "oneof") { result = GroupRule.ONE_OF; } if (select.ToLower() == "none") { result = GroupRule.NONE; } if (select.ToLower() == "any") { result = GroupRule.ANY; } return(result); }
public void TestRighSringSavedInSuccessCase() { // Arrange var symbol1 = 'g'; var symbol2 = 'b'; var rule11 = new SymbolRule(symbol: symbol1); var rule1 = new OneOrManyRule(rule11); var rule22 = new SymbolRule(symbol: symbol2); var rule2 = new ZeroOrManyRule(rule22); var rule = new GroupRule(new List <IRule> { rule1, rule2 }); var str = $"{symbol1}{symbol1}{symbol1}{symbol1}{symbol1}{symbol2}{symbol2}"; var stream = new MemoryStream().FromString(str); // Act var result = rule.Check(stream); // Assert Assert.AreEqual(str, rule.ChekedString); }
//----------------------------------------------------------------------------------------------------------- #region Group //in baseRepository /*public object GetAllGroup(){ * object result = null; * var query = from a in _DbContext.grouprules * select new { * a.ID, a.groupName, a.ruleParameter * }; * result = query.ToList(); * return result; * }*/ public int AddGroup(GroupRule newGroup) { int count = 0; try{ _DbContext.grouprules.Add(newGroup); count = _DbContext.SaveChanges(); }catch (Exception e) { count = ((MySqlException)e.InnerException).Number; } if (count == 1) { var dic = new Dictionary <string, string> { }; var opLog = new OperateLog() { operateID = newGroup.lastOperaAccID, active = "新增", category = "動作權限設定", createTime = definePara.dtNow() }; toNameFn.AddUpGroup_covertToDic(ref dic, newGroup); opLog.content = toNameFn.AddUpGroup_covertToText(dic); saveOperateLog(opLog); //紀錄操作紀錄 } return(count); }
private static void MakeGroupFromCurrentItemsIfAny( ref List <UsingDirective> currentItemSet, GroupRule lastRule, List <List <UsingDirective> > results) { if (currentItemSet != null && currentItemSet.Count > 0 && lastRule != null) { results.Add(currentItemSet); currentItemSet = null; } }
public GroupRule Group(params ApiRule[] rules) { var group = new GroupRule(); if (rules != null) { group.Rules.AddRange(rules); } return(group); }
protected void btnSave_Click(object sender, EventArgs e) { try { CustomList <Group> lstGroup = SearchGroupList; if (lstGroup.Count == 0) { Group newGroup = new Group(); lstGroup.Add(newGroup); } CustomList <GroupRule> lstGroupSecurityRule = SearchGroupSecurityRuleList; if (lstGroupSecurityRule.Count == 0) { GroupRule newGroupSecurityRule = new GroupRule(); lstGroupSecurityRule.Add(newGroupSecurityRule); } SetDataFromControls(ref lstGroup); objUserGroupList = UserGroupList.FindAll(f => f.IsSaved); foreach (UserGroup uG in objUserGroupList) { uG.SetAdded(); } if (groupList.IsNotNull()) { CustomList <UserGroup> TempUserGroup = manager.GetAllUserGroup(lstGroup[0].GroupCode); if (TempUserGroup.Count != 0) { foreach (UserGroup uG in TempUserGroup) { uG.Delete(); } } if (!CheckUserAuthentication(lstGroup, groupSecurityRuleList, objUserGroupList)) { return; } manager.SaveGroup(ref TempUserGroup, ref lstGroup, ref groupSecurityRuleList, ref objUserGroupList); txtGroupCode.Text = manager.GroupID; this.SuccessMessage = (StaticInfo.SavedSuccessfullyMsg); } } catch (SqlException ex) { this.ErrorMessage = (ExceptionHelper.getSqlExceptionMessage(ex)); } catch (Exception ex) { this.ErrorMessage = (ExceptionHelper.getExceptionMessage(ex)); } }
public ActionResult SearchGroup(EasyUIGridParamModel param, Group group) { int itemCount = 0; List <dynamic> groupList = new GroupRule().SearchGroup(param, group, out itemCount); var showList = from groups in groupList select new { ID = groups.ID, NAME = groups.NAME }; return(Json(new { total = itemCount, rows = showList }, JsonRequestBehavior.AllowGet)); }
public void CreateNode(TreeNode node, TagType type) { if (node == null || !(node.Tag is GroupRule)) { return; } GroupRule dataNode = node.Tag as GroupRule; TreeNode newNode = null; switch (type) { case TagType.TAG_BYTE: newNode = CreateIntegralNode <ByteTagRule, TagNodeByte>("Byte"); break; case TagType.TAG_SHORT: newNode = CreateIntegralNode <ShortTagRule, TagNodeShort>("Short"); break; case TagType.TAG_INT: newNode = CreateIntegralNode <IntTagRule, TagNodeInt>("Int"); break; case TagType.TAG_LONG: newNode = CreateIntegralNode <LongTagRule, TagNodeLong>("Long"); break; case TagType.TAG_FLOAT: newNode = CreateFloatNode <FloatTagRule, TagNodeFloat>("Float"); break; case TagType.TAG_DOUBLE: newNode = CreateFloatNode <DoubleTagRule, TagNodeDouble>("Double"); break; case TagType.TAG_STRING: newNode = CreateStringNode("String"); break; } if (newNode != null) { node.Nodes.Add(newNode); dataNode.Rules.Add(newNode.Tag as SearchRule); node.Expand(); } }
public GroupRule Location(int offset, params ApiLocationRule[] rules) { var group = new GroupRule(); if (rules == null) { return(group); } group.Rules.AddRange(rules.Select((r, ind) => { r.Index = offset + ind; return(r); })); return(group); }
private static bool SearchGroupRule(hwmAddressablesSystemConfig config, string groupName, out GroupRule groupRule) { for (int iGroupRule = 0; iGroupRule < config.GroupRules.Length; iGroupRule++) { GroupRule iterGroupRule = config.GroupRules[iGroupRule]; if (iterGroupRule.GroupName == groupName) { groupRule = iterGroupRule; return(true); } } groupRule = new GroupRule(); return(false); }
public void CreateIntersectNode(TreeNode node) { if (node == null || !(node.Tag is GroupRule)) { return; } GroupRule dataNode = node.Tag as GroupRule; TreeNode newNode = CreateNode(new IntersectRule()); node.Nodes.Add(newNode); dataNode.Rules.Add(newNode.Tag as SearchRule); node.Expand(); }
public void TestRulePriority() { // arrage var symbol = 'a'; // act var rule = new GroupRule(new List <IRule> { new SymbolRule(symbol: symbol) }); // assert Assert.AreEqual(rule.Priority, RulePriority.RuleGrouping); }
public void AddUpGroup_covertToDic(ref Dictionary <string, string> Dic, GroupRule data) { var code = new groupRuleCode(); data = (data == null? new GroupRule() : data); Dic.Add("groupName", data.groupName); Dic.Add("rulePara", data.ruleParameter.ToString()); Dic.Add("baseFn", (data.ruleParameter & code.baseActive) > 0 ? "啟用" : "停用"); //打卡/紀錄/請假/外出 Dic.Add("editPunLog", (data.ruleParameter & code.editPunchLog) > 0 ? "啟用" : "停用"); //編輯出勤紀錄 Dic.Add("departEm", (data.ruleParameter & code.departEmployeeList) > 0 ? "啟用" : "停用"); //查看部門員工 Dic.Add("allEm", (data.ruleParameter & code.allEmployeeList) > 0 ? "啟用" : "停用"); //查看所有員工 Dic.Add("editEm", (data.ruleParameter & code.employeeEdit) > 0 ? "啟用" : "停用"); //編輯員工 Dic.Add("setDepart", (data.ruleParameter & code.departmentList) > 0 ? "啟用" : "停用"); //部門職位相關 Dic.Add("setRule", (data.ruleParameter & code.setRule) > 0 ? "啟用" : "停用"); //設定規則 Dic.Add("applySign", (data.ruleParameter & code.applySign) > 0 ? "啟用" : "停用"); //相關審核 Dic.Add("adminFn", (data.ruleParameter & code.adminFn) > 0 ? "啟用" : "停用"); //開發者用功能 }
public static void GenerateAll(hwmAddressablesSystemConfig config) { AddressableAssetSettings settings = AddressableAssetSettingsDefaultObject.Settings; for (int iGroupRule = 0; iGroupRule < config.GroupRules.Length; iGroupRule++) { GroupRule iterGroupRule = config.GroupRules[iGroupRule]; if (string.IsNullOrWhiteSpace(iterGroupRule.GroupName)) { Debug.LogError(string.Format("Group index ({0}) name is empty", iGroupRule)); continue; } GenerateWithGroupRule(settings, config.MyGenerateSetting, iterGroupRule); } Debug.Log("Generate all group finish"); }
public override void Bind(INodeGraph nodeGraph) { _outputRule = new GroupRule[Outputs.Length]; OutputNodes = new NodeOutput[Outputs.Length]; for (var i = 0; i < Outputs.Length; i++) { var outputConfiguration = Outputs[i]; OutputNodes[i] = new NodeOutput { Name = outputConfiguration.RouteTo, Node = nodeGraph.NodeByName(outputConfiguration.RouteTo), }; _outputRule[i] = new GroupRule(outputConfiguration, _expressionParser); } }
public void TestFailChekingOneSymbol() { //arrange var symbol = 'd'; var rule = new GroupRule(new List <IRule> { new SymbolRule(symbol: symbol) }); var stream = new MemoryStream().FromString((symbol + 1).ToString()); //act var isCheckedSuccess = rule.Check(stream); //assert Assert.IsFalse(isCheckedSuccess); }
public void TestStreamPositionOffsetCorrectlyWithCorrectSymbol() { // Arrange var symbol = 'e'; var rule = new GroupRule(new List <IRule> { new SymbolRule(symbol: symbol) }); var stream = new MemoryStream().FromString("example test string that so biger then needed"); var startPosition = stream.Position; // Act rule.Check(stream); // Assert Assert.AreEqual(stream.Position - 1, startPosition); }
public ActionResult DeleteGroup(string guids) { AjaxResult result = new AjaxResult(); string[] guidArray = guids.Trim(';').Split(';'); bool flag = new GroupRule().DeleteGroup(new List <string>(guidArray)); if (flag) { result.Success = true; result.Message = "角色删除成功"; } else { result.Success = false; result.Message = "已存在用户的角色不能删除"; } return(Json(result, JsonRequestBehavior.AllowGet)); }
public void CreateWildcardNode(TreeNode node) { if (node == null || !(node.Tag is GroupRule)) { return; } GroupRule dataNode = node.Tag as GroupRule; TreeNode newNode = CreateWildcardNode("Wildcard"); if (newNode != null) { node.Nodes.Add(newNode); dataNode.Rules.Add(newNode.Tag as SearchRule); node.Expand(); } }
private IParserContext ParseRule(Stream stream) { var symbol = stream.CurrentSymbol(); switch (symbol) { case StartGroup: this._context.CurrentStream.TryToSeekToNext(); var context = this._selfBuilder.Build(this._context.CurrentStream); var result = context.Parse(this._context.CurrentStream).ParsedRules.ToArray().Reverse(); if (this._context.CurrentStream.CurrentSymbol() != EndGroup) { throw new LexerBadEndGroupDeclarationException(this._context); } this._context.CurrentStream.TryToSeekToNext(); var rule = new GroupRule(result.ToImmutableList()); this._context.ParsedRules.Push(rule); break; case EndGroup: return(this._context); default: if (this._parser.IsCurrentRule(this._context)) { this._context.ParsedRules.Push(this._parser.Parse(this._context)); break; } throw new ArgumentOutOfRangeException( $"{symbol} не разобран ни одним из существующих правил.{Environment.NewLine}Контекст: {this._context}"); } return(this._context); }
public void DeleteNode(TreeNode node) { if (node == null || !(node.Tag is SearchRule)) { return; } TreeNode parent = node.Parent; if (parent == null || !(parent.Tag is GroupRule)) { return; } GroupRule parentData = parent.Tag as GroupRule; SearchRule nodeData = node.Tag as SearchRule; parentData.Rules.Remove(nodeData); parent.Nodes.Remove(node); }
private void ExpandNode(TreeNode node, bool recurse) { GroupRule rule = node.Tag as GroupRule; if (rule == null) { return; } foreach (var subRule in rule.Rules) { TreeNode subNode = CreateNode(subRule); node.Nodes.Add(subNode); if (recurse) { ExpandNode(subNode, recurse); } } }
private void SetDataFromControls(ref CustomList <Group> lstGroup) { try { #region Group Group group = lstGroup[0]; group.GroupCode = txtGroupCode.Text; group.GroupName = txtGroupName.Text; #endregion #region Group Security Rule #region Delete CustomList <GroupRule> TempGroupSecurityRule = manager.GetAllGroupSecurityRule(lstGroup[0].GroupCode); if (TempGroupSecurityRule.Count != 0) { foreach (GroupRule objGroupSecurityRule in TempGroupSecurityRule) { objGroupSecurityRule.Delete(); } manager.DeleteTempData(ref TempGroupSecurityRule); } #endregion CustomList <SECURITY.DAO.SecurityRule> SelectedSecurityRuleList = SecurityRuleList.FindAll(f => f.IsSaved); foreach (SECURITY.DAO.SecurityRule sR in SelectedSecurityRuleList) { GroupRule gSR = new GroupRule(); gSR.ApplicationID = "1"; gSR.GroupCode = txtGroupCode.Text; gSR.SecurityRuleCode = sR.SecurityRuleCode; //gSR.CompanyID = drpCompany.SelectedValue; groupSecurityRuleList.Add(gSR); } #endregion } catch (Exception ex) { throw ex; } }
private void AddToGroup(Expression expression, GroupRule rule) { switch (rule) { case GroupRule.ALL: if (_allExpressionGroup == null) { _allExpressionGroup = expression; return; } _allExpressionGroup = Expression.AndAlso(_allExpressionGroup, expression); break; case GroupRule.ONE_OF: if (_oneOfExpressionGroup == null) { _oneOfExpressionGroup = expression; return; } _oneOfExpressionGroup = Expression.ExclusiveOr(_oneOfExpressionGroup, expression); break; case GroupRule.ANY: if (_anyExpressionGroup == null) { _anyExpressionGroup = expression; return; } _anyExpressionGroup = Expression.OrElse(_anyExpressionGroup, expression); break; case GroupRule.NONE: if (_noneExpressionGroup == null) { _noneExpressionGroup = Expression.Not(expression); return; } _noneExpressionGroup = Expression.AndAlso(_noneExpressionGroup, expression); break; default: FatalErr("Unexpected enumeration value: " + Enum.GetName(typeof(GroupRule), rule)); break; } }
private void CreateAttributeCondition(XbimQueryBuilder qBuilder, XmlNode attributeGroupNode) { GroupRule grpRule = GetGroupRule(attributeGroupNode); //apply logical operators according to the "select" XmlNodeList attrs = ((XmlElement)attributeGroupNode).GetElementsByTagName("attribute"); foreach (XmlNode attr in attrs) { //attribute name XmlNode nameNode = ((XmlElement)attr).GetElementsByTagName("name").Item(0); if (nameNode == null) { errLog.WriteLine("Attribute with unspecified name in element '" + eName + "', group '" + grpName + "'"); continue; } string attName = nameNode.InnerText; PropertyInfo propInfo = elemType.GetProperty(attName); if (propInfo == null) { errLog.WriteLine("Attribute with name '" + attName + "' doesn't exist in the element '" + eName + "' in group '" + grpName + "'"); continue; } //attribut value XmlNode valueNode = ((XmlElement)attr).GetElementsByTagName("value").Item(0); if (nameNode == null) { errLog.WriteLine("Attribute with unspecified value in element '" + eName + "', group '" + grpName + "'"); continue; } string attValue = valueNode.InnerText; ValueRule attValRule = GetValueRule(valueNode); //create part of the expression qBuilder.AddAttributeCondition(attName, attValue, attValRule, grpRule); } }
public void TestRighSringSavedInFaledCase() { var symbol1 = 'g'; var symbol2 = 'b'; var rule11 = new SymbolRule(symbol: symbol1); var rule1 = new OneOrManyRule(rule11); var rule22 = new SymbolRule(symbol: symbol2); var rule2 = new ZeroOrManyRule(rule22); var rule = new GroupRule(new List <IRule> { rule1, rule2 }); var str = $"${symbol2}"; var stream = new MemoryStream().FromString(str); // Act rule.Check(stream); // Assert Assert.AreEqual(string.Empty, rule.ChekedString); }
public void AddAttributeCondition(string attributName, string value, ValueRule valueRule, GroupRule groupRule) { if (attributName == null) { Err("Attribute name not specified"); return; } //check attribut existence in the specified type PropertyInfo attr = Type.GetProperty(attributName); if (attr == null) { Err("Attribute name '" + attributName + "' does not exist in specified type '" + Type.Name + "'."); return; } //create expression to access attribute Expression attrExp = Expression.Property(input, attr); //get value from the string Expression val = XbimQueryFactory.PromoteToConstant(attr.PropertyType, value); if (val == null) { Err("Value '" + value + "' could not be converted to the type of the attribute '" + attributName + "'."); return; } //create binary expression according to valueRule Expression expression = CreateValueExpression(attrExp, val, valueRule); if (expression == null) { Err("Value rule'" + Enum.GetName(typeof(ValueRule), valueRule)+ "' cannot be applied on the attribute '" + attributName + "'."); return; } //add resulting expression to the group AddToGroup(expression, groupRule); }
public void AddPropertyCondition(string pSetName, NameRule pSetNameRule, string propertyName, NameRule propNameRule, string value, ValueRule valueRule, GroupRule groupRule) { Expression psn = Expression.Constant(pSetName); Expression psnRl = Expression.Constant(pSetNameRule); Expression pn = Expression.Constant(propertyName); Expression pnRl = Expression.Constant(propNameRule); Expression valConst = Expression.Constant(value); Expression valRul = Expression.Constant(valueRule); MethodInfo getPropMeth = typeof(PropertyHelper).GetMethod("EvaluatePropertyValue"); if (getPropMeth == null) throw new Exception("Wrong method definition."); //public static IfcValue GetPropertyValue(IPersistIfcEntity element, string pSetName, NameRule pSetNameRule, string propertyName, NameRule propNameRule) Expression property = Expression.Call(getPropMeth, new Expression[] {input ,psn, psnRl, pn, pnRl, valConst, valRul}); //bool result of the test AddToGroup(property, groupRule); }
private void AddToGroup(Expression expression, GroupRule rule) { switch (rule) { case GroupRule.ALL: if (_allExpressionGroup == null) { _allExpressionGroup = expression; return;} _allExpressionGroup = Expression.AndAlso(_allExpressionGroup, expression); break; case GroupRule.ONE_OF: if (_oneOfExpressionGroup == null) { _oneOfExpressionGroup = expression; return; } _oneOfExpressionGroup = Expression.ExclusiveOr(_oneOfExpressionGroup, expression); break; case GroupRule.ANY: if (_anyExpressionGroup == null) { _anyExpressionGroup = expression; return; } _anyExpressionGroup = Expression.OrElse(_anyExpressionGroup, expression); break; case GroupRule.NONE: if (_noneExpressionGroup == null) { _noneExpressionGroup = Expression.Not(expression); return; } _noneExpressionGroup = Expression.AndAlso(_noneExpressionGroup, expression); break; default: FatalErr("Unexpected enumeration value: " + Enum.GetName(typeof(GroupRule), rule)); break; } }