Exemplo n.º 1
0
        //TODO: we should have an option to force only plain text email
        // html emails are a lot more likely to be phished with copies
        // because the link urls are obfuscated to some degree

        public SiteEmailMessageSender(
            ViewRenderer viewRenderer,
            IEmailSenderResolver emailSenderResolver,
            IStringLocalizer <CloudscribeCore> localizer,
            ILogger <SiteEmailMessageSender> logger
            )
        {
            _log                 = logger;
            _sr                  = localizer;
            _viewRenderer        = viewRenderer;
            _emailSenderResolver = emailSenderResolver;
        }
Exemplo n.º 2
0
 public HomeController(
     SiteContext currentSite,
     IEmailSenderResolver emailSenderResolver,
     ViewRenderer viewRenderer,
     GoogleAnalyticsHelper analyticsHelper
     )
 {
     _currentSite         = currentSite;
     _emailSenderResolver = emailSenderResolver;
     _viewRenderer        = viewRenderer;
     _analyticsHelper     = analyticsHelper;
 }
 public CoreProjectEmailService(
     ViewRenderer viewRenderer,
     ISiteContextResolver siteResolver,
     IEmailSenderResolver emailSenderResolver,
     ILogger <CoreProjectEmailService> logger
     )
 {
     _viewRenderer        = viewRenderer;
     _emailSenderResolver = emailSenderResolver;
     _siteResolver        = siteResolver;
     _log = logger;
 }
        private Dictionary <string, string> SamplePage(string samplePath, string componentPath)
        {
            Infragistics.IgniteUI.SamplesBrowser.Shared.Entities.Control control = this.ControlRepository.GetControl(componentPath);
            Dictionary <string, string> sampleData = new Dictionary <string, string>();

            sampleData["samplePage"] = "";
            if (control == null)
            {
                return(sampleData);
            }

            Infragistics.IgniteUI.SamplesBrowser.Shared.Entities.Sample sample = this.SampleRepository.GetSample(samplePath, control);
            if (sample == null || sample.ServerRuntime == XmlSchema.Values.ServerRuntime.ASPNETMVC)
            {
                return(sampleData);
            }

            SampleViewModel model = ViewModelFactory.CreateSampleViewModel(this.PathHelper, this.TableOfContentsRepository, this.ControlRepository, this.SampleRepository, sample, this.SampleSourceCodeRepository, MemoryCache.Default, new SourceCodeParsingOptions {
                IsLocalInstall = true
            }, this.ApplicationSamplesRepository);

            if (sample.ServerRuntime == XmlSchema.Values.ServerRuntime.Hosted)
            {
                model.RuntimeEnvLimitationMsg    = Resources.ServerRuntimeMessageHosted;
                model.RuntimeEnvLimitationWrkUrl = this.LiveSampleUrl(sample.Url);
            }
            else if (sample.ServerRuntime == XmlSchema.Values.ServerRuntime.HostedRemote)
            {
                model.RuntimeEnvLimitationMsg    = Resources.ServerRuntimeMessageHostedRemote;
                model.RuntimeEnvLimitationWrkUrl = this.LiveSampleUrl(sample.Url);
            }
            else if (sample.ServerRuntime == XmlSchema.Values.ServerRuntime.Remote)
            {
                model.RuntimeEnvLimitationMsg = Resources.ServerRuntimeMessageRemote;
            }

            var request = Config.GetHttpContext().Request;

            if (request.QueryString["mobileview"] != null && sample.Control.IsJQueryMobile)
            {
                sampleData["samplePage"] = ViewRenderer.RenderView("~/Views/Shared/MobileSample.cshtml", model,
                                                                   ControllerContext);
                return(sampleData);
            }
            sampleData["samplePage"] = ViewRenderer.RenderView("~/Views/Shared/Sample.cshtml", model,
                                                               ControllerContext);
            if (sample.Control.IsJQueryMobile && samplePath == "overview")
            {
                sampleData["redirectSourcePath"] = model.Sample.RedirectSourcePath;
            }

            return(sampleData);
        }
Exemplo n.º 5
0
        protected override void DoRender(HtmlTextWriter output)
        {
            using (new RenderingDiagnostics(output, Path + " (statically bound)", Cacheable, VaryByData, VaryByDevice, VaryByLogin, VaryByParm, VaryByQueryString, VaryByUser, ClearOnIndexUpdate, GetCachingID()))
            {
                Assert.IsNotNull(Path, "Path was null or empty, and must point to a valid virtual path to a Razor rendering.");

                var renderer = new ViewRenderer();
                var result = renderer.RenderPartialViewToString(Path, Model);

                output.Write(result);
            }
        }
Exemplo n.º 6
0
        public MapEditorViewVM(MapEditorVM parent, ViewRenderer renderer, RenderTarget renderTarget)
        {
            Parent        = parent;
            this.renderer = renderer;
            RenderTarget  = renderTarget;

            Transformation = new Matrix();
            Cursor         = new MapViewCursorVM(Parent);

            Cursor.ToWorldCoordsFunc = ToWorldCoords;
            Cursor.PropertyChanged  += Cursor_PropertyChanged;
        }
Exemplo n.º 7
0
        public async Task <IHttpActionResult> Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            UserProfile user = new UserProfile
            {
                UserName       = model.UserName,
                Email          = model.Email,
                EmailConfirmed = false
            };

            IdentityResult identityResult = await UserManager.CreateAsync(user, model.Password);

            IHttpActionResult createResult = GetErrorResult(identityResult);

            if (createResult != null)
            {
                return(createResult);
            }

            UserProfile justCreatedUser = await UserManager.FindByNameAsync(model.UserName);

            IdentityResult roleResult = await UserManager.AddToRoleAsync(justCreatedUser.Id, "User");

            IHttpActionResult addRoleResult = GetErrorResult(roleResult);

            if (addRoleResult != null)
            {
                return(addRoleResult);
            }

            string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

            var callbackUrl = Url.Link("ConfirmEmail", new { userId = user.Id, code = code });

            var notification = new AccountNotificationModel
            {
                Code        = code,
                Url         = callbackUrl,
                UserId      = justCreatedUser.Id,
                Email       = justCreatedUser.Email,
                DisplayName = justCreatedUser.UserName
            };

            string body = ViewRenderer.RenderView("~/Views/Mailer/NewAccount.cshtml", notification);
            await UserManager.SendEmailAsync(user.Id, "DurandalAuth account confirmation", body);

            return(Ok());
        }
Exemplo n.º 8
0
        public JsonResult GetSelUser(string userId)
        {
            try
            {
                int        imgtype = 1;
                int        online  = 1;
                string     imgpath = "user.svg";
                long       uID     = Convert.ToInt64(userId);
                onlineuser selUser = entities.onlineusers.Where(m => m.user_id == uID).FirstOrDefault();

                if (selUser.user_img != null)
                {
                    imgpath = selUser.user_img;
                    imgtype = 2;
                }

                if (selUser.is_online == false)
                {
                    online = 0;
                }

                List <chatmessage> chatmessageList = new List <chatmessage>();
                long curId   = (long)Session["USER_ID"];
                user curUser = entities.users.Find(curId);

                chatmessageList = entities.chatmessages.Where(
                    m => (m.from_user_id == curId && m.to_user_id == uID) ||
                    (m.from_user_id == uID && m.to_user_id == curId)).ToList();

                selUserViewModel viewModel = new selUserViewModel();
                viewModel.chatmessageList = chatmessageList;
                viewModel.curUser         = curUser;
                viewModel.selUser         = selUser;
                string patialView = "~/Views/comunicaciones/_chatbox.cshtml";
                string postsHtml  = ViewRenderer.RenderPartialView(patialView, viewModel);
                return(Json(new {
                    result = "success",
                    imgpath = imgpath,
                    imgtype = imgtype,
                    online = online,
                    html = postsHtml,
                    selUserId = uID.ToString(),
                    name = selUser.first_name + " " + selUser.last_name
                }));
            }catch (Exception ex)
            {
                return(Json(new {
                    result = "error",
                    exception = ex.Message
                }));
            }
        }
Exemplo n.º 9
0
        protected override void RenderModel(System.Web.UI.HtmlTextWriter writer)
        {
            Assert.IsNotNull(ViewPath, "ViewPath was null or empty, and must point to a valid virtual path to a Razor rendering.");

            var viewData = new Dictionary <string, object>();

            viewData[MetadataConstants.RenderingParametersViewDataKey] = RenderingParameters;

            var renderer = new ViewRenderer(ControllerContext);
            var result   = renderer.RenderPartialViewToString(ViewPath, Model, viewData);

            writer.Write(result);
        }
        //TODO: we should have an option to force only plain text email
        // html emails are a lot more likely to be phished with copies
        // because the link urls are obfuscated to some degree

        public SiteEmailMessageSender(
            ViewRenderer viewRenderer,
            IOptions<SmtpOptions> smtpOptionsAccessor,
            IStringLocalizer<CloudscribeCore> localizer,
            ILogger<SiteEmailMessageSender> logger
            )
        {
            log = logger;
            sr = localizer;
            this.viewRenderer = viewRenderer;
            globalSmtpSettings = smtpOptionsAccessor.Value;

        }
 public SmtpMessageProcessor(
     ViewRenderer viewRenderer,
     IContactFormResolver contactFormResolver,
     ISmtpOptionsProvider smtpOptionsProvider,
     IOptions <SmtpMessageProcessorOptions> messageProcessorOptionsAccessor,
     ILogger <SmtpMessageProcessor> logger
     )
 {
     this.viewRenderer        = viewRenderer;
     this.smtpOptionsProvider = smtpOptionsProvider;
     this.contactFormResolver = contactFormResolver;
     messageProcessorOptions  = messageProcessorOptionsAccessor.Value;
     log = logger;
 }
Exemplo n.º 12
0
 public SearchController(
     IElasticIndex elasticIndex,
     IEnumerable <IIndexer> searchableServices,
     IIntranetLocalizationService localizationService,
     ISearchUmbracoHelper searchUmbracoHelper,
     ISearchableTypeProvider searchableTypeProvider,
     ViewRenderer viewRenderer)
     : base(elasticIndex, searchableServices, localizationService, searchUmbracoHelper, searchableTypeProvider, viewRenderer)
 {
     _localizationService    = localizationService;
     _elasticIndex           = elasticIndex;
     _searchableTypeProvider = searchableTypeProvider;
     _viewRenderer           = viewRenderer;
 }
Exemplo n.º 13
0
        Element GetElement(object sender)
        {
            ViewRenderer renderer = sender as ViewRenderer;

            if (renderer == null)
            {
                FrameworkElement control = sender as FrameworkElement;
                renderer = control.Parent as ViewRenderer;
            }

            Element element = renderer.Element;

            return(element);
        }
 public InitTemplatedPostHandler(
     IBlogService blogService,
     IEnumerable <IModelSerializer> serializers,
     ViewRenderer viewRenderer,
     IStringLocalizer <cloudscribe.SimpleContent.Web.SimpleContent> localizer,
     ILogger <InitTemplatedPageHandler> logger
     )
 {
     _blogService  = blogService;
     _serializers  = serializers;
     _viewRenderer = viewRenderer;
     _localizer    = localizer;
     _log          = logger;
 }
Exemplo n.º 15
0
        //TODO: we should have an option to force only plain text email
        // html emails are a lot more likely to be phished with copies
        // because the link urls are obfuscated to some degree

        public SiteEmailMessageSender(
            ViewRenderer viewRenderer,
            ISmtpOptionsProvider smtpOptionsProvider,
            //IOptions<SmtpOptions> smtpOptionsAccessor,
            IStringLocalizer <CloudscribeCore> localizer,
            ILogger <SiteEmailMessageSender> logger
            )
        {
            log = logger;
            sr  = localizer;
            this.viewRenderer        = viewRenderer;
            this.smtpOptionsProvider = smtpOptionsProvider;
            //globalSmtpSettings = smtpOptionsAccessor.Value;
        }
Exemplo n.º 16
0
        private void BuildModule(int cateRootId, int categoryId, int year = 0)
        {
            if (Request.QueryString["page"] != null)
            {
                PageIndex = int.Parse(Request.QueryString["page"]);
            }
            PageSize = 10;

            var widget       = WorkContext.Resolve <IWidgetService>();
            var viewRenderer = new ViewRenderer {
                Context = ControllerContext
            };

            var sectionBannerSliderService = WorkContext.Resolve <ISlidersService>();
            var articlesService            = WorkContext.Resolve <IArticlesService>();

            articlesService.LanguageCode = WorkContext.CurrentCulture;

            #region SectionBannerSlider
            var modelSectionBannerSlider = new DataViewerModel();
            modelSectionBannerSlider.BannerImages = sectionBannerSliderService.GetRecords(x => x.Type == (int)PageSlider.Media).FirstOrDefault();
            var viewSectionBannerSlider = viewRenderer.RenderPartialView(Extensions.Constants.ViewPageBannerImage, modelSectionBannerSlider);
            WorkContext.Layout.SectionBannerSlider.Add(new MvcHtmlString(viewSectionBannerSlider));
            #endregion

            #region SectionPageContent
            var modelSectionPageContent = new DataViewerModel();
            modelSectionPageContent.CategoryInfo = categoryService.GetByIdCache(cateRootId);
            var category = categoryService.GetByIdCache(categoryId);
            modelSectionPageContent.ListCategories = categoryService.GetChildenByParentId(modelSectionPageContent.CategoryInfo.RefId);
            articlesService.CategoryId             = category.RefId;
            modelSectionPageContent.CategoryId     = categoryId;
            modelSectionPageContent.ListYear       = articlesService.GetAllYear().Select(x => x.Year).ToList();
            if (year == 0 && modelSectionPageContent.ListYear.Count > 0)
            {
                year = modelSectionPageContent.ListYear.FirstOrDefault();
            }
            modelSectionPageContent.Year = year;
            BuildBreadcrumb(modelSectionPageContent, categoryId, year);
            modelSectionPageContent.CategoryChilden = categoryService.GetByIdCache(categoryId);
            var total = 0;
            modelSectionPageContent.PageSize     = PageSize;
            modelSectionPageContent.PageIndex    = PageIndex;
            modelSectionPageContent.ListArticles = articlesService.GetMediaByCategoryId(year, PageIndex, PageSize, out total);
            modelSectionPageContent.TotalRow     = total;
            var viewSectionPageContent = viewRenderer.RenderPartialView(Extensions.Constants.ViewMedia, modelSectionPageContent);
            WorkContext.Layout.SectionPageContent.Add(new MvcHtmlString(viewSectionPageContent));
            #endregion
        }
Exemplo n.º 17
0
 protected SearchControllerBase(
     IElasticIndex elasticIndex,
     IEnumerable <IIndexer> searchableServices,
     IIntranetLocalizationService localizationService,
     ISearchUmbracoHelper searchUmbracoHelper,
     ISearchableTypeProvider searchableTypeProvider,
     ViewRenderer viewRenderer)
 {
     _elasticIndex           = elasticIndex;
     _searchableServices     = searchableServices;
     _localizationService    = localizationService;
     _searchUmbracoHelper    = searchUmbracoHelper;
     _searchableTypeProvider = searchableTypeProvider;
     _viewRenderer           = viewRenderer;
 }
Exemplo n.º 18
0
        public JsonResult AjaxListe(string search = null, Theme theme = null, StatutEvenement?statut = null)
        {
            var repo      = DAOFactory.GetRepository <Evenement>(db) as EvenementDAO;
            var list      = repo.listAll(null, search, theme, statut);
            var listTheme = DAOFactory.GetRepository <Theme>(db).listAll();

            ViewBag.listTheme = listTheme;
            var view = ViewRenderer.RenderPartialView("~/Views/Evenements/ListOrganizer.cshtml", list, ControllerContext);

            view = Regex.Replace(view, @"[\r\n]+", "");
            view = view.Replace("                        ", "");
            var res = new { Html = view };

            return(Json(res, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 19
0
 /// <summary>
 /// Renders a partial MVC view to the given writer. Use this method to render
 /// a partial view that doesn't merge with _Layout and doesn't fire
 /// _ViewStart.
 /// </summary>
 /// <param name="viewPath">
 /// The path to the view to render. Either in same controller, shared by
 /// name or as fully qualified ~/ path including extension
 /// </param>
 /// <param name="model">The model to pass to the viewRenderer</param>
 /// <param name="controllerContext">Active Controller context</param>
 /// <param name="writer">Writer to render the view to</param>
 /// <param name="errorMessage">optional out parameter that captures an error message instead of throwing</param>
 /// <returns>String of the rendered view or null on error</returns>
 public static void RenderView(string viewPath, object model, TextWriter writer,
                               ControllerContext controllerContext,
                               out string errorMessage)
 {
     errorMessage = null;
     try
     {
         ViewRenderer renderer = new ViewRenderer(controllerContext);
         renderer.RenderView(viewPath, model, writer);
     }
     catch (Exception ex)
     {
         errorMessage = ex.GetBaseException().Message;
     }
 }
Exemplo n.º 20
0
        public ActionResult Index()
        {
            var categoryService = WorkContext.Resolve <ICategoriesService>();

            categoryService.LanguageCode = WorkContext.CurrentCulture;
            var category = categoryService.GetHomePage();

            if (category != null)
            {
                ViewData[Extensions.Constants.SeoTitle]       = category.Name;
                ViewData[Extensions.Constants.SeoKeywords]    = category.Tags;
                ViewData[Extensions.Constants.SeoDescription] = category.Description;
            }

            var setting      = WorkContext.Resolve <CommonSettings>();
            var viewRenderer = new ViewRenderer {
                Context = ControllerContext
            };

            #region SectionBannerSlider
            var modelSectionBannerSlider = new DataViewerModel();
            var service = WorkContext.Resolve <IBannersService>();
            modelSectionBannerSlider.ListBannerImages = service.GetRecords(x => x.LanguageCode == WorkContext.CurrentCulture && x.CategoryId == category.Id).OrderBy(x => x.SortOrder).ToList();
            modelSectionBannerSlider.Settings         = setting;
            var viewSectionBannerSlider = viewRenderer.RenderPartialView("~/Views/Shared/SliderBanners.cshtml", modelSectionBannerSlider);
            WorkContext.Layout.SectionBanner.Add(new MvcHtmlString(viewSectionBannerSlider));
            #endregion

            #region Products
            var modelProducts      = new DataViewerModel();
            var seviceProductGroup = WorkContext.Resolve <IProductsGroupService>();
            modelProducts.ListProductGroup = seviceProductGroup.GetRecords().OrderBy(x => x.GroupName).ToList();
            modelProducts.Settings         = setting;
            var viewSectionProducts = viewRenderer.RenderPartialView("~/Views/Shared/PageProducts.cshtml", modelProducts);
            WorkContext.Layout.SectionProducts.Add(new MvcHtmlString(viewSectionProducts));
            #endregion

            #region News
            var modelNews   = new DataViewerModel();
            var serviceNews = WorkContext.Resolve <IArticlesService>();
            var list        = serviceNews.GetRecords(x => x.IsPublished).OrderBy(x => x.Id).ToList();
            modelNews.Data = BuildHtml(list, setting);
            var viewSectionNews = viewRenderer.RenderPartialView("~/Views/Shared/PageBlog.cshtml", modelNews);
            WorkContext.Layout.SectionBlog.Add(new MvcHtmlString(viewSectionNews));
            #endregion

            return(View("Empty"));
        }
Exemplo n.º 21
0
        public void BuildPage(int categoryId, bool isShowPartner = false)
        {
            var widget       = WorkContext.Resolve <IWidgetService>();
            var viewRenderer = new ViewRenderer {
                Context = ControllerContext
            };
            var categoryService = WorkContext.Resolve <ICategoriesService>();

            categoryService.LanguageCode = WorkContext.CurrentCulture;
            var partnerService = WorkContext.Resolve <IPartnerService>();

            #region PageHeaderTop
            var modelPageHeaderTop = new DataViewerModel();
            var languageService    = WorkContext.Resolve <ILanguageService>();
            modelPageHeaderTop.ListLanguages = languageService.GetRecords().Where(x => !x.IsBlocked).ToList();
            var viewPageHeaderTop = viewRenderer.RenderPartialView(Extensions.Constants.ViewPageHeaderTop, modelPageHeaderTop);
            WorkContext.Layout.PageHeaderTop.Add(new MvcHtmlString(viewPageHeaderTop));
            #endregion

            #region PageNavigationMenu
            var modelPageNavigationMenu = new DataViewerModel();
            modelPageNavigationMenu.CategoryId           = categoryId;
            modelPageNavigationMenu.ListCategoriesParent = categoryService.GetRecords(x => x.IsActived && !x.IsDeleted && x.IsDisplayMenu && x.ParentId == 0 && x.LanguageCode == WorkContext.CurrentCulture).OrderBy(x => x.OrderBy).ToList();
            modelPageNavigationMenu.ListCategories       = categoryService.GetRecords(x => x.IsActived && !x.IsDeleted && x.IsDisplayMenu && x.ParentId > 0 && x.LanguageCode == WorkContext.CurrentCulture);
            var viewPageNavigationMenu = viewRenderer.RenderPartialView(Extensions.Constants.ViewPageNavigationMenu, modelPageNavigationMenu);
            WorkContext.Layout.PageNavigationMenu.Add(new MvcHtmlString(viewPageNavigationMenu));
            #endregion

            #region SectionClient
            var modelSectionClient = new DataViewerModel();
            modelSectionClient.IsShowPartner = isShowPartner;
            var catePartner = categoryService.GetRecords(x => x.RefId == (int)CategoriesType.Partner && x.LanguageCode == WorkContext.CurrentCulture).FirstOrDefault();
            if (catePartner != null)
            {
                modelSectionClient.CategoryInfo = catePartner;
            }
            modelSectionClient.ListPartners = partnerService.GetRecords(x => !x.IsDeleted && x.LanguageCode == WorkContext.CurrentCulture).OrderBy(x => x.SortOrder).ToList();
            var viewSectionClient = viewRenderer.RenderPartialView(Extensions.Constants.ViewSectionClient, modelSectionClient);
            WorkContext.Layout.SectionClient.Add(new MvcHtmlString(viewSectionClient));
            #endregion

            #region PageFooter
            var modelPageFooter = new DataViewerModel();
            modelPageFooter.ListCategories = categoryService.GetRecords(x => x.IsActived && !x.IsDeleted && x.LanguageCode == WorkContext.CurrentCulture && x.IsDisplayFooter).OrderBy(x => x.OrderBy).ToList();
            var viewPageFooter = viewRenderer.RenderPartialView(Extensions.Constants.ViewPageFooter, modelPageFooter);
            WorkContext.Layout.PageFooter.Add(new MvcHtmlString(viewPageFooter));
            #endregion
        }
Exemplo n.º 22
0
        public JsonResult DeleteMessage(long selUserId, long messageId)
        {
            long uID   = selUserId;
            long curId = (long)Session["USER_ID"];
            List <chatmessage> chatmessageList = new List <chatmessage>();
            selUserViewModel   viewModel       = new selUserViewModel();

            try
            {
                chatmessage chatmessage = entities.chatmessages.Find(messageId);
                entities.chatmessages.Remove(chatmessage);
                entities.SaveChanges();
                user       curUser = entities.users.Find(curId);
                onlineuser selUser = entities.onlineusers.Where(m => m.user_id == uID).FirstOrDefault();
                chatmessageList = entities.chatmessages.Where(
                    m => (m.from_user_id == curId && m.to_user_id == uID) ||
                    (m.from_user_id == uID && m.to_user_id == curId)).ToList();
                viewModel.chatmessageList = chatmessageList;
                viewModel.curUser         = curUser;
                viewModel.selUser         = selUser;
                string patialView = "~/Areas/webmaster/Views/comunicaciones/_chatbox.cshtml";
                string postsHtml  = ViewRenderer.RenderPartialView(patialView, viewModel);
                return(Json(new
                {
                    result = "success",
                    html = postsHtml,
                }));
            }
            catch (Exception ex)
            {
                user       curUser = entities.users.Find(curId);
                onlineuser selUser = entities.onlineusers.Where(m => m.user_id == uID).FirstOrDefault();
                chatmessageList = entities.chatmessages.Where(
                    m => (m.from_user_id == curId && m.to_user_id == uID) ||
                    (m.from_user_id == uID && m.to_user_id == curId)).ToList();
                viewModel.chatmessageList = chatmessageList;
                viewModel.curUser         = curUser;
                viewModel.selUser         = selUser;
                string patialView = "~/Areas/webmaster/Views/comunicaciones/_chatbox.cshtml";
                string postsHtml  = ViewRenderer.RenderPartialView(patialView, viewModel);
                return(Json(new
                {
                    result = "error",
                    html = postsHtml,
                    exception = ex.Message
                }));
            }
        }
Exemplo n.º 23
0
 /// <summary>
 /// Renders a partial MVC view to string. Use this method to render
 /// a partial view that doesn't merge with _Layout and doesn't fire
 /// _ViewStart.
 /// </summary>
 /// <param name="viewPath">
 /// The path to the view to render. Either in same controller, shared by
 /// name or as fully qualified ~/ path including extension
 /// </param>
 /// <param name="model">The model to pass to the viewRenderer</param>
 /// <param name="controllerContext">Active Controller context</param>
 /// <param name="errorMessage">optional out parameter that captures an error message instead of throwing</param>
 /// <returns>String of the rendered view or null on error</returns>
 public static string RenderView(string viewPath, object model,
                                 ControllerContext controllerContext,
                                 out string errorMessage)
 {
     errorMessage = null;
     try
     {
         ViewRenderer renderer = new ViewRenderer(controllerContext);
         return(renderer.RenderViewToString(viewPath, model));
     }
     catch (Exception ex)
     {
         errorMessage = ex.GetBaseException().Message;
     }
     return(null);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="RawHtmlModel"/> class.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="context"></param>
        public RazorHtmlModel(DynamicContentItem item, ViewContext context) : base(item)
        {
            if (string.IsNullOrWhiteSpace(Html))
            {
                foreach (
                    var prop in
                    item.PropertyValues.Where(
                        prop => String.Equals(prop.Name, "RazorHtml", StringComparison.InvariantCultureIgnoreCase)))
                {
                    Html = prop.LongTextValue;
                    break;
                }
            }

            Html = ViewRenderer.RenderTemplate(Html, this, context.Controller.ControllerContext);
        }
Exemplo n.º 25
0
        public ActionResult ListInscrit(string search = null, Theme theme = null, StatutEvenement?statut = null)
        {
            var user              = db.GetFullUser(User.Identity.GetUserId());
            var repo              = DAOFactory.GetRepository <Evenement>(db) as EvenementDAO;
            var listTheme         = DAOFactory.GetRepository <Theme>(db).listAll();
            List <Evenement> list = repo.listAll(user.Utilisateur, search, theme, statut);

            ViewBag.listTheme = listTheme;
            var view = ViewRenderer.RenderPartialView("~/Views/Evenements/ListOrganizer.cshtml", list, ControllerContext);

            view = Regex.Replace(view, @"[\r\n]+", "");
            view = view.Replace("                        ", "");
            var res = new { Html = view };

            return(Json(res, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 26
0
 public InitTemplatedPageHandler(
     IPageService pageService,
     ITreeCache treeCache,
     IEnumerable <IModelSerializer> serializers,
     ViewRenderer viewRenderer,
     IStringLocalizer <cloudscribe.SimpleContent.Web.SimpleContent> localizer,
     ILogger <InitTemplatedPageHandler> logger
     )
 {
     _pageService     = pageService;
     _navigationCache = treeCache;
     _serializers     = serializers;
     _viewRenderer    = viewRenderer;
     _localizer       = localizer;
     _log             = logger;
 }
Exemplo n.º 27
0
 public ContactFormProcessor(
     ViewRenderer viewRenderer,
     ITenantResolver tenantResolver,
     IEmailSenderResolver emailSenderResolver,
     IContactFormResolver contactFormResolver,
     IOptions <ContactFormMessageOptions> messageProcessorOptionsAccessor,
     ILogger <ContactFormProcessor> logger
     )
 {
     _viewRenderer            = viewRenderer;
     _tenantResolver          = tenantResolver;
     _emailSenderResolver     = emailSenderResolver;
     _contactFormResolver     = contactFormResolver;
     _messageProcessorOptions = messageProcessorOptionsAccessor.Value;
     _log = logger;
 }
        private void BuildModule(string keyword)
        {
            if (Request.QueryString["page"] != null)
            {
                PageIndex = int.Parse(Request.QueryString["page"]);
            }
            PageSize = 10;

            var widget       = WorkContext.Resolve <IWidgetService>();
            var viewRenderer = new ViewRenderer {
                Context = ControllerContext
            };

            var sectionBannerSliderService = WorkContext.Resolve <ISlidersService>();
            var searchService = WorkContext.Resolve <ISearchService>();

            searchService.LanguageCode = WorkContext.CurrentCulture;

            #region SectionBannerSlider
            var modelSectionBannerSlider = new DataViewerModel();
            modelSectionBannerSlider.BannerImages = sectionBannerSliderService.GetRecords(x => x.Type == (int)PageSlider.Media).FirstOrDefault();
            var viewSectionBannerSlider = viewRenderer.RenderPartialView(Extensions.Constants.ViewPageBannerImage, modelSectionBannerSlider);
            WorkContext.Layout.SectionBannerSlider.Add(new MvcHtmlString(viewSectionBannerSlider));
            #endregion

            #region SectionPageContent
            var modelSectionPageContent = new DataViewerModel();
            BuildBreadcrumb(modelSectionPageContent, -1);
            var condition = new List <SearchCondition>
            {
                new SearchCondition(new[]
                {
                    SearchField.Title.ToString(),
                    SearchField.Keyword.ToString(),
                    SearchField.Sumary.ToString()
                }, keyword)
            };
            var total = 0;
            modelSectionPageContent.PageSize   = PageSize;
            modelSectionPageContent.PageIndex  = PageIndex;
            modelSectionPageContent.ListSearch = searchService.Search(condition, PageIndex, PageSize, ref total);
            modelSectionPageContent.TotalRow   = total;
            modelSectionPageContent.Keyword    = keyword;
            var viewSectionPageContent = viewRenderer.RenderPartialView(Extensions.Constants.ViewSearchResults, modelSectionPageContent);
            WorkContext.Layout.SectionPageContent.Add(new MvcHtmlString(viewSectionPageContent));
            #endregion
        }
        private void BuildModule(int rootId, int id)
        {
            var viewRenderer = new ViewRenderer {
                Context = ControllerContext
            };

            var sectionBannerSliderService = WorkContext.Resolve <ISlidersService>();
            var imageService    = WorkContext.Resolve <IImagesService>();
            var articlesService = WorkContext.Resolve <IArticlesService>();

            articlesService.LanguageCode = WorkContext.CurrentCulture;

            #region SectionBannerSlider
            var modelSectionBannerSlider = new DataViewerModel();
            modelSectionBannerSlider.BannerImages = sectionBannerSliderService.GetRecords(x => x.Type == (int)PageSlider.Businesses).FirstOrDefault();
            var viewSectionBannerSlider = viewRenderer.RenderPartialView(Extensions.Constants.ViewPageBannerImage, modelSectionBannerSlider);
            WorkContext.Layout.SectionBannerSlider.Add(new MvcHtmlString(viewSectionBannerSlider));
            #endregion

            #region SectionPageContent
            var modelSectionPageContent = new DataViewerModel();
            modelSectionPageContent.CategoryInfo = categoryService.GetByIdCache(id);
            var categoryId = modelSectionPageContent.CategoryInfo.RefId;
            if (rootId == id)
            {
                modelSectionPageContent.ListCategories = categoryService.GetChildenByParentId(categoryId);
                modelSectionPageContent.CategoryId     = rootId;
                BuildBreadcrumb(modelSectionPageContent, rootId);
            }
            else
            {
                var cateParent = categoryService.GetByIdCache(rootId);
                modelSectionPageContent.ListCategories = categoryService.GetChildenByParentId(cateParent.RefId);
                modelSectionPageContent.CategoryId     = id;
                BuildBreadcrumb(modelSectionPageContent, id);
            }

            modelSectionPageContent.Articles = articlesService.GetByCategoryId(categoryId);
            if (modelSectionPageContent.Articles != null)
            {
                modelSectionPageContent.ListImages = imageService.GetRecords(x => x.ArticlesId == modelSectionPageContent.Articles.RefId).ToList();
            }
            var viewSectionPageContent = viewRenderer.RenderPartialView(Extensions.Constants.ViewFineDiningRestaurants, modelSectionPageContent);
            WorkContext.Layout.SectionPageContent.Add(new MvcHtmlString(viewSectionPageContent));
            #endregion
        }
Exemplo n.º 30
0
 public override void WriteToStream(Type type, object value, Stream writeStream, System.Net.Http.HttpContent content)
 {
     using (var writer = new StreamWriter(writeStream))
     {
         var lp = value as LearningPlanDTO;
         if (lp == null)
         {
             throw new InvalidOperationException("Cannot serialize type");
         }
         var converter = new SelectPdf.HtmlToPdf();
         var html      = ViewRenderer.RenderView("~/Views/LearningPlanPDF.cshtml", lp);
         converter.Options.MarginTop    = 35;
         converter.Options.MarginBottom = 35;
         var doc = converter.ConvertHtmlString(html);
         doc.Save(writeStream);
     }
 }
Exemplo n.º 31
0
        public void HandleEvent(AdminTabStripCreated eventMessage)
        {
            if (eventMessage.TabStripName != "customer-edit")
            {
                return;
            }

            //get the currently being edited customer id
            var evc        = EngineContext.Current.Resolve <CustomerController>();
            var context    = evc.ControllerContext ?? new ControllerContext(System.Web.HttpContext.Current.Request.RequestContext, evc);
            var customerId = Convert.ToInt32(context.RequestContext.RouteData.Values["id"]);
            var viewName   = ViewHelpers.GetCorrectViewPath("Views/Customer/CustomerTab.cshtml");

            var content = ViewRenderer.RenderPartialView(viewName, customerId);

            eventMessage.BlocksToRender.Add(MvcHtmlString.Create(content));
        }
Exemplo n.º 32
0
        /// <summary>
        /// Renders the view.
        /// </summary>
        /// <param name="StatusCode">The status code.</param>
        /// <returns></returns>
        private string RenderView(int StatusCode)
        {
            var technicalContactEmail = System.Configuration.ConfigurationManager.AppSettings["TechnicalContactEmail"];

            var ErrorList = new List <HttpErrorPage>();

            ErrorList.Add(new HttpErrorPage()
            {
                ErrorCode = 400, ErrorTitle = "Bad Request ", ErrorDescription = "The server cannot process the request due to something that is perceived to be a client error.", TechnicalContact = technicalContactEmail
            });
            ErrorList.Add(new HttpErrorPage()
            {
                ErrorCode = 401, ErrorTitle = "Unauthorized", ErrorDescription = "The requested resource requires authentication.", TechnicalContact = technicalContactEmail
            });
            ErrorList.Add(new HttpErrorPage()
            {
                ErrorCode = 500, ErrorTitle = "Webservice currently unavailable ", ErrorDescription = "An unexpected condition was encountered.Our service team has been dispatched to bring it back online.", TechnicalContact = technicalContactEmail
            });

            var response = HttpContext.Current.Response;

            var z = ErrorList.Where(x => x.ErrorCode == StatusCode).FirstOrDefault();

            if (z == null)
            {
                z = new HttpErrorPage()
                {
                    ErrorCode        = StatusCode,
                    ErrorTitle       = "Unknown Error",
                    ErrorDescription = "An unknown error has occured.",
                    TechnicalContact = technicalContactEmail
                };
            }


            // Create an arbitrary controller instance
            var controller = ViewRenderer.CreateController <FakeController>();

            string html = ViewRenderer.RenderView(
                string.Format("~/views/shared/HttpErrorPages/Error.cshtml", StatusCode.ToString()),
                z,
                controller.ControllerContext);

            return(html);
        }
Exemplo n.º 33
0
        // used in WebRole for views built from pickled objects that are cached
        public string RenderDynamicViewWithCaching(ControllerContext context, string view_key, ViewRenderer view_renderer, string view, int count, DateTime from, DateTime to, Dictionary<string,object> args)
        {
            try
            {
                var view_is_cached = this.cache[view_key] != null;
                byte[] view_data;
                byte[] response_body;
                if (view_is_cached)
                    view_data = (byte[])cache[view_key];
                else
                    view_data = Encoding.UTF8.GetBytes(view_renderer(eventstore: null, view: view, count: count, from: from, to: to, args: args));

                response_body = CacheUtils.MaybeSuppressResponseBodyForView(context, view_data);
                return Encoding.UTF8.GetString(response_body);
            }
            catch (Exception e)
            {
                GenUtils.PriorityLogMsg("exception", "RenderDynamicViewWithCaching: " + view_key, e.Message + e.StackTrace);
                return RenderDynamicViewWithoutCaching(context, view_renderer, view, count, from, to, args: args);
            }
        }
Exemplo n.º 34
0
 public string RenderDynamicViewWithoutCaching(ControllerContext context, ViewRenderer view_renderer, String view, int count, DateTime from, DateTime to, Dictionary<string,object> args)
 {
     ZonelessEventStore es = GetEventStoreWithCaching(this.cache);
     return view_renderer(es, view, count, from, to, args);
 }
 public void TestFixtureSetUp()
 {
     renderer = ViewRenderer.ForAssemblyOf<SimpleModel>();
 }