Пример #1
0
        public async Task <Coordenate> GetKeyCardCoordenateFromCache(UserType type)
        {
            Coordenate coordenate = new Coordenate();

            try
            {
                if (type == UserType.Personal)
                {
                    coordenate.positionNumber = (string)_cache.Get("coordenate");
                }
                else
                {
                    coordenate.positionNumber = (string)_cache.Get("coordenate-empresarial");
                }

                if (string.IsNullOrEmpty(coordenate.positionNumber))
                {
                    return(new Coordenate());
                }
            }
            catch (Exception ex)
            {
                coordenate.Messages = ex.Message;
            }

            return(coordenate);
        }
        public void multiples_points_on_polygon1_boundary_should_be_true(double x, double y)
        {
            var point   = new Coordenate(x, y);
            var polygon = polygon1.ToArray();

            var result = Polygon.IsInside(polygon, point);

            Assert.True(result);
        }
        public void point_on_polygon1_boundary_should_be_true()
        {
            var boundaryPoint = new Coordenate(-72.2813487, 42.9291224);
            var polygon       = polygon1.ToArray();

            var result = Polygon.IsInside(polygon, boundaryPoint);

            Assert.True(result);
        }
        public void multiples_points_DONT_belongs_to_polygon3_should_be_false()
        {
            var boundaryPoint = new Coordenate(-43.2365066, -22.9165098);
            var polygon       = polygon3.ToArray();

            var result = Polygon.IsInside(polygon, boundaryPoint);

            Assert.True(result);
        }
        public void point_on_polygon3_boundary_should_be_true()
        {
            var boundaryPoint = new Coordenate(-43.235698, -22.916006);
            var polygon       = polygon3.ToArray();

            var result = Polygon.IsInside(polygon, boundaryPoint);

            Assert.True(result);
        }
        public void multiples_points_BELONGS_TO_polygon2_should_be_true(double x, double y)
        {
            var point   = new Coordenate(x, y);
            var polygon = polygon2.ToArray();

            var result = Polygon.IsInside(polygon, point);

            Assert.True(result);
        }
        public void multiples_points_DONT_belongs_to_polygon2_should_be_false(double x, double y)
        {
            var point   = new Coordenate(x, y);
            var polygon = polygon2.ToArray();

            var result = Polygon.IsInside(polygon, point);

            Assert.False(result);
        }
        public void point_on_polygon2_boundary_should_be_true()
        {
            var boundaryPoint = new Coordenate(-43.1947740, -22.9139550);
            var polygon       = polygon2.ToArray();

            var result = Polygon.IsInside(polygon, boundaryPoint);

            Assert.True(result);
        }
        public void Update(Coordenate coordenate, long val)
        {
            if (Math.Pow(-10, 9) > val || val > Math.Pow(10, 9))
            {
                throw new ValueNodeAssignOutLimitsException($"Value assigned outside the limits, value is {val}");
            }

            if (Nodes.Any(it => it.Key.X == coordenate.X && it.Key.Y == coordenate.Y && it.Key.Z == coordenate.Z))
            {
                Nodes[coordenate] = val;
            }
        }
Пример #10
0
 public long Query(Coordenate coordenate1, Coordenate coordenate2)
 {
     if (coordenate1.X <= coordenate2.X && coordenate1.Y <= coordenate2.Y && coordenate1.Z <= coordenate2.Z &&
         coordenate2.X <= XLenght && coordenate2.Y <= YLenght && coordenate2.Z <= ZLenght)
     {
         var nodes = Nodes.Where(it => it.Key.X >= coordenate1.X && it.Key.X <= coordenate2.X && it.Key.Y >= coordenate1.Y &&
                                 it.Key.Y <= coordenate2.Y && it.Key.Z >= coordenate1.Z && it.Key.Z <= coordenate2.Z);
         return(nodes?.Sum(it => it.Value) ?? 0);
     }
     else
     {
         throw new QueryOutRangeException("Query out limit of matrix");
     }
 }
Пример #11
0
        public async Task <IActionResult> ValidatePersonalKeyCard(ValidateKeyCard keyCard)
        {
            try
            {
                JwtData jwt  = (JwtData)RouteData.Values["jwtData"];
                var     type = string.IsNullOrEmpty(jwt.DocumentType) ? UserType.Personal : UserType.Empresarial;

                Coordenate coordenate = await _authPersonalRepository.GetKeyCardCoordenate(type);


                var brokerResponse = _authPersonalRepository.ValidateKeyCard(UserType.Personal, new KeyCardBase()
                {
                    KeyCardCoordinate = coordenate.positionNumber,
                    KeyCardValue      = keyCard.Value,
                    UserName          = jwt.UserName
                });

                if (string.IsNullOrEmpty(brokerResponse.validated.ToString()))
                {
                    return(StatusCode(502, Enums.GetEnumDescription(ApiMessages.BrokerNoResponse)));
                }

                if (brokerResponse.validated == false)
                {
                    return(BadRequest(new FrontStatusCode("Valor de la tarjéta de claves incorrecto")));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(500, string.Format($"{Enums.GetEnumDescription(ApiMessages.DefaultError)} {ex.Message} ")));
            }

            await Task.CompletedTask;

            return(Ok());
        }
Пример #12
0
        public async Task <IActionResult> Save(SaveNotificationType type)
        {
            try
            {
                var jwtToken = (JwtData)RouteData.Values["jwtData"];
                var userType = string.IsNullOrEmpty(jwtToken.DocumentType) ? UserType.Personal : UserType.Empresarial;

                Coordenate coordenate = await _authPersonalRepository.GetKeyCardCoordenateFromCache(userType);

                if (string.IsNullOrEmpty(coordenate.positionNumber))
                {
                    return(BadRequest(new FrontStatusCode("Debes solicitar la coordenada de tarjetas de claves para poder continuar.")));
                }

                var keyCardResponseCode = _authPersonalRepository.ValidateGeneralKeyCard(new KeyCardBase()
                {
                    KeyCardCoordinate = coordenate.positionNumber,
                    KeyCardValue      = type.KeyCardValue,
                    DeviceId          = type.DeviceId,
                    UserName          = jwtToken.UserName,
                    DocumentType      = jwtToken.DocumentType
                }, userType);

                if (keyCardResponseCode.Code == Enums.GetEnumDescription(ResponseCode.Fail))
                {
                    return(BadRequest(keyCardResponseCode));
                }


                SavePersonalNotificationType    personal    = new SavePersonalNotificationType();
                SaveEmpresarialNotificationType empresarial = new SaveEmpresarialNotificationType();

                if (jwtToken.Role == Enums.GetEnumDescription(UserType.Personal))
                {
                    personal = new SavePersonalNotificationType()
                    {
                        NotificationConfig = type.TargetDevice,
                        NotificationType   = ((int)type.Type).ToString(),
                        UserName           = jwtToken.UserName,
                        DeviceId           = type.DeviceId
                    };
                }
                else
                {
                    empresarial = new SaveEmpresarialNotificationType()
                    {
                        NotificationConfig = type.TargetDevice,
                        NotificationType   = ((int)type.Type).ToString(),
                        UserName           = jwtToken.UserName,
                        DeviceId           = type.DeviceId
                    };
                }

                var response = (jwtToken.Role == Enums.GetEnumDescription(UserType.Personal)
                    ? _broker.SendBroker <MQResponseResult>(personal)
                    : _broker.SendBroker <MQResponseResult>(empresarial));


                if (response.Code != Enums.GetEnumDescription(ResponseCode.Success))
                {
                    return(BadRequest(new FrontStatusCode("Error al registrar el medio de seguridad: " + response.Messages)));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(500, string.Format($"{Enums.GetEnumDescription(ApiMessages.DefaultError)} {ex.Message} ")));
            }

            await Task.CompletedTask;

            return(Ok());
        }