Advanced Developer Training James Vidler, Software Developer
Introduction Advanced Developer Training
What You’ll Learn Advanced User Generated Content (UGC) Components – learn how to define, save, search, and authenticate Website Users, Comments, and Feedback data REST API – learn how you can access your WCM data through a flexible API that can be used in apps, or other websites Caching and Performance – learn about caching techniques you can use to keep your site running optimally under high loads Custom Input Forms – learn how to use in the Input Forms API to hook into WCM input form events and get other WCM content Content Import API – learn how to use the Content Import API to batch import content into your website
User Generated Content Advanced Developer Training
Feedback Provides ability to store feedback data from website visitors such as Likes, Votes, Ratings and Approve/Disapprove An extension of the UGC API C# and JavaScript Can be attached to WCM and UGC definitions so that it can relate directly to content items/records Feedback data can be displayed on the website and viewed from within Agility in the Feedback Stats tab Jon - Not sure content type statuses is the right phrase. Jon - Add a final note that says there are other states like awaiting review or approved but these all sit under the Staging level. There is also Unpublished which doesn’t show up on either… Jon – Published description is not correct, content can be approved but it still isn’t published… Jon- Confused on the Content Workflow row. We should maybe revisit this slide, seems a bit confusing… Maybe something like: Development Mode, Pulls the latest content (staging and published content), Pulls realtime Preview, Pulls the latest content (staging and published content), Pulls realtime Live, Content is pushed to each web server on publish, Pushed when content is published and Agility does a content sync.
Lab – Adding Feedback to a Content Definition
Website Users A special type of UGC definition that includes login fields and password fields Allows you to authenticate a user Authenticated users that create other UGC records will store a ‘CreatedBy’ record Extension of the UGC API Includes methods to Authenticate, IsAuthenticated, RetrievePassword, ChangePassword, and LogOut
Website Users C# and JavaScript API available Use JavaScript API to avoid complications with Output Caching (when loading different content based on user data) Secure – only a logged in user can access their profile record (and only theirs)
Lab – Creating Website User Type in UGC Lab – Creating a Website User Type in UGC…
Lab – Implementing a Login Page
Comments Special type of UGC definition Extension of the UGC API Can be attached to WCM or UGC definitions (similar to Feedback data) Can be combined with Website Users to track who each commented was ‘CreatedBy’ Can be flat or threaded
Lab – Adding Comments to a Content Definition
Lab – Saving and Rendering Comments
Caching and Performance Advanced Developer Training
Output Caching By default, Any page generated by Agility is output cached Agility varies the cache by the page URL, once the page has been rendered once, it saves that outputted HTML for 5 minutes (configurable) Agility.Web will automatically clear any output cache on a page if any content relating to that page has been published from the Agility Content Manager Output cache is not enabled in Development Mode or Preview It is the developer’s responsibility to vary the cache by querystrings or cookies if that is required You can optionally set a custom output cache key in your Global.asax You can verify output cache by loading an Agility website in a browser and viewing the source, there’s a meta tag with the timestamp of the last page rendered
Caching in UGC UGC automatically caches search results for roughly a minute You can set custom cache keys in your UGC API calls to take control of the cache for a given set of records Ensure you use that cache key in your SearchRecords call Using a cache key in your SaveRecord call will clear the cache for that group Additional ClearCache call available to clear cache groups on demand
Agility Dependency Cache Allows you to cache content in server memory, as well as set a dependency to clear whenever specific Agility content is published Use when you are performing resource intensive filters on large lists or across multiple list Will only place objects in cache when you not in Development Mode or Preview
Accessing Volatile Resources Accessing slow resources can cause a bottleneck in your site Slow resources can includes REST services, database calls, etc. Server has to wait for a response before it can continue and under high load you could see your server CPU spike or crash entirely as it juggles queued threads
Accessing Volatile Resources Solution 1: Cache & Lock Resource requested Determine a cache key that identifies parameters used to access resource Check for the object in cache If found, return it Start a critical section ‘lock()’ Check cache again Access the resource Put the result in cache for a specified amount of time Return End the critical section What if the resource goes down??
Solution 2: Cache & Lock + Filesystem Resource is requested Determine a cache key and filename that identifies the parameters used to access the resource Check for the object in cache If found, return it Check for the object in the file system If found, check the last write time - make sure it isn't too old If not too old, return it Else save it to temp variable Start a critical section (lock()) Check cache again If found return it Access the resource with a reasonable timeout *If it errors out, use the temp variable from above if it's set* Write the object to the file system. Put the result in cache for a specific amount of time Return it End the critical section
Solution 3: Offline Process Pseudo-code - Offline Process Start timer to kick off process on a fixed time span. On timer interval: Determine list of resources from config file (or possibly hard coded) Loop each resource item if more than one Determine file path for the resource on this machine Access resource On success, save the result to file system On error, write to error log When loop is complete If any errors occurred, send an email reporting them If in a web farm, copy the file to the other servers
Solution 3: Offline Process (continued) Pseudo-code - Website Resource is requested Determine a cache key and filename that identifies the parameters used to access the resource Check for the object in cache If found, return it Start a critical section (lock()) Check cache again If found return it Access the file that contains the resource Put the result in cache Use a sliding interval, so it stays in cache as long as it's being regularly requested Use a CacheDependancy on the filepath so the cache is cleared when the file is overwritten Return the result End the critical section
Customizing Agility Input Forms Why you might want to customize your form: Adding additional HTML to the input form for contextual help Adding scripts that will manipulate data or validation in the form Getting data from other content lists to display or validate against Integrations with other third-party API’s using JavaScript
Ways to Customize your Form Adding a Custom Section Add as a field/property to WCM and UGC definitions Allows for HTML to be added and ordered like regular properties Using Custom Scripts Added in the Custom Scripts tab to WCM and UGC Definitions Use the Input Form API Using a Custom HTML Form Override the system generated form by using a custom HTML form Any properties in the definition MUST be present on the form
Note on Custom HTML Forms Do not use custom HTML forms unless there is no alternative Maintaining HTML forms can be cumbersome and prevent you from receiving new or improved input controls released by Agility
Input Form API Allows you to get other WCM content and hook into WCM input form events Common use cases include Adding custom validation Integrations into third-party APIs Events include: OnLoadComplete OnBeforeSave OnBeforePublish OnAfterPublish
Content Import API Allows you to import content into Agility Useful for initial content imports or keeping content synced with an external resource Actions include saving, publishing, approving, and deleting content Upload images to Media & Documents Does not support Pages API returns JSON Typically used in a Console Application or Windows Service Should not replace the everyday functions of the Agility Content Manager
Lab – Importing Content using a Console Application
REST API Designed for use in mobile apps, external websites, etc. Content is requested via specific URL schemes Available Content via the REST API includes: Content Lists Content Items Image Galleries Settings *Pages cannot be access via REST API (at this time)
REST API Required Parameters Optional Parameters (Content Lists Only) Time Unix timestamp Hash SHA1 hash of WebsiteName, SecurityKey, and Time Optional Parameters (Content Lists Only) Sort “Title ASC” Filter Standard DataView row filter syntax Skip Integer Take Integer (max page size of 1000)
REST API Request Paths Get Content List /api/content/{languageCode}/{referenceName} Get Content Item /api/content/{languageCode}/{contentID} Get Gallery /api/galleries/{galleryID} Get Settings /api/settings Sample Request: http://yourwebsite.com/api/content/en-us/Blogs?sort=Title%20ASC&filter=Category%3DFun&skip=10&take=5&time=1411006077&hash=04323a2eff88e6b3e78eff0a2fdd10d0237a9715
Lab – Getting Content via the REST API
Resources Agility Developer Website http://developer.agilitycms.com MSDN http://msdn.microsoft.com StackOverflow http://stackoverflow.com jQuery http://jquery.com Bootstrap http://getbootstrap.com/
Questions & Discussion Advanced Developer Training