public HttpResponseMessage Get(int lookupID) { try { RuleDTO retVal = null; //get rule by hash if (dbDal.ReadRule(lookupID, out retVal)) { return(Request.CreateResponse(HttpStatusCode.OK, retVal)); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Rule was not found")); } } catch (NpgsqlException e) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Database error occurred")); } catch (Exception e) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Failed to get the rule")); } }
public RuleDTO GetRuleDTO(string userId, string entityId) { validateParameters(userId, entityId); //we need to implement validator handlers so that we can entityId with respect to scope var dto = new RuleDTO(); setRuleSummaryProperties(dto); if (dto.Scope == RuleEntityScope.Global) { dto.Style = this.DefaultStyle.GetStyleDTO(); } else { var customStyle = StyleCustomizations.Where(sc => sc.UserId == userId && sc.EntityId == entityId).FirstOrDefault(); if (customStyle == null) { dto.Style = this.DefaultStyle.GetStyleDTO(); } else { dto.Style = customStyle.Style.GetStyleDTO(); } } return(dto); }
public void ShowRuleTrailsView(RuleDTO res) { var view = ServiceLocator.Current.GetInstance <IRuleTrailListView>(); ((RuleTrailListVM)view.ViewModel).Load(res); viewManager.ShowInDialog(view); }
private void init() { Rule = new RuleDTO(); SelectedRuleVersion = new RuleVersionDTO(); Versions = new ObservableCollection <RuleVersionDTO>(); Periods = new ObservableCollection <PeriodDescriptionDTO>(); }
public void ShowRuleView(RuleDTO rule, ActionType actionType) { var view = ServiceLocator.Current.GetInstance <IRuleView>(); ((RuleVM)view.ViewModel).Load(rule, actionType); viewManager.ShowInDialog(view); }
public RuleVersionVM() { init(); Rule = new RuleDTO { Name = "قانون یک" }; }
public async Task <IActionResult> CreateNewRule([FromBody] RuleModel ruleModel) { RuleDTO ruleDTO = _mapper.Map <RuleDTO>(ruleModel); var operationDetails = await _ruleService.CreateRule(ruleDTO); return(Ok(operationDetails)); }
public void Load(RuleDTO ruleParam, ActionEnum actionTypeParam) { preLoad(); Rule = ruleParam; actionType = actionTypeParam; actions[actionTypeParam].Invoke(); }
/// <summary> /// Phuong thuc suy dien tien: Tra ve bien trung gian( cac su kien da duoc suy dien) /// </summary> /// <param name="SAT"></param> /// <param name="rulesCopy"></param> /// <param name="rules"></param> /// <param name="mediate"></param> /// <returns>mediate</returns> private static List <string> ForwardChaining(Queue <int> SAT, List <RuleDTO> rulesCopy, List <RuleDTO> rules, List <string> mediate) { FilterSAT(SAT, rulesCopy, mediate); //Duyet SAT cho den khi tap SAT rong while (SAT.Count != 0) { // Xet rule dau tien trong tap SAT // Lay ra ruleId va xoa khoi hang doi var ruleId = SAT.Dequeue(); // Tim rule theo ruleid RuleDTO rule = rules.Find(item => item.Id == ruleId); // Neu khong tim duoc rule thì bo qu vong lap nay if (rule == null) { continue; } // Them su kien vao bien trung gian mediate.Add(rule.Right); // Tim SAT FilterSAT(SAT, rulesCopy, mediate); if (rulesCopy.Count == 0) { break; } } return(mediate); }
public void DoAction(GridRuleListVM vm) { var rule = new RuleDTO { PolicyId = vm.PolicyRules.PolicyId }; basicInfoController.ShowRuleView(rule, ActionType.AddRule); }
private void dgvRules_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { int row = e.RowIndex; int id = int.Parse(dgvRules.Rows[row].Cells[0].Value.ToString()); ruleDTOTemp = RulesBLL.FindByID(id); txtRuleLeft.Text = string.Join("^", ruleDTOTemp.Left); txtRuleRight.Text = ruleDTOTemp.Right.ToString(); }
public async Task <OperationDetails> UpdateRule(RuleDTO ruleDTO) { if (await _dataBase.RuleRepository.CheckIfExist(ruleDTO.RuleId) == false) { throw new ValidationException("There is no information about target rule.", $"Incorrect rule id - {ruleDTO.RuleId.ToString()}"); } _dataBase.RuleRepository.Update(_mapper.Map <Rule>(ruleDTO)); await _dataBase.SaveAsync(); return(new OperationDetails(true, "Rule was updated.", $"Rule id - {ruleDTO.RuleId.ToString()}")); }
public static RuleEN Convert(RuleDTO dto) { RuleEN newinstance = null; try { if (dto != null) { newinstance = new RuleEN(); newinstance.Id = dto.Id; newinstance.Name = dto.Name; newinstance.IsEnabled = dto.IsEnabled; if (dto.Condition != null) { MoSIoTGenNHibernate.CAD.MosIoT.IRuleConditionCAD ruleConditionCAD = new MoSIoTGenNHibernate.CAD.MosIoT.RuleConditionCAD(); newinstance.Condition = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.RuleConditionEN>(); foreach (RuleConditionDTO entry in dto.Condition) { newinstance.Condition.Add(RuleConditionAssemblerDTO.Convert(entry)); } } if (dto.RuleAction != null) { MoSIoTGenNHibernate.CAD.MosIoT.IRuleActionCAD ruleActionCAD = new MoSIoTGenNHibernate.CAD.MosIoT.RuleActionCAD(); newinstance.RuleAction = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.RuleActionEN>(); foreach (RuleActionDTO entry in dto.RuleAction) { newinstance.RuleAction.Add(RuleActionAssemblerDTO.Convert(entry)); } } if (dto.IoTScenario_oid != -1) { MoSIoTGenNHibernate.CAD.MosIoT.IIoTScenarioCAD ioTScenarioCAD = new MoSIoTGenNHibernate.CAD.MosIoT.IoTScenarioCAD(); newinstance.IoTScenario = ioTScenarioCAD.ReadOIDDefault(dto.IoTScenario_oid); } newinstance.IntervalTime = dto.IntervalTime; newinstance.Description = dto.Description; } } catch (Exception ex) { throw ex; } return(newinstance); }
public async Task <RuleDTO> UpdateRuleStyle(RuleDTO newRuleDto, IEnumerable <FileDataDTO> fileDtos, string userId, string entityId) { try { _muw.BeginTransaction(); if (fileDtos != null) { foreach (var fileData in fileDtos) { var EFFile = new EFFile { Data = fileData.Data, ContentType = fileData.ContentType, Length = fileData.Length, Name = fileData.Name }; _muw.Repository <EFFile>().Insert(EFFile); _muw.SaveChanges(); newRuleDto.Style.SetFilePropertyWithId(fileData.CssProperty, EFFile.Id); } } //remove old files var oldRuleDTO = await this.GetRuleDetails(newRuleDto.Id, userId, entityId); var clientFilePropertiesValues = newRuleDto.Style.GetFilePropertiesValues(); var oldFilePropertiesValues = oldRuleDTO.Style.GetFilePropertiesValues(); foreach (var oldFileIdValue in oldFilePropertiesValues) { if (!clientFilePropertiesValues.Contains(oldFileIdValue))//the file is delete or replaced with another one, then delete old one { _muw.Repository <EFFile>().Delete(_muw.Repository <EFFile>().FirstOrDefault(fd => fd.Id == oldFileIdValue)); } } _muw.SaveChanges(); var oldEFRule = _muw.Repository <EFRule>().GetList(r => r.Id == newRuleDto.Id).FirstOrDefault(); if (oldRuleDTO == null) { throw new Exception("No Css rule with Id=" + newRuleDto.Id); } oldEFRule.SetRuleStyle(newRuleDto.Style, userId, entityId); _muw.SaveChanges(); _muw.Commit(); return(oldEFRule.GetRuleDTO(userId, entityId)); } catch (Exception ex) { _muw.Rollback(); throw ex; } }
private IEnumerable <string> GetFollowInRule(string nonTerminal, RuleDTO rule, ICollection <string> checkedNonTerminals) { List <string> result = new List <string>(); string rightPart = rule.RightPart; int legnth = rightPart.Length; List <int> indexes = new List <int>(); for (int i = 0; i < legnth; i++) { if (rightPart[i].ToString() == nonTerminal) { indexes.Add(i); } } foreach (var i in indexes) { bool addEndRowSymbol = true;; for (int j = i + 1; j < legnth; j++) { if (_grammar.NonTerminals.Contains(rightPart[j].ToString())) { if (IsEpsNonTerminal(rightPart[j].ToString())) { result.AddRange(GetFirstForNonTerminal(rightPart[j].ToString()).Where(x => x != epsilon)); } else { result.AddRange(GetFirstForNonTerminal(rightPart[j].ToString()).Where(x => x != epsilon)); addEndRowSymbol = false; break; } } else { result.Add(rightPart[j].ToString()); addEndRowSymbol = false; break; } } if (addEndRowSymbol) { result.Add(epsilon); if (!checkedNonTerminals.Contains(rule.LeftPart)) { result.AddRange(GetFollow(rule.LeftPart, checkedNonTerminals)); } } } return(result); }
public async Task Insert(RuleDTO rule) { using (var uow = UnitOfWorkProvider.Create()) { _ruleRepository.Insert(new Rule() { IsEnabled = true, Regex = rule.Regex }); await uow.CommitAsync(); } }
public async Task <OperationDetails> CreateRule(RuleDTO ruleDTO) { if (ruleDTO == null) { throw new ValidationException("There is no information about target rule.", "Empty input parameter."); } if (await _dataBase.DeviceLogRepository.CheckIfExist(ruleDTO.RuleId)) { throw new ValidationException("Rule with this id already exists.", ruleDTO.RuleId.ToString()); } _dataBase.RuleRepository.Create(_mapper.Map <Rule>(ruleDTO)); await _dataBase.SaveAsync(); return(new OperationDetails(true, "Rule created succesfully", ruleDTO.RuleId.ToString())); }
//UtilsService<RuleCountDTO> Util = new UtilsService<RuleCountDTO>(); public IHttpActionResult Get() { try { var ruls = new RuleDTO(service.GetAll()); if (ruls.Allrules.Count != 0) { return(Ok(ruls.Allrules)); } return(ResponseMessage(new ResponseMessageService(HttpStatusCode.NotFound, "No rules found.", Request.RequestUri.AbsoluteUri))); } catch (Exception e) { return(ExceptionMSG(e)); } }
public IHttpActionResult GetSearchResults(int PageNum, int PageSize, string Searchtext) { try { var search = new RuleDTO(service.GetSearchedRules(PageNum, PageSize, Searchtext)); if (search.Allrules.Count != 0) { return(Ok(search.Allrules)); } return(ResponseMessage(new ResponseMessageService(HttpStatusCode.NotFound, "No rules found.", Request.RequestUri.AbsoluteUri))); } catch (Exception e) { return(ExceptionMSG(e)); } }
/// <summary> /// Phuong thuc <b>xoa su kien du thua</b> trong tap luat: <br/> /// Phuong thuc nay se xoa su kien du thua trong tap luat(xet nhưng luat co 2 su lien tro len). /// </summary> /// <param name="rules"></param> private static void RemoveEventRedundant(List <RuleDTO> rules) { int i = 0; var checkRuleTemp = new RuleDTO(); var SAT = new Queue <int>(); var rulesCopy = new List <RuleDTO>(); var mediate = new List <string>(); // Xet tung luat trong tap luat while (i < rules.Count) { // Buoc 1: Bo qua nhung luat co 1 su kien if (rules[i].Left.Length == 1) { i++; continue; } rulesCopy.AddRange(rules); // Buoc 2: Xet tung luat trong tap luat string[] checkRuleLeft = (string[])rules[i].Left; // Buoc 3: Xet tung su kien trong luat dang xet foreach (string eventLeft in checkRuleLeft) { // Buoc 3.1: Xoa su kien dang xet ra khoi luat do ta duoc luat moi //checkRuleTemp = rules[i]; // Xoa su kien ra khoi rule rules[i].Left = rules[i].Left.Where(e => e != eventLeft).ToArray(); // Buoc 3.2: Thuc hien suy dien tien den khi SAT rong mediate.AddRange(rules[i].Left); mediate = ForwardChaining(SAT, rulesCopy, rules, mediate); // Buoc 3.3: Trong ket qua suy dien tien if (!mediate.Contains(eventLeft)) { rules[i].Left = Append(rules[i].Left, eventLeft); } SAT.Clear(); mediate.Clear(); rulesCopy.Clear(); } i++; } }
/// <summary> /// Phuong thuc <b>loai bo luat du thua</b>:<br/> /// <i>Ngay cap nhat : 18/04/2021</i> /// </summary> /// <param name="rules"></param> private static void RemoveRuleRedundant(List <RuleDTO> rules) { int i = 0; var checkRule = new RuleDTO(); var SAT = new Queue <int>(); var rulesCopy = new List <RuleDTO>(); var mediate = new List <string>(); while (i < rules.Count) { //Buoc 1: Lay luat can xet checkRule = rules[i]; rulesCopy.AddRange(rules); rulesCopy.Remove(checkRule); // Buoc 2: Ve trái cua luat dang xet la gia thiet mediate.AddRange(checkRule.Left); foreach (RuleDTO rule in rules) { // Bo qua luat dang xet if (rule.Equals(checkRule)) { continue; } // Buoc 3: Thuc hien suy dien mediate = ForwardChaining(SAT, rulesCopy, rules, mediate); } // Buoc 4: Neu bien trung gian chua ve phai cua luat dang xet thi xoa luat do ra khoi tap luat. if (mediate.Contains(checkRule.Right.Trim())) { rules.RemoveAt(i); } else { i++; } // SAT.Clear(); mediate.Clear(); rulesCopy.Clear(); } }
private void btnDeleteRule_Click(object sender, EventArgs e) { if (ruleDTOTemp != null) { if (RulesBLL.Delete(ruleDTOTemp.Id)) { MessageBox.Show("Xóa luật thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadRule(); ruleDTOTemp = null; ClearTextBoxes(); } } else { MessageBox.Show("Xóa luật thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public void Load(RuleDTO rule) { ShowBusyIndicator("در حال دریافت اطلاعات..."); ruleService.GetAllRuleTrails( (res, exp) => appController.BeginInvokeOnDispatcher(() => { HideBusyIndicator(); if (exp == null) { RuleTrails.SourceCollection = res.Result; RuleTrails.TotalItemCount = res.TotalCount; RuleTrails.PageIndex = Math.Max(0, res.CurrentPage - 1); } else { appController.HandleException(exp); } }), rule.PolicyId, rule.Id, RuleTrails.PageSize, RuleTrails.PageIndex + 1); }
public static RuleDTO Create(AuthorizationMatchRule auth) { var obj = new RuleDTO() { BillingMethod = (int)auth.BillingMethod, InitialAuthID = auth.InitialAuthorizationID, InitialAuthCode = auth.InitialAuthorization?.Code, InitialMinimumMinutes = auth.InitialMinimumMinutes, InitialUnitSize = auth.InitialUnitSize, FinalAuthID = auth.FinalAuthorizationID, FinalAuthCode = auth.FinalAuthorization?.Code, FinalMinimumMinutes = auth.FinalMinimumMinutes, FinalUnitSize = auth.FinalUnitSize, AllowOverlapping = auth.AllowOverlapping, RequiresAuthBCBA = auth.RequiresAuthorizedBCBA, RequiresPreAuthorization = auth.RequiresPreAuthorization }; return(obj); }
public async Task <BaseHttpActionResult> UpdateRuleStyle() { var ruleJson = HttpContext.Current.Request.Form["rule"]; var baseUrl = HttpContext.Current.Request.Form["base_url"]; var entityId = HttpContext.Current.Request.Form["entity_id"]; if (string.IsNullOrEmpty(entityId)) { entityId = null; } if (string.IsNullOrEmpty(ruleJson)) { return(ErrorHttpActionResult.GenerateBadRequest("rule form data is required")); } RuleDTO rule = JsonConvert.DeserializeObject <RuleDTO>(ruleJson); // Get the uploaded files from the Files collection , add data to the fileinfo IList <FileDataDTO> fileDtos = new List <FileDataDTO>(); foreach (var cssProperty in HttpContext.Current.Request.Files.AllKeys) { var httpPostedFile = HttpContext.Current.Request.Files[cssProperty]; int length = httpPostedFile.ContentLength; string contentType = httpPostedFile.ContentType; string name = Path.GetFileName(httpPostedFile.FileName); var fileData = new FileDataDTO(cssProperty); fileData.Data = new byte[length]; fileData.Name = name; fileData.Length = length; fileData.ContentType = contentType; httpPostedFile.InputStream.Read(fileData.Data, 0, length); fileDtos.Add(fileData); } var updateRule = await _repo.UpdateRuleStyle(rule, fileDtos, UserId, entityId); return(new SuccessHttpActionResult(updateRule.Format(baseUrl))); }
public RuleDTO UpdateRule(RuleDTO dto) { var res = pmsRuleService.UpdateRule(new PolicyId(dto.PolicyId), new RuleId(dto.Id), dto.Name, dto.RuleText, Enumeration.FromValue <RuleType>(dto.ExcuteTime.ToString()), dto.ExcuteOrder); return(ruleMapper.MapToModel(res)); }
public void Load(RuleDTO ruleParam, ActionType actionTypeParam) { preLoad(); Rule = ruleParam; actionType = actionTypeParam; }
private void init() { Rule = new RuleDTO(); }
public UpdateRuleTrailListArgs(RuleDTO rule) { RuleDto = rule; }
private List <AuthorizationBreakdown> getAuthBreakdowns(Domain2.Hours.Hours entry) { var providerType = entry.Provider.ProviderType; var service = entry.Service; var insurance = ResolutionServiceRepository.GetActiveInsurance(entry.CaseID, entry.Date); if (insurance == null) { Log(new HoursResolutionLoggingEntry { WasResolved = false, HoursID = entry.ID, HoursDate = entry.Date, ServiceID = service.ID, BillableHours = entry.BillableHours, ProviderTypeID = providerType.ID, InsuranceID = 0, AuthMatchRuleDetailJSON = Serialize(new { Message = "No insurance" }) }); return(null); } var rules = insurance.AuthorizationMatchRules; if (rules == null || rules.Count == 0) { Log(new HoursResolutionLoggingEntry { WasResolved = false, HoursID = entry.ID, HoursDate = entry.Date, ServiceID = service.ID, BillableHours = entry.BillableHours, ProviderTypeID = providerType.ID, InsuranceID = insurance.ID, AuthMatchRuleDetailJSON = Serialize(new { Message = "No rules" }) }); return(null); } var matchedRule = rules.Where(x => x.ServiceID == service.ID && x.ProviderTypeID == providerType.ID).FirstOrDefault(); if (matchedRule == null) { Log(new HoursResolutionLoggingEntry { WasResolved = false, HoursID = entry.ID, HoursDate = entry.Date, ServiceID = service.ID, BillableHours = entry.BillableHours, ProviderTypeID = providerType.ID, InsuranceID = insurance.ID, AuthMatchRuleDetailJSON = Serialize(rules.Select(m => RuleDTO.Create(m))) }); return(null); } var breakdowns = getBreakdownsForRule(entry, matchedRule); if (breakdowns == null) { Log(new HoursResolutionLoggingEntry { WasResolved = false, HoursID = entry.ID, HoursDate = entry.Date, ServiceID = service.ID, BillableHours = entry.BillableHours, ProviderTypeID = providerType.ID, InsuranceID = insurance.ID, AuthMatchRuleDetailJSON = Serialize(RuleDTO.Create(matchedRule)), ActiveAuthorizationsJSON = Serialize(entry.Case.GetActiveAuthorizations()?.Select(m => CaseAuthDTO.Create(m))) }); } else { foreach (var b in breakdowns) { Log(new HoursResolutionLoggingEntry { WasResolved = true, HoursID = entry.ID, HoursDate = entry.Date, ServiceID = service.ID, BillableHours = entry.BillableHours, ProviderTypeID = providerType.ID, InsuranceID = insurance.ID, AuthMatchRuleDetailJSON = Serialize(RuleDTO.Create(matchedRule)), ResolvedAuthID = b.Authorization?.AuthorizationCode?.ID, ResolvedAuthCode = b.Authorization?.AuthorizationCode?.Code, ResolvedCaseAuthID = b.Authorization?.ID, ResolvedCaseAuthStart = b.Authorization?.StartDate, ResolvedCaseAuthEndDate = b.Authorization?.EndDate, ResolvedAuthMatchRuleID = matchedRule.ID, ResolvedMinutes = b.Minutes }); } } return(breakdowns); }