Ejemplo n.º 1
0
        public IEnumerable <DeviceRegistration> fromFirmware([FromQuery] int skip = 0, [FromQuery] int top = 0, [FromQuery] string filter = null, [FromQuery] string client = null)
        {
            var totalCount = new OptionalOutTotalCount();

            if (!User.IsInRole("SGI.MASTER"))
            {
                throw new Box.Common.BoxLogicException("Você não tem permissão de acessar esta funcionalidade.");
            }

            // passar o "User", para ver se tem acesso aos devices do cliente
            var devices = _sgiService.GetDevicesWithDataFirmware(User, skip, top, filter, client, totalCount);

            Request.SetListTotalCount(totalCount.Value);
            return(devices);
        }
Ejemplo n.º 2
0
        public IEnumerable <DashboardViewModels> Get(string id, [FromQuery] string de, [FromQuery] string ate, [FromQuery] int skip = 0, [FromQuery] int top = 0)
        {
            if (id == null)
            {
                throw new Box.Common.BoxLogicException("É necessário informar o id do dispositivo.");
            }

            var deviceRegistration = _sgiService.GetDeviceRegistrationFull(id);
            var totalCount         = new OptionalOutTotalCount();
            var reports            = _sgiService.GetReports(id, User, deviceRegistration.Package.Type, skip, top, de, ate, totalCount, null, false, true).ToArray();

            Request.SetListTotalCount(totalCount.Value);

            return(reports);
        }
Ejemplo n.º 3
0
        public IEnumerable <DashboardViewModels> Get([FromQuery] int skip = 0, [FromQuery] int top = 0, [FromQuery] string filter = null)
        {
            var totalCount = new OptionalOutTotalCount();

            bool isFullAcess = false;

            if (User.IsInRole("SGI.MASTER"))
            {
                isFullAcess = true;
            }

            var dashboard = _sgiService.GetDashboards(User, totalCount, isFullAcess);

            Request.SetListTotalCount(totalCount.Value);

            return(dashboard);
        }
Ejemplo n.º 4
0
        public IEnumerable <DeviceRegistration> ofClient(string id)
        {
            var totalCount = new OptionalOutTotalCount();

            bool isFullAcess = false;

            if (User.IsInRole("SGI.MASTER"))
            {
                isFullAcess = true;
            }

            // passar o "User", para ver se tem acesso aos devices do cliente
            var devices = _sgiService.GetDevicesOfClient(User, isFullAcess, id);

            Request.SetListTotalCount(totalCount.Value);
            return(devices);
        }
Ejemplo n.º 5
0
        public IEnumerable <DeviceRegistration> FromDashboard([FromQuery] int skip = 0, [FromQuery] int top = 0, [FromQuery] string filter = null)
        {
            var totalCount = new OptionalOutTotalCount();

            bool isFullAcess = false;

            if (User.IsInRole("SGI.MASTER"))
            {
                isFullAcess = true;
            }

            // passar o "User", para ver se tem acesso aos devices do cliente
            var devices = _sgiService.GetDevicesFromDashboard(User, skip, top, filter, totalCount, isFullAcess);

            Request.SetListTotalCount(totalCount.Value);
            return(devices);
        }
        public IEnumerable <Device> GetDevices(ClaimsPrincipal user, int skip = 0, int top = 0, string filter = null, OptionalOutTotalCount totalCount = null, bool isFullAcess = false, string scope = null)
        {
            IQueryable <Device> devicesQuery = _context.Devices.Where(w => w.Activable);

            if (!isFullAcess)
            {
                // filtrar apenas os dispositivos que tem acesso
                var userDevices = GetUserDevices(user.GetId());
                devicesQuery = devicesQuery.Where(c => userDevices.Any(a => a.Id == c.Id));
            }

            if (!String.IsNullOrEmpty(filter))
            {
                filter       = filter.ToLower();
                devicesQuery = devicesQuery.Where(f => f.Name.ToLower().Contains(filter) || f.Id.ToLower().Contains(filter));
            }

            // ordernação
            devicesQuery = devicesQuery.OrderBy(o => o.Id);
            if (totalCount != null)
            {
                totalCount.Value = devicesQuery.Count();
            }

            if (skip != 0)
            {
                devicesQuery = devicesQuery.Skip(skip);
            }

            if (top != 0)
            {
                devicesQuery = devicesQuery.Take(top);
            }

            var devices = devicesQuery.ToArray();

            if (devices != null && scope == null)
            {
                foreach (var d in devices)
                {
                    // adicionar dados da "message" para mostrar previamente nas telas de listagem algumas informações
                    var dashboard = GetDashboard(d.Id);
                    if (dashboard == null)
                    {
                        d.Bits = new ViewModels.Bits();
                    }
                    else
                    {
                        d.Bits = dashboard.Bits;
                    }
                }
            }

            return(devices);
        }
Ejemplo n.º 7
0
        public IEnumerable <DashboardViewModels> GetReportDataDJRF(string id, int skip = 0, int top = 0, string de = null, string ate = null, bool blocked = false, OptionalOutTotalCount totalCount = null, bool isCallByGraphic = false)
        {
            List <DashboardViewModels> newData  = new List <DashboardViewModels>();
            IQueryable <Message>       messages = _context.Messages
                                                  .AsNoTracking()
                                                  .Include(i => i.Device)
                                                  .Where(w => w.DeviceId == id && (w.TypePackage.Equals("12") || w.TypePackage.Equals("13")))
                                                  .OrderByDescending(o => o.Time);

            try
            {
                // verificar status de bloqueado ou has-out
                if (blocked)
                {
                    messages = messages.Where(c => c.Bits.EstadoBloqueio || c.Bits.EstadoSaidaRastreador);
                }

                if (!de.Equals("null"))
                {
                    var firstDate = Convert.ToDateTime(de).ToUniversalTime().AddHours(-3);
                    messages = messages.Where(c => c.Date >= firstDate);
                }
                if (!ate.Equals("null"))
                {
                    var lastDate = Convert.ToDateTime(ate).ToUniversalTime().AddHours(-3).AddDays(1);
                    messages = messages.Where(c => c.Date <= lastDate);
                }

                if (messages == null)
                {
                    return(null);
                }

                List <Message> tmpMessages = messages.ToList();
                if (totalCount != null)
                {
                    totalCount.Value = tmpMessages.Count();
                }

                if (isCallByGraphic)
                {
                    top = totalCount.Value;
                }

                while (tmpMessages.Count() > 0 && newData.Count() <= top)
                {
                    DashboardViewModels newItem = new DashboardViewModels();
                    var message12 = tmpMessages.FirstOrDefault(w => w.TypePackage.Equals("12"));
                    var message13 = tmpMessages.FirstOrDefault(w => w.TypePackage.Equals("13"));

                    // Convertendo os dados para pacote 12
                    if (message12 != null)
                    {
                        newItem.DeviceId           = message12.DeviceId;
                        newItem.Name               = message12.Device.Name;
                        newItem.Package            = message12.Data;
                        newItem.TypePackage        = message12.TypePackage;
                        newItem.Date               = message12.Date;
                        newItem.Country            = message12.Country;
                        newItem.Lqi                = message12.Lqi;
                        newItem.Bits               = message12.Bits;
                        newItem.EstadoDetector     = message12.EstadoDetector;
                        newItem.PeriodoTransmissao = message12.PeriodoTransmissao;
                        newItem.ContadorCarencias  = message12.ContadorCarencias;
                        newItem.ContadorBloqueios  = message12.ContadorBloqueios;
                    }

                    // Convertendo os dados para pacote 13
                    if (message13 != null)
                    {
                        var firstCaracter = message13.Temperature.Substring(0, message13.Temperature.Length - 1);
                        var lastCaracter  = message13.Temperature.Substring(message13.Temperature.Length - 1, 1);
                        newItem.Temperature = $"{firstCaracter},{lastCaracter}";
                        newItem.Alimentacao = message13.Alimentacao;
                    }

                    // set location on dashboard of device
                    // DeviceLocation deviceLocation = GetDeviceLocationByDeviceId(id);
                    // if (deviceLocation != null)
                    // {
                    //     newItem.Latitude = deviceLocation.Latitude.ToString();
                    //     newItem.Longitude = deviceLocation.Longitude.ToString();
                    //     newItem.Radius = deviceLocation.Radius;

                    //     newItem.LatitudeConverted = LocationDecimalToDegrees((decimal)deviceLocation.Latitude, "S");
                    //     newItem.LongitudeConverted = LocationDecimalToDegrees((decimal)deviceLocation.Longitude, "W");
                    //     newItem.RadiusConverted = RadiusFormated(deviceLocation.Radius);
                    // }

                    newData.Add(newItem);

                    tmpMessages.Remove(message12);
                    tmpMessages.Remove(message13);
                }

                if (skip != 0 && top != 0)
                {
                    if (isCallByGraphic)
                    {
                        return(newData.Skip(skip).Take(top).OrderBy(o => o.Date).ToArray());
                    }

                    return(newData.Skip(skip).Take(top).OrderByDescending(o => o.Date).ToArray());
                }

                if (skip != 0 && top == 0)
                {
                    if (isCallByGraphic)
                    {
                        return(newData.Skip(skip).OrderBy(o => o.Date).ToArray());
                    }

                    return(newData.Skip(skip).OrderByDescending(o => o.Date).ToArray());
                }

                if (skip == 0 && top != 0)
                {
                    if (isCallByGraphic)
                    {
                        return(newData.Take(top).OrderBy(o => o.Date).ToArray());
                    }

                    return(newData.Take(top).OrderByDescending(o => o.Date).ToArray());
                }

                if (isCallByGraphic)
                {
                    return(newData.OrderBy(o => o.Date).ToArray());
                }

                return(newData.OrderByDescending(o => o.Date).ToArray());
            }
            catch (System.Exception)
            {
                return(newData);
            }
        }
Ejemplo n.º 8
0
        public IEnumerable <DashboardViewModels> GetReportDataTRM10(string id, int skip = 0, int top = 0, string de = null, string ate = null, OptionalOutTotalCount totalCount = null, bool isCallByGraphic = false)
        {
            List <DashboardViewModels> newData      = new List <DashboardViewModels>();
            IQueryable <Message>       reportsQuery = _context.Messages.AsNoTracking().Include(i => i.Device).Where(w => w.DeviceId == id && (w.TypePackage.Equals("23"))).OrderByDescending(o => o.Id);

            try
            {
                if (!de.Equals("null"))
                {
                    DateTime firstDate = Convert.ToDateTime(de).ToUniversalTime();
                    reportsQuery = reportsQuery.Where(c => c.OperationDate.Value.Year >= firstDate.Year && c.OperationDate.Value.Month >= firstDate.Month && c.OperationDate.Value.Day >= firstDate.Day);
                }
                if (!ate.Equals("null"))
                {
                    var lastDate = Convert.ToDateTime(ate).ToUniversalTime();
                    reportsQuery = reportsQuery.Where(c => c.OperationDate.Value.Year <= lastDate.Year && c.OperationDate.Value.Month <= lastDate.Month && c.OperationDate.Value.Day <= lastDate.Day);
                }

                if (totalCount != null)
                {
                    totalCount.Value = reportsQuery.Count();
                }

                if (skip != 0)
                {
                    reportsQuery = reportsQuery.Skip(skip);
                }

                if (top != 0)
                {
                    reportsQuery = reportsQuery.Take(top);
                }

                foreach (var report in reportsQuery)
                {
                    DashboardViewModels newItem = new DashboardViewModels();
                    newItem.DeviceId    = report.DeviceId;
                    newItem.Name        = report.Device.Name;
                    newItem.Package     = report.Data;
                    newItem.TypePackage = report.TypePackage;
                    newItem.Date        = report.Date;
                    newItem.Country     = report.Country;
                    newItem.Lqi         = report.Lqi;
                    newItem.Bits        = report.Bits;

                    var _fluxoAgua   = FromFloatSafe(report.FluxoAgua);
                    var _consumoAgua = FromFloatSafe(report.ConsumoAgua);

                    newItem.FluxoAgua   = String.Format("{0:0.0}", _fluxoAgua);
                    newItem.ConsumoAgua = String.Format("{0:0.0}", _consumoAgua);

                    if (!isCallByGraphic)
                    {
                        var _display = Consts.GetDisplayTRM10(newItem.Bits.BAlertaMax, newItem.Bits.ModoFechado, newItem.Bits.ModoAberto);
                        newItem.Modo        = _display.DisplayModo;    // modo
                        newItem.Estado      = _display.DisplayEstado;  // alerta
                        newItem.Valvula     = _display.DisplayValvula; // válvula
                        newItem.EstadoColor = _display.EstadoColor;
                    }

                    newData.Add(newItem);
                }

                return(newData.OrderBy(o => o.Date).ToArray());
            }
            catch (System.Exception ex)
            {
                _log.Log("Erro GetReportDataTRM.", ex.Message, true);
                return(newData);
            }
        }
Ejemplo n.º 9
0
        public IEnumerable <DashboardViewModels> GetReportDataTRM(string id, int skip = 0, int top = 0, string de = null, string ate = null, OptionalOutTotalCount totalCount = null)
        {
            List <DashboardViewModels> newData      = new List <DashboardViewModels>();
            IQueryable <Message>       reportsQuery = _context.Messages.AsNoTracking().Include(i => i.Device).Where(w => w.DeviceId == id && (w.TypePackage.Equals("21"))).OrderByDescending(o => o.Id);

            try
            {
                if (!de.Equals("null"))
                {
                    DateTime firstDate = Convert.ToDateTime(de).ToUniversalTime();
                    reportsQuery = reportsQuery.Where(c => c.OperationDate.Value.Year >= firstDate.Year && c.OperationDate.Value.Month >= firstDate.Month && c.OperationDate.Value.Day >= firstDate.Day);
                }
                if (!ate.Equals("null"))
                {
                    DateTime lastDate = Convert.ToDateTime(ate).ToUniversalTime();
                    reportsQuery = reportsQuery.Where(c => c.OperationDate.Value.Year <= lastDate.Year && c.OperationDate.Value.Month <= lastDate.Month && c.OperationDate.Value.Day <= lastDate.Day);
                }

                if (totalCount != null)
                {
                    totalCount.Value = reportsQuery.Count();
                }

                if (skip != 0)
                {
                    reportsQuery = reportsQuery.Skip(skip);
                }

                if (top != 0)
                {
                    reportsQuery = reportsQuery.Take(top);
                }

                foreach (var report in reportsQuery)
                {
                    DashboardViewModels newItem = new DashboardViewModels();
                    newItem.DeviceId    = report.DeviceId;
                    newItem.Name        = report.Device.Name;
                    newItem.Package     = report.Data;
                    newItem.TypePackage = report.TypePackage;
                    newItem.Date        = report.Date;
                    newItem.Country     = report.Country;
                    newItem.Lqi         = report.Lqi;
                    newItem.Bits        = report.Bits;

                    var _entradaAnalogica = FromFloatSafe(report.EntradaAnalogica);
                    var _saidaAnalogica   = FromFloatSafe(report.SaidaAnalogica);

                    newItem.EntradaAnalogica = String.Format("{0:0.0}", _entradaAnalogica);
                    newItem.SaidaAnalogica   = String.Format("{0:0.0}", _saidaAnalogica);

                    newData.Add(newItem);
                }

                return(newData.OrderByDescending(o => o.Date).ToArray());
            }
            catch (System.Exception ex)
            {
                _log.Log("Erro GetReportDataTRM.", ex.Message, true);
                return(newData);
            }
        }
Ejemplo n.º 10
0
        public IEnumerable <DashboardViewModels> GetReportDataAguamon(string id, int skip = 0, int top = 0, OptionalOutTotalCount totalCount = null)
        {
            List <DashboardViewModels> newData      = new List <DashboardViewModels>();
            IQueryable <Message>       reportsQuery = _context.Messages
                                                      .AsNoTracking().Include(i => i.Device)
                                                      .Where(w => w.DeviceId == id && (w.TypePackage.Equals("10"))).OrderByDescending(o => o.Id);

            try
            {
                if (totalCount != null)
                {
                    totalCount.Value = reportsQuery.Count();
                }

                if (skip != 0)
                {
                    reportsQuery = reportsQuery.Skip(skip);
                }

                if (top != 0)
                {
                    reportsQuery = reportsQuery.Take(top);
                }

                foreach (var report in reportsQuery)
                {
                    DashboardViewModels newItem = new DashboardViewModels();
                    newItem.DeviceId    = report.DeviceId;
                    newItem.Name        = report.Device.Name;
                    newItem.Package     = report.Data;
                    newItem.TypePackage = report.TypePackage;
                    newItem.Date        = report.Date;
                    newItem.Country     = report.Country;
                    newItem.Lqi         = report.Lqi;
                    newItem.Bits        = report.Bits;

                    newItem.Temperature        = (decimal.Parse(report.Temperature) * 100).ToString();
                    newItem.Temperature        = report.Temperature.ToString().Substring(0, report.Temperature.Length - 2);
                    newItem.Envio              = report.Envio;
                    newItem.PeriodoTransmissao = report.PeriodoTransmissao;
                    newItem.Alimentacao        = $"{report.Alimentacao},0";
                    newItem.AlimentacaoMinima  = $"{report.AlimentacaoMinima},0";

                    newData.Add(newItem);
                }

                return(newData.OrderByDescending(o => o.Date).ToArray());
            }
            catch (System.Exception)
            {
                return(newData);
            }
        }
Ejemplo n.º 11
0
        public IEnumerable <DashboardViewModels> GetReportDataPQA(string id, int skip = 0, int top = 0, string de = null, string ate = null, OptionalOutTotalCount totalCount = null, bool isCallByGraphic = false)
        {
            List <DashboardViewModels> newData  = new List <DashboardViewModels>();
            IQueryable <Message>       messages = _context.Messages
                                                  .AsNoTracking()
                                                  .Include(i => i.Device)
                                                  .Where(w => w.DeviceId == id && (w.TypePackage.Equals("81") || w.TypePackage.Equals("82")))
                                                  .OrderByDescending(o => o.Time);

            try
            {
                if (!de.Equals("null"))
                {
                    DateTime firstDate = Convert.ToDateTime(de).ToUniversalTime();
                    messages = messages.Where(c => c.OperationDate.Value.Year >= firstDate.Year && c.OperationDate.Value.Month >= firstDate.Month && c.OperationDate.Value.Day >= firstDate.Day);
                }
                if (!ate.Equals("null"))
                {
                    var lastDate = Convert.ToDateTime(ate).ToUniversalTime();
                    messages = messages.Where(c => c.OperationDate.Value.Year <= lastDate.Year && c.OperationDate.Value.Month <= lastDate.Month && c.OperationDate.Value.Day <= lastDate.Day);
                }

                if (messages == null)
                {
                    return(null);
                }

                List <Message> tmpMessages = messages.ToList();
                if (totalCount != null)
                {
                    totalCount.Value = tmpMessages.Count();
                }

                if (isCallByGraphic)
                {
                    top = totalCount.Value;
                }

                while (tmpMessages.Count() > 0 && newData.Count() <= top)
                {
                    DashboardViewModels newItem = new DashboardViewModels();
                    var message81 = tmpMessages.FirstOrDefault(w => w.TypePackage.Equals("81"));
                    var message82 = tmpMessages.FirstOrDefault(w => w.TypePackage.Equals("82"));

                    // Convertendo os dados para pacote 81
                    if (message81 != null)
                    {
                        newItem.DeviceId    = message81.DeviceId;
                        newItem.Name        = message81.Device.Name;
                        newItem.Package     = message81.Data;
                        newItem.TypePackage = message81.TypePackage;
                        newItem.Date        = message81.Date;
                        newItem.Country     = message81.Country;
                        newItem.Lqi         = message81.Lqi;

                        if (isCallByGraphic)
                        {
                            newItem.Temperature = message81.Temperature.Length > 2 ? $"{message81.Temperature.Substring(0, 2)},{message81.Temperature.Substring(2, message81.Temperature.Length - 2)}" : message81.Temperature;
                        }
                        else
                        {
                            newItem.Temperature = message81.Temperature.Length > 2 ? $"{message81.Temperature.Substring(0, 2)},{message81.Temperature.Substring(2, message81.Temperature.Length - 2)}" : message81.Temperature;
                            newItem.Ph          = message81.Ph;
                            newItem.Fluor       = message81.Fluor;
                            newItem.Cloro       = message81.Cloro;
                            newItem.Turbidez    = message81.Turbidez;
                        }
                    }

                    // Convertendo os dados para pacote 82
                    if (message82 != null && !isCallByGraphic)
                    {
                        newItem.Rele = new Rele()
                        {
                            Rele1 = Utils.HexaToDecimal(message82.Package.Substring(0, 2)).ToString(),
                            Rele2 = Utils.HexaToDecimal(message82.Package.Substring(2, 2)).ToString(),
                            Rele3 = Utils.HexaToDecimal(message82.Package.Substring(4, 2)).ToString(),
                            Rele4 = Utils.HexaToDecimal(message82.Package.Substring(6, 2)).ToString(),
                            Rele5 = Utils.HexaToDecimal(message82.Package.Substring(8, 2)).ToString()
                        };
                    }

                    if (!isCallByGraphic)
                    {
                        newData.Add(newItem);
                    }
                    else
                    {
                        if (!message81.TemperatureIsZero)
                        {
                            newData.Add(newItem);
                        }
                    }

                    tmpMessages.Remove(message81);
                    tmpMessages.Remove(message82);
                }

                if (skip != 0 && top != 0)
                {
                    if (isCallByGraphic)
                    {
                        return(newData.Skip(skip).Take(top).OrderBy(o => o.Date).ToArray());
                    }

                    return(newData.Skip(skip).Take(top).OrderByDescending(o => o.Date).ToArray());
                }

                if (skip != 0 && top == 0)
                {
                    if (isCallByGraphic)
                    {
                        return(newData.Skip(skip).OrderBy(o => o.Date).ToArray());
                    }

                    return(newData.Skip(skip).OrderByDescending(o => o.Date).ToArray());
                }

                if (skip == 0 && top != 0)
                {
                    if (isCallByGraphic)
                    {
                        return(newData.Take(top).OrderBy(o => o.Date).ToArray());
                    }

                    return(newData.Take(top).OrderByDescending(o => o.Date).ToArray());
                }

                if (isCallByGraphic)
                {
                    return(newData.OrderBy(o => o.Date).ToArray());
                }

                return(newData.OrderByDescending(o => o.Date).ToArray());
            }
            catch (System.Exception)
            {
                return(newData);
            }
        }
Ejemplo n.º 12
0
        public IEnumerable <DashboardViewModels> GetReportDataHidroponia(string id, int skip = 0, int top = 0, string de = null, string ate = null, OptionalOutTotalCount totalCount = null, string orderBy = null)
        {
            List <DashboardViewModels> newData      = new List <DashboardViewModels>();
            IQueryable <Message>       reportsQuery = _context.Messages.AsNoTracking().Include(i => i.Device).Where(w => w.DeviceId == id).OrderByDescending(o => o.Id);

            try
            {
                if (totalCount != null)
                {
                    totalCount.Value = reportsQuery.Count();
                }

                DateTime?lastDate  = reportsQuery.Max(m => m.Date);
                DateTime?fisrtDate = reportsQuery.Min(m => m.Date);

                if (top != 0)
                {
                    fisrtDate = lastDate?.AddDays(-top);
                }

                if (!de.Equals("null"))
                {
                    fisrtDate = Convert.ToDateTime(de).ToUniversalTime().AddHours(-3);
                }

                if (!ate.Equals("null"))
                {
                    lastDate = Convert.ToDateTime(ate).ToUniversalTime().AddHours(-3);
                }

                for (DateTime i = fisrtDate.Value; i <= lastDate; i = i.AddDays(1))
                {
                    var deviceMessageType22 = reportsQuery
                                              .Where(w => w.DeviceId == id &&
                                                     w.TypePackage.Equals("22") &&
                                                     w.OperationDate.Value.Year == i.Year &&
                                                     w.OperationDate.Value.Month == i.Month &&
                                                     w.OperationDate.Value.Day == i.Day)
                                              .OrderByDescending(o => o.Id).FirstOrDefault();

                    var deviceMessageType23 = reportsQuery
                                              .Where(w => w.DeviceId == id &&
                                                     w.TypePackage.Equals("23") &&
                                                     w.OperationDate.Value.Year == i.Year &&
                                                     w.OperationDate.Value.Month == i.Month &&
                                                     w.OperationDate.Value.Day == i.Day)
                                              .OrderByDescending(o => o.Id).FirstOrDefault();


                    if (deviceMessageType22 != null && deviceMessageType23 != null)
                    {
                        DashboardViewModels newItem = new DashboardViewModels();
                        newItem.DeviceId           = deviceMessageType22.DeviceId;
                        newItem.Name               = deviceMessageType22.Device.Name;
                        newItem.Package            = $"{deviceMessageType22.Data} | {deviceMessageType23.Data}";
                        newItem.TypePackage        = $"{deviceMessageType22.TypePackage} e {deviceMessageType23.TypePackage}";
                        newItem.Date               = deviceMessageType22.Date;
                        newItem.Country            = deviceMessageType22.Country;
                        newItem.Lqi                = deviceMessageType22.Lqi;
                        newItem.Bits               = deviceMessageType22.Bits;
                        newItem.Level              = deviceMessageType22.Level;
                        newItem.Light              = deviceMessageType22.Light;
                        newItem.Temperature        = deviceMessageType22.Temperature;
                        newItem.Moisture           = deviceMessageType22.Moisture;
                        newItem.OxigenioDissolvido = deviceMessageType22.OxigenioDissolvido;
                        newItem.Ph                 = deviceMessageType23.Ph;
                        newItem.Condutividade      = deviceMessageType23.Condutividade;
                        newItem.PeriodoTransmissao = deviceMessageType23.PeriodoTransmissao;
                        newItem.BaseT              = deviceMessageType23.BaseT;

                        newData.Add(newItem);
                    }
                }
                // if (skip != 0)
                //     reportsQuery = reportsQuery.Skip(skip);
                // if (top != 0)
                //     newData = newData.Take(top);
                return(newData.OrderByDescending(o => o.Date).ToArray());
            }
            catch (System.Exception)
            {
                return(newData);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Get contents using several filters.
        /// </summary>
        /// <param name="filter">Search filter to be used at Name, Abstract, Tags and CustomIngo fields</param>
        /// <param name="skip">Skip those first contents</param>
        /// <param name="top">Max number of contents to be returned</param>
        /// <param name="location">Returns only contents at this location</param>
        /// <param name="kinds">Returns only contents of these kinds</param>
        /// <param name="order">Returns content ordered (DESC or ASC) by one of the following Name, Date, DisplayOrder, Comments, Share, PageView, Random, RandomOnDay, CrossLinkDisplayOrder, CustomFields</param>
        /// <param name="createdFrom">Retuns only contents created after this date will be returned</param>
        /// <param name="createdTo">Returns only contents created until this date will be returned</param>
        /// <param name="includeData">Use True to include content data</param>
        /// <param name="onlyPublished">Use True for only published content</param>
        /// <param name="queryFilter">A custom content query</param>
        /// <returns></returns>
        public IEnumerable <ContentHead> GetContents(string filter, int skip, int top, string location, string[] kinds, OptionalOutTotalCount totalCount = null, Orders order = Orders.Date, DateTime?createdFrom = null, DateTime?createdTo = null, bool includeData = false, bool onlyPublished = false, System.Linq.Expressions.Expression <Func <ContentHead, bool> > queryFilter = null)
        {
            IQueryable <ContentHead> contents = null;

            if (!includeData)
            {
                contents = _context.ContentHeads.Include(c => c.CrossLinks).Include(c => c.CommentsCount).Include(c => c.ShareCount).Include(c => c.PageViewCount).Include(c => c.Tags).Include(c => c.CustomInfo);
            }
            else
            {
                contents = _context.ContentHeads.Include(c => c.CrossLinks).Include(c => c.CommentsCount).Include(c => c.ShareCount).Include(c => c.PageViewCount).Include(c => c.Tags).Include(c => c.CustomInfo).Include(c => c.Data);
            }

            if (createdFrom.HasValue)
            {
                contents = contents.Where(c => c.ContentDate >= createdFrom.Value);
            }

            if (createdTo.HasValue)
            {
                contents = contents.Where(c => c.ContentDate <= createdTo.Value);
            }

            if (onlyPublished)
            {
                contents = OnlyPublishedContents(contents);
            }

            if (queryFilter != null)
            {
                contents = contents.Where(queryFilter);
            }

            if (!String.IsNullOrEmpty(filter))
            {
                filter   = filter.ToLower();
                contents = contents.Where(c =>
                                          (c.CustomInfo != null && (c.CustomInfo.Text1.ToLower().StartsWith(filter) || c.CustomInfo.Text2.ToLower().StartsWith(filter) || c.CustomInfo.Text3.ToLower().StartsWith(filter) || c.CustomInfo.Text4.ToLower().StartsWith(filter))) ||
                                          c.Name.ToLower().Contains(filter) ||
                                          c.Abstract.ToLower().Contains(filter) ||
                                          c.Tags.Any(t => t.Tag.Contains(filter)) ||
                                          c.CrossLinks.Any(x => x.PageArea.Contains(filter)));
            }

            contents = OrderContents(contents, order);

            if (location != null && location.ToLower() != "null")
            {
                location = location.ToLower();
                if (!location.EndsWith("/"))
                {
                    location = location + "/";
                }
                contents = contents.Where(c => c.Location == location);
            }

            if (kinds != null && kinds.Any(k => k != null))
            {
                contents = contents.Where(c => kinds.Contains(c.Kind.ToLower()));
            }

            if (skip != 0)
            {
                contents = contents.Skip(skip);
            }

            if (top != 0)
            {
                contents = contents.Take(top);
            }

            if (totalCount != null)
            {
                totalCount.Value = contents.Count();
            }

            return(contents.ToArray());
        }
Ejemplo n.º 14
0
        public IEnumerable <File> GetFiles(string filter, int skip, int top, string folder, bool unUsed, OptionalOutTotalCount totalCount = null)
        {
            IQueryable <File> files = _context.Files;

            if (unUsed)
            {
                files = files.Where(x => !_context.ContentDatas.Where(c => c.JSON.Contains(x.FileUId)).Any() && !_context.ContentHeads.Where(w => w.ThumbFilePath.Contains(x.FileUId)).Any());
            }

            if (!String.IsNullOrEmpty(filter))
            {
                filter = filter.ToLower();
                files  = files.Where(f => f.FileName.ToLower().Contains(filter));
            }

            if (folder != null)
            {
                files = files.Where(f => f.Folder == folder);
            }

            files = files.OrderBy(f => f.FileName);

            if (totalCount != null)
            {
                totalCount.Value = files.Count();
            }

            if (skip != 0)
            {
                files = files.Skip(skip);
            }

            if (top != 0)
            {
                files = files.Take(top);
            }


            return(files.ToArray());
        }
Ejemplo n.º 15
0
        public IEnumerable <DeviceRegistration> GetDevicesRegistrations(int skip = 0, int top = 0, string filter = null, OptionalOutTotalCount totalCount = null)
        {
            IQueryable <DeviceRegistration> devicesRegistrations = _context.DevicesRegistration.Include(i => i.Device).Include(i => i.Package).Include(i => i.Project);

            if (!String.IsNullOrEmpty(filter))
            {
                filter = filter.ToLower();
                devicesRegistrations = devicesRegistrations.Where(c =>
                                                                  c.Name.ToLower().Contains(filter));
            }

            // ordernação
            devicesRegistrations = devicesRegistrations.OrderBy(c => c.Name);

            if (totalCount != null)
            {
                totalCount.Value = devicesRegistrations.Count();
            }

            if (skip != 0)
            {
                devicesRegistrations = devicesRegistrations.Skip(skip);
            }

            if (top != 0)
            {
                devicesRegistrations = devicesRegistrations.Take(top);
            }

            return(devicesRegistrations.ToArray());
        }
Ejemplo n.º 16
0
        public IEnumerable <Client> GetClients(ClaimsPrincipal user, int skip = 0, int top = 0, string filter = null, bool?statusClient = null, bool isSubClient = false, OptionalOutTotalCount totalCount = null)
        {
            IQueryable <Client> clients = _context.Clients;

            if (isSubClient)
            {
                var clientsOfUser = _context.Clients.Include(i => i.Users).Where(c => c.Users.Any(a => a.ApplicationUserId == user.GetId()));
                clients = clients.Where(c => clientsOfUser.Any(a => a.ClientUId == c.ClientFatherUId));
            }

            if (statusClient != null)
            {
                clients = clients.Where(c => c.Active == statusClient);
            }

            if (!String.IsNullOrEmpty(filter))
            {
                filter  = filter.ToLower();
                clients = clients.Where(c =>
                                        c.Name.ToLower().Contains(filter) ||
                                        c.Document.ToLower().Contains(filter) ||
                                        c.Address.ToLower().Contains(filter)
                                        );
            }

            // ordernação
            clients = clients.OrderBy(c => c.Name);

            if (totalCount != null)
            {
                totalCount.Value = clients.Count();
            }

            if (skip != 0)
            {
                clients = clients.Skip(skip);
            }

            if (top != 0)
            {
                clients = clients.Take(top);
            }

            return(clients.ToArray());
        }
Ejemplo n.º 17
0
        public IEnumerable <Log> GetLogs(string filter = null, int skip = 0, int top = 0, DateTime?fromDate = null, DateTime?toDate = null, OptionalOutTotalCount totalCount = null)
        {
            IQueryable <Log> logs = _context.Logs;

            if (!String.IsNullOrEmpty(filter))
            {
                string[] tags = filter.ToLower().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                logs = logs.Where(l => tags.All(t =>
                                                l.SignedUser.ToLower() == t ||
                                                l.Url.ToLower().Contains(t) ||
                                                l.ActionDescription.ToLower().Contains(t) ||
                                                l.UserIp.ToLower() == t));
            }

            if (fromDate != null)
            {
                fromDate = fromDate.Value.Date;
                logs     = logs.Where(l => l.When >= fromDate.Value);
            }

            if (toDate != null)
            {
                DateTime dataAteDiaSeguinte = toDate.Value.AddDays(1).Date;
                logs = logs.Where(l => l.When < dataAteDiaSeguinte);
            }

            logs = logs.OrderByDescending(l => l.When);

            if (totalCount != null)
            {
                totalCount.Value = logs.Count();
            }


            if (skip != 0)
            {
                logs = logs.Skip(skip);
            }

            if (top != 0)
            {
                logs = logs.Take(top);
            }

            // dont return error description here
            return(logs.ToList().Select(l => new Log
            {
                ActionDescription = l.ActionDescription,
                ErrorDescription = l.ErrorDescription,
                LogType = l.LogType,
                LogUId = l.LogUId,
                SignedUser = l.SignedUser,
                Url = l.Url,
                UserIp = l.UserIp,
                When = l.When
            }).ToArray());
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Return users filtered by a given filter.
        /// </summary>
        /// <param name="filter">The filter</param>
        /// <param name="skip">Users to skip for pagination</param>
        /// <param name="top">Number os users for pagination</param>
        /// <param name="totalCount">Object to hold the total count</param>
        /// <param name="includeNameClaim">Include only the given_name claim</param>
        /// <param name="includeAllClaims">Include all claims</param>
        /// <param name="atRoles">filter only users at those roles</param>
        /// <param name="withClaims">filter only users with those claims</param>
        /// <returns></returns>
        public IEnumerable <Models.ApplicationUser> GetUsers(string filter = null, bool?lockedOut = null, int skip = 0, int top = 0, OptionalOutTotalCount totalCount = null, bool includeNameClaim = true, bool includeAllClaims = false, string[] atRoles = null, string[] withClaims = null)
        {
            IQueryable <Models.ApplicationUser> users;

            if (includeAllClaims || includeNameClaim)
            {
                users = _context.Users.Include(u => u.UserClaims).Include(u => u.UserRoles).AsQueryable();
            }
            else
            {
                users = _context.Users.AsQueryable();
            }

            if (atRoles != null && atRoles.Length > 0)
            {
                users = users.Where(u => atRoles.Any(rId => u.UserRoles.Any(ur => ur.RoleId == rId)));
            }

            if (withClaims != null && withClaims.Length > 0)
            {
                users = users.Where(u => withClaims.Any(c => u.UserClaims.Any(uc => uc.ClaimType == "role" && uc.ClaimValue == c)));
            }

            if (!string.IsNullOrEmpty(filter))
            {
                var tags = filter.ToLower().Split(' ', StringSplitOptions.RemoveEmptyEntries);
                users = users.Where(u =>
                                    tags.Any(t => u.UserName.ToLower().Contains(t)) ||
                                    tags.Any(t => u.Email.ToLower().Contains(t)) ||
                                    tags.Any(t => u.UserClaims.Any(c => c.ClaimType == "given_name" && c.ClaimValue.ToLower().Contains(t))));
            }

            // filter locked users
            var now = DateTime.Now;

            if (lockedOut == true)
            {
                users = users.Where(u => u.LockoutEnd != null && u.LockoutEnd >= now);
            }
            if (lockedOut == false)
            {
                users = users.Where(u => u.LockoutEnd == null || u.LockoutEnd < now);
            }

            users = users.OrderBy(u => u.UserName);

            if (totalCount != null)
            {
                totalCount.Value = users.Count();
            }

            if (skip != 0)
            {
                users = users.Skip(skip);
            }

            if (top != 0)
            {
                users = users.Take(top);
            }

            return(users.ToArray());
        }
        public IEnumerable <Project> GetProjects(int skip = 0, int top = 0, string filter = null, OptionalOutTotalCount totalCount = null)
        {
            IQueryable <Project> projects = _context.Projects;

            if (!String.IsNullOrEmpty(filter))
            {
                filter   = filter.ToLower();
                projects = projects.Where(c =>
                                          c.Name.ToLower().Contains(filter) ||
                                          c.Description.ToLower().Contains(filter));
            }

            // ordernação
            projects = projects.OrderBy(c => c.Name);

            if (totalCount != null)
            {
                totalCount.Value = projects.Count();
            }

            if (skip != 0)
            {
                projects = projects.Skip(skip);
            }

            if (top != 0)
            {
                projects = projects.Take(top);
            }

            return(projects.ToArray());
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Return roles filtered by a given filter.
        /// </summary>
        /// <param name="filter">The filter</param>
        /// <param name="skip">Users to skip for pagination</param>
        /// <param name="top">Number os users for pagination</param>
        /// <param name="totalCount">Object to hold the total count</param>
        /// <returns></returns>
        public IEnumerable <Models.ApplicationRole> GetRoles(string filter = null, int skip = 0, int top = 0, OptionalOutTotalCount totalCount = null, bool isSystemRole = false)
        {
            IQueryable <Models.ApplicationRole> roles = _context.Roles.Include(u => u.RoleClaims).AsQueryable();

            if (isSystemRole)
            {
                roles = roles.Where(c => c.IsSystemRole);
            }

            if (!string.IsNullOrEmpty(filter))
            {
                var tags = filter.ToLower().Split(' ', StringSplitOptions.RemoveEmptyEntries);
                roles = roles.Where(u =>
                                    tags.Any(t => u.Name.ToLower().Contains(t)) ||
                                    tags.Any(t => u.RoleClaims.Any(c => c.ClaimValue.ToLower().Contains(t))));
            }

            roles = roles.OrderBy(u => u.Name);

            if (totalCount != null)
            {
                totalCount.Value = roles.Count();
            }

            if (skip != 0)
            {
                roles = roles.Skip(skip);
            }

            if (top != 0)
            {
                roles = roles.Take(top);
            }

            return(roles.ToArray());
        }
        public IEnumerable <DeviceRegistration> GetDevicesWithDataFirmware(ClaimsPrincipal user, int skip = 0, int top = 0, string filter = null, string clientUId = null, OptionalOutTotalCount totalCount = null)
        {
            var devicesIdWithFirmware = _context.Messages.Where(c => c.TypePackage.Equals("51") || c.TypePackage.Equals("52")).Select(s => s.DeviceId);
            IQueryable <DeviceRegistration> devicesQuery = _context.DevicesRegistration
                                                           .Include(i => i.Device)
                                                           .Where(w => w.Device.Activable && devicesIdWithFirmware.Any(a => a == w.DeviceId));

            if (clientUId != null && !String.IsNullOrEmpty(clientUId) && clientUId != "null")
            {
                var devicesClient = _context.ClientsDevices.Where(c => c.ClientUId == clientUId);
                devicesQuery = devicesQuery.Where(c => devicesClient.Any(a => a.Id == c.DeviceId));
            }

            if (!String.IsNullOrEmpty(filter))
            {
                filter       = filter.ToLower();
                devicesQuery = devicesQuery.Where(f => f.Name.ToLower().Contains(filter) || f.DeviceId.ToLower().Contains(filter));
            }

            // ordernação
            devicesQuery = devicesQuery.OrderBy(o => o.DeviceId);
            if (totalCount != null)
            {
                totalCount.Value = devicesQuery.Count();
            }

            if (skip != 0)
            {
                devicesQuery = devicesQuery.Skip(skip);
            }

            if (top != 0)
            {
                devicesQuery = devicesQuery.Take(top);
            }

            return(devicesQuery.ToArray());
        }
        public IEnumerable <Outgoing> GetOutgoings(int skip = 0, int top = 0, string filter = null, int month = 0, int year = 0, OptionalOutTotalCount totalCount = null)
        {
            IQueryable <Outgoing> outgoings = _context.Outgoings;

            if (month != 0)
            {
                outgoings = outgoings.Where(c => c.Month == month);
            }

            if (year != 0)
            {
                outgoings = outgoings.Where(c => c.Year == year);
            }

            if (!String.IsNullOrEmpty(filter))
            {
                filter    = filter.ToLower();
                outgoings = outgoings.Where(c =>
                                            c.Description.ToLower().Contains(filter));
            }

            // ordernação
            outgoings = outgoings.OrderByDescending(c => c.Year).ThenByDescending(c => c.Month);

            if (totalCount != null)
            {
                totalCount.Value = outgoings.Count();
            }

            if (skip != 0)
            {
                outgoings = outgoings.Skip(skip);
            }

            if (top != 0)
            {
                outgoings = outgoings.Take(top);
            }

            return(outgoings.ToArray());
        }
Ejemplo n.º 23
0
        public IEnumerable <DashboardViewModels> GetReports(string id, ClaimsPrincipal user, string typePackage, int skip = 0, int top = 0, string de = null, string ate = null, OptionalOutTotalCount totalCount = null, string orderBy = null, bool blocked = false, bool isCallByGraphic = false)
        {
            // Projeto Aguamon
            if (typePackage.Equals("10"))
            {
                return(GetReportDataAguamon(id, skip, top, totalCount));
            }

            // Projeto Aguamon-2
            if (typePackage.Equals("81"))
            {
                return(GetReportDataPQA(id, skip, top, de, ate, totalCount, isCallByGraphic));
            }

            // Projeto Hidroponia
            if (typePackage.Equals("22"))
            {
                return(GetReportDataHidroponia(id, skip, top, de, ate, totalCount, orderBy));
            }

            // Projeto DJRF
            if (typePackage.Equals("12"))
            {
                return(GetReportDataDJRF(id, skip, top, de, ate, blocked, totalCount, isCallByGraphic));
            }

            // Projeto TRM
            if (typePackage.Equals("21"))
            {
                return(GetReportDataTRM(id, skip, top, de, ate, totalCount));
            }

            // Projeto TRM-10
            if (typePackage.Equals("23"))
            {
                return(GetReportDataTRM10(id, skip, top, de, ate, totalCount, isCallByGraphic));
            }

            return(null);
        }