public MessageHtmlWrapper MessagesHtml(string viewBy = null, int skip = 0) { List <MessageBag> message = new List <MessageBag>(); if (viewBy == "messageSend") { message = SentMessages(skip); } if (viewBy == "messageReceived") { message = ReceivedMessages(skip); } var rz = new RazorTemplate(); var sbuilder = new StringBuilder(); foreach (var msg in message) { sbuilder.Append(rz.ParseRazorTemplate <MessageBag> ("~/Website/Views/MessagePartials/MessagePartial.cshtml", msg)); } return(new MessageHtmlWrapper { Html = sbuilder.ToString(), Count = message.Count }); }
public void CreateModeratorInvite(Channel channel, User inviter, User invited) { var now = DateTime.UtcNow; var moderatorNotification = new ModeratorNotificationModel { SenderName = inviter.FirstName, SenderAvatarUrl = inviter.AvatarUrl, ChannelName = channel.Name, ChannelId = channel.Id, Date = now.ToShortDateString(), Time = now.ToShortTimeString(), Timestamp = now.ToFileTimeUtc(), Guid = Guid.NewGuid() //gera novo GUID }; var rz = new RazorTemplate(); string htmlNotif = rz.ParseRazorTemplate <ModeratorNotificationModel> ("~/Website/Views/NotificationPartials/Accept.cshtml", moderatorNotification); var wrapper = new ModeratorNotificationWrapper() { ChannelId = moderatorNotification.ChannelId, Html = htmlNotif }; NimbusHubContext.Clients.Group(NimbusHub.GetMessageGroupName(invited.Id)).newModeratorNotification(wrapper); StoreNotification(moderatorNotification, invited.Id); }
private void RazorPageLoad() { NBrightInfo objCat = null; if (RazorTemplate.Trim() != "") // if we don;t have a template, don't do anything { if (_displayentrypage) { // get correct itemid, based on eid given _eid = GetEntryIdFromName(_eid); RazorDisplayDataEntry(_eid); } else { // load meta data for category if (Utils.IsNumeric(_catid)) { var catData = new CategoryData(_catid, Utils.GetCurrentCulture()); if (catData.Name != null) { if (catData.SEOTitle != "") { BasePage.Title = catData.SEOTitle; } else { BasePage.Title = catData.SEOName; } if (BasePage.Title == "") { BasePage.Title = catData.Name; } if (catData.SEODescription != "") { BasePage.Description = catData.SEODescription; } if (catData.SEOTagwords != "") { BasePage.KeyWords = catData.SEOTagwords; } } } var pf = new ProductFunctions(); var strOut = pf.ProductAjaxViewList(Context, ModuleId, TabId, true); // load base template which should call ajax and load the list. //var strOut = NBrightBuyUtils.RazorTemplRender(RazorTemplate, ModuleId, "productdetailrazor" + ModuleId, new NBrightInfo(true), _controlPath, ModSettings.ThemeFolder, Utils.GetCurrentCulture(), ModSettings.Settings()); var lit = new Literal(); lit.Text = strOut; phData.Controls.Add(lit); } } }
public async void TestRender_LinkedEmails(RazorTemplate <LinkedEmailViewModel> template) { var service = CreateService(); var model = new LinkedEmailViewModel("www.TEST.com"); var html = await service.RenderTemplateToStringAsync(template, model); Assert.NotNull(html); Assert.Contains(model.Url, html); }
public async void TestRender_OrgAgreement(RazorTemplate <OrgAgreementRazorViewModel> template) { var service = CreateService(); var model = new OrgAgreementRazorViewModel("My Cool Site", DateTimeOffset.Now); var html = await service.RenderTemplateToStringAsync(template, model); Assert.NotNull(html); Assert.Contains(model.OrganizationName, html); Assert.Contains(model.AcceptedDate.Day.ToString(), html); }
public async void TestRender_EnrolleeRenewalEmails(RazorTemplate <EnrolleeRenewalEmailViewModel> template) { var service = CreateService(); var model = new EnrolleeRenewalEmailViewModel("first", "last", DateTimeOffset.Now); var html = await service.RenderTemplateToStringAsync(template, model); Assert.NotNull(html); Assert.Contains(model.EnrolleeName, html); // Not all emails contain the renewal date or URL despite sharing a view mmodel. }
private NotificationWrapper GenerateUserNotificationHtml(List <Notification <string> > allNotifications) { if (allNotifications.Count == 0) { return new NotificationWrapper() { Count = 0 } } ; var razor = new RazorTemplate(); var sbuilder = new StringBuilder(); //Parallel.ForEach(allNotifications, (notification) => foreach (var notification in allNotifications) { if (notification.Type == Model.NotificationTypeEnum.message) { MessageNotificationModel model = TypeSerializer.DeserializeFromString <MessageNotificationModel>(notification.NotificationObject); sbuilder.Append( razor.ParseRazorTemplate <MessageNotificationModel> ("~/Website/Views/NotificationPartials/Message.cshtml", model)); } else if (notification.Type == Model.NotificationTypeEnum.newtopic) { TopicNotificationModel model = TypeSerializer.DeserializeFromString <TopicNotificationModel>(notification.NotificationObject); sbuilder.Append( razor.ParseRazorTemplate <TopicNotificationModel> ("~/Website/Views/NotificationPartials/NewTopic.cshtml", model)); } else if (notification.Type == Model.NotificationTypeEnum.moderatorinvite) { ModeratorNotificationModel model = TypeSerializer.DeserializeFromString <ModeratorNotificationModel>(notification.NotificationObject); sbuilder.Append( razor.ParseRazorTemplate <ModeratorNotificationModel> ("~/Website/Views/NotificationPartials/Accept.cshtml", model)); } }//); return(new NotificationWrapper() { Count = allNotifications.Count, Html = sbuilder.ToString(), LastNotificationGuid = allNotifications.Last().Id }); }
public MessageHtmlWrapper MessageHtml(int id) { MessageBag bag = new MessageBag(); using (var db = DatabaseFactory.OpenDbConnection()) { var receiverMsg = db.Where <ReceiverMessage>(r => r.UserId == NimbusUser.UserId && r.MessageId == id && r.Status == Model.Enums.MessageType.received).FirstOrDefault(); if (receiverMsg != null) { var msg = db.Where <Message>(m => m.Id == id).FirstOrDefault(); if (msg == null) { return new MessageHtmlWrapper() { Count = 0 } } ; // .Select(r => // db.Where<Message>(m => m.Id == r.MessageId && m.Visible == true).FirstOrDefault()) // .Where(msg => msg != null); User user = db.SelectParam <User>(u => u.Id == msg.SenderId).FirstOrDefault(); bag.ChannelId = msg.ChannelId; bag.Date = msg.Date; bag.Id = msg.Id; bag.SenderId = msg.SenderId; bag.Text = msg.Text.Length > 100 ? msg.Text.Substring(0, 100) : msg.Text; bag.Title = msg.Title; bag.Visible = msg.Visible; bag.UserName = user.FirstName + " " + user.LastName; bag.AvatarUrl = user.AvatarUrl; bag.UserReadStatus = receiverMsg.UserReadStatus; } else { return(new MessageHtmlWrapper() { Count = 0 }); } } var rz = new RazorTemplate(); string htmlMessage = rz.ParseRazorTemplate <MessageBag> ("~/Website/Views/MessagePartials/MessagePartial.cshtml", bag); return(new MessageHtmlWrapper { Count = 1, Html = htmlMessage }); }
public MessageHtmlWrapper MessageExpandHtml(int id) { MessageBag message = ExpandMsg(id); var rz = new RazorTemplate(); var sbuilder = new StringBuilder(); sbuilder.Append(rz.ParseRazorTemplate <MessageBag> ("~/Website/Views/MessagePartials/MessageExpandPartial.cshtml", message)); return(new MessageHtmlWrapper { Html = sbuilder.ToString() }); }
public async void TestRender_SiteApprovalEmails(RazorTemplate <SiteApprovalEmailViewModel> template) { var service = CreateService(); var model = new SiteApprovalEmailViewModel { DoingBusinessAs = "dba", Pec = "pec" }; var html = await service.RenderTemplateToStringAsync(template, model); Assert.NotNull(html); Assert.Contains(model.DoingBusinessAs, html); // Not all emails contain the PEC despite sharing a View Model. }
public async void TestRender_ProvisionerAccessEmails(RazorTemplate <ProvisionerAccessEmailViewModel> template) { var service = CreateService(); var model = new ProvisionerAccessEmailViewModel { EnrolleeFullName = "NAme", TokenUrl = "www.TEST.com", ExpiresInDays = 3 }; var html = await service.RenderTemplateToStringAsync(template, model); Assert.NotNull(html); Assert.Contains(model.EnrolleeFullName, html); Assert.Contains(model.TokenUrl, html); Assert.Contains(model.ExpiresInDays.ToString(), html); }
public async void TestRender_Agreement(RazorTemplate <Agreement> template) { var service = CreateService(); var agreementText = "AGREEMENT TEXT"; var model = new Agreement { AgreementVersion = new AgreementVersion { Text = agreementText } }; var html = await service.RenderTemplateToStringAsync(template, model); Assert.NotNull(html); Assert.Contains(agreementText, html); }
public ChnByCategoryHtmlWrapper AbstChannelHtml(int id, string nameCat) { var rz = new RazorTemplate(); string html = ""; List <Nimbus.Model.ORM.Channel> channel = new List <Nimbus.Model.ORM.Channel>(); channel = ChannelByCategory(id, nameCat); foreach (var item in channel) { html += rz.ParseRazorTemplate <Nimbus.Model.ORM.Channel> ("~/Website/Views/ChannelPartials/ChannelPartial.cshtml", item); } return(new ChnByCategoryHtmlWrapper { Html = html, Count = channel.Count }); }
public CommentHtmlWrapper CommentsHtml(int id = 0, int skip = 0, string type = null) { List <CommentBag> comments = new List <CommentBag>(); string partial = "~/Website/Views/CommentPartials/PartialComment.cshtml"; if (type == "channel") { comments = ShowChannelComment(id, skip); } else if (type == "topic") { comments = ShowTopicComment(id, skip); } else if (type == "notificationtopic") { comments = ShowTopicComment(id, skip); partial = "~/Website/Views/CommentPartials/PartialTopicComment.cshtml"; } else if (type == "child") { comments = ShowMoreCommentChild(id, skip); } else if (type == "oneparent") { comments = ShowParentComment(id, 0); //comments.FirstOrDefault().IsRazorEngine = true; partial = "~/Website/Views/CommentPartials/PartialTopicComment.cshtml"; } else if (type == "onechild") { comments = ShowChildComment(id); } var rz = new RazorTemplate(); string html = ""; foreach (var cmt in comments) { html += rz.ParseRazorTemplate <CommentBag>(partial, cmt); } return(new CommentHtmlWrapper { Html = html, Count = comments.Count }); }
public async Task <string> RenderOrgAgreementHtmlAsync(AgreementType type, string orgName, DateTimeOffset?acceptedDate, bool forPdf) { RazorTemplate <OrgAgreementRazorViewModel> template = (type, forPdf) switch { (AgreementType.CommunityPharmacyOrgAgreement, false) => RazorTemplates.OrgAgreements.CommunityPharmacy, (AgreementType.CommunityPharmacyOrgAgreement, true) => RazorTemplates.OrgAgreements.CommunityPharmacyPdf, (AgreementType.CommunityPracticeOrgAgreement, false) => RazorTemplates.OrgAgreements.CommunityPractice, (AgreementType.CommunityPracticeOrgAgreement, true) => RazorTemplates.OrgAgreements.CommunityPracticePdf, _ => throw new ArgumentException($"Invalid AgreementType {type} in {nameof(RenderOrgAgreementHtmlAsync)}") }; var displayDate = acceptedDate ?? DateTimeOffset.Now; // Converting to BC time here since we aren't localizing this time in the web client displayDate = displayDate.ToOffset(new TimeSpan(-7, 0, 0)); return(await _razorConverterService.RenderTemplateToStringAsync(template, new OrgAgreementRazorViewModel(orgName, displayDate))); }
/// <summary> /// Envia notificações de tópico novo para os usuários seguidores do canal. /// Utiliza mesmo canal de notificações de mensagem. /// </summary> /// <param name="topic"></param> public void NewTopic(Topic topic) { using (var db = DatabaseFactory.OpenDbConnection()) { var channelFollowers = db.Where <ChannelUser>(chu => chu.ChannelId == topic.ChannelId && chu.Follow == true && chu.Accepted == true && chu.Visible == true); var channel = db.Where <Channel>(ch => ch.Id == topic.ChannelId).FirstOrDefault(); var now = DateTime.UtcNow; var nt = new TopicNotificationModel() { TopicId = topic.Id, TopicName = topic.Title, ChannelId = topic.ChannelId, ChannelName = channel.Name, TopicImage = topic.ImgUrl, NotificationType = Model.NotificationTypeEnum.newtopic, Date = now.ToShortDateString(), Time = now.ToShortTimeString(), Timestamp = now.ToFileTimeUtc(), }; var rz = new RazorTemplate(); string htmlNotif = rz.ParseRazorTemplate <TopicNotificationModel> ("~/Website/Views/NotificationPartials/NewTopic.cshtml", nt); foreach (var follower in channelFollowers) { var ntClone = new TopicNotificationModel(nt); NimbusHubContext.Clients.Group(NimbusHub.GetFollowerGroupName(follower.UserId)).newMessageNotification(htmlNotif); StoreNotification(ntClone, follower.UserId); } var ntChClone = new TopicNotificationModel(nt); StoreNotificationChannel(ntChClone); } }
public IFubuRazorView GetView(RazorTemplate descriptor) { Type viewType; var filePath = descriptor.FilePath; _cache.TryGetValue(filePath, out viewType); var lastModified = filePath.LastModified(); if (viewType == null || (_lastModifiedCache[filePath] != lastModified)) { viewType = getViewType(descriptor); lock (_cache) { _cache[filePath] = viewType; _lastModifiedCache[filePath] = lastModified; } } return(Activator.CreateInstance(viewType).As <IFubuRazorView>()); }
public void NewMessage(Model.ORM.Message msg) { var sender = msg.Receivers.Where(r => r.UserId == msg.SenderId).FirstOrDefault(); List <int> receivers = msg.Receivers.Where(r => r.UserId != msg.SenderId).Select(s => s.UserId).ToList(); if (receivers.Count() == 0) { receivers = new List <int>(); receivers.Add(sender.UserId); } var messageNotification = new MessageNotificationModel { SenderName = sender.Name, SenderAvatarUrl = sender.AvatarUrl, Subject = msg.Title, MessageId = msg.Id, Date = msg.Date.ToShortDateString(), Time = msg.Date.ToShortTimeString(), Timestamp = msg.Date.ToFileTimeUtc() }; Parallel.ForEach(receivers, (receiver) => { var msgCopy = new MessageNotificationModel(messageNotification); var rz = new RazorTemplate(); string htmlNotif = rz.ParseRazorTemplate <MessageNotificationModel> ("~/Website/Views/NotificationPartials/Message.cshtml", msgCopy); var wrapper = new MessageNotificationWrapper() { MessageId = msgCopy.MessageId, Html = htmlNotif }; NimbusHubContext.Clients.Group(NimbusHub.GetMessageGroupName(receiver)).newMessageNotification(wrapper); StoreNotification(msgCopy, receiver); }); }
private Type getViewType(RazorTemplate descriptor) { var className = ParserHelpers.SanitizeClassName(descriptor.ViewPath); var baseTemplateType = _razorEngineSettings.BaseTemplateType; var generatedClassContext = new GeneratedClassContext("Execute", "Write", "WriteLiteral", "WriteTo", "WriteLiteralTo", "FubuMVC.Razor.Rendering.TemplateHelper", "DefineSection"); var codeLanguage = RazorCodeLanguageFactory.Create(descriptor.FilePath.FileExtension()); var host = new RazorEngineHost(codeLanguage) { DefaultBaseClass = baseTemplateType.FullName, DefaultNamespace = "FubuMVC.Razor.GeneratedTemplates", GeneratedClassContext = generatedClassContext }; host.NamespaceImports.UnionWith(_commonViewNamespaces.Namespaces); var results = _templateGenerator.GenerateCode(descriptor, className, host); return(_templateCompiler.Compile(className, results.GeneratedCode, host)); }
private void RazorPageLoad() { NBrightInfo objCat = null; if (RazorTemplate.Trim() != "") // if we don;t have a template, don't do anything { if (_displayentrypage) { // get correct itemid, based on eid given _eid = GetEntryIdFromName(_eid); RazorDisplayDataEntry(_eid); } else { // load base template which should call ajax and load the list. var strOut = NBrightBuyUtils.RazorTemplRender(RazorTemplate, ModuleId, "productdetailrazor" + ModuleId, new NBrightInfo(true), _controlPath, ModSettings.ThemeFolder, Utils.GetCurrentCulture(), ModSettings.Settings()); var lit = new Literal(); lit.Text = strOut; phData.Controls.Add(lit); } } }
public async void TestRender_Agreement_WithLimits(RazorTemplate <Agreement> template) { var service = CreateService(); var agreementText = "AGREEMENT TEXT"; var limitsText = "ThIs iS a LiMIt"; var model = new Agreement { AgreementVersion = new AgreementVersion { Text = "AGREEMENT TEXT" }, LimitsConditionsClause = new LimitsConditionsClause { Text = limitsText } }; var html = await service.RenderTemplateToStringAsync(template, model); Assert.NotNull(html); Assert.Contains(agreementText, html); Assert.Contains(limitsText, html); }
public async Task <string> RenderTemplateToStringAsync <TModel>(RazorTemplate <TModel> template, TModel viewModel) { var actionContext = GetActionContext(); var view = GetView(actionContext, template.ViewPath); using var output = new StringWriter(); var viewContext = new ViewContext( actionContext, view, new ViewDataDictionary <TModel>( metadataProvider: new EmptyModelMetadataProvider(), modelState: new ModelStateDictionary()) { Model = viewModel }, new TempDataDictionary(actionContext.HttpContext, _tempDataProvider), output, new HtmlHelperOptions()); await view.RenderAsync(viewContext); return(output.ToString()); }
protected override void OnInit(EventArgs e) { base.OnInit(e); if (ModSettings.Settings().ContainsKey("themefolder") && ModSettings.Settings()["themefolder"] != "") { ThemeFolder = ModSettings.Settings()["themefolder"]; } if (ThemeFolder == "") { ThemeFolder = StoreSettings.Current.ThemeFolder; } if (ModSettings.Settings().ContainsKey("razortemplate") && ModSettings.Settings()["razortemplate"] != "") { RazorTemplate = ModSettings.Settings()["razortemplate"]; } // insert page header text NBrightBuyUtils.RazorIncludePageHeader(ModuleId, Page, "frontofficepageheader.cshtml", ControlPath, ThemeFolder, ModSettings.Settings()); if (ModuleContext.Configuration != null) { if (String.IsNullOrEmpty(RazorTemplate)) { RazorTemplate = ModuleConfiguration.DesktopModule.ModuleName + ".cshtml"; } // insert page header text NBrightBuyUtils.RazorIncludePageHeader(ModuleId, Page, Path.GetFileNameWithoutExtension(RazorTemplate) + "_head" + Path.GetExtension(RazorTemplate), ControlPath, ThemeFolder, ModSettings.Settings()); } var strOut = "<span class='container_" + ThemeFolder + "_" + RazorTemplate + "'>"; Controls.AddAt(0, new LiteralControl("<div class='container_" + ThemeFolder.ToLower().Replace(" ", "_") + "_" + RazorTemplate.ToLower().Replace(".cshtml", "").Replace(" ", "_") + "'>")); Controls.AddAt(Controls.Count, new LiteralControl("</div>")); }
protected override void OnInit(EventArgs e) { base.OnInit(e); _controlPath = ControlPath; if (ModSettings.Settings().ContainsKey("themefolder") && ModSettings.Settings()["themefolder"] != "") { ThemeFolder = ModSettings.Settings()["themefolder"]; } if (ThemeFolder == "") { ThemeFolder = StoreSettings.Current.ThemeFolder; } if (ModSettings.Settings().ContainsKey("razortemplate") && ModSettings.Settings()["razortemplate"] != "") { RazorTemplate = ModSettings.Settings()["razortemplate"]; } if (RazorTemplate == "" && ModSettings.Settings().ContainsKey("razorlisttemplate") && ModSettings.Settings()["razorlisttemplate"] != "") { RazorTemplate = ModSettings.Settings()["razorlisttemplate"]; } if (RazorTemplate == "" && ModSettings.Settings().ContainsKey("razordetailtemplate") && ModSettings.Settings()["razordetailtemplate"] != "") { RazorTemplate = ModSettings.Settings()["razordetailtemplate"]; } if (ModSettings != null) { // check if we're using a provider controlpath for the templates. var providercontrolpath = ModSettings.Get("providercontrolpath"); if (providercontrolpath != "") { _controlPath = "/DesktopModules/NBright/" + providercontrolpath + "/"; } } // insert page header text NBrightBuyUtils.RazorIncludePageHeader(ModuleId, Page, "FrontOfficePageHeader.cshtml", _controlPath, ThemeFolder, ModSettings.Settings()); // insert text in body. NBrightBuyUtils.RazorIncludePageBody(ModuleId, Page, "FrontOfficePageBody.cshtml", _controlPath, ThemeFolder, ModSettings.Settings()); if (ModuleContext.Configuration != null) { if (String.IsNullOrEmpty(RazorTemplate)) { RazorTemplate = ModuleConfiguration.DesktopModule.ModuleName + ".cshtml"; } // insert page header text NBrightBuyUtils.RazorIncludePageHeader(ModuleId, Page, Path.GetFileNameWithoutExtension(RazorTemplate) + "_head" + Path.GetExtension(RazorTemplate), _controlPath, ThemeFolder, ModSettings.Settings()); // insert page body text for template name. NBrightBuyUtils.RazorIncludePageBody(ModuleId, Page, Path.GetFileNameWithoutExtension(RazorTemplate) + "_pageinject" + Path.GetExtension(RazorTemplate), _controlPath, ThemeFolder, ModSettings.Settings()); } var strOut = "<span class='container_" + ThemeFolder + "_" + RazorTemplate + "'>"; Controls.AddAt(0, new LiteralControl("<div class='container_" + ThemeFolder.ToLower().Replace(" ", "_") + "_" + RazorTemplate.ToLower().Replace(".cshtml", "").Replace(" ", "_") + "'>")); Controls.AddAt(Controls.Count, new LiteralControl("</div>")); }