public static IRepositoryBuilder UseDocumentPreviewProvider(this IRepositoryBuilder repositoryBuilder, DocumentPreviewProvider previewProvider) { Providers.Instance.PreviewProvider = previewProvider; return(repositoryBuilder); }
public void Finalize(SnTaskResult result) { if (result.Successful || result.Task == null || result.Task.Type.CompareTo("AsposePreviewGenerator") != 0 || string.IsNullOrEmpty(result.Task.TaskData)) { return; } try { var settings = new JsonSerializerSettings { DateFormatHandling = DateFormatHandling.IsoDateFormat }; var serializer = JsonSerializer.Create(settings); using (var jreader = new JsonTextReader(new StringReader(result.Task.TaskData))) { var previewData = serializer.Deserialize(jreader) as JObject; var contentId = previewData["Id"].Value <int>(); using (new SystemAccount()) { DocumentPreviewProvider.SetPreviewStatus(Node.Load <File>(contentId), PreviewStatus.Error); } } } catch (Exception ex) { Logger.WriteException(ex); } }
// ================================================================================= Observer methods protected override void OnNodeCreated(object sender, NodeEventArgs e) { base.OnNodeCreated(sender, e); if (e.SourceNode.CopyInProgress) { return; } DocumentPreviewProvider.StartPreviewGeneration(e.SourceNode, GetPriority(e.SourceNode as File)); }
// ================================================================================= Observer methods protected override void OnNodeCreating(object sender, CancellableNodeEventArgs e) { base.OnNodeCreating(sender, e); if (e.SourceNode.CopyInProgress) { return; } DocumentPreviewProvider.InitializePreviewGeneration(e.SourceNode); }
protected override void OnNodeModified(object sender, NodeEventArgs e) { base.OnNodeModified(sender, e); // check: fire only when the relevant fields had been modified (binary, version, ...) if (!e.ChangedData.Any(d => MONITORED_FIELDS.Contains(d.Name))) { return; } DocumentPreviewProvider.StartPreviewGeneration(e.SourceNode, GetPriority(e.SourceNode as File)); }
public virtual void Finalize(SnTaskResult result) { // not enough information if (result.Task == null || string.IsNullOrEmpty(result.Task.TaskData)) { return; } // the task was executed successfully without an error message if (result.Successful && result.Error == null) { return; } try { if (result.Error != null) { // log the error message and details for admins Logger.WriteError(ContentRepository.EventId.Preview.PreviewGenerationError, "Preview generation error, see the details below.", properties: new Dictionary <string, object> { { "ErrorCode", result.Error.ErrorCode }, { "ErrorType", result.Error.ErrorType }, { "Message", result.Error.Message }, { "Details", result.Error.Details } }); } // deserialize task data to retrieve content info var settings = new JsonSerializerSettings { DateFormatHandling = DateFormatHandling.IsoDateFormat }; var serializer = JsonSerializer.Create(settings); using (var jreader = new JsonTextReader(new IO.StringReader(result.Task.TaskData))) { var previewData = serializer.Deserialize(jreader) as JObject; var contentId = previewData["Id"].Value <int>(); using (new SystemAccount()) { DocumentPreviewProvider.SetPreviewStatus(Node.Load <File>(contentId), PreviewStatus.Error); } } } catch (Exception ex) { Logger.WriteException(ex); } }
protected override void OnNodeModified(object sender, NodeEventArgs e) { base.OnNodeModified(sender, e); // check: fire only when the relevant fields had been modified (binary, version, ...) if (!e.ChangedData.Any(d => MONITORED_FIELDS.Contains(d.Name))) { return; } var versionData = e.ChangedData.FirstOrDefault(d => d.Name.Equals("Version", StringComparison.OrdinalIgnoreCase)); if (versionData != null) { var originalVersion = VersionNumber.Parse(versionData.Original.ToString()); // if the status changed from Locked to not locked, and the version number has been decreesed: undo or checkin if (originalVersion.Status == VersionStatus.Locked && e.SourceNode.Version.Status != VersionStatus.Locked && originalVersion > e.SourceNode.Version && DocumentPreviewProvider.Current.IsContentSupported(e.SourceNode)) { // Undo or Checkin: we will start to delete unnecessary images for the // removed version (w/o waiting for the delete operations to complete). DocumentPreviewProvider.Current.RemovePreviewImagesAsync(e.SourceNode.Id, originalVersion); // This was an UNDO operation, it is unnecessary to start a preview generator process if (string.Compare(NodeOperation.UndoCheckOut, e.SourceNode.NodeOperation, StringComparison.OrdinalIgnoreCase) == 0) { return; } } } DocumentPreviewProvider.StartPreviewGeneration(e.SourceNode, GetPriority(e.SourceNode as File)); }