コード例 #1
0
        private void MetaFileOnBeforeSave(object sender, ObjectEventArgs e)
        {
            if (e.Object == null)
            {
                return;
            }

            if (e.Object is MetaFileInfo metaFile)
            {
                var optimizer = new TinyPngImageOptimizer(SiteContext.CurrentSiteName);
                optimizer.Optimize(metaFile);
            }
        }
コード例 #2
0
        private void AttachmentOnBeforeSave(object sender, ObjectEventArgs e)
        {
            if (e.Object == null)
            {
                return;
            }

            // If workflow enabled
            if (e.Object is AttachmentHistoryInfo attachmentVersion)
            {
                var latestAttachmentVersion = AttachmentHistoryInfoProvider.GetAttachmentHistories()
                                              .WhereEquals("AttachmentGUID", attachmentVersion.AttachmentGUID)
                                              .OrderByDescending("AttachmentLastModified")
                                              .TopN(1)
                                              .FirstOrDefault();

                if (latestAttachmentVersion == null ||
                    latestAttachmentVersion.AttachmentSize != attachmentVersion.AttachmentSize)
                {
                    var optimizer = new TinyPngImageOptimizer(SiteContext.CurrentSiteName);
                    optimizer.Optimize(attachmentVersion);
                }
            }

            // If workflow disabled
            if (e.Object is AttachmentInfo attachment)
            {
                var document = DocumentHelper.GetDocument(attachment.AttachmentDocumentID, new TreeProvider());

                if (document.WorkflowStep == null)
                {
                    var currentAttachment = AttachmentInfoProvider.GetAttachmentInfo(attachment.AttachmentID, true);

                    if (currentAttachment == null || currentAttachment.AttachmentSize != attachment.AttachmentSize)
                    {
                        var optimizer = new TinyPngImageOptimizer(SiteContext.CurrentSiteName);
                        optimizer.Optimize(attachment);
                    }
                }
            }
        }