/// <summary> /// Initializes a new instance of the <see cref="JsIncludeDescriptor" /> class. /// </summary> /// <param name="module">The container module.</param> /// <param name="name">The module name.</param> /// <param name="fileName">Name of the module file.</param> /// <param name="minFileName">Name of the minified file.</param> /// <param name="isAutoGenerated">if set to <c>true</c> then it indicates that this JS include file is auto generated and is not going to be minimized or loaded from CDN.</param> public JsIncludeDescriptor(ModuleDescriptor module, string name, string fileName = null, string minFileName = null, bool isAutoGenerated = false, bool isExternal = false, JsShimConfigDescriptor shimConfig = null) { Links = new List <IActionProjection>(); Globalization = new List <IActionProjection>(); Module = module; Name = name; IsAutoGenerated = isAutoGenerated; ShimConfiguration = shimConfig; if (isExternal) { if (string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(minFileName)) { throw new CmsException("Paths for the external JS file and minified JS file can not by empty"); } FileName = System.IO.Path.GetFileName(fileName); Path = fileName; MinPath = minFileName; } else { FileName = fileName ?? name + ".js"; Path = VirtualPath.Combine(module.JsBasePath, fileName ?? name + ".js"); // If minFileName is not given then CMS will try to load it from a bcms.[module-name].min.js file. if (!string.IsNullOrEmpty(minFileName)) { MinPath = VirtualPath.Combine(module.JsBasePath, minFileName); } } }
public void T1_CombieTest() { var part1 = "foo"; var part2 = "bar"; var path = VirtualPath.Combine(part1, part2); Assert.AreEqual("foo/bar", path); }
internal Control LoadControl(VirtualPath virtualPath) { // If it's relative, make it *app* relative. Treat is as relative to this // user control (ASURT 55513) virtualPath = VirtualPath.Combine(this.TemplateControlVirtualDirectory, virtualPath); // Process the user control and get its BuildResult BuildResult result = BuildManager.GetVPathBuildResult(Context, virtualPath); return(LoadControl((IWebObjectFactory)result, virtualPath, null /*Type*/, null /*parameters*/)); }
internal ITemplate LoadTemplate(VirtualPath virtualPath) { // If it's relative, make it *app* relative. Treat is as relative to this // user control (ASURT 55513) virtualPath = VirtualPath.Combine(TemplateControlVirtualDirectory, virtualPath); // Compile the declarative template and get its object factory ITypedWebObjectFactory objectFactory = (ITypedWebObjectFactory)BuildManager.GetVPathBuildResult( Context, virtualPath); return(new SimpleTemplate(objectFactory)); }
public DatePickerJsModuleIncludeDescriptor(RootModuleDescriptor module) : base(module, "bcms.datepicker") { Links = new IActionProjection[] { new JavaScriptModuleLink(this, "calendarImageUrl", VirtualPath.Combine(module.CssBasePath, "images", "icn-calendar.png")) }; Globalization = new IActionProjection[] { }; }
public async Task ImportDirectory(DirectoryInfo source, string targetDirectoryPath, Action <ProgressArgs> progressCallback, CancellationToken cancellationToken) { if (source == null) { throw new ArgumentNullException(nameof(source)); } var targetDirectory = getDirectoryFromPath(targetDirectoryPath); var directories = source.GetDirectories("*", SearchOption.AllDirectories).Concat(new[] { source }); var idx = 0; foreach (var directory in directories) { if (idx++ == 0) { _synchronizationContext.Post(x => progressCallback?.Invoke((ProgressArgs)x), new ImportProgressArgs(0, directory.Name)); } if (cancellationToken.IsCancellationRequested) { break; } var relativePath = directory.FullName.Replace(Path.GetDirectoryName(source.FullName), string.Empty).Replace(Path.DirectorySeparatorChar, VirtualPath.Separator); var targetDir = targetDirectory; if (!string.IsNullOrWhiteSpace(relativePath)) { var importedDirectoryPath = targetDirectory.Id != 0 ? VirtualPath.Combine(targetDirectory.Name, relativePath) : relativePath; targetDir = CreateDirectory(importedDirectoryPath); } var files = directory.GetFiles(); var completeFiles = 0; foreach (var file in files) { if (cancellationToken.IsCancellationRequested) { break; } var complete = completeFiles; await ImportFile(file, targetDir.Name, x => progressCallback?.Invoke(new ImportProgressArgs((int)((float)complete / files.Length * 100 + (float)x.Progress / files.Length), x.Message)), cancellationToken); completeFiles++; } } }
public DatePickerJsModuleIncludeDescriptor(RootModuleDescriptor module) : base(module, "bcms.datepicker") { Links = new IActionProjection[] { new JavaScriptModuleLink(this, "calendarImageUrl", VirtualPath.Combine(module.CssBasePath, "images", "icn-calendar.png")) }; Globalization = new IActionProjection[] { new JavaScriptModuleGlobalization(this, "dateFormat", () => Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern.ToLower().Replace("yy", "y")), new JavaScriptModuleGlobalization(this, "currentCulture", () => Thread.CurrentThread.CurrentCulture.Name), }; }
/// <summary> /// Initializes a new instance of the <see cref="JsIncludeDescriptor" /> class. /// </summary> /// <param name="module">The container module.</param> /// <param name="name">The module name.</param> /// <param name="fileName">Name of the module file.</param> /// <param name="minFileName">Name of the minified file.</param> /// <param name="isAutoGenerated">if set to <c>true</c> then it indicates that this JS include file is auto generated and is not going to be minimized or loaded from CDN.</param> public JsIncludeDescriptor(ModuleDescriptor module, string name, string fileName = null, string minFileName = null, bool isAutoGenerated = false) { Links = new List <IActionProjection>(); Globalization = new List <IActionProjection>(); Module = module; Name = name; FileName = fileName ?? name + ".js"; IsAutoGenerated = isAutoGenerated; Path = VirtualPath.Combine(module.JsBasePath, fileName ?? name + ".js"); // If minFileName is not given then CMS will try to load it from a bcms.[module-name].min.js file. if (!string.IsNullOrEmpty(minFileName)) { MinPath = VirtualPath.Combine(module.JsBasePath, minFileName); } }
/// <summary> /// Initializes a new instance of the <see cref="CssIncludeDescriptor" /> class. /// </summary> /// <param name="module">The container module.</param> /// <param name="fileName">Name of the file.</param> /// <param name="minFileName">Name of the minified CSS file version.</param> /// <param name="isPublic">if set to <c>true</c> then this CSS include is public (visible for in the edit/non-edit mode).</param> public CssIncludeDescriptor(CmsModuleDescriptor module, string fileName, string minFileName = null, bool isPublic = false) { if (isPublic && string.IsNullOrEmpty(minFileName)) { throw new CoreException("Public CSS includes should describe a minified file version itself.", new ArgumentNullException("minFileName", "Please define the minFileName parameter.")); } ContainerModule = module; IsPublic = isPublic; Path = VirtualPath.Combine(module.CssBasePath, fileName); // If minFileName is not given then CMS will load it from a bcms.[module-name].min.css file. if (!string.IsNullOrEmpty(minFileName)) { MinPath = VirtualPath.Combine(module.CssBasePath, minFileName); } }
/// <summary> /// Reads an executable file image into memory. /// </summary> /// <param name="fileName">Full path to file to load in the firtual file system.</param> /// <param name="vm">Virtual machine instance which is loading the file.</param> /// <returns>Loaded program image.</returns> public static ProgramImage Load(string fileName, VirtualMachine vm) { if (fileName == null) { throw new ArgumentNullException(nameof(fileName)); } if (vm == null) { throw new ArgumentNullException(nameof(vm)); } var fullPath = new VirtualPath(fileName); if (fullPath.PathType == VirtualPathType.Relative) { fullPath = VirtualPath.Combine(vm.FileSystem.WorkingDirectory, fullPath); } int signature; using var fileStream = vm.FileSystem.OpenFile(fullPath, FileMode.Open, FileAccess.Read).Result; if (fileStream == null) { throw new FileNotFoundException("Executable file not found.", fileName); } signature = fileStream.ReadByte(); signature |= fileStream.ReadByte() << 8; fileStream.Position = 0; if (signature == 0x5A4D) { return(new ExeFile(fullPath, fileStream)); } else { return(new ComFile(fullPath, fileStream)); } }
/* * Compile a source file into an assembly, and import it */ private void ImportSourceFile(VirtualPath virtualPath) { // Get a full path to the source file VirtualPath baseVirtualDir = _virtualPath.Parent; VirtualPath fullVirtualPath = baseVirtualDir.Combine(virtualPath); // Add the source file to the list of files we depend on AddSourceDependency(fullVirtualPath); // CompilationUtil.GetCompilerInfoFromVirtualPath(fullVirtualPath); // Compile it into an assembly BuildResultCompiledAssembly result = (BuildResultCompiledAssembly)BuildManager.GetVPathBuildResult( fullVirtualPath); Assembly a = result.ResultAssembly; // Add a dependency to the assembly AddAssemblyDependency(a); }
public DatePickerJsModuleIncludeDescriptor(RootModuleDescriptor module) : base(module, "bcms.datepicker") { Links = new IActionProjection[] { new JavaScriptModuleLink(this, "calendarImageUrl", VirtualPath.Combine(module.CssBasePath, "images", "calendar.svg")) }; Globalization = new IActionProjection[] { new JavaScriptModuleGlobalization(this, "dateFormat", () => { // C# date format map to jQuery date picked. // References: // * http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx // * http://www.phpeveryday.com/articles/jQuery-UI-Changing-the-date-format-for-Datepicker-P1023.html var datePattern = Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern; // Year: if (datePattern.Contains("yyyy")) { // year (four digits). datePattern = datePattern.Replace("yyyy", "yy"); } else if (datePattern.Contains("yy")) { // year (two digits). datePattern = datePattern.Replace("yy", "y"); } // Month: if (datePattern.Contains("MMMM")) { // long month name. datePattern = datePattern.Replace("MMMM", "MM"); } else if (datePattern.Contains("MMM")) { // short month name. datePattern = datePattern.Replace("MMM", "M"); } else if (datePattern.Contains("MM")) { // month of year (two digits). datePattern = datePattern.Replace("MM", "mm"); } else if (datePattern.Contains("M")) { // month of year (single digit where applicable). datePattern = datePattern.Replace("M", "m"); } // Day: if (datePattern.Contains("dddd")) { // full day name. datePattern = datePattern.Replace("dddd", "DD"); } else if (datePattern.Contains("ddd")) { // short day name. datePattern = datePattern.Replace("ddd", "D"); } return(datePattern); }), new JavaScriptModuleGlobalization(this, "currentCulture", () => Thread.CurrentThread.CurrentCulture.Name), }; }
private RenderPageViewModel CreatePageViewModel(Page renderingPage, List <PageContent> allPageContents, Page page, GetPageToRenderRequest request, List <Page> childPagesList) { if (request.PreviewPageContentId == null && !request.IsAuthenticated && page.Status != PageStatus.Published) { throw new HttpException(403, "403 Access Forbidden"); } // Preview and published pages can be accessible to users without content managing roles // Unpublished pages can be accessible only to content managers if (page.Status != PageStatus.Published && page.Status != PageStatus.Preview && !request.HasContentAccess) { if (!cmsConfiguration.Security.AccessControlEnabled) { return(null); // Force 404. } } RenderPageViewModel renderPageViewModel = new RenderPageViewModel(page); renderPageViewModel.CanManageContent = request.CanManageContent; renderPageViewModel.AreRegionsEditable = request.CanManageContent && !childPagesList.Any(); if (page.Layout != null) { renderPageViewModel.LayoutPath = page.Layout.LayoutPath; renderPageViewModel.Options = GetMergedOptionValues(page.Layout.LayoutOptions, page.Options, childPagesList); renderPageViewModel.Regions = page.Layout.LayoutRegions .Distinct() .Select(f => new PageRegionViewModel { RegionId = f.Region.Id, RegionIdentifier = f.Region.RegionIdentifier }) .ToList(); } else if (page.MasterPage != null) { var masterPage = renderingPage.MasterPages.FirstOrDefault(p => p.Master.Id == page.MasterPage.Id); if (masterPage == null) { throw new InvalidOperationException(string.Format("Cannot find a master page in master pages path collection for page {0}.", request.PageUrl)); } childPagesList.Insert(0, page); renderPageViewModel.MasterPage = CreatePageViewModel(renderingPage, allPageContents, masterPage.Master, request, childPagesList); childPagesList.Remove(page); var masterOptions = new List <PageOption>(); foreach (var optionValue in renderingPage.MasterPages .SelectMany(mp => mp.Master.Options.Where(optionValue => !masterOptions.Contains(optionValue)))) { masterOptions.Add(optionValue); } renderPageViewModel.Options = GetMergedOptionValues(masterOptions, page.Options, childPagesList); renderPageViewModel.Regions = allPageContents .Where(pc => pc.Page == page.MasterPage) .SelectMany(pc => pc.Content.ContentRegions.Distinct()) .Select(cr => new PageRegionViewModel { RegionId = cr.Region.Id, RegionIdentifier = cr.Region.RegionIdentifier }) .ToList(); } else { throw new InvalidOperationException(string.Format("Failed to load layout or master page for page {0}.", request.PageUrl)); } var pageContents = allPageContents.Where(pc => pc.Page.Id == page.Id).Where(pc => pc.Parent == null || allPageContents.All(apc => apc.Id != pc.Parent.Id)); var contentProjections = pageContents.Distinct() .Select(f => contentProjectionService.CreatePageContentProjection(request.CanManageContent, f, allPageContents, null, request.PreviewPageContentId)) .Where(c => c != null).ToList(); renderPageViewModel.Contents = contentProjections; renderPageViewModel.Metadata = pageAccessor.GetPageMetaData(page).ToList(); if (page.AccessRules != null) { var list = page.AccessRules.Cast <IAccessRule>().ToList(); list.RemoveDuplicates((a, b) => a.Id == b.Id ? 0 : -1); renderPageViewModel.AccessRules = list; } if (cmsConfiguration.Security.AccessControlEnabled) { SetIsReadOnly(renderPageViewModel, renderPageViewModel.AccessRules); } renderPageViewModel.HasEditRole = SecurityService.IsAuthorized(RootModuleConstants.UserRoles.EditContent); // Add <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> if current view is in an edit mode. if (request.CanManageContent) { if (renderPageViewModel.Metadata == null) { renderPageViewModel.Metadata = new List <IPageActionProjection>(); } renderPageViewModel.Metadata.Insert(0, new MetaDataProjection("X-UA-Compatible", "IE=edge,chrome=1")); } // Attach styles. var styles = new List <IStylesheetAccessor>(); styles.Add(pageStylesheetProjectionFactory.Create(page, renderPageViewModel.Options)); styles.AddRange(contentProjections); renderPageViewModel.Stylesheets = styles; // Attach JavaScript includes. var js = new List <IJavaScriptAccessor>(); js.Add(pageJavaScriptProjectionFactory.Create(page, renderPageViewModel.Options)); js.AddRange(contentProjections); renderPageViewModel.JavaScripts = js; // TODO: Fix main.js and processor.js IE cache. renderPageViewModel.MainJsPath = string.Format(RootModuleConstants.AutoGeneratedJsFilePathPattern, "bcms.main.js"); renderPageViewModel.RequireJsPath = VirtualPath.Combine(rootModuleDescriptor.JsBasePath, cmsConfiguration.UseMinifiedResources ? "bcms.require-2.1.5.min.js" : "bcms.require-2.1.5.js"); renderPageViewModel.Html5ShivJsPath = VirtualPath.Combine(rootModuleDescriptor.JsBasePath, "html5shiv.js"); return(renderPageViewModel); }
/// <summary> /// Executes this command. /// </summary> /// <param name="request">The request data with page data.</param> /// <returns>Executed command result.</returns> public CmsRequestViewModel Execute(GetPageToRenderRequest request) { var pageQuery = GetPageFutureQuery(request); var pageContentsQuery = GetPageContentFutureQuery(request); var page = pageQuery.ToList().FirstOrDefault(); if (page == null) { return(FindRedirect(request.PageUrl)); } if (request.PreviewPageContentId == null && !request.IsAuthenticated && page.Status != PageStatus.Published) { throw new HttpException(403, "403 Access Forbidden"); } // Preview and published pages can be accessible to users without content managing roles // Unpublished pages can be accessible only to content managers if (page.Status != PageStatus.Published && page.Status != PageStatus.Preview && !request.HasContentAccess) { if (!cmsConfiguration.Security.AccessControlEnabled) { return(null); // Force 404. } } var pageContents = pageContentsQuery.ToList(); var contentProjections = pageContents.Distinct().Select(f => CreatePageContentProjection(request, f)).Where(c => c != null).ToList(); RenderPageViewModel renderPageViewModel = new RenderPageViewModel(page); renderPageViewModel.CanManageContent = request.CanManageContent; renderPageViewModel.LayoutPath = page.Layout.LayoutPath; renderPageViewModel.Regions = page.Layout.LayoutRegions.Distinct().Select(f => new PageRegionViewModel { RegionId = f.Region.Id, RegionIdentifier = f.Region.RegionIdentifier }) .ToList(); renderPageViewModel.Contents = contentProjections; renderPageViewModel.Metadata = pageAccessor.GetPageMetaData(page).ToList(); renderPageViewModel.Options = optionService.GetMergedOptionValues(page.Layout.LayoutOptions, page.Options).ToList(); if (page.AccessRules != null) { var list = page.AccessRules.Cast <IAccessRule>().ToList(); list.RemoveDuplicates((a, b) => a.Id == b.Id ? 0 : -1); renderPageViewModel.AccessRules = list; } if (cmsConfiguration.Security.AccessControlEnabled) { SetIsReadOnly(renderPageViewModel, renderPageViewModel.AccessRules); } renderPageViewModel.HasEditRole = SecurityService.IsAuthorized(RootModuleConstants.UserRoles.EditContent); // Add <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> if current view is in an edit mode. if (request.CanManageContent) { if (renderPageViewModel.Metadata == null) { renderPageViewModel.Metadata = new List <IPageActionProjection>(); } renderPageViewModel.Metadata.Insert(0, new MetaDataProjection("X-UA-Compatible", "IE=edge,chrome=1")); } // Attach styles. var styles = new List <IStylesheetAccessor>(); styles.Add(pageStylesheetProjectionFactory.Create(page, renderPageViewModel.Options)); styles.AddRange(contentProjections); renderPageViewModel.Stylesheets = styles; // Attach JavaScript includes. var js = new List <IJavaScriptAccessor>(); js.Add(pageJavaScriptProjectionFactory.Create(page, renderPageViewModel.Options)); js.AddRange(contentProjections); renderPageViewModel.JavaScripts = js; // TODO: Fix main.js and processor.js IE cache. renderPageViewModel.MainJsPath = string.Format(RootModuleConstants.AutoGeneratedJsFilePathPattern, "bcms.main.js"); renderPageViewModel.RequireJsPath = VirtualPath.Combine(rootModuleDescriptor.JsBasePath, cmsConfiguration.UseMinifiedResources ? "bcms.require-2.1.5.min.js" : "bcms.require-2.1.5.js"); renderPageViewModel.Html5ShivJsPath = VirtualPath.Combine(rootModuleDescriptor.JsBasePath, "html5shiv.js"); // Notify about retrieved page. var result = Events.RootEvents.Instance.OnPageRetrieved(renderPageViewModel, page); switch (result) { case PageRetrievedEventResult.ForcePageNotFound: return(null); default: return(new CmsRequestViewModel(renderPageViewModel)); } }
/// <devdoc> /// Creates a MailMessage using the body parameter. /// </devdoc> public MailMessage CreateMailMessage(string recipients, IDictionary replacements, string body, Control owner) { if (owner == null) { throw new ArgumentNullException("owner"); } string from = From; if (String.IsNullOrEmpty(from)) { System.Net.Configuration.SmtpSection smtpSection = RuntimeConfig.GetConfig().Smtp; if (smtpSection == null || smtpSection.Network == null || String.IsNullOrEmpty(smtpSection.From)) { throw new HttpException(SR.GetString(SR.MailDefinition_NoFromAddressSpecified)); } else { from = smtpSection.From; } } MailMessage message = null; try { message = new MailMessage(from, recipients); if (!String.IsNullOrEmpty(CC)) { message.CC.Add(CC); } if (!String.IsNullOrEmpty(Subject)) { message.Subject = Subject; } message.Priority = Priority; if (replacements != null && !String.IsNullOrEmpty(body)) { foreach (object key in replacements.Keys) { string fromString = key as string; string toString = replacements[key] as string; if ((fromString == null) || (toString == null)) { throw new ArgumentException(SR.GetString(SR.MailDefinition_InvalidReplacements)); } // DevDiv 151177 // According to http://msdn2.microsoft.com/en-us/library/ewy2t5e0.aspx, some special // constructs (starting with "$") are recognized in the replacement patterns. References of // these constructs will be replaced with predefined strings in the final output. To use the // character "$" as is in the replacement patterns, we need to replace all references of single "$" // with "$$", because "$$" in replacement patterns are replaced with a single "$" in the // final output. toString = toString.Replace("$", "$$"); body = Regex.Replace(body, fromString, toString, RegexOptions.IgnoreCase); } } // If there are any embedded objects, we need to construct an alternate view with text/html // And add all of the embedded objects as linked resouces if (EmbeddedObjects.Count > 0) { string viewContentType = (IsBodyHtml ? MediaTypeNames.Text.Html : MediaTypeNames.Text.Plain); AlternateView view = AlternateView.CreateAlternateViewFromString(body, null, viewContentType); foreach (EmbeddedMailObject part in EmbeddedObjects) { string path = part.Path; if (String.IsNullOrEmpty(path)) { throw ExceptionUtil.PropertyNullOrEmpty("EmbeddedMailObject.Path"); } if (!UrlPath.IsAbsolutePhysicalPath(path)) { VirtualPath virtualPath = VirtualPath.Combine(owner.TemplateControlVirtualDirectory, VirtualPath.Create(path)); path = virtualPath.AppRelativeVirtualPathString; } // The FileStream will be closed by MailMessage.Dispose() LinkedResource lr = null; try { Stream stream = null; try { stream = owner.OpenFile(path); lr = new LinkedResource(stream); } catch { if (stream != null) { ((IDisposable)stream).Dispose(); } throw; } lr.ContentId = part.Name; lr.ContentType.Name = UrlPath.GetFileName(path); view.LinkedResources.Add(lr); } catch { if (lr != null) { lr.Dispose(); } throw; } } message.AlternateViews.Add(view); } else if (!String.IsNullOrEmpty(body)) { message.Body = body; } message.IsBodyHtml = IsBodyHtml; return(message); } catch { if (message != null) { message.Dispose(); } throw; } }
public void Should_Combine_Path_Correctly() { var path = VirtualPath.Combine("c:\\a", "b", "f"); Assert.AreEqual(path, "c:/a/b/f"); }
public MailMessage CreateMailMessage(string recipients, IDictionary replacements, string body, Control owner) { MailMessage message2; if (owner == null) { throw new ArgumentNullException("owner"); } string from = this.From; if (string.IsNullOrEmpty(from)) { SmtpSection smtp = RuntimeConfig.GetConfig().Smtp; if (((smtp == null) || (smtp.Network == null)) || string.IsNullOrEmpty(smtp.From)) { throw new HttpException(System.Web.SR.GetString("MailDefinition_NoFromAddressSpecified")); } from = smtp.From; } MailMessage message = null; try { message = new MailMessage(from, recipients); if (!string.IsNullOrEmpty(this.CC)) { message.CC.Add(this.CC); } if (!string.IsNullOrEmpty(this.Subject)) { message.Subject = this.Subject; } message.Priority = this.Priority; if ((replacements != null) && !string.IsNullOrEmpty(body)) { foreach (object obj2 in replacements.Keys) { string pattern = obj2 as string; string replacement = replacements[obj2] as string; if ((pattern == null) || (replacement == null)) { throw new ArgumentException(System.Web.SR.GetString("MailDefinition_InvalidReplacements")); } replacement = replacement.Replace("$", "$$"); body = Regex.Replace(body, pattern, replacement, RegexOptions.IgnoreCase); } } if (this.EmbeddedObjects.Count > 0) { string mediaType = this.IsBodyHtml ? "text/html" : "text/plain"; AlternateView item = AlternateView.CreateAlternateViewFromString(body, null, mediaType); foreach (EmbeddedMailObject obj3 in this.EmbeddedObjects) { string path = obj3.Path; if (string.IsNullOrEmpty(path)) { throw ExceptionUtil.PropertyNullOrEmpty("EmbeddedMailObject.Path"); } if (!UrlPath.IsAbsolutePhysicalPath(path)) { path = VirtualPath.Combine(owner.TemplateControlVirtualDirectory, VirtualPath.Create(path)).AppRelativeVirtualPathString; } LinkedResource resource = null; try { Stream contentStream = null; try { contentStream = owner.OpenFile(path); resource = new LinkedResource(contentStream); } catch { if (contentStream != null) { contentStream.Dispose(); } throw; } resource.ContentId = obj3.Name; resource.ContentType.Name = UrlPath.GetFileName(path); item.LinkedResources.Add(resource); } catch { if (resource != null) { resource.Dispose(); } throw; } } message.AlternateViews.Add(item); } else if (!string.IsNullOrEmpty(body)) { message.Body = body; } message.IsBodyHtml = this.IsBodyHtml; message2 = message; } catch { if (message != null) { message.Dispose(); } throw; } return(message2); }
/// <summary> /// Executes this command. /// </summary> /// <param name="request">The request data with page data.</param> /// <returns>Executed command result.</returns> public CmsRequestViewModel Execute(GetPageToRenderRequest request) { var pageQuery = GetPageFutureQuery(request); var pageContentsQuery = GetPageContentFutureQuery(request); var page = pageQuery.FirstOrDefault(); if (page == null) { return(Redirect(request.PageUrl)); } // Redirect user to login page, if page is inaccessible for public users // and user is not authenticated if (request.PreviewPageContentId == null && !request.IsAuthenticated && page.Status != PageStatus.Published && !string.IsNullOrWhiteSpace(cmsConfiguration.LoginUrl)) { // TODO: uncomment redirect to login form, when login form will be im return(null); // return Redirect(cmsConfiguration.LoginUrl); } var pageContents = pageContentsQuery.ToList(); var contentProjections = pageContents.Distinct().Select(f => CreatePageContentProjection(request, f)).Where(c => c != null).ToList(); RenderPageViewModel renderPageViewModel = new RenderPageViewModel(page); renderPageViewModel.CanManageContent = request.CanManageContent; renderPageViewModel.LayoutPath = page.Layout.LayoutPath; renderPageViewModel.Regions = page.Layout.LayoutRegions.Distinct().Select(f => new PageRegionViewModel { RegionId = f.Region.Id, RegionIdentifier = f.Region.RegionIdentifier }) .ToList(); renderPageViewModel.Contents = contentProjections; renderPageViewModel.Metadata = pageAccessor.GetPageMetaData(page).ToList(); renderPageViewModel.Options = optionService.GetMergedOptionValues(page.Layout.LayoutOptions, page.Options).ToList(); // Attach styles. var styles = new List <IStylesheetAccessor>(); styles.Add(pageStylesheetProjectionFactory.Create(page)); styles.AddRange(contentProjections); renderPageViewModel.Stylesheets = styles; // Attach JavaScript includes. var js = new List <IJavaScriptAccessor>(); js.Add(pageJavaScriptProjectionFactory.Create(page)); js.AddRange(contentProjections); renderPageViewModel.JavaScripts = js; // TODO: Fix main.js and processor.js IE cache. renderPageViewModel.MainJsPath = string.Format(RootModuleConstants.AutoGeneratedJsFilePathPattern, "bcms.main.js"); renderPageViewModel.RequireJsPath = VirtualPath.Combine(rootModuleDescriptor.JsBasePath, cmsConfiguration.UseMinifiedResources ? "bcms.require-2.1.5.min.js" : "bcms.require-2.1.5.js"); renderPageViewModel.Html5ShivJsPath = VirtualPath.Combine(rootModuleDescriptor.JsBasePath, "html5shiv.js"); // Notify about retrieved page. var result = Events.RootEvents.Instance.OnPageRetrieved(renderPageViewModel, page); switch (result) { case PageRetrievedEventResult.ForcePageNotFound: return(null); default: return(new CmsRequestViewModel(renderPageViewModel)); } }