public override void InstallWidget(WidgetPackage pack) { var pluginRootPath = PluginBase.GetPath <SectionPlug>(); var templates = GetAvailableTemplates(); foreach (var file in pack.Files) { if (templates.Contains(file.FileName)) { continue; } var pathArray = file.FilePath.Replace("\\", "/").Split('/'); file.FilePath = Path.Combine(pluginRootPath, pathArray[pathArray.Length - 2], pathArray[pathArray.Length - 1]); var directory = Path.GetDirectoryName(file.FilePath); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } File.WriteAllBytes(file.FilePath, file.Content); TemplateService.EnsureHasViewImports(file.FilePath, "@using ZKEACMS.SectionWidget", "@using ZKEACMS.SectionWidget.Models", "@using ZKEACMS.SectionWidget.Service"); } pack.Widget = null; var widget = JsonConvert.DeserializeObject <Models.SectionWidget>(JObject.Parse(pack.Content.ToString()).GetValue("Widget").ToString(), new SectionContentJsonConverter()); if (_sectionTemplateService.Count(m => m.TemplateName == widget.Template.TemplateName) == 0) { _sectionTemplateService.Add(widget.Template); } widget.PageID = null; widget.LayoutID = null; widget.ZoneID = null; widget.IsSystem = false; widget.IsTemplate = true; widget.Description = "Install"; if (!widget.Thumbnail.StartsWith("http://", StringComparison.OrdinalIgnoreCase) && !widget.Thumbnail.StartsWith("https://", StringComparison.OrdinalIgnoreCase)) { widget.Thumbnail = Helper.Url.Combine(Loader.PluginFolder, new DirectoryInfo(pluginRootPath).Name, "Thumbnail", Path.GetFileName(widget.Thumbnail)); } AddWidget(widget); }
public virtual object Install(Package package) { var filePackage = package as FilePackage; if (filePackage != null) { if (filePackage.Files != null) { filePackage.Files.ForEach(file => { string filePath = MapPath(file.FilePath); var directory = Path.GetDirectoryName(filePath); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } File.WriteAllBytes(filePath, file.Content); TemplateService.EnsureHasViewImports(filePath); }); } } return(package); }