// // GET: /Home/ public ActionResult Index() { // Redirect to Sign up if we're multi-store // TODO - Change this to return the signup view instead if (!WebAppSettings.IsIndividualMode) { if (MTApp.CurrentStore.StoreName == "www") { return Redirect("/signup/home"); } } if (WebAppSettings.IsCommercialVersion || WebAppSettings.IsIndividualMode) { // Wizard Check if (MTApp.CurrentStore.Settings.WizardComplete == false) { Response.Redirect(this.MTApp.StoreUrl(false, false) + "adminaccount/login?wizard=1"); } } SessionManager.CategoryLastId = string.Empty; ViewBag.Title = MTApp.CurrentStore.Settings.FriendlyName; ViewBag.BodyClass = "store-home-page"; string template = this.MTApp.ThemeManager().GetTemplateFromCurrentTheme("home.html"); Processor p = new Processor(this.MTApp, template, new TagProvider()); List<ITemplateAction> model = p.RenderForDisplay(); return View("~/views/shared/templateengine.cshtml", model); }
public void CanProcessTemplateWithNoTags() { string template = "<html>\n<head><title>Page Title</title></head>\n<body><h1>My Page</h1></body>\n</html>\n"; Processor target = new Processor(app, template, tagProvider); var actual = target.RenderForDisplay(); List<ITemplateAction> expected = new List<ITemplateAction>(); expected.Add(new MerchantTribeStore.code.TemplateEngine.Actions.LiteralText("<html>")); expected.Add(new MerchantTribeStore.code.TemplateEngine.Actions.LiteralText("\n")); expected.Add(new MerchantTribeStore.code.TemplateEngine.Actions.LiteralText("<head>")); expected.Add(new MerchantTribeStore.code.TemplateEngine.Actions.LiteralText("<title>")); expected.Add(new MerchantTribeStore.code.TemplateEngine.Actions.LiteralText("Page Title")); expected.Add(new MerchantTribeStore.code.TemplateEngine.Actions.LiteralText("</title>")); expected.Add(new MerchantTribeStore.code.TemplateEngine.Actions.LiteralText("</head>")); expected.Add(new MerchantTribeStore.code.TemplateEngine.Actions.LiteralText("\n")); expected.Add(new MerchantTribeStore.code.TemplateEngine.Actions.LiteralText("<body>")); expected.Add(new MerchantTribeStore.code.TemplateEngine.Actions.LiteralText("<h1>")); expected.Add(new MerchantTribeStore.code.TemplateEngine.Actions.LiteralText("My Page")); expected.Add(new MerchantTribeStore.code.TemplateEngine.Actions.LiteralText("</h1>")); expected.Add(new MerchantTribeStore.code.TemplateEngine.Actions.LiteralText("</body>")); expected.Add(new MerchantTribeStore.code.TemplateEngine.Actions.LiteralText("\n")); expected.Add(new MerchantTribeStore.code.TemplateEngine.Actions.LiteralText("</html>")); expected.Add(new MerchantTribeStore.code.TemplateEngine.Actions.LiteralText("\n")); Assert.IsNotNull(actual); Assert.AreEqual(expected.Count, actual.Count); Assert.AreEqual(TemplateActionType.Custom, actual[4].ActionType()); Assert.AreEqual("Page Title", actual[4].RenderCustom()); }
public ActionResult Index(string slug) { ViewBag.BodyClass = "store-category-page"; Category cat = MTApp.CatalogServices.Categories.FindBySlugForStore(slug, MTApp.CurrentRequestContext.CurrentStore.Id); if (cat == null) cat = new Category(); ViewBag.Title = cat.MetaTitle; if (String.IsNullOrEmpty(ViewBag.Title)) { ViewBag.Title = cat.Name; } ViewBag.MetaKeywords = cat.MetaKeywords; ViewBag.MetaDescription = cat.MetaDescription; // Record Category View MerchantTribe.Commerce.SessionManager.CategoryLastId = cat.Bvin; MTApp.CurrentRequestContext.CurrentCategory = cat; string viewName = cat.TemplateName.Trim(); viewName = viewName.Replace(' ', '-'); viewName = viewName.ToLowerInvariant(); ThemeManager tm = MTApp.ThemeManager(); string templateName = "category-" + viewName + ".html"; string template = tm.GetTemplateFromCurrentTheme(true, templateName, "category-grid.html"); ITagProvider tagProvider = new TagProvider(); Processor proc = new Processor(this.MTApp, this.ViewBag, template, tagProvider); StringBuilder output = new StringBuilder(); proc.RenderForDisplay(output); return Content(output.ToString()); }
// // GET: /Home/ public ActionResult Index() { var profiler = MvcMiniProfiler.MiniProfiler.Current; using (profiler.Step("Home Page Index Action")) { using (profiler.Step("Multi-Store Check")) { // Redirect to Sign up if we're multi-store // TODO - Change this to return the signup view instead if (!WebAppSettings.IsIndividualMode) { if (MTApp.CurrentStore.StoreName == "www") { return Redirect("/signup/home"); } } } using (profiler.Step("Wizard Check")) { if (WebAppSettings.IsCommercialVersion || WebAppSettings.IsIndividualMode) { // Wizard Check if (MTApp.CurrentStore.Settings.WizardComplete == false) { Response.Redirect(this.MTApp.StoreUrl(false, false) + "adminaccount/login?wizard=1"); } } } using (profiler.Step("Session Setup")) { SessionManager.CategoryLastId = string.Empty; ViewBag.Title = MTApp.CurrentStore.Settings.HomepageTitle(); ViewBag.MetaKeywords = MTApp.CurrentStore.Settings.GetProp("HomepageMetaKeywords"); ViewBag.MetaDescription = MTApp.CurrentStore.Settings.GetProp("HomepageMetaDescription"); ViewData["AdditionalMetaTags"] = MTApp.CurrentStore.Settings.GetProp("HomepageMetaExtras"); ViewBag.BodyClass = "store-home-page"; } using (profiler.Step("Load Template")) { string template = this.MTApp.ThemeManager().GetTemplateFromCurrentTheme("home.html"); using (profiler.Step("Process Template")) { Processor p = new Processor(this.MTApp, template, new TagProvider()); using (profiler.Step("Render Template Actions")) { List<ITemplateAction> model = p.RenderForDisplay(); using (profiler.Step("return view")) { return View("~/views/shared/templateengine.cshtml", model); } } } } } }
public ActionResult FullFooter(dynamic currentViewBag) { string template = this.MTApp.ThemeManager().GetTemplatePartFromCurrentTheme("full-footer.html"); Processor p = new Processor(this.MTApp, currentViewBag, template, new TagProvider()); StringBuilder output = new StringBuilder(); p.RenderForDisplay(output); return Content(output.ToString()); }
public ActionResult FullFooter(string AnalyticsTop, string AnalyticsBottom, string AdditionalMetaTags) { ViewData["analyticstop"] = AnalyticsTop; ViewData["analyticsbottom"] = AnalyticsBottom; ViewData["AdditionalMetaTags"] += AdditionalMetaTags; string template = this.MTApp.ThemeManager().GetTemplatePartFromCurrentTheme("full-footer.html"); Processor p = new Processor(this.MTApp, template, new TagProvider()); List<ITemplateAction> model = p.RenderForDisplay(); return View("~/views/shared/templateengine.cshtml", model); }
// // GET: /TemplateTest/ public ActionResult Index() { ViewBag.PageTitle = "My Test Page"; string template; Processor p; template = this.MTApp.ThemeManager().GetSystemTemplate("home.html"); p = new Processor(this.MTApp, template, new TagProvider()); List<ITemplateAction> actions; actions = p.RenderForDisplay(); return View("~/views/shared/TemplateEngine.cshtml", actions); }
// // GET: /CustomPage/ public ActionResult Index(string slug) { ViewBag.BodyClass = "store-category-page"; Category cat = MTApp.CatalogServices.Categories.FindBySlugForStore(slug, MTApp.CurrentRequestContext.CurrentStore.Id); if (cat == null) cat = new Category(); MTApp.CurrentRequestContext.CurrentCategory = cat; ViewBag.Title = cat.MetaTitle; if (String.IsNullOrEmpty(ViewBag.Title)) { ViewBag.Title = cat.Name; } ViewBag.MetaKeywords = cat.MetaKeywords; ViewBag.MetaDescription = cat.MetaDescription; // Record View for Analytics RecordCategoryView(cat.Bvin); // Get page.html Template ThemeManager tm = MTApp.ThemeManager(); if (cat.TemplateName == string.Empty) { cat.TemplateName = "default.html"; } string template = tm.GetTemplateFromCurrentTheme(true, cat.TemplateName, "default.html"); // Try default in theme before system // Fill with data from category, making sure legacy description is used if no area data CategoryPageVersion version = cat.GetCurrentVersion(); if (version.Id == 0) { // Create Initial Version version.PublishedStatus = PublishStatus.Draft; version.PageId = cat.Bvin; cat.Versions.Add(version); MTApp.CatalogServices.Categories.Update(cat); version = cat.GetCurrentVersion(); } if (!version.Areas.HasArea("main")) { version.Areas.SetAreaContent("main", cat.PreTransformDescription); } ITagProvider tagProvider = new TagProvider(); Processor proc = new Processor(this.MTApp, this.ViewBag, template, tagProvider); // Render Bread Crumbs var breadRender = new code.TemplateEngine.TagHandlers.BreadCrumbs(); ViewBag.BreadCrumbsFinal = breadRender.RenderCategory(MTApp, new List<BreadCrumbItem>(), cat); var columnRenderer = new code.TemplateEngine.TagHandlers.ContentColumn(); ViewBag.SideColumn = columnRenderer.RenderColumnToString("4", MTApp, ViewBag); StringBuilder output = new StringBuilder(); proc.RenderForDisplay(output); return Content(output.ToString()); }
public ActionResult FullFooter(string AnalyticsTop, string AnalyticsBottom, string AdditionalMetaTags) { ViewData["analyticstop"] = AnalyticsTop; ViewData["analyticsbottom"] = AnalyticsBottom; ViewData["AdditionalMetaTags"] += AdditionalMetaTags; string template = this.MTApp.ThemeManager().GetTemplatePartFromCurrentTheme("full-footer.html"); Processor p = new Processor(this.MTApp, this.ViewBag, template, new TagProvider()); StringBuilder output = new StringBuilder(); p.RenderForDisplay(output); return Content(output.ToString()); }
public void CanProcessTemplateWithNoTags() { string template = "<html>\n<head><title>Page Title</title></head>\n<body><h1>My Page</h1></body>\n</html>\n"; Processor target = new Processor(app, viewBag, template, tagProvider); StringBuilder output = new StringBuilder(); target.RenderForDisplay(output); var actual = output.ToString(); Assert.IsNotNull(actual); Assert.AreEqual(template, actual); }
public void CanProcessTemplateWithTag() { string template = "<html><sys:pagetitle /></html>"; string expected = "<html>My Page Title</html>"; viewBag.PageTitle = "My Page Title"; Processor target = new Processor(app, viewBag, template, tagProvider); StringBuilder output = new StringBuilder(); target.RenderForDisplay(output); var actual = output.ToString(); Assert.IsNotNull(actual); Assert.AreEqual(expected, actual); }
public void SpeedTestTokenization() { long count = 10000; System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Start(); for (long i = 0; i < count; i++) { string template = app.ThemeManager().GetSystemTemplate("category-grid.html"); Processor target = new Processor(app, viewBag, template, tagProvider); var tokens = target.Tokenize(); int tokenCount = tokens.Count(); } watch.Stop(); decimal avg = ((decimal)watch.ElapsedMilliseconds / (decimal)count); Console.WriteLine("Avg Milliseconds = " + avg); }
public void CanProcessTemplateWithTag() { string template = "<html><sys:adminpanel /></html>"; Processor target = new Processor(app, template, tagProvider); var actual = target.RenderForDisplay(); List<ITemplateAction> expected = new List<ITemplateAction>(); expected.Add(new LiteralText("<html>")); expected.Add(new PartialView("~/views/shared/_adminpanel.cshtml", null)); expected.Add(new LiteralText("</html>")); Assert.IsNotNull(actual); Assert.AreEqual(expected.Count, actual.Count); Assert.AreEqual(TemplateActionType.PartialView, actual[1].ActionType()); Assert.AreEqual("~/views/shared/_adminpanel.cshtml", ((PartialView)actual[1]).ViewName); }
// // GET: /CustomPage/ public ActionResult Index(string slug) { Category cat = MTApp.CatalogServices.Categories.FindBySlugForStore(slug, MTApp.CurrentRequestContext.CurrentStore.Id); if (cat == null) cat = new Category(); MTApp.CurrentRequestContext.CurrentCategory = cat; ViewBag.Title = cat.MetaTitle; if (String.IsNullOrEmpty(ViewBag.Title)) { ViewBag.Title = cat.Name; } ViewBag.MetaKeywords = cat.MetaKeywords; ViewBag.MetaDescription = cat.MetaDescription; // Record View for Analytics RecordCategoryView(cat.Bvin); // Get page.html Template ThemeManager tm = MTApp.ThemeManager(); if (cat.TemplateName == string.Empty) { cat.TemplateName = "default.html"; } string template = tm.GetTemplateFromCurrentTheme(cat.TemplateName, "default.html"); // Try default in theme before system // Fill with data from category, making sure legacy description is used if no area data CategoryPageVersion version = cat.GetCurrentVersion(); if (version.Id == 0) { // Create Initial Version version.PublishedStatus = PublishStatus.Draft; version.PageId = cat.Bvin; cat.Versions.Add(version); MTApp.CatalogServices.Categories.Update(cat); version = cat.GetCurrentVersion(); } if (!version.Areas.HasArea("main")) { version.Areas.SetAreaContent("main", cat.PreTransformDescription); } ITagProvider tagProvider = new TagProvider(); Processor proc = new Processor(this.MTApp, template, tagProvider); var model = proc.RenderForDisplay(); return View("~/views/shared/templateengine.cshtml", model); }
// // GET: /TemplateTest/ public ActionResult Index() { ViewBag.PageTitle = "My Test Page"; var profiler = MvcMiniProfiler.MiniProfiler.Current; string template; Processor p; using (profiler.Step("Load Template")) { template = this.MTApp.ThemeManager().GetSystemTemplate("home.html"); } using (profiler.Step("Create Processor")) { p = new Processor(this.MTApp, template, new TagProvider()); } List<ITemplateAction> actions; using (profiler.Step("Get Actions")) { actions = p.RenderForDisplay(); } return View("~/views/shared/TemplateEngine.cshtml", actions); }
public void SpeedTestRenderActions() { long count = 100; System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Start(); for (long i = 0; i < count; i++) { string template = app.ThemeManager().GetSystemTemplate("default.html"); Processor target = new Processor(app, viewBag, template, tagProvider); StringBuilder output = new StringBuilder(); target.RenderForDisplay(output); var actions = output.ToString(); } watch.Stop(); decimal avg = ((decimal)watch.ElapsedMilliseconds / (decimal)count); Console.WriteLine("Avg Milliseconds = " + avg); }
public ActionResult Index(string slug) { Category cat = MTApp.CatalogServices.Categories.FindBySlugForStore(slug, MTApp.CurrentRequestContext.CurrentStore.Id); if (cat == null) cat = new Category(); if (cat.SourceType != CategorySourceType.FlexPage) { CheckFor301("/" + slug); return Redirect("~/Error?type=category"); } if (cat.Hidden) { return Redirect("~/Error?type=category"); } FlexPageEditorViewModel editorModel = new FlexPageEditorViewModel(); editorModel.CategoryId = cat.Bvin; editorModel.IsPreview = false; editorModel.CurrentPageUrl = Request.AppRelativeCurrentExecutionFilePath; editorModel.IsEditMode = false; ViewBag.Title = cat.MetaTitle; ViewBag.MetaKeywords = cat.MetaKeywords; ViewBag.MetaDescription = cat.MetaDescription; ViewData["basecss"] = Url.Content("~/content/FlexBase.css"); ViewData["slug"] = slug; MTApp.CurrentRequestContext.FlexPageId = cat.Bvin; MTApp.CurrentRequestContext.UrlHelper = this.Url; if (MTApp.IsEditMode) { editorModel.IsEditMode = true; string editCSS = "<link href=\"" + Url.Content("~/content/flexedit.css") + "\" rel=\"stylesheet\" type=\"text/css\" />"; string editJS = "<script type=\"text/javascript\" src=\"" + Url.Content("~/content/FlexEdit.js") + "\"></script>"; editJS += "<script type=\"text/javascript\" src=\"" + Url.Content("~/scripts/Silverlight.js") + "\"></script>"; // Inject CSS and JS into head section of page ViewData["AdditionalMetaTags"] += "\n" + editCSS + "\n" + editJS; } // Pre-Populate Empty Page if (cat.Versions.Count < 1) { cat.Versions.Add(new CategoryPageVersion() { AdminName = "First Version", PublishedStatus = PublishStatus.Published, Root = cat.GetSimpleSample() }); MTApp.CatalogServices.Categories.Update(cat); cat = MTApp.CatalogServices.Categories.Find(cat.Bvin); } // Load Content Parts for Page try { if (MTApp.IsEditMode) { if (Request["preview"] == "1") { ViewData["ContentParts"] = cat.Versions[0].Root.RenderForDisplay(MTApp, cat); editorModel.IsPreview = true; } else { ViewData["ContentParts"] = cat.Versions[0].Root.RenderForEdit(MTApp, cat); editorModel.IsPreview = false; } } else { ViewData["ContentParts"] = cat.Versions[0].Root.RenderForDisplay(MTApp, cat); editorModel.IsPreview = false; } } catch (Exception ex) { ViewData["ContentParts"] = ex.Message + ex.StackTrace; } // Save Editor Model to View Data ViewData["FlexEditorModel"] = editorModel; // Stuff the flex page content into the area field on the category // it will be rendered in main area tag if (cat.Versions[0].Areas == null) cat.Versions[0].Areas = new AreaData(); cat.Versions[0].Areas.SetAreaContent("Main", (string)ViewData["ContentParts"]); MTApp.CurrentRequestContext.CurrentCategory = cat; string template = this.MTApp.ThemeManager().GetTemplateFromCurrentTheme("default-no-menu.html"); Processor p = new Processor(this.MTApp, this.ViewBag, template, new TagProvider()); StringBuilder output = new StringBuilder(); p.RenderForDisplay(output); return Content(output.ToString()); }
public ActionResult Index(string slug) { ViewBag.BodyClass = "store-category-page"; Category cat = MTApp.CatalogServices.Categories.FindBySlugForStore(slug, MTApp.CurrentRequestContext.CurrentStore.Id); if (cat == null) cat = new Category(); ViewBag.Title = cat.MetaTitle; if (String.IsNullOrEmpty(ViewBag.Title)) { ViewBag.Title = cat.Name; } ViewBag.MetaKeywords = cat.MetaKeywords; ViewBag.MetaDescription = cat.MetaDescription; //ViewBag.DisplayHtml = TagReplacer.ReplaceContentTags(cat.Description, // this.MTApp, // "", // Request.IsSecureConnection); //ViewBag.AddToCartButton = this.MTApp.ThemeManager().ButtonUrl("AddToCart", Request.IsSecureConnection); //ViewBag.DetailsButton = this.MTApp.ThemeManager().ButtonUrl("View", Request.IsSecureConnection); //int pageNumber = GetPageNumber(); //int pageSize = 9; //int totalItems = 0; CategoryPageViewModel model = new CategoryPageViewModel(); //List<Product> products = MTApp.CatalogServices.FindProductForCategoryWithSort( // cat.Bvin, // CategorySortOrder.ManualOrder, // false, // pageNumber, pageSize, ref totalItems); //model.Products = PrepProducts(products); //model.LocalCategory = cat; //model.PagerData.PageSize = pageSize; //model.PagerData.TotalItems = totalItems; //model.PagerData.CurrentPage = pageNumber; //model.PagerData.PagerUrlFormat = UrlRewriter.BuildUrlForCategory(new CategorySnapshot(cat), // MTApp.CurrentRequestContext.RoutingContext, // "{0}"); //model.PagerData.PagerUrlFormatFirst = UrlRewriter.BuildUrlForCategory(new CategorySnapshot(cat), // MTApp.CurrentRequestContext.RoutingContext); model.SubCategories = PrepSubCategories(MTApp.CatalogServices.Categories.FindVisibleChildren(cat.Bvin)); // Banner //if (cat.BannerImageUrl.Trim().Length > 0) //{ // ViewBag.ShowBanner = true; // ViewBag.BannerUrl = MerchantTribe.Commerce.Storage.DiskStorage.CategoryBannerUrl( // MTApp, // cat.Bvin, // cat.BannerImageUrl, // Request.IsSecureConnection); //} //else //{ // ViewBag.ShowBanner = false; //} // Record Category View MerchantTribe.Commerce.SessionManager.CategoryLastId = cat.Bvin; MTApp.CurrentRequestContext.CurrentCategory = cat; // Render Bread Crumbs //var breadRender = new code.TemplateEngine.TagHandlers.BreadCrumbs(); //ViewBag.BreadCrumbsFinal = breadRender.RenderCategory(MTApp, new List<BreadCrumbItem>(), cat); // Render Columns //var columnRender = new code.TemplateEngine.TagHandlers.ContentColumn(); //model.LeftColumn = columnRender.RenderColumnToString("4", MTApp, ViewBag); //model.PreColumn = columnRender.RenderColumnToString(cat.PreContentColumnId, MTApp, ViewBag); //model.PostColumn = columnRender.RenderColumnToString(cat.PostContentColumnId, MTApp, ViewBag); if (cat.TemplateName == "BV Grid") cat.TemplateName = "Grid"; // Safety Check from older versions string viewName = cat.TemplateName.Trim(); if (viewName.Trim().ToLowerInvariant() == "grid") { ThemeManager tm = MTApp.ThemeManager(); string template = tm.GetTemplateFromCurrentTheme("category-grid.html"); ITagProvider tagProvider = new TagProvider(); Processor proc = new Processor(this.MTApp, this.ViewBag, template, tagProvider); StringBuilder output = new StringBuilder(); proc.RenderForDisplay(output); return Content(output.ToString()); } else { return View(viewName, model); } }