SlideShare une entreprise Scribd logo
1  sur  9
EPiServer Scheduled Jobs
In my previous entry on Creating a episerver package I turned some EPiServer reports into
a nugget package. Now I want to allow the export this data in a format that can be reused, in
this case JSON.
To do this I’m going to create a Scheduled Jobs, which are simple classes that inherit from
JobBase and are decorated with the ScheduledPlugIn attribute.
[ScheduledPlugIn(DisplayName = "Usage Report Collection Job",
Description = "A exports of usage reports in Json”.
SortIndex = 10001)]
public class UsageReportCollectionJob : JobBase
{
public override string Execute()
{
Once we’ve create out class we can place code we wish to execute inside the overridden
Execute method.
Create JSON
Before we can create the JSON, we need to install a serialize. However while we do have
multiple options, Newtonsoft’s Json.Net is the sensible choice as it’s already used in
EPiServer. However, we do need to be careful what version we install. For CMS 7.5 and we
can use anything from version 6 but less that version 8.
Install-Package Newtonsoft.Json -Version 6.0.1
Previously I refactor all my reports into a separate service layer, which give me the ability to
call these reports without separately from the ASPX page.
var contentUsage = UsageReportsService.GetContentTypesUsage();
var contentUsageJson = JsonConvert.SerializeObject(contentUsage,
Formatting.Indented)
This means I can call GetContentTypesUsage and retrieve a list of objects, which can be
passed to Json.Net for serialization into JSON. I’ve also chosen to include the
Formatting.Indented, this will increase the readability but at expense of size.
Compressing JSON files
While JSON is a more efficient than XML bu it will still benefit from compression. Additional
it will act as a container for multiple files. Again I’ve chosen to use the same compression
library as EPiServer, in this case DotNetZip.
PM> Install-Package DotNetZip -Version 1.9.1.8
DotNetZip allows you to directly add content, with the AddEntry method, allowing us to avoid
the creation a temporary file.
ZipFile loanZip = new ZipFile();
loanZip.AddEntry("content-usage-report.json", contentUsage);
It’s also possible to combine previous steps into one, this is the preferred approach as we’re
no longer creating unnecessary objects.
loanZip.AddEntry("content-usage-report.json",
JsonConvert.SerializeObject(contentUsage,
Formatting.Indented),
Encoding.UTF8);
Zip Content Data
Before we can save our file we need to create a new MediaData object, the base class for
any file type stored inside EPiServer. However, it’s our responsibility to create new class for
each file type we wish to store.
[ContentType(GUID = "{1BDDB51F-83AA-4D4B-8664-E40AE58DF2C6}")]
[MediaDescriptor(ExtensionString = ".zip")]
public class ZippedFile : MediaData
{
public virtual string Description { get; set; }
}
The instance of ZippedFile class we’ve created is used an associate with our physical zip file
and can also contain metadata.
var report = contentRepository.GetDefault<ZippedFile>(assetRoot);
report.Name = "content-usage-report.json";
report.Description = "A zipped collection of usage reports";
This approach is similar to that used to store Pages and Blocks and provides a useful
abstraction over the under lying technology.
Save the Zip
Now we have the content reference we can write our zip file to it. This is done by creating a
BLOB or Binary Large Object. The blob can then be passes to our zip library via a stream.
The advantage of using BLOB’s is we’re no longer tied to a file system. We could for instance
use Microsoft Azure or Amazon S3 Storage.
var blob = blobFactory.CreateBlob(report.BinaryDataContainer, ".zip");
var stream = blob.OpenWrite();
loanZip.Save(stream);
The final step is to associate the saved Blob with our zip content and then save publish.
Finally, I’m return a message to say the reports has been created and included a URL.
newReport.BinaryData = blob;
var reference = contentRepository.Save(newReport, SaveAction.Publish);
return $"Report Completed <a
href='{urlResolver.GetUrl(reference)}'>Usage Report</a>";
My finial code does differ slightly, for instance I’ve introduced some feature, like name the
report by date and replace previous versions. However these changes don’t alter anything
fundamental, but fill free to check out my code at bit.ly/1PiwIIi
Update Nuspec
The next setup is add the additional dependencies, into the package.nuspec, for JSON.Net
and DotNetZip.
<dependencies>
<group targetFramework="net40
<dependency id="Newtonsoft.Json" version="[6.0.1,8)" />
<dependency id="DotNetZip" version="[1.9.1.8, 2)"/>
<dependency id="log4net" version="1.2.10" />
<dependency id="EPiServer.CMS.Core" version="[7.6,9)" />
</group>
</dependencies>
While this step isn’t strictly necessary as we know the EPiServer use these packages, it’s
good practise to included them. As it’s possible that in future release they may be replaced.
Update this package, is a simple as it’s versioned, however it’s vital to check against the
different version of EPiServer. As major release will introduce breaking changes.
Run Job Manually
Currently I’m running version 8, but compiling against version 7.6, so this is a real test. So
all I need to do is run this Job it manual. This is possible via the admin screen.
Unfortunately, I’m seeing a error. Which after some research I’ve found is due to changes
to the IContentRepository in version 8. The change was to replace the ILanguageSelector
with a CultureInfo as the methods for selecting the preferred language branch.
Fix Error
The solution is simple to release multiple packages targeting at the different versions of
EPiServer. First I’ll create a new branch for each version I require.
Then update the EPiServer to packge, whilst not forgetting to update the nuspec as well.
PM> Update-Package EPiServer.CMS.UI.Core -Version 8.0.0
Conclusion
Scheduled Jobs are the first resort for any long running or repeating tasks. With full access
to EPiServer like page, blocks and files. Alternatively, you can use execute other services
like email or even micro services. Finally, you have fine grain control over when this Job
executes from seconds to years.
Next I’ll be bringing this series of entries to a close buy creating something useful with the
JSON.
Additional Resources
http://world.episerver.com/Documentation/Items/Developers-Guide/EPiServer-
CMS/75/Scheduled-jobs/Scheduled-jobs/
http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-
CMS/8/BLOB-providers/BLOB-storage-and-BLOB-providers/
http://tedgustaf.com/blog/2008/8/create-a-scheduled-job-in-episerver/

Contenu connexe

Tendances

Do you know all of Puppet?
Do you know all of Puppet?Do you know all of Puppet?
Do you know all of Puppet?Julien Pivotto
 
Performance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-MechanizePerformance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-Mechanizecoreygoldberg
 
Groovy example in mule
Groovy example in muleGroovy example in mule
Groovy example in muleMohammed246
 
Drupal 7 Deployment Using Apache Ant. Dmitriy Svetlichniy.
Drupal 7 Deployment Using Apache Ant. Dmitriy Svetlichniy.Drupal 7 Deployment Using Apache Ant. Dmitriy Svetlichniy.
Drupal 7 Deployment Using Apache Ant. Dmitriy Svetlichniy.DrupalCampDN
 
Manage Windows Like Linux via SSH using Ansible
Manage Windows Like Linux via SSH using AnsibleManage Windows Like Linux via SSH using Ansible
Manage Windows Like Linux via SSH using AnsibleOmpragash Viswanathan
 
Build service with_docker_in_90mins
Build service with_docker_in_90minsBuild service with_docker_in_90mins
Build service with_docker_in_90minsLarry Cai
 
CloudOps CloudStack Days, Austin April 2015
CloudOps CloudStack Days, Austin April 2015CloudOps CloudStack Days, Austin April 2015
CloudOps CloudStack Days, Austin April 2015CloudOps2005
 
Implementation of a state machine for a longrunning background task in androi...
Implementation of a state machine for a longrunning background task in androi...Implementation of a state machine for a longrunning background task in androi...
Implementation of a state machine for a longrunning background task in androi...Somenath Mukhopadhyay
 
Unit 59 diary
Unit 59 diaryUnit 59 diary
Unit 59 diaryinwill12
 
RDSDataSource: Мастер-класс по Dip
RDSDataSource: Мастер-класс по DipRDSDataSource: Мастер-класс по Dip
RDSDataSource: Мастер-класс по DipRAMBLER&Co
 
Inithub.org presentation
Inithub.org presentationInithub.org presentation
Inithub.org presentationAaron Welch
 
Big query - Command line tools and Tips - (MOSG)
Big query - Command line tools and Tips - (MOSG)Big query - Command line tools and Tips - (MOSG)
Big query - Command line tools and Tips - (MOSG)Soshi Nemoto
 
How to build your own OpenStack distro using Puppet OpenStack
How to build your own OpenStack distro using Puppet OpenStackHow to build your own OpenStack distro using Puppet OpenStack
How to build your own OpenStack distro using Puppet OpenStackOpenStack
 
Forget MAMP and WAMP, Use Virtual Box to Have a Real Ubuntu Server
Forget MAMP and WAMP, Use Virtual Box to Have a Real Ubuntu ServerForget MAMP and WAMP, Use Virtual Box to Have a Real Ubuntu Server
Forget MAMP and WAMP, Use Virtual Box to Have a Real Ubuntu Serveraaroncouch
 

Tendances (20)

Mule esb db_2
Mule esb db_2Mule esb db_2
Mule esb db_2
 
Mule esb db_1
Mule esb db_1Mule esb db_1
Mule esb db_1
 
Authoring CPAN modules
Authoring CPAN modulesAuthoring CPAN modules
Authoring CPAN modules
 
Do you know all of Puppet?
Do you know all of Puppet?Do you know all of Puppet?
Do you know all of Puppet?
 
Performance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-MechanizePerformance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-Mechanize
 
Groovy example in mule
Groovy example in muleGroovy example in mule
Groovy example in mule
 
Drupal 7 Deployment Using Apache Ant. Dmitriy Svetlichniy.
Drupal 7 Deployment Using Apache Ant. Dmitriy Svetlichniy.Drupal 7 Deployment Using Apache Ant. Dmitriy Svetlichniy.
Drupal 7 Deployment Using Apache Ant. Dmitriy Svetlichniy.
 
Manage Windows Like Linux via SSH using Ansible
Manage Windows Like Linux via SSH using AnsibleManage Windows Like Linux via SSH using Ansible
Manage Windows Like Linux via SSH using Ansible
 
Process file one after another
Process file one after anotherProcess file one after another
Process file one after another
 
Build service with_docker_in_90mins
Build service with_docker_in_90minsBuild service with_docker_in_90mins
Build service with_docker_in_90mins
 
CloudOps CloudStack Days, Austin April 2015
CloudOps CloudStack Days, Austin April 2015CloudOps CloudStack Days, Austin April 2015
CloudOps CloudStack Days, Austin April 2015
 
Implementation of a state machine for a longrunning background task in androi...
Implementation of a state machine for a longrunning background task in androi...Implementation of a state machine for a longrunning background task in androi...
Implementation of a state machine for a longrunning background task in androi...
 
CloudInit Introduction
CloudInit IntroductionCloudInit Introduction
CloudInit Introduction
 
Unit 59 diary
Unit 59 diaryUnit 59 diary
Unit 59 diary
 
Fabric: A Capistrano Alternative
Fabric:  A Capistrano AlternativeFabric:  A Capistrano Alternative
Fabric: A Capistrano Alternative
 
RDSDataSource: Мастер-класс по Dip
RDSDataSource: Мастер-класс по DipRDSDataSource: Мастер-класс по Dip
RDSDataSource: Мастер-класс по Dip
 
Inithub.org presentation
Inithub.org presentationInithub.org presentation
Inithub.org presentation
 
Big query - Command line tools and Tips - (MOSG)
Big query - Command line tools and Tips - (MOSG)Big query - Command line tools and Tips - (MOSG)
Big query - Command line tools and Tips - (MOSG)
 
How to build your own OpenStack distro using Puppet OpenStack
How to build your own OpenStack distro using Puppet OpenStackHow to build your own OpenStack distro using Puppet OpenStack
How to build your own OpenStack distro using Puppet OpenStack
 
Forget MAMP and WAMP, Use Virtual Box to Have a Real Ubuntu Server
Forget MAMP and WAMP, Use Virtual Box to Have a Real Ubuntu ServerForget MAMP and WAMP, Use Virtual Box to Have a Real Ubuntu Server
Forget MAMP and WAMP, Use Virtual Box to Have a Real Ubuntu Server
 

En vedette

Using the extensibility benefits of EPiServer
Using the extensibility benefits of EPiServerUsing the extensibility benefits of EPiServer
Using the extensibility benefits of EPiServerPatrick van Kleef
 
Secure development in .NET with EPiServer Solita
Secure development in .NET with EPiServer SolitaSecure development in .NET with EPiServer Solita
Secure development in .NET with EPiServer SolitaJoona Immonen
 
Progressive EPiServer Development
Progressive EPiServer DevelopmentProgressive EPiServer Development
Progressive EPiServer Developmentjoelabrahamsson
 

En vedette (7)

Dataquest - Young CIO
Dataquest - Young CIODataquest - Young CIO
Dataquest - Young CIO
 
7
77
7
 
EPiServer 8: First Release Since Ektron Merger
EPiServer 8: First Release Since Ektron MergerEPiServer 8: First Release Since Ektron Merger
EPiServer 8: First Release Since Ektron Merger
 
Using the extensibility benefits of EPiServer
Using the extensibility benefits of EPiServerUsing the extensibility benefits of EPiServer
Using the extensibility benefits of EPiServer
 
Secure development in .NET with EPiServer Solita
Secure development in .NET with EPiServer SolitaSecure development in .NET with EPiServer Solita
Secure development in .NET with EPiServer Solita
 
Progressive EPiServer Development
Progressive EPiServer DevelopmentProgressive EPiServer Development
Progressive EPiServer Development
 
Drupal vs. EPiServer
Drupal vs. EPiServerDrupal vs. EPiServer
Drupal vs. EPiServer
 

Similaire à A guide to EPiServer CMS Scheduled Job

Creating an nuget package for EPiServer
Creating an nuget package for EPiServerCreating an nuget package for EPiServer
Creating an nuget package for EPiServerPaul Graham
 
3 Ways to Get Started with a React App in 2024.pdf
3 Ways to Get Started with a React App in 2024.pdf3 Ways to Get Started with a React App in 2024.pdf
3 Ways to Get Started with a React App in 2024.pdfBOSC Tech Labs
 
You can now use PVS-Studio with Visual Studio absent; just give it the prepro...
You can now use PVS-Studio with Visual Studio absent; just give it the prepro...You can now use PVS-Studio with Visual Studio absent; just give it the prepro...
You can now use PVS-Studio with Visual Studio absent; just give it the prepro...Andrey Karpov
 
Improving build solutions dependency management with webpack
Improving build solutions  dependency management with webpackImproving build solutions  dependency management with webpack
Improving build solutions dependency management with webpackNodeXperts
 
Migraine Drupal - syncing your staging and live sites
Migraine Drupal - syncing your staging and live sitesMigraine Drupal - syncing your staging and live sites
Migraine Drupal - syncing your staging and live sitesdrupalindia
 
RubyMotion Inspect Conference - 2013. (With speaker notes.)
RubyMotion Inspect Conference - 2013. (With speaker notes.)RubyMotion Inspect Conference - 2013. (With speaker notes.)
RubyMotion Inspect Conference - 2013. (With speaker notes.)alloy020
 
Frankenstein's IDE: NetBeans and OSGi
Frankenstein's IDE: NetBeans and OSGiFrankenstein's IDE: NetBeans and OSGi
Frankenstein's IDE: NetBeans and OSGiToni Epple
 
Java EE 02-First Servlet
Java EE 02-First ServletJava EE 02-First Servlet
Java EE 02-First ServletFernando Gil
 
A winning combination: Plone as CMS and your favorite Python web framework as...
A winning combination: Plone as CMS and your favorite Python web framework as...A winning combination: Plone as CMS and your favorite Python web framework as...
A winning combination: Plone as CMS and your favorite Python web framework as...Carlos de la Guardia
 
Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concur...
Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concur...Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concur...
Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concur...Amit Singh
 
Free EJB Tutorial | VirtualNuggets
Free EJB Tutorial | VirtualNuggetsFree EJB Tutorial | VirtualNuggets
Free EJB Tutorial | VirtualNuggetsVirtual Nuggets
 
Feed the Masses
Feed the MassesFeed the Masses
Feed the Massespbugni
 
Angular Optimization Web Performance Meetup
Angular Optimization Web Performance MeetupAngular Optimization Web Performance Meetup
Angular Optimization Web Performance MeetupDavid Barreto
 
Springboot2 postgresql-jpa-hibernate-crud-example with test
Springboot2 postgresql-jpa-hibernate-crud-example with testSpringboot2 postgresql-jpa-hibernate-crud-example with test
Springboot2 postgresql-jpa-hibernate-crud-example with testHyukSun Kwon
 
[Patel] SPFx: An ISV Insight into latest Microsoft's customization model
[Patel] SPFx: An ISV Insight into latest Microsoft's customization model[Patel] SPFx: An ISV Insight into latest Microsoft's customization model
[Patel] SPFx: An ISV Insight into latest Microsoft's customization modelEuropean Collaboration Summit
 
ReactJS software installation
ReactJS software installationReactJS software installation
ReactJS software installationHopeTutors1
 
How to install ReactJS software
How to install ReactJS software How to install ReactJS software
How to install ReactJS software VigneshVijay21
 

Similaire à A guide to EPiServer CMS Scheduled Job (20)

Creating an nuget package for EPiServer
Creating an nuget package for EPiServerCreating an nuget package for EPiServer
Creating an nuget package for EPiServer
 
3 Ways to Get Started with a React App in 2024.pdf
3 Ways to Get Started with a React App in 2024.pdf3 Ways to Get Started with a React App in 2024.pdf
3 Ways to Get Started with a React App in 2024.pdf
 
You can now use PVS-Studio with Visual Studio absent; just give it the prepro...
You can now use PVS-Studio with Visual Studio absent; just give it the prepro...You can now use PVS-Studio with Visual Studio absent; just give it the prepro...
You can now use PVS-Studio with Visual Studio absent; just give it the prepro...
 
Improving build solutions dependency management with webpack
Improving build solutions  dependency management with webpackImproving build solutions  dependency management with webpack
Improving build solutions dependency management with webpack
 
Migraine Drupal - syncing your staging and live sites
Migraine Drupal - syncing your staging and live sitesMigraine Drupal - syncing your staging and live sites
Migraine Drupal - syncing your staging and live sites
 
RubyMotion Inspect Conference - 2013. (With speaker notes.)
RubyMotion Inspect Conference - 2013. (With speaker notes.)RubyMotion Inspect Conference - 2013. (With speaker notes.)
RubyMotion Inspect Conference - 2013. (With speaker notes.)
 
Frankenstein's IDE: NetBeans and OSGi
Frankenstein's IDE: NetBeans and OSGiFrankenstein's IDE: NetBeans and OSGi
Frankenstein's IDE: NetBeans and OSGi
 
Java EE 02-First Servlet
Java EE 02-First ServletJava EE 02-First Servlet
Java EE 02-First Servlet
 
A winning combination: Plone as CMS and your favorite Python web framework as...
A winning combination: Plone as CMS and your favorite Python web framework as...A winning combination: Plone as CMS and your favorite Python web framework as...
A winning combination: Plone as CMS and your favorite Python web framework as...
 
Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concur...
Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concur...Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concur...
Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concur...
 
Free EJB Tutorial | VirtualNuggets
Free EJB Tutorial | VirtualNuggetsFree EJB Tutorial | VirtualNuggets
Free EJB Tutorial | VirtualNuggets
 
Feed the Masses
Feed the MassesFeed the Masses
Feed the Masses
 
BPMS1
BPMS1BPMS1
BPMS1
 
BPMS1
BPMS1BPMS1
BPMS1
 
Angular Optimization Web Performance Meetup
Angular Optimization Web Performance MeetupAngular Optimization Web Performance Meetup
Angular Optimization Web Performance Meetup
 
django
djangodjango
django
 
Springboot2 postgresql-jpa-hibernate-crud-example with test
Springboot2 postgresql-jpa-hibernate-crud-example with testSpringboot2 postgresql-jpa-hibernate-crud-example with test
Springboot2 postgresql-jpa-hibernate-crud-example with test
 
[Patel] SPFx: An ISV Insight into latest Microsoft's customization model
[Patel] SPFx: An ISV Insight into latest Microsoft's customization model[Patel] SPFx: An ISV Insight into latest Microsoft's customization model
[Patel] SPFx: An ISV Insight into latest Microsoft's customization model
 
ReactJS software installation
ReactJS software installationReactJS software installation
ReactJS software installation
 
How to install ReactJS software
How to install ReactJS software How to install ReactJS software
How to install ReactJS software
 

Plus de Paul Graham

Publising a nuget package
Publising a nuget packagePublising a nuget package
Publising a nuget packagePaul Graham
 
EPiServer report generation
EPiServer report generationEPiServer report generation
EPiServer report generationPaul Graham
 
Adding disqus to ghost blog
Adding disqus to ghost blogAdding disqus to ghost blog
Adding disqus to ghost blogPaul Graham
 
Creating EPiServer Usage Reports
Creating EPiServer Usage ReportsCreating EPiServer Usage Reports
Creating EPiServer Usage ReportsPaul Graham
 
Entity framework (EF) 7
Entity framework (EF) 7Entity framework (EF) 7
Entity framework (EF) 7Paul Graham
 
Code syntax highlighting in ghost
Code syntax highlighting in ghostCode syntax highlighting in ghost
Code syntax highlighting in ghostPaul Graham
 

Plus de Paul Graham (7)

Publising a nuget package
Publising a nuget packagePublising a nuget package
Publising a nuget package
 
EPiServer report generation
EPiServer report generationEPiServer report generation
EPiServer report generation
 
Adding disqus to ghost blog
Adding disqus to ghost blogAdding disqus to ghost blog
Adding disqus to ghost blog
 
Creating EPiServer Usage Reports
Creating EPiServer Usage ReportsCreating EPiServer Usage Reports
Creating EPiServer Usage Reports
 
C# 6.0
C# 6.0C# 6.0
C# 6.0
 
Entity framework (EF) 7
Entity framework (EF) 7Entity framework (EF) 7
Entity framework (EF) 7
 
Code syntax highlighting in ghost
Code syntax highlighting in ghostCode syntax highlighting in ghost
Code syntax highlighting in ghost
 

Dernier

VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girladitipandeya
 
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$kojalkojal131
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...singhpriety023
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxellan12
 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...Escorts Call Girls
 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...tanu pandey
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLimonikaupta
 
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663Call Girls Mumbai
 
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.CarlotaBedoya1
 
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024APNIC
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...APNIC
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...SofiyaSharma5
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Delhi Call girls
 
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Standkumarajju5765
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)Damian Radcliffe
 

Dernier (20)

VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
 
@9999965857 🫦 Sexy Desi Call Girls Laxmi Nagar 💓 High Profile Escorts Delhi 🫶
@9999965857 🫦 Sexy Desi Call Girls Laxmi Nagar 💓 High Profile Escorts Delhi 🫶@9999965857 🫦 Sexy Desi Call Girls Laxmi Nagar 💓 High Profile Escorts Delhi 🫶
@9999965857 🫦 Sexy Desi Call Girls Laxmi Nagar 💓 High Profile Escorts Delhi 🫶
 
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
 
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
 
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
 
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
 
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
 
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)
 

A guide to EPiServer CMS Scheduled Job

  • 1. EPiServer Scheduled Jobs In my previous entry on Creating a episerver package I turned some EPiServer reports into a nugget package. Now I want to allow the export this data in a format that can be reused, in this case JSON. To do this I’m going to create a Scheduled Jobs, which are simple classes that inherit from JobBase and are decorated with the ScheduledPlugIn attribute. [ScheduledPlugIn(DisplayName = "Usage Report Collection Job", Description = "A exports of usage reports in Json”. SortIndex = 10001)] public class UsageReportCollectionJob : JobBase { public override string Execute() { Once we’ve create out class we can place code we wish to execute inside the overridden Execute method.
  • 2. Create JSON Before we can create the JSON, we need to install a serialize. However while we do have multiple options, Newtonsoft’s Json.Net is the sensible choice as it’s already used in EPiServer. However, we do need to be careful what version we install. For CMS 7.5 and we can use anything from version 6 but less that version 8. Install-Package Newtonsoft.Json -Version 6.0.1 Previously I refactor all my reports into a separate service layer, which give me the ability to call these reports without separately from the ASPX page. var contentUsage = UsageReportsService.GetContentTypesUsage(); var contentUsageJson = JsonConvert.SerializeObject(contentUsage, Formatting.Indented) This means I can call GetContentTypesUsage and retrieve a list of objects, which can be passed to Json.Net for serialization into JSON. I’ve also chosen to include the Formatting.Indented, this will increase the readability but at expense of size.
  • 3. Compressing JSON files While JSON is a more efficient than XML bu it will still benefit from compression. Additional it will act as a container for multiple files. Again I’ve chosen to use the same compression library as EPiServer, in this case DotNetZip. PM> Install-Package DotNetZip -Version 1.9.1.8 DotNetZip allows you to directly add content, with the AddEntry method, allowing us to avoid the creation a temporary file. ZipFile loanZip = new ZipFile(); loanZip.AddEntry("content-usage-report.json", contentUsage); It’s also possible to combine previous steps into one, this is the preferred approach as we’re no longer creating unnecessary objects. loanZip.AddEntry("content-usage-report.json", JsonConvert.SerializeObject(contentUsage, Formatting.Indented), Encoding.UTF8);
  • 4. Zip Content Data Before we can save our file we need to create a new MediaData object, the base class for any file type stored inside EPiServer. However, it’s our responsibility to create new class for each file type we wish to store. [ContentType(GUID = "{1BDDB51F-83AA-4D4B-8664-E40AE58DF2C6}")] [MediaDescriptor(ExtensionString = ".zip")] public class ZippedFile : MediaData { public virtual string Description { get; set; } } The instance of ZippedFile class we’ve created is used an associate with our physical zip file and can also contain metadata. var report = contentRepository.GetDefault<ZippedFile>(assetRoot); report.Name = "content-usage-report.json"; report.Description = "A zipped collection of usage reports"; This approach is similar to that used to store Pages and Blocks and provides a useful abstraction over the under lying technology.
  • 5. Save the Zip Now we have the content reference we can write our zip file to it. This is done by creating a BLOB or Binary Large Object. The blob can then be passes to our zip library via a stream. The advantage of using BLOB’s is we’re no longer tied to a file system. We could for instance use Microsoft Azure or Amazon S3 Storage. var blob = blobFactory.CreateBlob(report.BinaryDataContainer, ".zip"); var stream = blob.OpenWrite(); loanZip.Save(stream); The final step is to associate the saved Blob with our zip content and then save publish. Finally, I’m return a message to say the reports has been created and included a URL. newReport.BinaryData = blob; var reference = contentRepository.Save(newReport, SaveAction.Publish); return $"Report Completed <a href='{urlResolver.GetUrl(reference)}'>Usage Report</a>"; My finial code does differ slightly, for instance I’ve introduced some feature, like name the report by date and replace previous versions. However these changes don’t alter anything fundamental, but fill free to check out my code at bit.ly/1PiwIIi
  • 6. Update Nuspec The next setup is add the additional dependencies, into the package.nuspec, for JSON.Net and DotNetZip. <dependencies> <group targetFramework="net40 <dependency id="Newtonsoft.Json" version="[6.0.1,8)" /> <dependency id="DotNetZip" version="[1.9.1.8, 2)"/> <dependency id="log4net" version="1.2.10" /> <dependency id="EPiServer.CMS.Core" version="[7.6,9)" /> </group> </dependencies> While this step isn’t strictly necessary as we know the EPiServer use these packages, it’s good practise to included them. As it’s possible that in future release they may be replaced. Update this package, is a simple as it’s versioned, however it’s vital to check against the different version of EPiServer. As major release will introduce breaking changes.
  • 7. Run Job Manually Currently I’m running version 8, but compiling against version 7.6, so this is a real test. So all I need to do is run this Job it manual. This is possible via the admin screen. Unfortunately, I’m seeing a error. Which after some research I’ve found is due to changes to the IContentRepository in version 8. The change was to replace the ILanguageSelector with a CultureInfo as the methods for selecting the preferred language branch.
  • 8. Fix Error The solution is simple to release multiple packages targeting at the different versions of EPiServer. First I’ll create a new branch for each version I require. Then update the EPiServer to packge, whilst not forgetting to update the nuspec as well. PM> Update-Package EPiServer.CMS.UI.Core -Version 8.0.0
  • 9. Conclusion Scheduled Jobs are the first resort for any long running or repeating tasks. With full access to EPiServer like page, blocks and files. Alternatively, you can use execute other services like email or even micro services. Finally, you have fine grain control over when this Job executes from seconds to years. Next I’ll be bringing this series of entries to a close buy creating something useful with the JSON. Additional Resources http://world.episerver.com/Documentation/Items/Developers-Guide/EPiServer- CMS/75/Scheduled-jobs/Scheduled-jobs/ http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer- CMS/8/BLOB-providers/BLOB-storage-and-BLOB-providers/ http://tedgustaf.com/blog/2008/8/create-a-scheduled-job-in-episerver/