private void CreateDeviceNotWorkingIncident(RuleDomain rule, DevicePingDomain devicePing) { _incidentRepository.AddIncident(new POSTIncidentDomain() { TenantId = rule.TenantId, IncidentStatus = 1, // 1 indicates a new incident DeviceId = devicePing.DeviceId, Priority = 4, // high priority if device is not working IncidentType = 5, // device not working AssigneeId = 7, // who to assign if multiple users belong to the same tenant? ReporterId = 7, // who's the reporter if the issue was detected by the rule engine? }, rule.TenantId); }
private void CreateIncident(RuleDomain rule, DevicePingDomain devicePing) { _incidentRepository.AddIncident(new POSTIncidentDomain() { TenantId = rule.TenantId, IncidentStatus = 1, // 1 indicates a new incident DeviceId = devicePing.DeviceId, Priority = 2, // low priority by default IncidentType = FindOrCreateIncidentType(rule), AssigneeId = 7, // who to assign if multiple users belong to the same tenant? ReporterId = 8, // who's the reporter if the issue was detected by the rule engine? }, rule.TenantId); }
private void Evaluate(RuleDomain rule, DevicePingDomain devicePing) { try { if (!_ruleEvaluator.Evaluate(rule)) { CreateIncident(rule, devicePing); } } catch (Exception) { CreateDeviceNotWorkingIncident(rule, devicePing); } }
private int FindOrCreateIncidentType(RuleDomain rule) { var types = _incidentTypeRepository .GetAllIncidentTypes() .Where(x => x.Name == rule.Name); if (types.Any()) { return(types.First().IncidentTypeId); } return(_incidentTypeRepository.AddIncidentType(new IncidentTypeDomain() { TenantId = rule.TenantId, Name = rule.Name, Code = "1", // all existing types had this code IsActive = true })); }
public static Rule FromDomainModel(this Rule obj, RuleDomain domain) { if (obj == null) { obj = new Rule(); } obj.RuleId = domain.RuleId; obj.Name = domain.Name; obj.Description = domain.Description; obj.DateCreated = domain.DateCreated; obj.CreatedBy = domain.CreatedBy; obj.DateModified = domain.DateModified; obj.ModifiedBy = domain.ModifiedBy; obj.IsActive = domain.IsActive; obj.IsDeleted = domain.IsDeleted; return(obj); }
public bool Evaluate(RuleDomain rule) { ComparatorFactory factory = new ComparatorFactory(); foreach (var condition in rule.Conditions) { var latestDevicePing = _devicePingRepository.LastDevicePingForDevice(condition.Device.DeviceId); DevicePropertyValue latestValue = latestDevicePing.DevicePropertyValues.Find( x => x.PropertyId == condition.Property.PropertyId ); if (!factory.Make(condition.ComparisonOperator).Compare(latestValue.Value, condition.ComparisonValue)) { return(false); } } return(true); }