public int AddDevicePing(int tenantId, DevicePingDomain device) { if (device == null) { throw new ArgumentNullException("device cannot be null"); } if (tenantId <= 0) { throw new NsiArgumentException("Invalid tenant ID"); } device.TenantId = tenantId; var devicePingDb = new NSI.EF.DevicePing().FromDomainModel(device); _context.DevicePing.Add(devicePingDb); // Set devicePingId to newly added record id device.DevicePropertyValues.ForEach(dpv => { dpv.DevicePingId = devicePingDb.DevicePingId; dpv.TenantId = tenantId; }); device.DevicePropertyValues.ForEach(devicePropertyValue => { _context.DevicePropertyValue.Add((new NSI.EF.DevicePropertyValue()).FromDomainModel(devicePropertyValue)); }); _context.SaveChanges(); return(devicePingDb.DevicePingId); }
public void EvaluateAll(DevicePingDomain devicePing) { IEnumerable <RuleDomain> rules = _ruleRepository.GetAllByDeviceId(devicePing.DeviceId); foreach (var rule in rules) { Evaluate(rule, devicePing); } }
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); } }
public static NSI.EF.DevicePing FromDomainModel(this NSI.EF.DevicePing obj, DevicePingDomain domain) { if (obj == null) { obj = new NSI.EF.DevicePing(); } obj.DevicePingId = domain.Id; obj.TenantId = domain.TenantId; obj.RuleId = domain.RuleId; obj.DateCreated = domain.DateCreated; obj.ActionId = domain.ActionId; obj.DeviceId = domain.DeviceId; return(obj); }
public int Add(int tenantId, List <DevicePropertyValue> devicePropertyValues) { if (devicePropertyValues == null) { throw new ArgumentNullException("devicePropertyValues cannot be null"); } if (devicePropertyValues.Count == 0) { throw new ArgumentException("devicePropertyValues cannot be an empty list"); } devicePropertyValues.ForEach(x => x.DateCreated = DateTime.Now); DevicePingDomain devicePing = new DevicePingDomain { DateCreated = DateTime.Now, DevicePropertyValues = devicePropertyValues, DeviceId = devicePropertyValues[0].DeviceId, TenantId = tenantId, ActionId = 1, RuleId = null }; var createdDevicePingId = _devicePingRepository.AddDevicePing(tenantId, devicePing); var cretedDevicePing = _devicePingRepository.GetDevicePingById(tenantId, createdDevicePingId); if (cretedDevicePing != null) { _publishEndpoint.Publish <IDevicePingReceived>(new { MessageId = Guid.NewGuid(), Timestamp = DateTime.Now, DevicePing = cretedDevicePing }); } return(createdDevicePingId); }
public void GetDevicePingById_Success() { DevicePingDomain devicePing = _devicePingManipulation.GetById(1, 1); Assert.AreEqual(1, devicePing.Id); }