예제 #1
0
        public async Task <bool> PushCall(StandardPushCall call, string userId, UserProfile profile = null, DepartmentCallPriority priority = null)
        {
            if (Config.SystemBehaviorConfig.DoNotBroadcast)
            {
                return(false);
            }

            if (call == null)
            {
                return(false);
            }

            if (profile == null)
            {
                profile = _userProfileService.GetProfileByUserId(userId);
            }

            string color = null;

            if (priority != null)
            {
                color = priority.Color;
            }

            if (profile != null && profile.SendPush)
            {
                await _notificationProvider.SendAllNotifications(call.SubTitle, call.Title, userId, string.Format("C{0}", call.CallId), ConvertCallPriorityToSound((int)call.Priority, priority), profile.CustomPushSounds, call.ActiveCallCount, color);
            }

            return(true);
        }
예제 #2
0
        public async Task <bool> PushCallUnit(StandardPushCall call, int unitId, DepartmentCallPriority priority = null)
        {
            if (Config.SystemBehaviorConfig.DoNotBroadcast)
            {
                return(false);
            }

            if (call == null)
            {
                return(false);
            }

            string color = null;

            if (priority != null)
            {
                color = priority.Color;
            }

            await _unitNotificationProvider.SendAllNotifications(call.SubTitle, call.Title, unitId, string.Format("C{0}", call.CallId), ConvertCallPriorityToSound((int)call.Priority, priority), true, call.ActiveCallCount, color);

            return(true);
        }
예제 #3
0
        public void SendTroubleAlert(TroubleAlertEvent troubleAlertEvent, Unit unit, Call call, string departmentNumber, int departmentId, string callAddress, string unitAddress, List <UserProfile> recipients)
        {
            string personnelNames = "No Unit Roles (Accountability) Set";

            if (troubleAlertEvent.Roles != null && troubleAlertEvent.Roles.Count() > 0)
            {
                personnelNames = "";
                foreach (var role in troubleAlertEvent.Roles)
                {
                    if (String.IsNullOrWhiteSpace(personnelNames))
                    {
                        personnelNames = role.UserFullName;
                    }
                    else
                    {
                        personnelNames = personnelNames + $",{role.UserFullName}";
                    }
                }
            }

            foreach (var recipient in recipients)
            {
                // Send a Push Notification
                if (recipient.SendPush)
                {
                    var spc = new StandardPushCall();

                    if (call != null)
                    {
                        spc.CallId = call.CallId;
                    }

                    spc.Title           = string.Format("TROUBLE ALERT for {0}", unit.Name);
                    spc.Priority        = (int)CallPriority.Emergency;
                    spc.ActiveCallCount = 1;

                    string subTitle = String.Empty;
                    if (!String.IsNullOrWhiteSpace(unitAddress))
                    {
                        spc.Title = string.Format("TROUBLE ALERT for {0} at {1}", unit.Name, unitAddress);
                    }

                    spc.Title = StringHelpers.StripHtmlTagsCharArray(spc.Title);

                    try
                    {
#pragma warning disable 4014
                        Task.Run(async() => { await _pushService.PushCall(spc, recipient.UserId, recipient); }).ConfigureAwait(false);
#pragma warning restore 4014
                    }
                    catch (Exception ex)
                    {
                        Logging.LogException(ex);
                    }
                }

                // Send an SMS Message
                if (recipient.SendSms)
                {
                    try
                    {
#pragma warning disable 4014
                        Task.Run(() => { _smsService.SendTroubleAlert(unit, call, unitAddress, departmentNumber, departmentId, recipient); }).ConfigureAwait(false);
#pragma warning restore 4014
                    }
                    catch (Exception ex)
                    {
                        Logging.LogException(ex);
                    }
                }

                // Send an Email
                if (recipient.SendEmail)
                {
                    try
                    {
#pragma warning disable 4014
                        Task.Run(() => { _emailService.SendTroubleAlert(troubleAlertEvent, unit, call, callAddress, unitAddress, personnelNames, recipient); }).ConfigureAwait(false);
#pragma warning restore 4014
                    }
                    catch (Exception ex)
                    {
                        Logging.LogException(ex);
                    }
                }
            }
        }
예제 #4
0
        public void SendUnitCall(Call call, CallDispatchUnit dispatch, string departmentNumber, string address = null)
        {
            var spc = new StandardPushCall();

            spc.CallId          = call.CallId;
            spc.Title           = string.Format("Call {0}", call.Name);
            spc.Priority        = call.Priority;
            spc.ActiveCallCount = 1;

            if (call.CallPriority != null && !String.IsNullOrWhiteSpace(call.CallPriority.Color))
            {
                spc.Color = call.CallPriority.Color;
            }
            else
            {
                spc.Color = "#000000";
            }

            string subTitle = String.Empty;

            if (String.IsNullOrWhiteSpace(address) && !String.IsNullOrWhiteSpace(call.Address))
            {
                subTitle = call.Address;
            }
            else if (!String.IsNullOrWhiteSpace(address))
            {
                subTitle = address;
            }
            else if (!string.IsNullOrEmpty(call.GeoLocationData))
            {
                try
                {
                    string[] points = call.GeoLocationData.Split(char.Parse(","));

                    if (points != null && points.Length == 2)
                    {
                        subTitle = _geoLocationProvider.GetAproxAddressFromLatLong(double.Parse(points[0]), double.Parse(points[1]));
                    }
                }
                catch
                { }
            }

            if (!string.IsNullOrEmpty(subTitle))
            {
                spc.SubTitle = subTitle.Truncate(200);
            }
            else
            {
                if (!string.IsNullOrEmpty(call.NatureOfCall))
                {
                    spc.SubTitle = call.NatureOfCall.Truncate(200);
                }
            }

            if (!String.IsNullOrWhiteSpace(spc.SubTitle))
            {
                spc.SubTitle = StringHelpers.StripHtmlTagsCharArray(spc.SubTitle);
            }

            spc.Title = StringHelpers.StripHtmlTagsCharArray(spc.Title);

            try
            {
#pragma warning disable 4014
                Task.Run(async() => { await _pushService.PushCallUnit(spc, dispatch.UnitId, call.CallPriority); }).ConfigureAwait(false);
#pragma warning restore 4014
            }
            catch (Exception ex)
            {
                Logging.LogException(ex);
            }
        }
예제 #5
0
        public void SendCall(Call call, CallDispatch dispatch, string departmentNumber, int departmentId, UserProfile profile = null, string address = null)
        {
            if (profile == null)
            {
                profile = _userProfileService.GetProfileByUserId(dispatch.UserId);
            }

            // Send a Push Notification
            if (profile == null || profile.SendPush)
            {
                var spc = new StandardPushCall();
                spc.CallId          = call.CallId;
                spc.Title           = string.Format("Call {0}", call.Name);
                spc.Priority        = call.Priority;
                spc.ActiveCallCount = 1;

                if (call.CallPriority != null && !String.IsNullOrWhiteSpace(call.CallPriority.Color))
                {
                    spc.Color = call.CallPriority.Color;
                }
                else
                {
                    spc.Color = "#000000";
                }

                string subTitle = String.Empty;

                if (String.IsNullOrWhiteSpace(address) && !String.IsNullOrWhiteSpace(call.Address))
                {
                    subTitle = call.Address;
                }
                else if (!String.IsNullOrWhiteSpace(address))
                {
                    subTitle = address;
                }
                else if (!string.IsNullOrEmpty(call.GeoLocationData))
                {
                    try
                    {
                        string[] points = call.GeoLocationData.Split(char.Parse(","));

                        if (points != null && points.Length == 2)
                        {
                            subTitle = _geoLocationProvider.GetAproxAddressFromLatLong(double.Parse(points[0]), double.Parse(points[1]));
                        }
                    }
                    catch
                    { }
                }

                if (!string.IsNullOrEmpty(subTitle))
                {
                    spc.SubTitle = subTitle.Truncate(200);
                }
                else
                {
                    if (!string.IsNullOrEmpty(call.NatureOfCall))
                    {
                        spc.SubTitle = call.NatureOfCall.Truncate(200);
                    }
                }

                if (!String.IsNullOrWhiteSpace(spc.SubTitle))
                {
                    spc.SubTitle = StringHelpers.StripHtmlTagsCharArray(spc.SubTitle);
                }

                spc.Title = StringHelpers.StripHtmlTagsCharArray(spc.Title);

                try
                {
#pragma warning disable 4014
                    Task.Run(async() => { await _pushService.PushCall(spc, dispatch.UserId, profile, call.CallPriority); }).ConfigureAwait(false);
#pragma warning restore 4014
                }
                catch (Exception ex)
                {
                    Logging.LogException(ex);
                }
            }

            // Send an SMS Message
            if (profile == null || profile.SendSms)
            {
                try
                {
#pragma warning disable 4014
                    Task.Run(() => { _smsService.SendCall(call, dispatch, departmentNumber, departmentId, profile); }).ConfigureAwait(false);
#pragma warning restore 4014
                }
                catch (Exception ex)
                {
                    Logging.LogException(ex);
                }
            }

            // Send an Email
            if (profile == null || profile.SendEmail)
            {
                try
                {
#pragma warning disable 4014
                    Task.Run(() => { _emailService.SendCall(call, dispatch, profile); }).ConfigureAwait(false);
#pragma warning restore 4014
                }
                catch (Exception ex)
                {
                    Logging.LogException(ex);
                }
            }

            // Initiate a Telephone Call
            if (profile == null || profile.VoiceForCall)
            {
                try
                {
#pragma warning disable 4014
                    if (!Config.SystemBehaviorConfig.DoNotBroadcast)
                    {
                        Task.Run(() => { _outboundVoiceProvider.CommunicateCall(departmentNumber, profile, call); }).ConfigureAwait(false);
                    }
#pragma warning restore 4014
                }
                catch (Exception ex)
                {
                    Logging.LogException(ex);
                }
            }
        }
예제 #6
0
        public async Task <bool> SendCallAsync(Call call, CallDispatch dispatch, string departmentNumber, int departmentId, UserProfile profile = null, string address = null)
        {
            if (profile == null)
            {
                profile = await _userProfileService.GetProfileByUserIdAsync(dispatch.UserId);
            }

            // Send a Push Notification
            if (profile == null || profile.SendPush)
            {
                try
                {
                    var spc = new StandardPushCall();
                    spc.CallId          = call.CallId;
                    spc.Title           = string.Format("Call {0}", call.Name);
                    spc.Priority        = call.Priority;
                    spc.ActiveCallCount = 1;
                    spc.DepartmentId    = departmentId;

                    if (call.CallPriority != null && !String.IsNullOrWhiteSpace(call.CallPriority.Color))
                    {
                        spc.Color = call.CallPriority.Color;
                    }
                    else
                    {
                        spc.Color = "#000000";
                    }

                    string subTitle = String.Empty;

                    if (String.IsNullOrWhiteSpace(address) && !String.IsNullOrWhiteSpace(call.Address))
                    {
                        subTitle = call.Address;
                    }
                    else if (!String.IsNullOrWhiteSpace(address))
                    {
                        subTitle = address;
                    }
                    else if (!string.IsNullOrEmpty(call.GeoLocationData))
                    {
                        try
                        {
                            string[] points = call.GeoLocationData.Split(char.Parse(","));

                            if (points != null && points.Length == 2)
                            {
                                subTitle = await _geoLocationProvider.GetAproxAddressFromLatLong(double.Parse(points[0]), double.Parse(points[1]));
                            }
                        }
                        catch
                        { }
                    }

                    if (!string.IsNullOrEmpty(subTitle))
                    {
                        spc.SubTitle = subTitle.Truncate(200);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(call.NatureOfCall))
                        {
                            spc.SubTitle = call.NatureOfCall.Truncate(200);
                        }
                    }

                    if (!String.IsNullOrWhiteSpace(spc.SubTitle))
                    {
                        spc.SubTitle = StringHelpers.StripHtmlTagsCharArray(spc.SubTitle);
                    }

                    spc.SubTitle = Regex.Replace(spc.SubTitle, @"((http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?)", "");

                    spc.Title = StringHelpers.StripHtmlTagsCharArray(spc.Title);
                    spc.Title = Regex.Replace(spc.Title, @"((http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?)", "");

                    spc.Title    = spc.Title.Replace(char.Parse("/"), char.Parse(" "));
                    spc.SubTitle = spc.SubTitle.Replace(char.Parse("/"), char.Parse(" "));

                    await _pushService.PushCall(spc, dispatch.UserId, profile, call.CallPriority);
                }
                catch (Exception ex)
                {
                    Logging.LogException(ex);
                }
            }

            // Send an SMS Message
            if (profile == null || profile.SendSms)
            {
                await _smsService.SendCallAsync(call, dispatch, departmentNumber, departmentId, profile);
            }

            // Send an Email
            if (profile == null || profile.SendEmail)
            {
                await _emailService.SendCallAsync(call, dispatch, profile);
            }

            // Initiate a Telephone Call
            if (profile == null || profile.VoiceForCall)
            {
                try
                {
                    if (!Config.SystemBehaviorConfig.DoNotBroadcast || Config.SystemBehaviorConfig.BypassDoNotBroadcastDepartments.Contains(departmentId))
                    {
                        _outboundVoiceProvider.CommunicateCall(departmentNumber, profile, call);
                    }
                }
                catch (Exception ex)
                {
                    Logging.LogException(ex);
                }
            }

            return(true);
        }