public HttpResponseMessage TroubleAlert(TroubleAlertEvent troubleInput)
        {
            if (troubleInput == null)
            {
                throw HttpStatusCode.NotFound.AsException();
            }

            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);

                _cqrsProvider.EnqueueCqrsEvent(registerUnitPushEvent);

                return(Request.CreateResponse(HttpStatusCode.Created));
            }
            catch (Exception ex)
            {
                Logging.LogException(ex);
                throw HttpStatusCode.InternalServerError.AsException();
            }

            throw HttpStatusCode.BadRequest.AsException();
        }
Beispiel #2
0
        public HttpResponseMessage 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);

                _cqrsProvider.EnqueueCqrsEvent(registerUnitPushEvent);
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
        public async Task <DeviceRegistrationResult> RegisterDevice([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;

                    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;

                    //push = _pushUriService.SavePushUri(push);

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

                    //await _pushService.Register(push);

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

                    _cqrsProvider.EnqueueCqrsEvent(registerUnitPushEvent);

                    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();
        }
Beispiel #4
0
        public HttpResponseMessage SetUnitLocation(UnitLocationInput locationInput)
        {
            var unit = _unitsService.GetUnitById(locationInput.Uid);

            if (unit == null)
            {
                throw HttpStatusCode.NotFound.AsException();
            }

            if (unit.DepartmentId != DepartmentId)
            {
                throw HttpStatusCode.Unauthorized.AsException();
            }

            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);
                        _cqrsProvider.EnqueueCqrsEvent(locationEvent);

                        return(Request.CreateResponse(HttpStatusCode.Created));
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.NotModified));
                    }
                }
                catch (Exception ex)
                {
                    Logging.LogException(ex);
                    throw HttpStatusCode.InternalServerError.AsException();
                }
            }

            throw HttpStatusCode.BadRequest.AsException();
        }