public EventResult Receive(IEventContext context) { EventResult eventResult = new EventResult(); if (context is ContentEventContext && HttpContext.Current != null) { try { ContentEventContext contentEventContext = (ContentEventContext)context; var content = contentEventContext.Content; var result = (contentEventContext.ContentAction & ContentAction.PreAdd) == ContentAction.PreAdd || (contentEventContext.ContentAction & ContentAction.PreUpdate) == ContentAction.PreUpdate; if (result) { var cropField = HttpContext.Current.Request.Form["Kooboo-Image-Crop-Field"]; var toRemove = new List <string>(); if (!string.IsNullOrEmpty(cropField)) { var fields = cropField.Split(','); foreach (var field in fields) { var imgParam = JsonHelper.Deserialize <ImageParam>(HttpContext.Current.Request.Form[field + "_param"].ToString()); if (imgParam != null) { string sourceFilePath = HttpContext.Current.Server.MapPath(imgParam.Url); toRemove.Add(sourceFilePath); var contentPath = new TextContentPath(content); var vPath = Kooboo.Web.Url.UrlUtility.Combine(contentPath.VirtualPath, "kooboo-crop-" + Path.GetFileName(imgParam.Url)); Kooboo.IO.IOUtility.EnsureDirectoryExists(contentPath.PhysicalPath); var phyPath = HttpContext.Current.Server.MapPath(vPath); Kooboo.Drawing.ImageTools.CropImage(sourceFilePath, phyPath, imgParam.X, imgParam.Y, imgParam.Width, imgParam.Height); content[field] = vPath; } } } foreach (var r in toRemove) { if (File.Exists(r)) { File.Delete(r); } } } } catch (Exception e) { eventResult.Exception = e; } } return(eventResult); }
public ContentVersionPath(TextContent content) { var contentPath = new TextContentPath(content); var basePath = Kooboo.CMS.Common.Runtime.EngineContext.Current.Resolve <Kooboo.CMS.Common.IBaseDir>(); var versionPath = Path.Combine(basePath.Cms_DataPhysicalPath, VersionPathName); this.PhysicalPath = contentPath.PhysicalPath.Replace(basePath.Cms_DataPhysicalPath, versionPath); }
public ContentVersionPath(TextContent content) { var contentPath = new TextContentPath(content); var basePath = Path.Combine(Kooboo.Settings.BaseDirectory, RepositoryPath.Cms_Data); var versionPath = Path.Combine(basePath, VersionPathName); this.PhysicalPath = contentPath.PhysicalPath.Replace(basePath, versionPath); // this.VirtualPath = UrlUtility.Combine(contentPath.VirtualPath, VersionPathName); }
public string Save(TextContent content, ContentFile file) { var extension = Path.GetExtension(file.FileName); var fileName = Kooboo.Extensions.StringExtensions.NormalizeUrl(Path.GetFileNameWithoutExtension(file.FileName)) + extension; TextContentPath contentPath = new TextContentPath(content); string filePath = Path.Combine(contentPath.PhysicalPath, fileName); file.Stream.SaveAs(filePath, true); return(UrlUtility.Combine(contentPath.VirtualPath, fileName)); }
public void DeleteFiles(TextContent content) { var contentPath = new TextContentPath(content); try { if (Directory.Exists(contentPath.PhysicalPath)) { IOUtility.DeleteDirectory(contentPath.PhysicalPath, true); } } catch (Exception e) { Kooboo.HealthMonitoring.Log.LogException(e); } }