コード例 #1
0
        public IActionResult DeleteCallPriority(int priorityId)
        {
            var priority = _callsService.GetCallPrioritesById(DepartmentId, priorityId, true);

            if (priority != null)
            {
                priority.IsDeleted = true;
                _callsService.SaveCallPriority(priority);
            }

            return(RedirectToAction("Types", "Department", new { Area = "User" }));
        }
コード例 #2
0
        public HttpResponseMessage GetPushAudioForPriority(int priorityId)
        {
            var priority = _callsService.GetCallPrioritesById(DepartmentId, priorityId, true);

            if (priority == null || priority.PushNotificationSound == null)
            {
                return(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }

            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new ByteArrayContent(priority.PushNotificationSound);
            response.Content.Headers.ContentDisposition          = new ContentDispositionHeaderValue("attachment");
            response.Content.Headers.ContentType                 = new MediaTypeHeaderValue("audio/wav");
            response.Content.Headers.ContentDisposition.FileName = $"CallPAudio_{priorityId}.wav";

            return(response);
        }
コード例 #3
0
        /// <summary>
        /// Gets all the meta-data around a call, dispatched personnel, units, groups and responses
        /// </summary>
        /// <param name="callId">CallId to get data for</param>
        /// <returns></returns>
        public CallDataResult GetCallExtraData(int callId)
        {
            var result = new CallDataResult();

            var call       = _callsService.GetCallById(callId);
            var groups     = _departmentGroupsService.GetAllGroupsForDepartment(DepartmentId);
            var units      = _unitsService.GetUnitsForDepartment(call.DepartmentId);
            var unitStates = _unitsService.GetUnitStatesForCall(call.DepartmentId, callId).OrderBy(x => x.UnitId).OrderBy(y => y.Timestamp).ToList();
            var actionLogs = _actionLogsService.GetActionLogsForCall(call.DepartmentId, callId).OrderBy(x => x.UserId).OrderBy(y => y.Timestamp).ToList();
            var names      = _usersService.GetUserGroupAndRolesByDepartmentId(DepartmentId, true, true, true);
            var priority   = _callsService.GetCallPrioritesById(call.DepartmentId, call.Priority, false);

            if (priority != null)
            {
                result.Priority                         = new CallPriorityDataResult();
                result.Priority.Id                      = priority.DepartmentCallPriorityId;
                result.Priority.DepartmentId            = priority.DepartmentId;
                result.Priority.Name                    = priority.Name;
                result.Priority.Color                   = priority.Color;
                result.Priority.Sort                    = priority.Sort;
                result.Priority.IsDeleted               = priority.IsDeleted;
                result.Priority.IsDefault               = priority.IsDefault;
                result.Priority.DispatchPersonnel       = priority.DispatchPersonnel;
                result.Priority.DispatchUnits           = priority.DispatchUnits;
                result.Priority.ForceNotifyAllPersonnel = priority.ForceNotifyAllPersonnel;
                result.Priority.Tone                    = priority.Tone;
                result.Priority.IsSystemPriority        = priority.IsSystemPriority;
            }

            foreach (var actionLog in actionLogs)
            {
                var eventResult = new DispatchedEventResult();
                eventResult.Id        = actionLog.ActionLogId.ToString();
                eventResult.Timestamp = actionLog.Timestamp;
                eventResult.Type      = "User";

                var name = names.FirstOrDefault(x => x.UserId == actionLog.UserId);
                if (name != null)
                {
                    eventResult.Name = name.Name;

                    if (name.DepartmentGroupId.HasValue)
                    {
                        eventResult.GroupId = name.DepartmentGroupId.Value;
                        eventResult.Group   = name.DepartmentGroupName;
                    }
                }
                else
                {
                    eventResult.Name = "Unknown User";
                }

                eventResult.StatusId = actionLog.ActionTypeId;
                eventResult.Location = actionLog.GeoLocationData;
                eventResult.Note     = actionLog.Note;

                result.Activity.Add(eventResult);
            }

            foreach (var unitLog in unitStates)
            {
                var eventResult = new DispatchedEventResult();
                eventResult.Id        = unitLog.UnitStateId.ToString();
                eventResult.Timestamp = unitLog.Timestamp;
                eventResult.Type      = "Unit";
                eventResult.Name      = unitLog.Unit.Name;

                var group = groups.FirstOrDefault(x => x.DepartmentGroupId == unitLog.Unit.StationGroupId);
                if (group != null)
                {
                    eventResult.GroupId = group.DepartmentGroupId;
                    eventResult.Group   = group.Name;
                }

                eventResult.StatusId = eventResult.StatusId;
                eventResult.Location = eventResult.Location;
                eventResult.Note     = eventResult.Note;

                result.Activity.Add(eventResult);
            }

            foreach (var dispatch in call.Dispatches)
            {
                var eventResult = new DispatchedEventResult();
                eventResult.Id = dispatch.UserId;
                if (dispatch.LastDispatchedOn.HasValue)
                {
                    eventResult.Timestamp = dispatch.LastDispatchedOn.Value;
                }
                eventResult.Type = "User";

                var name = names.FirstOrDefault(x => x.UserId == dispatch.UserId);
                if (name != null)
                {
                    eventResult.Name = name.Name;

                    if (name.DepartmentGroupId.HasValue)
                    {
                        eventResult.GroupId = name.DepartmentGroupId.Value;
                        eventResult.Group   = name.DepartmentGroupName;
                    }
                }
                else
                {
                    eventResult.Name = "Unknown User";
                }

                result.Dispatches.Add(eventResult);
            }

            if (call.GroupDispatches != null && call.GroupDispatches.Any())
            {
                foreach (var groupDispatch in call.GroupDispatches)
                {
                    var eventResult = new DispatchedEventResult();
                    eventResult.Id = groupDispatch.DepartmentGroupId.ToString();
                    if (groupDispatch.LastDispatchedOn.HasValue)
                    {
                        eventResult.Timestamp = groupDispatch.LastDispatchedOn.Value;
                    }
                    eventResult.Type = "Group";

                    var name = groups.FirstOrDefault(x => x.DepartmentGroupId == groupDispatch.DepartmentGroupId);
                    if (name != null)
                    {
                        eventResult.Name    = name.Name;
                        eventResult.GroupId = name.DepartmentGroupId;
                        eventResult.Group   = name.Name;
                    }
                    else
                    {
                        eventResult.Name = "Unknown Group";
                    }

                    result.Dispatches.Add(eventResult);
                }
            }

            if (call.UnitDispatches != null && call.UnitDispatches.Any())
            {
                foreach (var unitDispatch in call.UnitDispatches)
                {
                    var eventResult = new DispatchedEventResult();
                    eventResult.Id = unitDispatch.UnitId.ToString();
                    if (unitDispatch.LastDispatchedOn.HasValue)
                    {
                        eventResult.Timestamp = unitDispatch.LastDispatchedOn.Value;
                    }
                    eventResult.Type = "Unit";

                    var unit = units.FirstOrDefault(x => x.UnitId == unitDispatch.UnitId);
                    if (unit != null)
                    {
                        eventResult.Name = unit.Name;

                        if (unit.StationGroupId.HasValue)
                        {
                            var group = groups.FirstOrDefault(x => x.DepartmentGroupId == unit.StationGroupId.GetValueOrDefault());
                            if (group != null)
                            {
                                eventResult.GroupId = group.DepartmentGroupId;
                                eventResult.Group   = group.Name;
                            }
                        }
                    }
                    else
                    {
                        eventResult.Name = "Unknown Unit";
                    }

                    result.Dispatches.Add(eventResult);
                }
            }

            return(result);
        }
コード例 #4
0
        public static void ProcessCallQueueItem(CallQueueItem cqi)
        {
            try
            {
                if (cqi != null && cqi.Call != null && cqi.Call.HasAnyDispatches())
                {
                    if (_communicationService == null)
                    {
                        _communicationService = Bootstrapper.GetKernel().Resolve <ICommunicationService>();
                    }

                    if (_callsService == null)
                    {
                        _callsService = Bootstrapper.GetKernel().Resolve <ICallsService>();
                    }

                    List <int> groupIds = new List <int>();

                    /* Trying to see if I can eek out a little perf here now that profiles are in Redis. Previously the
                     * the parallel operation would cause EF errors. This shouldn't be the case now because profiles are
                     * cached and GetProfileForUser operations will hit that first.
                     */
                    if (cqi.Profiles == null || !cqi.Profiles.Any())
                    {
                        if (_userProfilesService == null)
                        {
                            _userProfilesService = Bootstrapper.GetKernel().Resolve <IUserProfileService>();
                        }

                        cqi.Profiles = _userProfilesService.GetAllProfilesForDepartment(cqi.Call.DepartmentId).Select(x => x.Value).ToList();
                    }

                    if (cqi.CallDispatchAttachmentId > 0)
                    {
                        //var callsService = Bootstrapper.GetKernel().Resolve<ICallsService>();
                        cqi.Call.ShortenedAudioUrl = _callsService.GetShortenedAudioUrl(cqi.Call.CallId, cqi.CallDispatchAttachmentId);
                    }

                    cqi.Call.ShortenedCallUrl = _callsService.GetShortenedCallLinkUrl(cqi.Call.CallId);

                    try
                    {
                        cqi.Call.CallPriority = _callsService.GetCallPrioritesById(cqi.Call.DepartmentId, cqi.Call.Priority, false);
                    }
                    catch { /* Doesn't matter */ }

                    var dispatchedUsers = new HashSet <string>();

                    // Dispatch Personnel
                    if (cqi.Call.Dispatches != null && cqi.Call.Dispatches.Any())
                    {
                        Parallel.ForEach(cqi.Call.Dispatches, d =>
                        {
                            dispatchedUsers.Add(d.UserId);

                            try
                            {
                                var profile = cqi.Profiles.FirstOrDefault(x => x.UserId == d.UserId);

                                if (profile != null)
                                {
                                    _communicationService.SendCall(cqi.Call, d, cqi.DepartmentTextNumber, cqi.Call.DepartmentId, profile, cqi.Address);
                                }
                            }
                            catch (SocketException sex)
                            {
                            }
                        });
                    }

                    if (_departmentGroupsService == null)
                    {
                        _departmentGroupsService = Bootstrapper.GetKernel().Resolve <IDepartmentGroupsService>();
                    }

                    // Dispatch Groups
                    if (cqi.Call.GroupDispatches != null && cqi.Call.GroupDispatches.Any())
                    {
                        foreach (var d in cqi.Call.GroupDispatches)
                        {
                            if (!groupIds.Contains(d.DepartmentGroupId))
                            {
                                groupIds.Add(d.DepartmentGroupId);
                            }

                            var members = _departmentGroupsService.GetAllMembersForGroup(d.DepartmentGroupId);

                            foreach (var member in members)
                            {
                                if (!dispatchedUsers.Contains(member.UserId))
                                {
                                    dispatchedUsers.Add(member.UserId);
                                    try
                                    {
                                        var profile = cqi.Profiles.FirstOrDefault(x => x.UserId == member.UserId);
                                        _communicationService.SendCall(cqi.Call, new CallDispatch()
                                        {
                                            UserId = member.UserId
                                        }, cqi.DepartmentTextNumber, cqi.Call.DepartmentId, profile, cqi.Address);
                                    }
                                    catch (SocketException sex)
                                    {
                                    }
                                    catch (Exception ex)
                                    {
                                        Logging.LogException(ex);
                                    }
                                }
                            }
                        }
                    }

                    // Dispatch Units
                    if (cqi.Call.UnitDispatches != null && cqi.Call.UnitDispatches.Any())
                    {
                        if (_unitsService == null)
                        {
                            _unitsService = Bootstrapper.GetKernel().Resolve <IUnitsService>();
                        }

                        foreach (var d in cqi.Call.UnitDispatches)
                        {
                            var unit = _unitsService.GetUnitById(d.UnitId);

                            if (unit != null && unit.StationGroupId.HasValue)
                            {
                                if (!groupIds.Contains(unit.StationGroupId.Value))
                                {
                                    groupIds.Add(unit.StationGroupId.Value);
                                }
                            }

                            _communicationService.SendUnitCall(cqi.Call, d, cqi.DepartmentTextNumber, cqi.Address);

                            var unitAssignedMembers = _unitsService.GetCurrentRolesForUnit(d.UnitId);

                            if (unitAssignedMembers != null && unitAssignedMembers.Count() > 0)
                            {
                                foreach (var member in unitAssignedMembers)
                                {
                                    if (!dispatchedUsers.Contains(member.UserId))
                                    {
                                        dispatchedUsers.Add(member.UserId);
                                        try
                                        {
                                            var profile = cqi.Profiles.FirstOrDefault(x => x.UserId == member.UserId);
                                            _communicationService.SendCall(cqi.Call, new CallDispatch()
                                            {
                                                UserId = member.UserId
                                            }, cqi.DepartmentTextNumber, cqi.Call.DepartmentId, profile, cqi.Address);
                                        }
                                        catch (SocketException sex)
                                        {
                                        }
                                        catch (Exception ex)
                                        {
                                            Logging.LogException(ex);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (unit.StationGroupId.HasValue)
                                {
                                    var members = _departmentGroupsService.GetAllMembersForGroup(unit.StationGroupId.Value);

                                    foreach (var member in members)
                                    {
                                        if (!dispatchedUsers.Contains(member.UserId))
                                        {
                                            dispatchedUsers.Add(member.UserId);
                                            try
                                            {
                                                var profile = cqi.Profiles.FirstOrDefault(x => x.UserId == member.UserId);
                                                _communicationService.SendCall(cqi.Call, new CallDispatch()
                                                {
                                                    UserId = member.UserId
                                                }, cqi.DepartmentTextNumber, cqi.Call.DepartmentId, profile, cqi.Address);
                                            }
                                            catch (SocketException sex)
                                            {
                                            }
                                            catch (Exception ex)
                                            {
                                                Logging.LogException(ex);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    // Dispatch Roles
                    if (cqi.Call.RoleDispatches != null && cqi.Call.RoleDispatches.Any())
                    {
                        if (_rolesService == null)
                        {
                            _rolesService = Bootstrapper.GetKernel().Resolve <IPersonnelRolesService>();
                        }

                        foreach (var d in cqi.Call.RoleDispatches)
                        {
                            var members = _rolesService.GetAllMembersOfRole(d.RoleId);

                            foreach (var member in members)
                            {
                                if (!dispatchedUsers.Contains(member.UserId))
                                {
                                    dispatchedUsers.Add(member.UserId);
                                    try
                                    {
                                        var profile = cqi.Profiles.FirstOrDefault(x => x.UserId == member.UserId);
                                        _communicationService.SendCall(cqi.Call, new CallDispatch()
                                        {
                                            UserId = member.UserId
                                        }, cqi.DepartmentTextNumber, cqi.Call.DepartmentId, profile, cqi.Address);
                                    }
                                    catch (SocketException sex)
                                    {
                                    }
                                    catch (Exception ex)
                                    {
                                        Logging.LogException(ex);
                                    }
                                }
                            }
                        }
                    }

                    // Send Call Print to Printer
                    if (_printerProvider == null)
                    {
                        _printerProvider = Bootstrapper.GetKernel().Resolve <IPrinterProvider>();
                    }

                    Dictionary <int, DepartmentGroup> fetchedGroups = new Dictionary <int, DepartmentGroup>();
                    if (cqi.Call.Dispatches != null && cqi.Call.Dispatches.Any())
                    {
                        foreach (var d in cqi.Call.Dispatches)
                        {
                            var group = _departmentGroupsService.GetGroupForUser(d.UserId, cqi.Call.DepartmentId);

                            if (group != null)
                            {
                                if (!groupIds.Contains(group.DepartmentGroupId))
                                {
                                    groupIds.Add(group.DepartmentGroupId);
                                }

                                if (!fetchedGroups.ContainsKey(group.DepartmentGroupId))
                                {
                                    fetchedGroups.Add(group.DepartmentGroupId, group);
                                }
                            }
                        }
                    }

                    foreach (var groupId in groupIds)
                    {
                        try
                        {
                            DepartmentGroup group = null;

                            if (fetchedGroups.ContainsKey(groupId))
                            {
                                group = fetchedGroups[groupId];
                            }
                            else
                            {
                                group = _departmentGroupsService.GetGroupById(groupId);
                            }

                            if (!String.IsNullOrWhiteSpace(group.PrinterData) && group.DispatchToPrinter)
                            {
                                var printerData = JsonConvert.DeserializeObject <DepartmentGroupPrinter>(group.PrinterData);
                                var apiKey      = SymmetricEncryption.Decrypt(printerData.ApiKey, Config.SystemBehaviorConfig.ExternalLinkUrlParamPassphrase);
                                var callUrl     = _callsService.GetShortenedCallPdfUrl(cqi.Call.CallId, true, groupId);

                                var printJob = _printerProvider.SubmitPrintJob(apiKey, printerData.PrinterId, "CallPrint", callUrl);
                            }
                        }
                        catch (Exception ex)
                        {
                            Logging.LogException(ex);
                        }
                    }
                }
            }
            finally
            {
                _communicationService = null;
            }
        }