Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Research Episerver CMS #7

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
bf618d4
Research Content - Page types
lamkhai Oct 11, 2023
b4ab366
Research Content - Block types
lamkhai Oct 11, 2023
f39f8a4
Research Renderings - Partial page
lamkhai Oct 11, 2023
595d7bc
Research Renderings - TemplateDescriptor - Pages without controllers
lamkhai Oct 11, 2023
c9ecb7c
Research Renderings - Tags - Register multiple templates
lamkhai Oct 11, 2023
1fa81ae
Research Renderings - Select page, block rendering
lamkhai Oct 12, 2023
2fb0da7
Research Renderings - Create a display channel
lamkhai Oct 12, 2023
b1a4f2f
Research Renderings - Add preview resolutions and devices
lamkhai Oct 12, 2023
9136ec4
Research Renderings - Change template programmatically
lamkhai Oct 13, 2023
52cccfa
Research Renderings - Display options
lamkhai Oct 13, 2023
1c9dee5
Research Renderings - Create a block preview template
lamkhai Oct 16, 2023
1108af7
Research Renderings - Create a block preview template
lamkhai Oct 16, 2023
d01fa3a
Merge branch 'feature/CMS' of https://github.com/lamkhai/episerver in…
lamkhai Oct 16, 2023
81516ca
Research Renderings - Add editing attributes
lamkhai Oct 16, 2023
3946469
Research Renderings - Render properties with Tag Helpers
lamkhai Oct 17, 2023
3055fc1
Research Globalization - Localize the user interface - Setup
lamkhai Oct 18, 2023
d475644
Research Globalization - Localize the user interface - Add localized …
lamkhai Oct 18, 2023
30eaf27
Research Globalization - Localize the user interface - Add localized …
lamkhai Oct 18, 2023
e6940a7
Merge conflicts
lamkhai Oct 18, 2023
5f52280
Research Globalization - Localize the user interface - Reuse localiza…
lamkhai Oct 18, 2023
a4694a2
Research Globalization - Localize the user interface - Localize headers
lamkhai Oct 18, 2023
36fe7f8
Research Globalization - Configure a custom localization provider
lamkhai Oct 18, 2023
1944e88
Research Globalization - Retrieve localization service - Retrieve a l…
lamkhai Oct 19, 2023
b1dbda8
Research Media support - Adding media types
lamkhai Oct 19, 2023
2a398c6
Research Media support - Adding media types
lamkhai Oct 19, 2023
99a0d58
Merge conflicts
lamkhai Oct 19, 2023
ce2bb2d
Research Media support - The Image Editor
lamkhai Oct 19, 2023
851c836
Research Media support - Adding an image link property
lamkhai Oct 19, 2023
fc3f339
Research BLOB storage and providers - BLOB architecture
lamkhai Oct 19, 2023
c2fe9c1
Research BLOB storage and providers - Configure a custom BLOB provider
lamkhai Oct 19, 2023
b2304a2
Research Security - Integrate Azure AD using OpenID Connect
lamkhai Oct 20, 2023
bc2e25c
Research Security - ASP.NET Identity
lamkhai Oct 20, 2023
26dbe65
Research Security - Mixed-mode authentication
lamkhai Oct 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/CMS/Business/Channels/KhaiTestDisplayChannel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using EPiServer.Framework.Web;
using EPiServer.Web;

namespace CMS.Business.Channels;

public class KhaiTestDisplayChannel : DisplayChannel
{
public override bool IsActive(HttpContext context)
{
return true;
//The sample code uses package 'Wangkanai.Detection' for device detection
//var detection = context.RequestServices.GetRequiredService<IDetection>();
//return detection.Device.Type == DeviceType.Mobile;
}

public override string ChannelName
{
get { return "Khai Test DisplayChannel"; }
}
}
28 changes: 28 additions & 0 deletions src/CMS/Business/Channels/MobileDisplayChannel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using EPiServer.Framework.Web;
using EPiServer.Web;

namespace CMS.Business.Channels;

public class MobileDisplayChannel : DisplayChannel
{
public override bool IsActive(HttpContext context)
{
return true;
//The sample code uses package 'Wangkanai.Detection' for device detection
//var detection = context.RequestServices.GetRequiredService<IDetection>();
//return detection.Device.Type == DeviceType.Mobile;
}

public override string ChannelName
{
get { return RenderingTags.Mobile; }
}

public override string ResolutionId
{
get
{
return typeof(MobileResolution).FullName;
}
}
}
26 changes: 26 additions & 0 deletions src/CMS/Business/Channels/MobileResolution.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using EPiServer.Web;

namespace CMS.Business.Channels;

public class MobileResolution : IDisplayResolution
{
public int Height
{
get { return 568; }
}

public string Id
{
get { return GetType().FullName; }
}

public string Name
{
get { return "Mobile (320x568)"; }
}

public int Width
{
get { return 320; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using EPiServer.Framework.Initialization;
using EPiServer.Framework;
using EPiServer.ServiceLocation;

namespace CMS.Business.Initialization;

[InitializableModule]
[ModuleDependency(typeof(FrameworkInitialization))]
public class CustomLocalizationProviderInitialization : IConfigurableModule
{
public void ConfigureContainer(ServiceConfigurationContext context)
{
// ClassInMyAssembly can be any class in the Assembly where the resources are embedded
//context.Services.AddEmbeddedLocalization<ClassInMyAssembly>();
}

public void Initialize(InitializationEngine context) { }
public void Uninitialize(InitializationEngine context) { }
}
36 changes: 36 additions & 0 deletions src/CMS/Business/ViewTemplateModelRegistrator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using CMS.Models.Blocks;
using EPiServer.Framework.Web;
using EPiServer.Web.Mvc;

namespace CMS.Business;

public class ViewTemplateModelRegistrator : IViewTemplateModelRegistrator
{
public void Register(TemplateModelCollection viewTemplateModelRegistrator)
{
viewTemplateModelRegistrator.Add(typeof(ThirdBlock),
new TemplateModel()
{
Name = "SidebarTeaserRight",
Description = "Displays a teaser for a page.",
Path = "~/Views/Shared/SidebarThirdBlockRight.cshtml",
AvailableWithoutTag = true
},
new TemplateModel()
{
Name = "SidebarTeaserLeft",
Description = "Displays a teaser for a page.",
Path = "~/Views/Shared/SidebarThirdBlockLeft.cshtml",
Tags = new string[] { RenderingTags.Sidebar }
});

viewTemplateModelRegistrator.Add(typeof(FourthBlock),
new TemplateModel()
{
Name = "SidebarTeaser",
Description = "Displays a teaser of a page.",
Path = "~/Views/Shared/FourthBlock.cshtml",
Tags = new string[] { RenderingTags.Sidebar }
});
}
}
15 changes: 10 additions & 5 deletions src/CMS/CMS.csproj
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<Using Include="EPiServer"/>
<Using Include="EPiServer.Core"/>
<Using Include="EPiServer.DataAbstraction"/>
<Using Include="EPiServer.DataAnnotations"/>
<Using Include="EPiServer" />
<Using Include="EPiServer.Core" />
<Using Include="EPiServer.DataAbstraction" />
<Using Include="EPiServer.DataAnnotations" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="EPiServer.CMS" Version="12.18.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Resources\Translations\**\*" />
</ItemGroup>

<ItemGroup>
<None Remove="Resources\Translations\ContentTypeNames.xml" />
</ItemGroup>
</Project>
15 changes: 15 additions & 0 deletions src/CMS/Components/PagePartialComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using CMS.Models.Pages;
using EPiServer.Framework.DataAnnotations;
using EPiServer.Web.Mvc;
using Microsoft.AspNetCore.Mvc;

namespace CMS.Components;

[TemplateDescriptor(Inherited = true)]
public class PagePartialComponent : PartialContentComponent<SitePageData>
{
protected override IViewComponentResult InvokeComponent(SitePageData currentContent)
{
return View("/Views/Shared/Components/PagePartial/Default.cshtml", currentContent);
}
}
15 changes: 15 additions & 0 deletions src/CMS/Controllers/DefaultPageController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using CMS.Models.Pages;
using EPiServer.Framework.DataAnnotations;
using EPiServer.Web.Mvc;
using Microsoft.AspNetCore.Mvc;

namespace CMS.Controllers;

[TemplateDescriptor(Inherited = true)]
public class DefaultPageController : PageController<SitePageData>
{
public ViewResult Index(SitePageData currentPage)
{
return View($"~/Views/{currentPage.GetOriginalType().Name}/Index.cshtml", currentPage);
}
}
36 changes: 36 additions & 0 deletions src/CMS/Controllers/FirstPageController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using CMS.Models.Pages;
using EPiServer.Framework.DataAnnotations;
using EPiServer.Framework.Localization;
using EPiServer.Framework.Web;
using EPiServer.Web.Mvc;
using Microsoft.AspNetCore.Mvc;
using System.Text;

namespace CMS.Controllers;

[TemplateDescriptor(
Inherited = false,
Description = "Default template to be used by first pages")]
public class FirstPageController : PageControllerBase<FirstPage>
{
public ActionResult Index(FirstPage currentPage)
{
// Implementation of action view the page.

return View(currentPage);
}
}

[TemplateDescriptor(Tags = new string[] { RenderingTags.Mobile })]
public class FirstPageMobileController : PageController<FirstPage>
{
public ActionResult Index(FirstPage currentPage)
{
// Implementation of action view the page.
StringBuilder builder = new();
builder.Append(LocalizationService.Current.GetString("/mystring"));
builder.Append(LocalizationService.Current.GetString("/subnode/myotherstring"));

return View(currentPage);
}
}
55 changes: 55 additions & 0 deletions src/CMS/Controllers/ImagePageController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using CMS.Models.Pages;
using EPiServer.Framework.Blobs;
using EPiServer.ServiceLocation;
using EPiServer.Web.Mvc;
using Microsoft.AspNetCore.Mvc;

namespace CMS.Controllers;

public class ImagePageController : PageController<ImagePage>
{
public async Task<ActionResult> Index(ImagePage currentPage)
{
await ReadWriteBlobs(currentPage.BlobPathToReadWrite);

return View(currentPage);
}

public async Task ReadWriteBlobs(string path)
{
var blobFactory = ServiceLocator.Current.GetInstance<IBlobFactory>();

//Define a container
var container = Blob.GetContainerIdentifier(Guid.NewGuid());

//Uploading a file to a blob
var blob1 = blobFactory.CreateBlob(container, ".jpg");
using (var fs = new FileStream(path, FileMode.Open))
{
blob1.Write(fs);
}

//Writing custom data to a blob
var blob2 = blobFactory.CreateBlob(container, ".txt");
using (var s = blob2.OpenWrite())
{
var w = new StreamWriter(s);
await w.WriteLineAsync("Hello World!");
await w.FlushAsync();
}

//Reading from a blob based on ID
var blobID = blob2.ID;
var blob3 = blobFactory.GetBlob(blobID);
using (var s = blob3.OpenRead())
{
var helloWorld = await new StreamReader(s).ReadToEndAsync();
}

//Delete single blob
blobFactory.Delete(blobID);

//Delete container
blobFactory.Delete(container);
}
}
55 changes: 55 additions & 0 deletions src/CMS/Controllers/MobileTemplate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using CMS.Models.Pages;
using EPiServer.Framework;
using EPiServer.Framework.DataAnnotations;
using EPiServer.Framework.Initialization;
using EPiServer.Web;
using EPiServer.Web.Mvc;

namespace CMS.Controllers;

[TemplateDescriptor(Name = "MobileTemplate")]
public partial class MobileTemplate : PageController<PageData>
{
}

[InitializableModule]
public class MobileRedirectSample : IInitializableModule
{
private IHttpContextAccessor _httpContextAccessor;
public void Initialize(InitializationEngine context)
{
_httpContextAccessor = context.Locate.Advanced.GetRequiredService<IHttpContextAccessor>();
context.Locate.Advanced.GetRequiredService<ITemplateResolverEvents>().TemplateResolved
+= new EventHandler<TemplateResolverEventArgs>(MobileRedirectSample_TemplateResolved);
}

public void Uninitialize(InitializationEngine context)
{
//context.Locate.Advanced.GetRequiredService<ITemplateResolverEvents>().TemplateResolved
// -= new EventHandler<TemplateResolverEventArgs>MobileRedirectSample_TemplateResolved);
}

void MobileRedirectSample_TemplateResolved(object sender, TemplateResolverEventArgs eventArgs)
{
if (eventArgs.ItemToRender != null && eventArgs.ItemToRender is FirstPage)
{
//The sample code uses package 'Wangkanai.Detection' for device detection
//var detection = _httpContextAccessor.HttpContext.RequestServices.GetRequiredService<IDetection>();
//if (detection.Device.Type == DeviceType.Mobile)
//{
// var mobileRender = eventArgs.SupportedTemplates
// .SingleOrDefault(r => r.Name.Contains("Mobile") &&
// r.TemplateTypeCategory == eventArgs.SelectedTemplate.TemplateTypeCategory);

// if (mobileRender != null)
// {
// eventArgs.SelectedTemplate = mobileRender;
// }
//}
}
}

public void Preload(string[] parameters)
{
}
}
15 changes: 15 additions & 0 deletions src/CMS/Controllers/PageControllerBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using CMS.Models.Pages;
using EPiServer.Web.Mvc;
using Microsoft.AspNetCore.Mvc;

namespace CMS.Controllers;

public abstract class PageControllerBase<T> : PageController<T> where T : SitePageData
{
// Providing a logout action for the page.
public ActionResult Logout()
{
// LKTODO: FormsAuthentication.SignOut();
return RedirectToAction("Index");
}
}
Loading