Exemplo n.º 1
0
        public async Task <ActionResult <DeviceRegistrationResult> > RegisterDevice([FromBody] DeviceRegistrationInput registrationInput, CancellationToken cancellationToken)
        {
            if (this.ModelState.IsValid)
            {
                var result = new DeviceRegistrationResult();

                try
                {
                    if (registrationInput == null)
                    {
                        return(BadRequest());
                    }

                    var push = new PushUri();
                    push.UserId       = UserId;
                    push.PlatformType = registrationInput.Plt;

                    if (!String.IsNullOrWhiteSpace(registrationInput.Uri))
                    {
                        push.PushLocation = HttpUtility.UrlDecode(registrationInput.Uri);
                    }
                    else if (registrationInput.Plt == (int)Platforms.Android)
                    {
                        push.PushLocation = "Android";
                    }
                    else if (registrationInput.Plt == (int)Platforms.iPhone || registrationInput.Plt == (int)Platforms.iPad)
                    {
                        push.PushLocation = "Apple";
                    }

                    push.DeviceId     = registrationInput.Did;
                    push.Uuid         = registrationInput.Id;
                    push.DepartmentId = DepartmentId;

                    CqrsEvent registerUnitPushEvent = new CqrsEvent();
                    registerUnitPushEvent.Type = (int)CqrsEventTypes.PushRegistration;
                    registerUnitPushEvent.Data = ObjectSerialization.Serialize(push);

                    await _cqrsProvider.EnqueueCqrsEventAsync(registerUnitPushEvent);

                    result.Sfl = true;
                    result.Id  = push.PushUriId;

                    return(result);
                }
                catch (Exception ex)
                {
                    result.Sfl = false;
                    Framework.Logging.LogException(ex);

                    return(result);
                }
            }

            return(BadRequest());
        }
Exemplo n.º 2
0
        public async Task <ActionResult> TroubleAlert(TroubleAlertEvent troubleInput)
        {
            if (troubleInput == null)
            {
                return(NotFound());
            }

            try
            {
                troubleInput.DepartmentId = DepartmentId;
                troubleInput.UserId       = UserId;
                troubleInput.TimeStamp    = DateTime.UtcNow;

                CqrsEvent registerUnitPushEvent = new CqrsEvent();
                registerUnitPushEvent.Type = (int)CqrsEventTypes.TroubleAlert;
                registerUnitPushEvent.Data = ObjectSerialization.Serialize(troubleInput);

                await _cqrsProvider.EnqueueCqrsEventAsync(registerUnitPushEvent);

                return(CreatedAtAction(nameof(TroubleAlert), new { id = troubleInput.DepartmentId }, troubleInput));
            }
            catch (Exception ex)
            {
                Logging.LogException(ex);
                return(BadRequest());
            }

            return(BadRequest());
        }
Exemplo n.º 3
0
        public async Task <ActionResult> NotifyNewChat([FromBody] NotifyChatInput notifyChatInput)
        {
            if (notifyChatInput != null && notifyChatInput.RecipientUserIds != null && notifyChatInput.RecipientUserIds.Count > 0)
            {
                var newChatEvent = new NewChatNotificationEvent();
                newChatEvent.Id               = notifyChatInput.Id;
                newChatEvent.GroupName        = notifyChatInput.GroupName;
                newChatEvent.Message          = notifyChatInput.Message;
                newChatEvent.RecipientUserIds = notifyChatInput.RecipientUserIds;
                newChatEvent.SendingUserId    = notifyChatInput.SendingUserId;
                newChatEvent.Type             = notifyChatInput.Type;

                CqrsEvent registerUnitPushEvent = new CqrsEvent();
                registerUnitPushEvent.Type      = (int)CqrsEventTypes.NewChatMessage;
                registerUnitPushEvent.Timestamp = DateTime.UtcNow;
                registerUnitPushEvent.Data      = ObjectSerialization.Serialize(newChatEvent);

                await _cqrsProvider.EnqueueCqrsEventAsync(registerUnitPushEvent);
            }

            return(Ok());
        }
Exemplo n.º 4
0
        public async Task <DeviceRegistrationResult> RegisterUnitDevice([FromBody] DeviceRegistrationInput registrationInput)
        {
            if (this.ModelState.IsValid)
            {
                var result = new DeviceRegistrationResult();

                try
                {
                    if (registrationInput == null)
                    {
                        throw HttpStatusCode.BadRequest.AsException();
                    }

                    var push = new PushUri();
                    push.UserId       = UserId;
                    push.PlatformType = registrationInput.Plt;
                    push.PushLocation = registrationInput.Id;
                    push.DepartmentId = DepartmentId;

                    if (!String.IsNullOrWhiteSpace(registrationInput.Uri))
                    {
                        push.PushLocation = HttpUtility.UrlDecode(registrationInput.Uri);
                    }

                    push.DeviceId = registrationInput.Did;

                    if (registrationInput.Uid != 0)
                    {
                        push.UnitId = registrationInput.Uid;
                    }

                    try
                    {
                        push = _pushUriService.SavePushUri(push);
                    }
                    catch { }

                    PushRegisterionEvent pushRegisterionEvent = new PushRegisterionEvent();
                    pushRegisterionEvent.PushUriId    = push.PushUriId;
                    pushRegisterionEvent.UserId       = UserId;
                    pushRegisterionEvent.PlatformType = registrationInput.Plt;
                    pushRegisterionEvent.PushLocation = registrationInput.Id;
                    pushRegisterionEvent.DepartmentId = DepartmentId;
                    pushRegisterionEvent.DeviceId     = registrationInput.Did;
                    pushRegisterionEvent.Uuid         = registrationInput.Id;

                    if (registrationInput.Uid != 0)
                    {
                        pushRegisterionEvent.UnitId = registrationInput.Uid;
                    }

                    CqrsEvent registerUnitPushEvent = new CqrsEvent();
                    registerUnitPushEvent.Type = (int)CqrsEventTypes.UnitPushRegistration;
                    registerUnitPushEvent.Data = ObjectSerialization.Serialize(pushRegisterionEvent);

                    await _cqrsProvider.EnqueueCqrsEventAsync(registerUnitPushEvent);

                    //await _pushService.RegisterUnit(push);

                    result.Sfl = true;
                    result.Id  = push.PushUriId;

                    return(result);
                }
                catch (Exception ex)
                {
                    result.Sfl = false;
                    Framework.Logging.LogException(ex);

                    return(result);
                }
            }

            throw HttpStatusCode.BadRequest.AsException();
        }
Exemplo n.º 5
0
        public async Task <ActionResult> SetUnitLocation(UnitLocationInput locationInput, CancellationToken cancellationToken)
        {
            var unit = await _unitsService.GetUnitByIdAsync(locationInput.Uid);

            if (unit == null)
            {
                return(NotFound());
            }

            if (unit.DepartmentId != DepartmentId)
            {
                return(Unauthorized());
            }

            if (this.ModelState.IsValid)
            {
                try
                {
                    CqrsEvent    locationEvent = new CqrsEvent();
                    UnitLocation location      = new UnitLocation();
                    location.UnitId = locationInput.Uid;

                    if (locationInput.Tms.HasValue)
                    {
                        location.Timestamp = locationInput.Tms.Value;
                    }
                    else
                    {
                        location.Timestamp = DateTime.UtcNow;
                    }

                    if (!String.IsNullOrWhiteSpace(locationInput.Lat) && locationInput.Lat != "NaN" && !String.IsNullOrWhiteSpace(locationInput.Lon) && locationInput.Lon != "NaN")
                    {
                        location.Latitude  = decimal.Parse(locationInput.Lat);
                        location.Longitude = decimal.Parse(locationInput.Lon);

                        if (!String.IsNullOrWhiteSpace(locationInput.Acc) && locationInput.Acc != "NaN")
                        {
                            location.Accuracy = decimal.Parse(locationInput.Acc);
                        }

                        if (!String.IsNullOrWhiteSpace(locationInput.Alt) && locationInput.Alt != "NaN")
                        {
                            location.Altitude = decimal.Parse(locationInput.Alt);
                        }

                        if (!String.IsNullOrWhiteSpace(locationInput.Alc) && locationInput.Alc != "NaN")
                        {
                            location.AltitudeAccuracy = decimal.Parse(locationInput.Alc);
                        }

                        if (!String.IsNullOrWhiteSpace(locationInput.Spd) && locationInput.Spd != "NaN")
                        {
                            location.Speed = decimal.Parse(locationInput.Spd);
                        }

                        if (!String.IsNullOrWhiteSpace(locationInput.Hdn) && locationInput.Hdn != "NaN")
                        {
                            location.Heading = decimal.Parse(locationInput.Hdn);
                        }

                        locationEvent.Type = (int)CqrsEventTypes.UnitLocation;
                        locationEvent.Data = ObjectSerialization.Serialize(location);
                        await _cqrsProvider.EnqueueCqrsEventAsync(locationEvent);

                        return(CreatedAtAction(nameof(SetUnitLocation), new { id = locationInput.Uid }, locationEvent));
                    }
                    else
                    {
                        return(Ok());
                    }
                }
                catch (Exception ex)
                {
                    Logging.LogException(ex);
                    return(BadRequest());
                }
            }

            return(BadRequest());
        }