Posts

EPiServer CMS 11 Useful SQL Queries - 2

Here is a set of few queries that we have been using in different investigations


Get usages of EPiServer contents including pages and blocksCheck Table sizeNo contents have been added for following content typesLooking into Activity LogsUnmapped Property List

Get usages of EPiServer contents including pages and blocks
SELECT
  tct.Name, 
  tct.ModelType, 
  COUNT(tc.pkID) AS PageCount
FROM
  tblContent AS tc RIGHT OUTER JOIN
  tblContentType AS tct ON tc.fkContentTypeID = tct.pkID
Where tct.ModelType is not null and tct.ModelType not like 'EPiServer.%'
GROUP BY
  tct.Name, tct.ModelType
ORDER BY
 PageCount desc

Check table size
EXEC sp_spaceused 'tblBigTable'

No contents have been added for following content types
SELECT
  tct.Name, 
  tct.ModelType
FROM
  tblContent AS tc RIGHT OUTER JOIN
  tblContentType AS tct ON tc.fkContentTypeID = tct.pkID
Where tct.ModelType is not null and tct.ModelType not like 'EPiServer.%'
GROUP BY
  tct.Name, tct.ModelType

Having COUNT(tc.pkID) = 0

Looking int…

EPiServer CMS 11 Useful SQL Queries - 1

Here is a set of few queries that we have been using in different investigations
Check How Big is your DatabaseGet Data for Each Property and from Each Content TypeComplete Tree Structure of your web siteCheck EPiServer DB Version
Check How Big is Database
SELECT 
    t.NAME AS TableName,
    s.Name AS SchemaName,
    p.rows AS RowCounts,
    SUM(a.total_pages) * 8 AS TotalSpaceKB, 
    CAST(ROUND(((SUM(a.total_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS TotalSpaceMB,
    SUM(a.used_pages) * 8 AS UsedSpaceKB, 
    CAST(ROUND(((SUM(a.used_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS UsedSpaceMB, 
    (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB,
    CAST(ROUND(((SUM(a.total_pages) - SUM(a.used_pages)) * 8) / 1024.00, 2) AS NUMERIC(36, 2)) AS UnusedSpaceMB
FROM 
    sys.tables t
INNER JOIN      
    sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN 
    sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN 
    sys.allocation_units a ON p.partiti…

Get Specific Elements Blocks from EPiServer Forms

A small extension to get the specific form elements block with all properties rather relying on  FriendlyNameInfo with the limited set of properties.
EPi Form Extensions Gist
Example: Custom form element block: publicclassHiddenExternalValueElementBlock : HiddenElementBlockBase {     [Display(Name = "Enable if its a special campaign")]     publicvirtualbool MySpecialCampaign { get; set; }    [Display(Name = "Propperty 1")]     publicvirtualbool Property1 { get; set; }    [Display(Name = "Property 2")]     publicvirtualbool Property2 { get; set; } }
Extension Methods:
using EPiServer.Core; using EPiServer.Forms.Core; using EPiServer.Forms.Core.Models; using EPiServer.Forms.Helpers.Internal; using EPiServer.Forms.Implementation.Elements; using System.Collections.Generic; using System.Linq; namespace PixieDigital.EpiServer.Extensions {     publicstaticclassFormExtensions     {         publicstaticIEnumerable<T> GetSpecificFormElements<T>(thisForm…

Azure based architecture for serving EPiServer CMS As Content Hub

Image
This architecture uses the Azure API Management to provide access to content from EPiServer for different channels. Contents are exposed via headless API and other Custom written APIs.Editors and admins will have secure access to EPIServer CMS.API Management is used to publish APIs to external, partner and channels, securely and at scale.Application Insights is used to detect issues, diagnose crashes and track usages.AAD - Azure Active Directory is used for secure, enterprise-grade authentication.Traffic Manager is used to determining which web app is geographically best placed to handle each request, and will be used to obtain zero downtime. A CDN - content delivery network serves static content, such as images, script, and CSS for different channels.Azure SQL DB/Redis Cache/Azure Blob Storage to server data about the site in a high performance and highly scalable way
References: Episerver headless white paperContent delivery api

Serialize IContent to use in Angular like front technologies

(A self note) A generic service to convert IContent into an Expando Object, ExpandoObject  can be converted into JSON to use in Angular/React components.
Find the code gist https://gist.github.com/khurramkhang/e8d4b9ef093fe30610be986efa352744


Limitations:

not supporting multilingualnot preparing friendly urls

Few best practises while working with orders

Validate the status of line item (at required stage in sale flow) to make sure the product is active, within the valid date range, and that the catalog entry is available in the current market.Validate the status of line item (at required stage in sale flow) to make sure business does not lose money.It is important to add coupons to the IOrderForm before running apply discounts(cart.ApplyDiscount method)Avoid saving carts unnecessarily and repeatedly.You should avoid casting back and forth between concrete Order classes (OrderGroup, OrderForm, etc.) and the new abstraction interfaces (IOrderGroup, IOrderForm, etc.).
For example, from the time you load the cart or purchase order until you save it, only use one API. While this is not always possible, doing it whenever possible helps avoid hidden problems when casting.Do not use Math.Round() for rounding. The following methods return a value with the correct number of decimals, which is determined by the input currency.
- Currency.Round()
-…

Schedule Jobs revised

Schedule jobs has been revised in version 10.8. we have a new property Restartable on the ScheduledPlugIn attribute, that can be defined as following

[ScheduledPlugIn(Restartable = true)]

Jobs having property "Restartable=true" will make sure it can be re-run to completion in case of crashes before next schedule time. There are few considerations for developers before using this.

The job should also be implemented in such a way that it can be started repeatedly. If the job processes data, it should be able to continue where it was aborted. It is also recommended to implement a stoppable job, but be aware that the Stop method will only be called for controlled shutdowns which can be picked up by ASP.NET, and not for uncontrolled shutdowns such as an IIS crash or other external changes.In the unlikely event the job is repeatedly cancelled, or the job it