Example #1
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);
                }
            }
        }
Example #2
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);
        }