protected override BatchJobExecutionResult OnExecute(UpdateUrlBatchJob batchJob) { using (new NotificationDisabler()) { var webpage = _session.Get <Webpage>(batchJob.WebpageId); if (webpage == null) { return(BatchJobExecutionResult.Failure("Could not find the webpage with id " + batchJob.WebpageId)); } _session.Transact(session => { var urlHistories = webpage.Urls.ToList(); foreach (var webpageUrl in urlHistories) { if (!batchJob.NewUrl.Equals(webpageUrl.UrlSegment, StringComparison.InvariantCultureIgnoreCase)) { continue; } webpage.Urls.Remove(webpageUrl); session.Delete(webpageUrl); } webpage.UrlSegment = batchJob.NewUrl; session.Update(webpage); }); return(BatchJobExecutionResult.Success()); } }
public async Task <bool> Execute(BatchRun batchRun) { Stopwatch stopWatch = Stopwatch.StartNew(); NextJobToRunResult result = _getNextJobToRun.Get(batchRun); BatchRunResult runResult = result.Result; if (runResult == null) { if (result.Complete) { _setRunStatus.Complete(batchRun); } if (result.Paused) { _setRunStatus.Paused(batchRun); } return(false); } if (runResult.BatchJob == null) { _setBatchJobExecutionStatus.Complete(runResult, BatchJobExecutionResult.Failure("No job associated to result")); } await _runBatchRunResult.Run(runResult, stopWatch); return(true); }
protected override BatchJobExecutionResult OnExecute(CompleteMergeBatchJob batchJob) { using (new NotificationDisabler()) { var webpage = _session.Get <Webpage>(batchJob.WebpageId); if (webpage == null) { return(BatchJobExecutionResult.Failure("Could not find the webpage with id " + batchJob.WebpageId)); } var mergeInto = _session.Get <Webpage>(batchJob.MergedIntoId); if (mergeInto == null) { return(BatchJobExecutionResult.Failure("Could not find the webpage with id " + batchJob.MergedIntoId)); } _session.Transact(session => { ApplyCustomMergeLogic(webpage, mergeInto); var urlSegment = webpage.UrlSegment; session.Delete(webpage); var urlHistory = new UrlHistory { UrlSegment = urlSegment, Webpage = mergeInto, }; mergeInto.Urls.Add(urlHistory); session.Save(urlHistory); }); return(BatchJobExecutionResult.Success()); } }
protected override BatchJobExecutionResult OnExecute(MoveWebpageBatchJob batchJob) { using (new NotificationDisabler()) { var webpage = _session.Get <Webpage>(batchJob.WebpageId); if (webpage == null) { return(BatchJobExecutionResult.Failure("Could not find the webpage with id " + batchJob.WebpageId)); } var parent = batchJob.NewParentId.HasValue ? _session.Get <Webpage>(batchJob.NewParentId) : null; if (batchJob.NewParentId.HasValue && parent == null) { return(BatchJobExecutionResult.Failure("Could not find the parent webpage with id " + batchJob.NewParentId)); } _session.Transact(session => { webpage.Parent = parent; session.Update(webpage); }); return(BatchJobExecutionResult.Success()); } }
protected override BatchJobExecutionResult OnExecute(ImportDocumentBatchJob batchJob) { using (EventContext.Instance.Disable <IOnTransientNotificationPublished>()) using (EventContext.Instance.Disable <IOnPersistentNotificationPublished>()) using (EventContext.Instance.Disable <UpdateIndicesListener>()) using (EventContext.Instance.Disable <UpdateUniversalSearch>()) using (EventContext.Instance.Disable <WebpageUpdatedNotification>()) using (EventContext.Instance.Disable <DocumentAddedNotification>()) using (EventContext.Instance.Disable <MediaCategoryUpdatedNotification>()) { var documentImportDto = batchJob.DocumentImportDto; var webpage = GetWebpageByUrl(documentImportDto.UrlSegment); var isNew = webpage == null; if (isNew) { webpage = (Webpage) Activator.CreateInstance(DocumentMetadataHelper.GetTypeByName(documentImportDto.DocumentType)); } if (!String.IsNullOrEmpty(documentImportDto.ParentUrl)) { var parent = GetWebpageByUrl(documentImportDto.ParentUrl); webpage.Parent = parent; } if (documentImportDto.UrlSegment != null) { webpage.UrlSegment = documentImportDto.UrlSegment; } webpage.Name = documentImportDto.Name; webpage.BodyContent = documentImportDto.BodyContent; webpage.MetaTitle = documentImportDto.MetaTitle; webpage.MetaDescription = documentImportDto.MetaDescription; webpage.MetaKeywords = documentImportDto.MetaKeywords; webpage.RevealInNavigation = documentImportDto.RevealInNavigation; webpage.RequiresSSL = documentImportDto.RequireSSL; webpage.DisplayOrder = documentImportDto.DisplayOrder; webpage.PublishOn = documentImportDto.PublishDate; _updateTagsService.SetTags(documentImportDto, webpage); _updateUrlHistoryService.SetUrlHistory(documentImportDto, webpage); _session.Transact(session => { if (isNew) { session.Save(webpage); } else { session.Update(webpage); } }); return(BatchJobExecutionResult.Success()); } }
public async Task <BatchJobExecutionResult> Run(BatchRunResult runResult, Stopwatch stopWatch = null) { stopWatch = stopWatch ?? Stopwatch.StartNew(); _setBatchJobExecutionStatus.Starting(runResult); BatchJobExecutionResult batchJobExecutionResult = await _batchJobExecutionService.Execute(runResult.BatchJob); runResult.MillisecondsTaken = Convert.ToDecimal(stopWatch.Elapsed.TotalMilliseconds); _setBatchJobExecutionStatus.Complete(runResult, batchJobExecutionResult); return(batchJobExecutionResult); }
protected override BatchJobExecutionResult OnExecute(RebuildUniversalSearchIndex batchJob) { try { _universalSearchIndexManager.ReindexAll(); return(BatchJobExecutionResult.Success()); } catch (Exception exception) { CurrentRequestData.ErrorSignal.Raise(exception); return(BatchJobExecutionResult.Failure(exception.Message)); } }
protected override BatchJobExecutionResult OnExecute(ImportProductBatchJob batchJob) { using (new NotificationDisabler()) { try { _importProductsService.ImportProduct(batchJob.DTO); return(BatchJobExecutionResult.Success()); } catch (Exception exception) { CurrentRequestData.ErrorSignal.Raise(exception); return(BatchJobExecutionResult.Failure(exception.Message)); } } }
protected override BatchJobExecutionResult OnExecute(MigrateFilesBatchJob batchJob) { List <Guid> guids = JsonConvert.DeserializeObject <HashSet <Guid> >(batchJob.Data).ToList(); IList <MediaFile> mediaFiles = _session.QueryOver <MediaFile>().Where(x => x.Guid.IsIn(guids)).List(); foreach (MediaFile mediaFile in mediaFiles) { IFileSystem from = MediaFileExtensions.GetFileSystem(mediaFile.FileUrl, _fileSystems); IFileSystem to = CurrentFileSystem; if (from.GetType() == to.GetType()) { continue; } _session.Transact(session => { // remove resized images (they will be regenerated on the to system) foreach (ResizedImage resizedImage in mediaFile.ResizedImages.ToList()) { // check for resized file having same url as the original - // do not delete from disc yet in that case, or else it will cause an error when copying if (resizedImage.Url != mediaFile.FileUrl) { from.Delete(resizedImage.Url); } mediaFile.ResizedImages.Remove(resizedImage); session.Delete(resizedImage); } string existingUrl = mediaFile.FileUrl; using (System.IO.Stream readStream = @from.GetReadStream(existingUrl)) { mediaFile.FileUrl = to.SaveFile(readStream, GetNewFilePath(mediaFile), mediaFile.ContentType); } from.Delete(existingUrl); session.Update(mediaFile); }); } return(BatchJobExecutionResult.Success()); }
protected override BatchJobExecutionResult OnExecute(RebuildLuceneIndex batchJob) { _indexService.Reindex(batchJob.IndexName); return(BatchJobExecutionResult.Success()); }