private string saveTemplate(string templateName, string templateAlias, string templateContents, int templateID, int masterTemplateID) { cms.businesslogic.template.Template _template = new global::umbraco.cms.businesslogic.template.Template(templateID); string retVal = "false"; if (_template != null) { _template.Text = templateName; _template.Alias = templateAlias; _template.MasterTemplate = masterTemplateID; _template.Design = templateContents; retVal = "true"; // Clear cache in rutime if (UmbracoSettings.UseDistributedCalls) { cache.dispatcher.Refresh( new Guid("dd12b6a0-14b9-46e8-8800-c154f74047c8"), _template.Id); } else { template.ClearCachedTemplate(_template.Id); } } else { return("false"); } return(retVal); }
static void Template_AfterDelete(global::umbraco.cms.businesslogic.template.Template sender, global::umbraco.cms.businesslogic.DeleteEventArgs e) { if (!uSync.EventsPaused) { LogHelper.Info <uSync>("Template after delete"); XmlDoc.ArchiveFile("Template", XmlDoc.ScrubFile(sender.Alias)); } }
static void Template_AfterSave(global::umbraco.cms.businesslogic.template.Template sender, global::umbraco.cms.businesslogic.SaveEventArgs e) { if (!uSync.EventsPaused) { LogHelper.Info <uSync>("Template After Save"); SaveToDisk(ApplicationContext.Current.Services.FileService.GetTemplate(sender.Alias)); } }
private static void Template_AfterSave(global::umbraco.cms.businesslogic.template.Template sender, global::umbraco.cms.businesslogic.SaveEventArgs e) { LogHelper.Info <SyncTemplates>("Template Saved"); var template = ApplicationContext.Current.Services.FileService.GetTemplate(sender.Alias); if (template != null) { SaveToDisk((Template)template); } }
private static int GetMasterId(ITemplate item) { // go old school to the get the master id. global::umbraco.cms.businesslogic.template.Template t = new global::umbraco.cms.businesslogic.template.Template(item.Id); if (t.MasterTemplate > 0) { return(t.MasterTemplate); } return(-1); }
private static string GetDocPath(global::umbraco.cms.businesslogic.template.Template item) { string path = ""; if (item != null) { if (item.MasterTemplate > 0) { path = GetDocPath(new global::umbraco.cms.businesslogic.template.Template(item.MasterTemplate)); } path = string.Format("{0}\\{1}", path, uSyncIO.ScrubFileName(item.Alias)); } return(path); }
private static void Template_AfterDelete(global::umbraco.cms.businesslogic.template.Template sender, global::umbraco.cms.businesslogic.DeleteEventArgs e) { LogHelper.Info <SyncTemplates>("Template Deleted"); // to do - because i don't think we can swap old to new // here - after all it's just been deleted.. }
/// <summary> /// replacing packagingService, template import. /// </summary> /// <param name="node"></param> /// <returns></returns> private static void ImportTemplate(XElement node) { if (node.Name.LocalName != "Template") { LogHelper.Warn <SyncTemplate>("Template file not properly formatted"); return; } var name = node.Element("Name") != null?node.Element("Name").Value : string.Empty; var alias = node.Element("Alias") != null?node.Element("Alias").Value : string.Empty; var master = node.Element("Master") != null?node.Element("Master").Value : string.Empty; var design = node.Element("Design") != null?node.Element("Design").Value : string.Empty; LogHelper.Debug <SyncTemplate>("Template Values: {0}, {1}, {2}", () => name, () => alias, () => master); var masterpage = MasterpagePath(alias); var view = ViewPath(alias); LogHelper.Debug <SyncTemplate>("Looking for existing template file: {0} and {1}", () => masterpage, () => view); ITemplate template = null; if (!global::System.IO.File.Exists(masterpage) && !global::System.IO.File.Exists(view)) { LogHelper.Debug <SyncTemplate>("No Template files calling Package Service to Import {0}", () => alias); // no master page or view - use import to create the template var packagingService = ApplicationContext.Current.Services.PackagingService; var templates = packagingService.ImportTemplates(node); template = templates.FirstOrDefault(); } else { template = ApplicationContext.Current.Services.FileService.GetTemplate(alias); if (template == null) { LogHelper.Debug <SyncTemplate>("New Template but files exist {0}", () => alias); var isMasterPage = IsMasterPageSyntax(design); var path = isMasterPage ? MasterpagePath(alias) : ViewPath(alias); template = new Template(path, name, alias); if (template != null) { // need to load the file into template.content, so the save doesn't // destroy it. LogHelper.Debug <SyncTemplate>("Importing content from disk, to preserve changes: {0}", () => path); var content = global::System.IO.File.ReadAllText(path); template.Content = content; SetMaster(template, master); ApplicationContext.Current.Services.FileService.SaveTemplate(template); } else { LogHelper.Warn <SyncTemplate>("Error creating template (for existing files), {0}", () => alias); } } else { LogHelper.Debug <SyncTemplate>("Existing Template updating stuff.. {0}", () => alias); // TODO - renames - but they can't happen in the import have to be part of file ops. SetMaster(template, master); ApplicationContext.Current.Services.FileService.SaveTemplate(template); if (template.Name != name) { // can't change things, because ITemplate is mainly readonly, need to use old api // to do the rename var t = new global::umbraco.cms.businesslogic.template.Template(template.Id); t.Text = name; t.Save(); } } } }
private string saveTemplate(string templateName, string templateAlias, string templateContents, int templateID, int masterTemplateID) { cms.businesslogic.template.Template _template = new global::umbraco.cms.businesslogic.template.Template(templateID); string retVal = "false"; if (_template != null) { _template.Text = templateName; _template.Alias = templateAlias; _template.MasterTemplate = masterTemplateID; _template.Design = templateContents; retVal = "true"; // Clear cache in rutime if (UmbracoSettings.UseDistributedCalls) cache.dispatcher.Refresh( new Guid("dd12b6a0-14b9-46e8-8800-c154f74047c8"), _template.Id); else template.ClearCachedTemplate(_template.Id); } else return "false"; return retVal; }