Exemple #1
0
        private void SendCallViaEmailSmsGateway(Call call, string address, UserProfile profile)
        {
            MailMessage email = new MailMessage();

            email.To.Add(string.Format(Carriers.CarriersMap[(MobileCarriers)profile.MobileCarrier], profile.GetPhoneNumber()));

            email.From    = new MailAddress(Config.OutboundEmailServerConfig.FromMail, "RGCall");
            email.Subject = call.Name;

            if (!string.IsNullOrEmpty(call.NatureOfCall))
            {
                email.Body = HtmlToTextHelper.ConvertHtml(call.NatureOfCall);
                email.Body = StringHelpers.StripHtmlTagsCharArray(email.Body);
            }

            email.Body = email.Body + " " + address;

            if (!String.IsNullOrWhiteSpace(call.ShortenedAudioUrl))
            {
                email.Body = email.Body + " " + call.ShortenedAudioUrl;
            }
            //else if (!String.IsNullOrWhiteSpace(call.ShortenedCallUrl))
            //{
            //	email.Body = email.Body + " " + call.ShortenedCallUrl;
            //}

            email.IsBodyHtml = false;

            _emailSender.SendEmail(email);
        }
Exemple #2
0
        public void TestConvertHtml()
        {
            var testHtml = "<h1 style=margin-top:0px;margin-bottom:0px;padding:0px;'>Just testing to see if the text message section of resgrid works</h1>";
            var test     = HtmlToTextHelper.ConvertHtml(testHtml);

            test.Should().Be("Just testing to see if the text message section of resgrid works");
        }
Exemple #3
0
        public async Task <bool> SendMessageMail(string email, string subject, string messageSubject, string messageBody, string senderEmail, string senderName, string sentOn, int messageId)
        {
            var templateModel = new Dictionary <string, object> {
                { "sender_name", senderName },
                { "title", subject },
                { "body", HtmlToTextHelper.ConvertHtml(messageBody) },
                //{ "attachment_details", new []{
                //new Dictionary<string,object> {
                //	{ "attachmnet_url", "attachmnet_url_Value" },
                //	{ "attachment_name", "attachment_name_Value" },
                //	{ "attachment_size", "attachment_size_Value" },
                //	{ "attachment_type", "attachment_type_Value" },
                //}
                //}
                //},

                { "action_url", $"https://resgrid.com/User/Messages/ViewMessage?messageId={messageId}" },
                { "timestamp", sentOn },
                { "commenter_name", senderName }
            };

            if (SystemBehaviorConfig.OutboundEmailType == OutboundEmailTypes.Postmark)
            {
                var message = new TemplatedPostmarkMessage
                {
                    From          = DONOTREPLY_EMAIL,
                    To            = email,
                    TemplateId    = Config.OutboundEmailServerConfig.PostmarkMessageTemplateId,
                    TemplateModel = templateModel,
                };

                var client = new PostmarkClient(Config.OutboundEmailServerConfig.PostmarkApiKey);
                try
                {
                    PostmarkResponse response = await client.SendMessageAsync(message);

                    if (response.Status != PostmarkStatus.Success)
                    {
                        return(false);
                    }

                    return(true);
                }
                catch (Exception) {     }
            }
            else
            {
                var template = Mustachio.Parser.Parse(GetTempate("Message.html"));
                var content  = template(templateModel);

                Email newEmail = new Email();
                newEmail.HtmlBody = content;
                newEmail.Sender   = FROM_EMAIL;
                newEmail.To.Add(email);

                return(await _emailSender.Send(newEmail));
            }

            return(false);
        }
Exemple #4
0
        public void SendNotification(string userId, int departmentId, string message, string departmentNumber, UserProfile profile = null)
        {
            if (profile == null)
            {
                profile = _userProfileService.GetProfileByUserId(userId);
            }

            var email = new MailMessage();

            if (profile != null && profile.SendNotificationSms)
            {
                if (Config.SystemBehaviorConfig.DepartmentsToForceSmsGateway.Contains(departmentId))
                {
                    _textMessageProvider.SendTextMessage(profile.GetPhoneNumber(), message,
                                                         departmentNumber, (MobileCarriers)profile.MobileCarrier, departmentId, true, false);
                }
                else if (Carriers.DirectSendCarriers.Contains((MobileCarriers)profile.MobileCarrier))
                {
                    //string departmentNumber = _departmentSettingsService.GetTextToCallNumberForDepartment(departmentId);
                    _textMessageProvider.SendTextMessage(profile.GetPhoneNumber(), message,
                                                         departmentNumber, (MobileCarriers)profile.MobileCarrier, departmentId, false, false);
                }
                else
                {
                    email.To.Add(string.Format(Carriers.CarriersMap[(MobileCarriers)profile.MobileCarrier], profile.GetPhoneNumber()));

                    email.From       = new MailAddress(Config.OutboundEmailServerConfig.FromMail, "Resgrid");
                    email.Subject    = "Notification";
                    email.Body       = HtmlToTextHelper.ConvertHtml(message);
                    email.IsBodyHtml = false;

                    _emailSender.SendEmail(email);
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// 全文检索处理
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        public NpgsqlTsVector GetNpgsqlTsVector(string content)
        {
            NpgsqlTsVector vector;

            try
            {
                var segmenter = new JiebaSegmenter();
                HtmlToTextHelper htmlToTextHelper = new HtmlToTextHelper();
                if (string.IsNullOrWhiteSpace(content))
                {
                    return(null);;
                }
                string noHtmlConent = htmlToTextHelper.Convert(content);
                var    list         = segmenter.CutForSearch(noHtmlConent, hmm: true);
                var    cutList      = new List <string>();
                foreach (var item in list)
                {
                    if (item.Length > 1)
                    {
                        cutList.Add(item.ToUpper());
                    }
                }
                string str = string.Join(" ", cutList);
                vector = NpgsqlTsVector.Parse(str);
            }
            catch (Exception ex)
            {
                return(null);
            }

            return(vector);
        }
Exemple #6
0
        private string FormatTextForMessage(string title, string body)
        {
            string text = HtmlToTextHelper.ConvertHtml(body);

            text = StringHelpers.StripHtmlTagsCharArray(text);

            return(String.Format("{0} : {1}", title, text));
        }
Exemple #7
0
        public async Task <bool> SendMessageAsync(Message message, string departmentNumber, int departmentId, UserProfile profile = null)
        {
            if (profile == null && !String.IsNullOrWhiteSpace(message.ReceivingUserId))
            {
                profile = await _userProfileService.GetProfileByUserIdAsync(message.ReceivingUserId);
            }

            MailMessage email = new MailMessage();

            if (profile != null && profile.SendMessageSms)
            {
                if (Config.SystemBehaviorConfig.DepartmentsToForceSmsGateway.Contains(departmentId))
                {
                    string text = HtmlToTextHelper.ConvertHtml(message.Body);
                    text = StringHelpers.StripHtmlTagsCharArray(text);
                    _textMessageProvider.SendTextMessage(profile.GetPhoneNumber(), FormatTextForMessage(message.Subject, text),
                                                         departmentNumber, (MobileCarriers)profile.MobileCarrier, departmentId, true, false);
                }
                else if (Carriers.DirectSendCarriers.Contains((MobileCarriers)profile.MobileCarrier))
                {
                    string text = HtmlToTextHelper.ConvertHtml(message.Body);
                    text = StringHelpers.StripHtmlTagsCharArray(text);
                    _textMessageProvider.SendTextMessage(profile.GetPhoneNumber(), FormatTextForMessage(message.Subject, text),
                                                         departmentNumber, (MobileCarriers)profile.MobileCarrier, departmentId, false, false);
                }
                else
                {
                    email.To.Add(string.Format(Carriers.CarriersMap[(MobileCarriers)profile.MobileCarrier], profile.GetPhoneNumber()));

                    email.From    = new MailAddress(Config.OutboundEmailServerConfig.FromMail, "RGMsg");
                    email.Subject = message.Subject;

                    if (!string.IsNullOrEmpty(message.Body))
                    {
                        email.Body = HtmlToTextHelper.ConvertHtml(message.Body);
                        email.Body = StringHelpers.StripHtmlTagsCharArray(email.Body);
                    }
                    email.IsBodyHtml = false;

                    _emailSender.SendEmail(email);
                }
            }

            return(true);
        }
Exemple #8
0
        /// <summary>
        /// 全文检索 查询
        /// </summary>
        /// <param name="keyword"></param>
        /// <returns></returns>
        public NpgsqlTsQuery GetSerachNpgsqlTsQuery(string keyword)
        {
            if (keyword.Contains('&'))
            {
                string[] keys = keyword.Split('&');
                return(GetSerachNpgsqlTsQuery_And(keys));
            }
            if (keyword.Contains("|"))
            {
                string[] keys = keyword.Split('|');
                return(GetSerachNpgsqlTsQuery_Or(keys));
            }


            NpgsqlTsQuery vector;

            try
            {
                var segmenter = new JiebaSegmenter();
                HtmlToTextHelper htmlToTextHelper = new HtmlToTextHelper();
                if (string.IsNullOrWhiteSpace(keyword))
                {
                    return(null);;
                }
                string noHtmlConent = htmlToTextHelper.Convert(keyword);
                var    list         = segmenter.Cut(noHtmlConent, hmm: true);
                var    cutList      = new List <string>();
                foreach (var item in list)
                {
                    if (item.Length > 1)
                    {
                        cutList.Add(item.ToUpper());
                    }
                }
                string str = string.Join(" & ", cutList);
                vector = NpgsqlTsQuery.Parse(str);
            }
            catch (Exception ex)
            {
                return(null);
            }

            return(vector);
        }
        public void ConvertTest()
        {
            HtmlToTextHelper convert = new HtmlToTextHelper();
            string           md_text = File.ReadAllText(@"html.txt");
            string           html    = "";

            using (var reader = new StringReader(md_text))
            {
                using (var writer = new StringWriter())
                {
                    CommonMark.CommonMarkConverter.Convert(reader, writer);
                    //writer.ToString()即为转换好的html
                    html = writer.ToString();
                }
            }
            string text = convert.Convert(html);

            Console.WriteLine(text);
        }
Exemple #10
0
        public async Task <bool> SendTextAsync(string userId, string title, string message, int departmentId, string departmentNumber, UserProfile profile = null)
        {
            // TODO: This method should only be working with Twilio for inbound text message support

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

            var email = new MailMessage();

            if (profile != null && profile.SendMessageSms)
            {
                if (Carriers.DirectSendCarriers.Contains((MobileCarriers)profile.MobileCarrier))
                {
                    //string departmentNumber = _departmentSettingsService.GetTextToCallNumberForDepartment(departmentId);
                    _textMessageProvider.SendTextMessage(profile.GetPhoneNumber(), FormatTextForMessage(title, message), departmentNumber, (MobileCarriers)profile.MobileCarrier, departmentId, false, false);
                }
                else
                {
                    email.To.Add(string.Format(Carriers.CarriersMap[(MobileCarriers)profile.MobileCarrier], profile.GetPhoneNumber()));

                    email.From = new MailAddress(Config.OutboundEmailServerConfig.FromMail, "RGNot");

                    if (!string.IsNullOrEmpty(title))
                    {
                        email.Subject = title;
                    }

                    if (!string.IsNullOrEmpty(message))
                    {
                        email.Body = HtmlToTextHelper.ConvertHtml(message);
                        email.Body = StringHelpers.StripHtmlTagsCharArray(email.Body);
                    }
                    email.IsBodyHtml = false;

                    _emailSender.SendEmail(email);
                }
            }

            return(true);
        }
Exemple #11
0
        public async Task <bool> SendCallAsync(Call call, CallDispatch dispatch, string departmentNumber, int departmentId, UserProfile profile = null, string address = null)
        {
            if (Config.SystemBehaviorConfig.DoNotBroadcast && !Config.SystemBehaviorConfig.BypassDoNotBroadcastDepartments.Contains(departmentId))
            {
                return(false);
            }

            if (profile == null)
            {
                profile = await _userProfileService.GetProfileByUserIdAsync(dispatch.UserId);
            }

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

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

                if (Config.SystemBehaviorConfig.DepartmentsToForceSmsGateway.Contains(departmentId))
                {
                    string text = HtmlToTextHelper.ConvertHtml(call.NatureOfCall);
                    text = StringHelpers.StripHtmlTagsCharArray(text);
                    text = text + " " + address;

                    if (call.Protocols != null && call.Protocols.Any())
                    {
                        string protocols = String.Empty;
                        foreach (var protocol in call.Protocols)
                        {
                            if (!String.IsNullOrWhiteSpace(protocol.Data))
                            {
                                if (String.IsNullOrWhiteSpace(protocols))
                                {
                                    protocols = protocol.Data;
                                }
                                else
                                {
                                    protocols = protocol + "," + protocol.Data;
                                }
                            }
                        }

                        if (!String.IsNullOrWhiteSpace(protocols))
                        {
                            text = text + " (" + protocols + ")";
                        }
                    }

                    if (!String.IsNullOrWhiteSpace(call.ShortenedAudioUrl))
                    {
                        text = text + " " + call.ShortenedAudioUrl;
                    }
                    //else if (!String.IsNullOrWhiteSpace(call.ShortenedCallUrl))
                    //{
                    //	text = text + " " + call.ShortenedCallUrl;
                    //}

                    _textMessageProvider.SendTextMessage(profile.GetPhoneNumber(), FormatTextForMessage(call.Name, text), departmentNumber, (MobileCarriers)profile.MobileCarrier, departmentId, true, true);

                    if (Config.SystemBehaviorConfig.SendCallsToSmsEmailGatewayAdditionally)
                    {
                        SendCallViaEmailSmsGateway(call, address, profile);
                    }
                }
                else if (Carriers.DirectSendCarriers.Contains((MobileCarriers)profile.MobileCarrier))
                {
                    string text = HtmlToTextHelper.ConvertHtml(call.NatureOfCall);
                    text = StringHelpers.StripHtmlTagsCharArray(text);
                    text = text + " " + address;

                    if (call.Protocols != null && call.Protocols.Any())
                    {
                        string protocols = String.Empty;
                        foreach (var protocol in call.Protocols)
                        {
                            if (!String.IsNullOrWhiteSpace(protocol.Data))
                            {
                                if (String.IsNullOrWhiteSpace(protocols))
                                {
                                    protocols = protocol.Data;
                                }
                                else
                                {
                                    protocols = protocol + "," + protocol.Data;
                                }
                            }
                        }

                        if (!String.IsNullOrWhiteSpace(protocols))
                        {
                            text = text + " (" + protocols + ")";
                        }
                    }

                    if (!String.IsNullOrWhiteSpace(call.ShortenedAudioUrl))
                    {
                        text = text + " " + call.ShortenedAudioUrl;
                    }
                    //else if (!String.IsNullOrWhiteSpace(call.ShortenedCallUrl))
                    //{
                    //	text = text + " " + call.ShortenedCallUrl;
                    //}

                    _textMessageProvider.SendTextMessage(profile.GetPhoneNumber(), FormatTextForMessage(call.Name, text), departmentNumber, (MobileCarriers)profile.MobileCarrier, departmentId, false, true);

                    if (Config.SystemBehaviorConfig.SendCallsToSmsEmailGatewayAdditionally)
                    {
                        SendCallViaEmailSmsGateway(call, address, profile);
                    }
                }
                else
                {
                    SendCallViaEmailSmsGateway(call, address, profile);
                }
            }

            return(true);
        }
        public MessageResult GetMessage(int messageId)
        {
            var department = _departmentsService.GetDepartmentById(DepartmentId, false);

            var  savedMessage  = _messageService.GetMessageById(messageId);
            bool outboxMessage = false;

            if (savedMessage != null)
            {
                if (!_authorizationService.CanUserViewMessage(UserId, savedMessage))
                {
                    Unauthorized();
                }

                if (savedMessage.SendingUserId == UserId)
                {
                    outboxMessage = true;
                }

                _messageService.ReadMessageRecipient(messageId, UserId);

                var message = new MessageResult();
                message.Mid = savedMessage.MessageId;
                message.Sub = savedMessage.Subject;
                message.Sys = savedMessage.SystemGenerated;

                if (!String.IsNullOrEmpty(savedMessage.Body))
                {
                    message.Bdy = HtmlToTextHelper.ConvertHtml(savedMessage.Body);
                }

                message.Son  = savedMessage.SentOn.TimeConverter(department);
                message.SUtc = savedMessage.SentOn;
                message.Typ  = savedMessage.Type;
                message.Exp  = savedMessage.ExpireOn;

                if (!String.IsNullOrWhiteSpace(savedMessage.SendingUserId))
                {
                    message.Uid = savedMessage.SendingUserId;
                }

                if (!outboxMessage)
                {
                    var respose = savedMessage.MessageRecipients.FirstOrDefault(x => x.UserId == UserId);

                    if (respose != null)
                    {
                        if (!String.IsNullOrWhiteSpace(respose.Response))
                        {
                            message.Rsp = true;
                            message.Rty = respose.Response;
                        }

                        message.Not = respose.Note;
                        message.Ron = respose.ReadOn;
                    }
                    else
                    {
                        message.Ron = savedMessage.ReadOn;
                    }

                    message.Rcpts = new List <MessageRecipientResult>();

                    foreach (var recipient in savedMessage.MessageRecipients)
                    {
                        var recipResult = new MessageRecipientResult();
                        recipResult.Mid = savedMessage.MessageId;
                        recipResult.Uid = recipient.UserId;
                        recipResult.Rty = recipient.Response;
                        recipResult.Not = recipient.Note;
                        recipResult.Ron = recipient.ReadOn;

                        message.Rcpts.Add(recipResult);
                    }
                }
                else
                {
                    message.Rcpts = new List <MessageRecipientResult>();

                    foreach (var recipient in savedMessage.MessageRecipients)
                    {
                        var recipResult = new MessageRecipientResult();
                        recipResult.Mid = savedMessage.MessageId;
                        recipResult.Uid = recipient.UserId;
                        recipResult.Rty = recipient.Response;
                        recipResult.Not = recipient.Note;
                        recipResult.Ron = recipient.ReadOn;

                        message.Rcpts.Add(recipResult);
                    }
                }

                return(message);
            }

            return(null);
        }
Exemple #13
0
        public async Task <bool> SendCallMail(string email, string subject, string title, string priority, string natureOfCall, string mapPage, string address,
                                              string dispatchedOn, int callId, string userId, string coordinates, string shortenedAudioUrl)
        {
            string callQuery = String.Empty;

            try
            {
                callQuery = HttpUtility.UrlEncode(SymmetricEncryption.Encrypt(callId.ToString(), Config.SystemBehaviorConfig.ExternalLinkUrlParamPassphrase));
            }
            catch { }

            var templateModel = new Dictionary <string, object>
            {
                { "subject", title },
                { "date", dispatchedOn },
                { "nature", HtmlToTextHelper.ConvertHtml(natureOfCall) },
                { "priority", priority },
                { "address", address },
                { "map_page", mapPage },
                { "action_url", $"{Config.SystemBehaviorConfig.ResgridBaseUrl}/User/Dispatch/CallExportEx?query={callQuery}" },
                { "userId", userId },
                { "coordinates", coordinates }
            };

            if (!String.IsNullOrWhiteSpace(shortenedAudioUrl))
            {
                templateModel.Add("hasCallAudio", "true");
                templateModel.Add("callAudio_url", shortenedAudioUrl);
            }

            if (SystemBehaviorConfig.OutboundEmailType == OutboundEmailTypes.Postmark)
            {
                var message = new TemplatedPostmarkMessage
                {
                    From          = DONOTREPLY_EMAIL,
                    To            = email,
                    TemplateId    = Config.OutboundEmailServerConfig.PostmarkCallEmailTemplateId,
                    TemplateModel = templateModel
                };

                var client = new PostmarkClient(Config.OutboundEmailServerConfig.PostmarkApiKey);

                try
                {
                    PostmarkResponse response = await client.SendMessageAsync(message);

                    if (response.Status != PostmarkStatus.Success)
                    {
                        return(false);
                    }

                    return(true);
                }
                catch (Exception) { }
            }
            else
            {
                var template = Mustachio.Parser.Parse(GetTempate("Call.html"));
                var content  = template(templateModel);

                Email newEmail = new Email();
                newEmail.HtmlBody = content;
                newEmail.Sender   = FROM_EMAIL;
                newEmail.To.Add(email);

                return(await _emailSender.Send(newEmail));
            }

            return(false);
        }
Exemple #14
0
        public void SendCall(Call call, CallDispatch dispatch, string departmentNumber, int departmentId, UserProfile profile = null, string address = null)
        {
            if (Config.SystemBehaviorConfig.DoNotBroadcast)
            {
                return;
            }

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

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

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

                if (Config.SystemBehaviorConfig.DepartmentsToForceSmsGateway.Contains(departmentId))
                {
                    string text = HtmlToTextHelper.ConvertHtml(call.NatureOfCall);
                    text = StringHelpers.StripHtmlTagsCharArray(text);
                    text = text + " " + address;

                    if (!String.IsNullOrWhiteSpace(call.ShortenedAudioUrl))
                    {
                        text = text + " " + call.ShortenedAudioUrl;
                    }
                    else if (!String.IsNullOrWhiteSpace(call.ShortenedCallUrl))
                    {
                        text = text + " " + call.ShortenedCallUrl;
                    }

                    _textMessageProvider.SendTextMessage(profile.GetPhoneNumber(), FormatTextForMessage(call.Name, text), departmentNumber, (MobileCarriers)profile.MobileCarrier, true);

                    if (Config.SystemBehaviorConfig.SendCallsToSmsEmailGatewayAdditionally)
                    {
                        SendCallViaEmailSmsGateway(call, address, profile);
                    }
                }
                else if (Carriers.DirectSendCarriers.Contains((MobileCarriers)profile.MobileCarrier))
                {
                    string text = HtmlToTextHelper.ConvertHtml(call.NatureOfCall);
                    text = StringHelpers.StripHtmlTagsCharArray(text);
                    text = text + " " + address;

                    if (!String.IsNullOrWhiteSpace(call.ShortenedAudioUrl))
                    {
                        text = text + " " + call.ShortenedAudioUrl;
                    }
                    else if (!String.IsNullOrWhiteSpace(call.ShortenedCallUrl))
                    {
                        text = text + " " + call.ShortenedCallUrl;
                    }

                    _textMessageProvider.SendTextMessage(profile.GetPhoneNumber(), FormatTextForMessage(call.Name, text), departmentNumber, (MobileCarriers)profile.MobileCarrier);

                    if (Config.SystemBehaviorConfig.SendCallsToSmsEmailGatewayAdditionally)
                    {
                        SendCallViaEmailSmsGateway(call, address, profile);
                    }
                }
                else
                {
                    SendCallViaEmailSmsGateway(call, address, profile);
                }
            }
        }