Posts

Showing posts from 2017

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 multilingual not 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. - Curre

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

How CDN can effect personalisation

Image
Without going into detailed benefits of CDN, generally CDNs are used to deliver the contents from fastest and closest available server.  In Episerver Digital Experience Cloud services, CDN has its own URL pointing to the original URL. The visitor will navigate to something like "www.customer.com". The request will go to the CDN, which in turn goes to the origin URL for non-cached data. The request will return to the CDN, which will cache the content.   Personalisation based on Geolocation will be effected as IP detection services will receive edge server’s IP. In a CDN setup, requests to the web server often come from an edge server and not from the actual client; therefore the HttpContext.Request.UserHostAddress property reflects the edge server's IP address rather than the connecting client's. This can be corrected by configuring the header with true IP.  Add following settings in AppSettings key="episerver:ClientIPAddressHeader" value=&q

How to render SVG in edit mode

Self note: SVG is a smart media format that enables us to use same image in different sizes without compromising on quality and performance. EPiServer supports SVGs but images will not display in editor mode while using the IMG tag, as media urls are updated with version details. e.g. "globalassets/160-835st_bilok_2_screw_straight8mm_x_35mm.svg" will change as  "/episerver/CMS/Content/globalassets/en/160-835st_bilok_2_screw_straight8mm_x_35mm.svg,,1823?epieditmode=False&visitorgroupsByID=undefined". EpiServer will resolve urls for media in this way in Edit and Preview mode. In result svg will not be shown in editor mode. To display the SVG in edit mode, we will be required to resolve url in Default mode, this can be done by calling an overload of the GetUrl-method of the UrlResolver: UrlResolver.Current.GetUrl(svgContent, language, new VirtualPathArguments () { ContextMode = ContextMode.Default })