public async Task <ActionResult> UpdateRuleProperties(EditLocationRuleModel editModel) { LocationRule updatedRule = CreateLocationRuleFromEditModel(editModel); TableStorageResponse <LocationRule> result = await _locationRulesLogic.SaveLocationRuleAsync(updatedRule); return(BuildRuleUpdateResponse(result)); }
/// <summary> /// Retrieve the default location rule. /// </summary> /// <returns></returns> public async Task <LocationRule> GetDefaultLocationRuleAsync() { LocationRule defaultRule = await GetLocationRuleAsync("default", "default"); if (defaultRule == null) { defaultRule = new LocationRule("default") { RegionId = "default", Region = "All", RegionLatitude = 300.0, RegionLongitude = 300.0, VerticalThreshold = 25.05, LateralThreshold = 20.0, ForwardThreshold = 15.8, RuleOutput = "DefaultJerk", Etag = "", EnabledState = true }; await SaveLocationRuleAsync(defaultRule); } return(defaultRule); }
private string GetIncorrectInputDetails(LocationRule rule) { if (string.IsNullOrWhiteSpace(rule.RuleId)) { return(Strings.EmptyRuleId); } return(Strings.IncorrectRegionID); }
public async Task <ActionResult> GetRuleProperties(string regionId, string ruleId) { LocationRule rule = await _locationRulesLogic.GetLocationRuleAsync(regionId, ruleId); EditLocationRuleModel editModel = CreateEditModelFromLocationRule(rule); editModel.IsCreateRequest = false; return(PartialView("_LocationRuleProperties", editModel)); }
/// <summary> /// Удаляет из цели правило выбора географической локации /// </summary> /// <param name="target">Цель геолокации</param> /// <param name="location">Географическая локация</param> public void RemoveLocationFromTarget(Target target, Location location) { LocationRule rule = LocationRuleRepository.FindByTargetAndLocation(target, location); if (rule != null) { LocationRuleRepository.Delete(rule); } }
public async Task <ActionResult> Default() { LocationRule rule = await _locationRulesLogic.GetDefaultLocationRuleAsync(); EditLocationRuleModel editModel = CreateEditModelFromLocationRule(rule); editModel.IsCreateRequest = false; return(View("EditLocationRuleProperties", editModel)); }
/// <summary> /// Retrieve a single rule from AzureTableStorage or default if none exists. /// A distinct rule is defined by the combination key regionID/ruleId /// </summary> /// <param name="regionLatitude"></param> /// <param name="regionLongitude"></param> /// <param name="ruleId"></param> /// <returns></returns> public async Task <LocationRule> GetLocationRuleAsync(string regionId, string ruleId) { TableOperation query = TableOperation.Retrieve <LocationRuleTableEntity>(regionId, ruleId); TableResult response = await Task.Run(() => _azureTableStorageClient.Execute(query) ); LocationRule result = BuildRuleFromTableEntity((LocationRuleTableEntity)response.Result); return(result); }
/// <summary> /// Generate a new rule with bare-bones configuration. This new rule can then be configured and sent /// back through the SaveDeviceRuleAsync method to persist. /// </summary> /// <param name="regionId"></param> /// <param name="latitude"></param> /// <param name="longitude"></param> /// <returns></returns> public async Task <LocationRule> GetNewRuleAsync(string regionId, double latitude, double longitude) { //making sure we have only 2 decimal places counted double regionLatitude = Math.Truncate(latitude * 100) / 100; double regionLongitude = Math.Truncate(longitude * 100) / 100; return(await Task.Run(() => { var rule = new LocationRule(); rule.InitializeNewRule(regionId, regionLatitude, regionLongitude); return rule; })); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } LocationRule = await _context.LocationRule.FirstOrDefaultAsync(m => m.LocationRuleID == id); if (LocationRule == null) { return(NotFound()); } return(Page()); }
/// <summary> /// Selects all records from the LocationRule table. /// </summary> public virtual List <LocationRule> SelectAll() { using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "LocationRuleSelectAll")) { List <LocationRule> locationRuleList = new List <LocationRule>(); while (dataReader.Read()) { LocationRule locationRule = MakeLocationRule(dataReader); locationRuleList.Add(locationRule); } dataReader.Close(); return(locationRuleList); } }
public async Task <TableStorageResponse <LocationRule> > DeleteLocationRuleAsync(string regionId, string ruleId) { LocationRule found = await _locationRulesRepository.GetLocationRuleAsync(regionId, ruleId); if (found == null) { var response = new TableStorageResponse <LocationRule>(); response.Entity = found; response.Status = TableStorageResponseStatus.NotFound; return(response); } return(await _locationRulesRepository.DeleteLocationRuleAsync(found)); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } LocationRule = await _context.LocationRule.FindAsync(id); if (LocationRule != null) { _context.LocationRule.Remove(LocationRule); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
/// <summary> /// Creates a new instance of the LocationRule class and populates it with data from the specified SqlDataReader. /// </summary> protected virtual LocationRule MakeLocationRule(SqlDataReader dataReader) { LocationRule locationRule = new LocationRule(); locationRule.ID = SqlClientUtility.GetInt32(dataReader, "ID", 0); locationRule.Code = SqlClientUtility.GetString(dataReader, "Code", String.Empty); locationRule.LocationID = SqlClientUtility.GetInt32(dataReader, "LocationID", 0); locationRule.RuleID = SqlClientUtility.GetInt32(dataReader, "RuleID", 0); locationRule.IsActive = SqlClientUtility.GetBoolean(dataReader, "IsActive", false); locationRule.Comments = SqlClientUtility.GetString(dataReader, "Comments", String.Empty); locationRule.InternalComment = SqlClientUtility.GetString(dataReader, "InternalComment", String.Empty); locationRule.CreatedBy = SqlClientUtility.GetString(dataReader, "CreatedBy", String.Empty); locationRule.CreatedOn = SqlClientUtility.GetDateTime(dataReader, "CreatedOn", DateTime.Now); locationRule.AuditActionBy = SqlClientUtility.GetString(dataReader, "AuditActionBy", String.Empty); locationRule.AuditActionOn = SqlClientUtility.GetDateTime(dataReader, "AuditActionOn", DateTime.Now); return(locationRule); }
public async Task <ActionResult> CreateOrUpdate(double lat, double lng) { var regionId = $"{Math.Truncate(lat * 10)/10}_{Math.Truncate(lng*10)/10}"; LocationRule rule = await _locationRulesLogic.GetLocationRuleOrDefaultAsync(regionId, lat, lng); EditLocationRuleModel editModel = CreateEditModelFromLocationRule(rule); if (string.IsNullOrWhiteSpace(rule.RuleId)) { editModel.IsCreateRequest = true; } else { editModel.IsCreateRequest = false; } return(View("EditLocationRuleProperties", editModel)); }
private EditLocationRuleModel CreateEditModelFromLocationRule(LocationRule rule) { EditLocationRuleModel model = new EditLocationRuleModel() { RegionId = rule.RegionId, Region = rule.Region, RuleId = rule.RuleId, RegionLatitude = rule.RegionLatitude, RegionLongitude = rule.RegionLongitude, VerticalThreshold = rule.VerticalThreshold, LateralThreshold = rule.LateralThreshold, ForwardThreshold = rule.ForwardThreshold, EnabledState = rule.EnabledState, RuleOutput = rule.RuleOutput, Etag = rule.Etag }; return(model); }
private LocationRule CreateLocationRuleFromEditModel(EditLocationRuleModel editModel) { LocationRule rule = new LocationRule() { EnabledState = editModel.EnabledState, RegionId = editModel.RegionId, RegionLatitude = editModel.RegionLatitude, RegionLongitude = editModel.RegionLongitude, Region = editModel.Region, RuleId = editModel.RuleId, VerticalThreshold = editModel.VerticalThreshold, LateralThreshold = editModel.LateralThreshold, ForwardThreshold = editModel.ForwardThreshold, RuleOutput = editModel.RuleOutput, Etag = editModel.Etag }; return(rule); }
/// <summary> /// Selects all records from the LocationRule table by a foreign key. /// </summary> public virtual List <LocationRule> SelectAllByRuleID(int ruleID) { SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@RuleID", ruleID) }; using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "LocationRuleSelectAllByRuleID", parameters)) { List <LocationRule> locationRuleList = new List <LocationRule>(); while (dataReader.Read()) { LocationRule locationRule = MakeLocationRule(dataReader); locationRuleList.Add(locationRule); } return(locationRuleList); } }
/// <summary> /// Saves a record to the LocationRule table. /// </summary> public virtual void Insert(LocationRule locationRule) { ValidationUtility.ValidateArgument("locationRule", locationRule); SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@Code", locationRule.Code), new SqlParameter("@LocationID", locationRule.LocationID), new SqlParameter("@RuleID", locationRule.RuleID), new SqlParameter("@IsActive", locationRule.IsActive), new SqlParameter("@Comments", locationRule.Comments), new SqlParameter("@InternalComment", locationRule.InternalComment), new SqlParameter("@CreatedBy", locationRule.CreatedBy), new SqlParameter("@CreatedOn", locationRule.CreatedOn), new SqlParameter("@AuditActionBy", locationRule.AuditActionBy), new SqlParameter("@AuditActionOn", locationRule.AuditActionOn) }; locationRule.ID = Convert.ToInt32(SqlClientUtility.ExecuteScalar(connectionStringName, CommandType.StoredProcedure, "LocationRuleInsert", parameters)); }
// <summary> /// Navigate to the LocationReport screen /// </summary> /// <param name="latitude"></param> /// <param name="longitude"></param> /// <returns></returns> public async Task <ActionResult> LocationReport(LocationPropertiesModel locationProperties) { var errorMessage = locationProperties.CheckForErrorMessage(); if (!String.IsNullOrWhiteSpace(errorMessage)) { return(Json(new { error = errorMessage })); } var regionLatitude = Math.Truncate((double)locationProperties.Latitude * 100) / 100; var regionLongitude = Math.Truncate((double)locationProperties.Longitude * 100) / 100; var regionId = $"{Math.Truncate(regionLatitude * 10)/10}_{Math.Truncate(regionLongitude * 10)/10}"; LocationRule rule = await _locationRulesLogic.GetLocationRuleOrDefaultAsync(regionId, regionLatitude, regionLongitude); locationProperties.RuleId = rule.RuleId; locationProperties.RegionLatitude = rule.RegionLatitude; locationProperties.RegionLongitude = rule.RegionLongitude; locationProperties.JerkedDeviceSelectList = GetSelectListFromJsonList(locationProperties.JsonList); return(View("LocationReport", locationProperties)); }
/// <summary> /// Добавляет к цели правило выбора географической локации /// </summary> /// <param name="target">Цель геолокации</param> /// <param name="location">Географическая локация</param> /// <param name="kind">Вид правила включения</param> public void AddLocationToTarget(Target target, Location location, RuleKind kind) { LocationRule rule = LocationRuleRepository.FindByTargetAndLocation(target, location); if (rule == null) { rule = new LocationRule() { TargetId = target.Id, LocationId = location.Id, Kind = kind }; LocationRuleRepository.Create(rule); } else if (rule.Kind != kind) { rule.Kind = kind; LocationRuleRepository.Save(rule); } }
private LocationRuleTableEntity BuildTableEntityFromRule(LocationRule incomingRule) { LocationRuleTableEntity tableEntity = new LocationRuleTableEntity(incomingRule.RegionId, incomingRule.RuleId) { Enabled = incomingRule.EnabledState, Region = incomingRule.Region, RegionLatitude = incomingRule.RegionLatitude, RegionLongitude = incomingRule.RegionLongitude, VerticalThreshold = incomingRule.VerticalThreshold, LateralThreshold = incomingRule.LateralThreshold, ForwardThreshold = incomingRule.ForwardThreshold, RuleOutput = incomingRule.RuleOutput }; if (!string.IsNullOrWhiteSpace(incomingRule.Etag)) { tableEntity.ETag = incomingRule.Etag; } return(tableEntity); }
private LocationRule BuildRuleFromTableEntity(LocationRuleTableEntity tableEntity) { if (tableEntity == null) { return(null); } var updatedRule = new LocationRule(tableEntity.RuleId) { RegionId = tableEntity.RegionId, Region = tableEntity.Region, EnabledState = tableEntity.Enabled, RegionLatitude = tableEntity.RegionLatitude, RegionLongitude = tableEntity.RegionLongitude, VerticalThreshold = tableEntity.VerticalThreshold, LateralThreshold = tableEntity.LateralThreshold, ForwardThreshold = tableEntity.ForwardThreshold, RuleOutput = tableEntity.RuleOutput, Etag = tableEntity.ETag }; return(updatedRule); }
public async Task <TableStorageResponse <LocationRule> > DeleteLocationRuleAsync(LocationRule ruleToDelete) { LocationRuleTableEntity incomingEntity = BuildTableEntityFromRule(ruleToDelete); TableStorageResponse <LocationRule> result = await _azureTableStorageClient.DoDeleteAsync <LocationRule, LocationRuleTableEntity>(incomingEntity, BuildRuleFromTableEntity); if (result.Status == TableStorageResponseStatus.Successful) { // Build up a new blob to push up for ASA job ref data List <LocationRuleBlobEntity> blobList = await BuildBlobEntityListFromTableRows(); await PersistRulesToBlobStorageAsync(blobList); } return(result); }
/// <summary> /// Save a rule to the data store. This method should be used for new rules as well as updating existing rules /// </summary> /// <param name="newRule"></param> /// <returns></returns> public async Task <TableStorageResponse <LocationRule> > SaveLocationRuleAsync(LocationRule newRule) { if (newRule.RegionId == "default") { return(await _locationRulesRepository.SaveLocationRuleAsync(newRule)); } string regionId = $"{Math.Truncate(newRule.RegionLatitude * 10)/10}_{Math.Truncate(newRule.RegionLongitude *10)/10}"; if (newRule.RegionId != regionId || string.IsNullOrWhiteSpace(newRule.RuleId)) { var response = new TableStorageResponse <LocationRule>(); response.Entity = newRule; response.Status = TableStorageResponseStatus.IncorrectEntry; return(response); } //Enforce single instance of a rule for a data field for a given device List <LocationRule> foundForRegion = await _locationRulesRepository.GetAllRulesForRegionAsync(newRule.RegionId); foreach (LocationRule rule in foundForRegion) { if ((rule.RuleId != newRule.RuleId) && (rule.RegionLatitude == newRule.RegionLatitude) && (rule.RegionLongitude == newRule.RegionLongitude)) { var response = new TableStorageResponse <LocationRule>(); response.Entity = rule; response.Status = TableStorageResponseStatus.DuplicateInsert; return(response); } } return(await _locationRulesRepository.SaveLocationRuleAsync(newRule)); }
public void AddRule(LocationRule r) { rules.Add(r); }
public void RemoveRule(LocationRule r) { rules.Remove(r); }