private static ContentGenRecipes GetContentRecipes(string sContentUniqueId, string sContentHashCode) { string sRecipesJson = ContentGenJob.ReadContentRecipesJson(sContentUniqueId, sContentHashCode); if (sRecipesJson != null) { return(ContentGenRecipes.FromJson(sRecipesJson)); } return(null); }
public void GenerateContentReq(string sContentUniqueId, string sContentGenRecipesJson) { lock (quartzScheduler) { // Create a ContentGenJob per Content if none has existed if (null == quartzScheduler.GetJobDetail( sContentUniqueId, ContentGenConstants.ContentGenGroupName)) { // Create a durable ContentGenJob and add to the scheduler JobDetail oJob = new JobDetail( sContentUniqueId, ContentGenConstants.ContentGenGroupName, typeof(ContentGenJob), false, true, false); oJob.JobDataMap[ContentGenJobDataMapConstants.OverallCompletion] = "0%"; quartzScheduler.AddJob(oJob, true); } // Create and initialize the trigger for the specific job request string sTriggerName = sContentUniqueId + " (" + quartzScheduler.GetTriggersOfJob( sContentUniqueId, ContentGenConstants.ContentGenGroupName).Count + ")"; Trigger oTrigger = new SimpleTrigger( sTriggerName, ContentGenConstants.ContentGenGroupName, // Compute a time that is on the next round minute TriggerUtils.GetNextGivenSecondDate(DateTime.UtcNow, 5)); // #################################################################### oTrigger.MisfireInstruction = MisfireInstruction.SimpleTrigger.FireNow; // #################################################################### oTrigger.JobName = sContentUniqueId; oTrigger.JobGroup = ContentGenConstants.ContentGenGroupName; ContentGenRecipes oJson = ContentGenRecipes.FromJson(sContentGenRecipesJson); oTrigger.JobDataMap[GeneralJobDataMapConstants.ContentUniqueId] = sContentUniqueId; oTrigger.JobDataMap[ContentGenJobDataMapConstants.ContentRecipesJson] = ContentGenRecipes.GetJson(oJson); quartzScheduler.ScheduleJob(oTrigger); } }
public void Execute(JobExecutionContext context) { string sContentHashCode = ""; ContentGenRecipes oContentRecipes; JobDataMap oJobDataMap = context.JobDetail.JobDataMap; string sContentUniqueId = (string)context.MergedJobDataMap[GeneralJobDataMapConstants.ContentUniqueId]; string sContentRecipesJson = (string)context.MergedJobDataMap[ContentGenJobDataMapConstants.ContentRecipesJson]; #region Content (Metafiles / Torrents) Generating (support for interruption) try { //============================================================================= log.InfoFormat(AppResource.StartJobExecution, typeof(ContentGenJob).Name); //============================================================================= // Validate the settings & the input data map parameters Check.IsNullOrEmpty(sContentUniqueId, GeneralJobDataMapConstants.ContentUniqueId); Check.IsNullOrEmpty(sContentRecipesJson, ContentGenJobDataMapConstants.ContentRecipesJson); // Check the existence of the content versioning file CheckAndCreateContentVersionFile(sContentUniqueId); // Deserialize Content Recipes from the input Json oContentRecipes = ContentGenRecipes.FromJson(sContentRecipesJson); if (oContentRecipes.ContentHashCode == null || oContentRecipes.ContentHashCode == "") { // Do the torrent generating process oJobDataMap[ContentGenJobDataMapConstants.OverallCompletion] = "0%"; ProcessTorrentGen( sContentUniqueId, oContentRecipes, (o, ev) => { // Update the overall completion rate of the job oJobDataMap[ContentGenJobDataMapConstants.OverallCompletion] = ev.OverallCompletion.ToString("#0.##\\%"); }, out sContentHashCode); } else { // Skip the torrent generating process oJobDataMap[ContentGenJobDataMapConstants.OverallCompletion] = "100%"; sContentHashCode = oContentRecipes.ContentHashCode; } // Update the content hash code to the job data map oJobDataMap[GeneralJobDataMapConstants.ContentHashCode] = sContentHashCode; //============================================================================= log.InfoFormat(AppResource.TaskExecutionDone, AppResource.MetafileGenTaskName); //============================================================================= } catch (Exception oEx) { Rollback(sContentUniqueId, sContentHashCode); //=================================================================================================== log.ErrorFormat(AppResource.JobExecutionFailed, oEx, typeof(ContentGenJob).Name, oEx.Message); //=================================================================================================== return; } #endregion #region Downloader Generating // The most brutal way to make sure of the job be executed synchronouly try { // Validate the settings & the input data map parameters Check.IsNullOrEmpty(sContentHashCode, GeneralJobDataMapConstants.ContentHashCode); lock (sigResUpdateLock) // To protect the global memory used in the ResourceLib { // Generate the downloader accordingly ProcessDownloaderGen(oContentRecipes, sContentUniqueId, sContentHashCode); } // Save the Content Recipes Json when downloader generating successfully Uri uri = new Uri(oContentRecipes.ContentSourceUrl); oContentRecipes.ContentFileName = Path.GetFileName(uri.LocalPath); // Get the file name oContentRecipes.ContentHashCode = sContentHashCode; oContentRecipes.CreateDateTime = DateTime.Now; SaveContentRecipesJson( sContentUniqueId, sContentHashCode, ContentGenRecipes.GetJson(oContentRecipes)); // Update the history file when downloader generating successfully AppendHistoryFile(ContentRecipesPropHistory.DownloaderDisplayName, sContentUniqueId, oContentRecipes.DownloaderDisplayName); AppendHistoryFile(ContentRecipesPropHistory.DownloaderHomeUrl, sContentUniqueId, oContentRecipes.DownloaderHomeUrl); AppendHistoryFile(ContentRecipesPropHistory.GAProfileId, sContentUniqueId, oContentRecipes.GAProfileId); AppendHistoryFile(ContentRecipesPropHistory.OnlineFaqUrl, sContentUniqueId, oContentRecipes.OnlineFaqUrl); AppendHistoryFile(ContentRecipesPropHistory.PromoEventId, sContentUniqueId, oContentRecipes.PromotionEventID); AppendHistoryFile(ContentRecipesPropHistory.PromoEventServerUrl, sContentUniqueId, oContentRecipes.PromotionEventServerUrl); //============================================================================= log.InfoFormat(AppResource.TaskExecutionDone, AppResource.DownloaderGenTaskName); //============================================================================= } catch (Exception oEx) { Rollback(sContentUniqueId, sContentHashCode); //=================================================================================================== log.ErrorFormat(AppResource.JobExecutionFailed, oEx, typeof(ContentGenJob).Name, oEx.Message); //=================================================================================================== return; } #endregion #region Content Deployment if specified // Do the content deployment if specified if (oContentRecipes.AutoDeploy) { try { // Validate the settings & the input data map parameters Check.IsNullOrEmpty(sContentHashCode, GeneralJobDataMapConstants.ContentHashCode); // The most brutal way to make sure of the job be executed synchronouly lock (sigResUpdateLock) { // Do the content deployment task ContentDeployJob.ProcessContentDeploy(sContentUniqueId, sContentHashCode); } //============================================================================= log.InfoFormat(AppResource.TaskExecutionDone, AppResource.MetafileDeployTaskName); //============================================================================= } catch (Exception oEx) { // Do nothing here so users can re-deploy again without re-generating all the files // And keep on the next task for the aforementioned reason. //=================================================================================================== log.ErrorFormat(AppResource.JobExecutionFailed, oEx, typeof(ContentGenJob).Name, oEx.Message); //=================================================================================================== } } #endregion #region Update Content Version File try { // Update the content versioning file in the very end of the job // to maintain the consistence as possible AppendContentVersionFile(sContentUniqueId, sContentHashCode); //============================================================================= log.InfoFormat(AppResource.EndJobExecution, typeof(ContentGenJob).Name); //============================================================================= } catch (Exception oEx) { // Clear up all the generated files & the deployed files since it should be a sever error! if (oContentRecipes.AutoDeploy) { ContentDeployJob.Rollback(sContentHashCode); } Rollback(sContentUniqueId, sContentHashCode); //=================================================================================================== log.ErrorFormat(AppResource.JobExecutionFailed, oEx, typeof(ContentGenJob).Name, oEx.Message); //=================================================================================================== return; } #endregion }