public async Task <IActionResult> Post([FromBody] ThingGroup thingGroup)
        {
            thingGroup.thingGroupId = 0;
            thingGroup.thingsIds    = new int[0];
            if (ModelState.IsValid)
            {
                thingGroup = await _thingGroupService.createThingGroup(thingGroup);

                return(Created($"api/thinggroups/{thingGroup.thingGroupId}", thingGroup));
            }
            return(BadRequest(ModelState));
        }
        public async Task <IActionResult> Put(int id, [FromBody] ThingGroup thingGroup)
        {
            if (ModelState.IsValid)
            {
                var curThing = await _thingGroupService.updateThingGroup(id, thingGroup);

                if (id != thingGroup.thingGroupId)
                {
                    return(NotFound());
                }
                return(NoContent());
            }
            return(BadRequest(ModelState));
        }
Esempio n. 3
0
        public async Task <ThingGroup> updateThingGroup(int thingGroupId, ThingGroup thingGroup)
        {
            var curThing = await _context.ThingGroups
                           .AsNoTracking()
                           .Where(x => x.thingGroupId == thingGroupId)
                           .FirstOrDefaultAsync();

            thingGroup.thingsIds = curThing.thingsIds;
            if (thingGroupId != thingGroup.thingGroupId)
            {
                return(null);
            }
            _context.ThingGroups.Update(thingGroup);
            await _context.SaveChangesAsync();

            return(await getThingGroup(thingGroupId));
        }
Esempio n. 4
0
        private bool CriarListaAlarmes()
        {
            try
            {
                _alarmesAtivosList = new List <Alarm>();

                AtualizaListaTags();

                _log.Debug("Criando os objetos de monitoramento");


                ThingGroup thingGroup = null;
                ThingAlarm thingAlarm = null;

                foreach (var tag in _tagsList.OrderBy(x => x.thingGroupId))
                {
                    if (thingGroup == null || thingGroup.thingGroupId != tag.thingGroupId)
                    {
                        thingGroup = _httpOtherAPI.GetAPIThingGroup(tag.thingGroupId);
                        thingAlarm = _httpOtherAPI.GetAPIAlarm(thingGroup.thingsIds.FirstOrDefault());
                    }

                    Alarm alarm = thingAlarm.alarms.Where(x => x.alarmName == tag.tagName).FirstOrDefault();

                    if (alarm == null)
                    {
                        alarm         = new Alarm();
                        alarm.thingId = thingGroup.thingsIds.FirstOrDefault();
                    }
                    alarm.tagIL = tag.physicalTag;

                    _alarmesAtivosList.Add(alarm);
                }

                return(true);
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message);
                return(false);
            }
        }
Esempio n. 5
0
 public async Task<ThingGroup> GetThingGroup(int groupId)
 {
     HttpClient client = new HttpClient();
     ThingGroup returnGroups = null;
     client.DefaultRequestHeaders.Accept.Clear();
     client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
     var builder = new UriBuilder(_configuration["thingGroupServiceEndpoint"] + groupId);
     string url = builder.ToString();
     var result = await client.GetAsync(url);
     switch (result.StatusCode)
     {
         case HttpStatusCode.OK:
             returnGroups = JsonConvert.DeserializeObject<ThingGroup>(await client.GetStringAsync(url));
             return returnGroups;
         case HttpStatusCode.NotFound:
             return returnGroups;
         case HttpStatusCode.InternalServerError:
             return returnGroups;
     }
     return returnGroups;
 }
        public ThingGroup GetAPIThingGroup(int thingGroupId)
        {
            try
            {
                HttpRequestOtherAPI restComunication = new HttpRequestOtherAPI();

                StringBuilder urlBuilder = new StringBuilder();
                urlBuilder.Append(ConfigurationManager.AppSettings["GetThingGroup"]);
                urlBuilder.Append(thingGroupId.ToString());

                var content = RequestOtherAPI("get", urlBuilder.ToString(), "xpto", "application/json", null);

                ThingGroup thingGroup = JsonConvert.DeserializeObject <ThingGroup>(content);

                return(thingGroup);
            }
            catch (Exception ex)
            {
                _log.Error(ex.ToString());
                return(null);
            }
        }