private void log(LogLevels level, object message, Exception exception) { if (!_start) { return; } StringBuilder sb = null; if (_sb != null && _sb.ContainsKey(Thread.CurrentThread.ManagedThreadId)) { sb = _sb[Thread.CurrentThread.ManagedThreadId]; } if (sb != null) { Dictionary <string, object> rp = new Dictionary <string, object>(); rp.Add("level", level.ToString()); rp.Add("date", DateTime.Now.ToString("HH:mm:ss,fff")); rp.Add("logger", Name); rp.Add("message", message); rp.Add("exception", exception?.SerializeToString() ?? String.Empty); rp.Add("newline", Environment.NewLine); string finalMessage = StringFormatUtility.ReplaceParams(_template, rp, "{", "}"); sb.Append(finalMessage); } }
public string GetRawContent(string content, object parameters) { if (string.IsNullOrEmpty(content)) { return(""); } if (parameters == null) { return(content); } bool hasParameter = content.IndexOf("[[") >= 0; if (!hasParameter) { return(content); } return(StringFormatUtility.ReplaceParams(content, parameters, "[[", "]]")); }
public ActionResponse Response(DescriptionModel model) { var pk = int.Parse(model.SelectedRows); var entity = GetEntity(pk, null); var rprovider = ObjectRegistry.GetObject <IResourceProvider>(); if (String.IsNullOrEmpty(entity.Email) && String.IsNullOrEmpty(entity.Mobile)) { return(new ActionResponse(rprovider.GetResource(Constants.Resources.Sections.Messages, Constants.Resources.Messages.feedback_has_no_email_and_mobile))); } entity.Status = Constants.FeedbackStates.Responsed; entity.Response = model.Description; Save(entity); var noty = ObjectRegistry.GetObject <INotificationProvider>(); if (!String.IsNullOrEmpty(entity.Email)) { string subject = rprovider.GetResource(Constants.Resources.Sections.Messages, Constants.Resources.Messages.feed_back_response_subject); string body_template = rprovider.GetResource(Constants.Resources.Sections.Messages, Constants.Resources.Messages.feed_back_response_body_template); body_template = StringFormatUtility.ReplaceParams(body_template, new { UserName = entity.UserName, Description = entity.Description, Response = entity.Response }, "[[", "]]"); noty.SendEmail(subject, body_template, entity.Email, true); } else { string sms = rprovider.GetResource(Constants.Resources.Sections.Messages, Constants.Resources.Messages.feed_back_response_sms_template); sms = StringFormatUtility.ReplaceParams(sms, new { Response = entity.Response, }, "[[", "]]"); noty.SendSms(sms, new[] { entity.Mobile }); } return(new ActionResponse(true)); }
public ActionResponse SendConfirmEmail(UserProfile profile) { var userSrv = ServiceFactory.Create <IAspNetUserService>(); var user = userSrv.GetCurrent(); if (!String.IsNullOrEmpty(profile.Email)) { user.Email = profile.Email; if (String.Compare(user.Email, profile.Email, true) != 0) { user.EmailConfirmed = false; } userSrv.Save(user); } if (String.IsNullOrEmpty(user.Email)) { return(new ActionResponse("آدرس ایمیل تنظیم نشده است.")); } profile.ResetChanges(); int sendCount = profile.EmailConfirmSendCount + 1; if (profile.EmailConfirmSendDt != null) { var time_diff = profile.EmailTimeDiff.Value; if (profile.EmailExceedWaitTimeLimit) { return(new ActionResponse(string.Format("برای ارسال مجدد تاییدیه ایمیل لطفا حداقل {0} ثانیه صبر نمایید.", (profile.EmailWaitTime.Value - DateTime.Now).TotalSeconds))); } if (profile.EmailExceedSendCountLimit) { return(new ActionResponse(string.Format("ارسال تاییدیه ایمیل بیشتر از {0} بار در طول یک روز امکانپذیر نمی باشد.", Constants.Notification.MaxCount))); } if (time_diff.TotalHours > 24) { sendCount = 1; } } var msgSrv = ServiceFactory.Create <ISystemMessageService>(); var subject = msgSrv.GetByCode(Constants.Messages.email_confirm_subject, Constants.SystemMessage.Media.Sms, null).FirstOrDefault()?.Text.Trim(); var body = msgSrv.GetByCode(Constants.Messages.email_confirm_body); var code = EmbedRsaCryptoService.XorEncryptSafeBase64(user.Id + "|" + user.Email); body = StringFormatUtility.ReplaceParams(body, new { username = user.UserName, code = code }, "[[", "]]"); var noty = ObjectRegistry.GetObject <INotificationProvider>(); var result = noty.VerifyEmail(subject, body, user.Email, true); if (result.Result == NotificationResultType.Success) { string username = user.UserName; Repository.BulkUpdate(x => username.Equals(x.Username, StringComparison.CurrentCultureIgnoreCase), x => new UserProfile { EmailConfirmSendDt = DateTime.Now, EmailConfirmSendCount = sendCount }); } return(new ActionResponse { Success = result.Result == NotificationResultType.Success, Message = result.Result == NotificationResultType.Success ? "تاییدیه آدرس ایمیل ارسال شد" : result.Message }); }