private void SaveFile(Template template, string originalAlias = null) { string content; var templateOnDisk = template as TemplateOnDisk; if (templateOnDisk != null && templateOnDisk.IsOnDisk) { // if "template on disk" load content from disk content = _viewHelper.GetFileContents(template); } else { // else, create or write template.Content to disk if (DetermineTemplateRenderingEngine(template) == RenderingEngine.Mvc) { content = originalAlias == null ? _viewHelper.CreateView(template, true) : _viewHelper.UpdateViewFile(template, originalAlias); } else { content = originalAlias == null ? _masterPageHelper.CreateMasterPage(template, this, true) : _masterPageHelper.UpdateMasterPageFile(template, originalAlias, this); } } // once content has been set, "template on disk" are not "on disk" anymore template.Content = content; SetVirtualPath(template); }
public void CreateViewThrowExceptionOnNullArgumentsTest() { Action <InvalidOperationException> checkExceptionAction = x => { Assert.IsTrue(x.Message.Contains(ViewHelper.Error_CreateViewMissArguments)); Assert.IsTrue(x.Message.Contains(ViewHelper.HelpLink_CreateViewMissArguments)); }; AssertHelper.AssertThrows <InvalidOperationException>(() => ViewHelper.CreateView(ViewLocator.Default, null), checkExceptionAction); AssertHelper.AssertThrows <InvalidOperationException>(() => ViewHelper.CreateAndInitializeView(viewLocator: ViewLocator.Default, documentType: null, viewModel: null, parameter: null, parentViewModel: null, viewTemplate: null, viewTemplateSelector: null), checkExceptionAction); AssertHelper.AssertThrows <InvalidOperationException>(() => ViewHelper.CreateAndInitializeView(viewLocator: ViewLocator.Default, documentType: null, viewModel: null, parameter: null, parentViewModel: null, documentOwner: null, viewTemplate: null, viewTemplateSelector: null), checkExceptionAction); }
private void SaveFile(Template template, TemplateDto dto, string originalAlias = null) { string content; var templateOnDisk = template as TemplateOnDisk; if (templateOnDisk != null && templateOnDisk.IsOnDisk) { // if "template on disk" load content from disk content = _viewHelper.GetFileContents(template); } else { // else, create or write template.Content to disk if (DetermineTemplateRenderingEngine(template) == RenderingEngine.Mvc) { content = originalAlias == null ? _viewHelper.CreateView(template, true) : _viewHelper.UpdateViewFile(template, originalAlias); } else { content = originalAlias == null ? _masterPageHelper.CreateMasterPage(template, this, true) : _masterPageHelper.UpdateMasterPageFile(template, originalAlias, this); } } // once content has been set, "template on disk" are not "on disk" anymore template.Content = content; SetVirtualPath(template); if (dto.Design == content) { return; } dto.Design = content; Database.Update(dto); // though... we don't care about the db value really??!! }
protected override void PersistNewItem(ITemplate entity) { EnsureValidAlias(entity); //Save to db var template = (Template)entity; template.AddingEntity(); var factory = new TemplateFactory(NodeObjectTypeId); var dto = factory.BuildDto(template); //Create the (base) node data - umbracoNode var nodeDto = dto.NodeDto; nodeDto.Path = "-1," + dto.NodeDto.NodeId; var o = Database.IsNew(nodeDto) ? Convert.ToInt32(Database.Insert(nodeDto)) : Database.Update(nodeDto); //Update with new correct path var parent = Get(template.MasterTemplateId.Value); if (parent != null) { nodeDto.Path = string.Concat(parent.Path, ",", nodeDto.NodeId); } else { nodeDto.Path = "-1," + dto.NodeDto.NodeId; } Database.Update(nodeDto); //Insert template dto dto.NodeId = nodeDto.NodeId; Database.Insert(dto); //Update entity with correct values template.Id = nodeDto.NodeId; //Set Id on entity to ensure an Id is set template.Path = nodeDto.Path; //now do the file work if (DetermineTemplateRenderingEngine(entity) == RenderingEngine.Mvc) { var result = _viewHelper.CreateView(template, true); if (result != entity.Content) { entity.Content = result; //re-persist it... though we don't really care about the templates in the db do we??!! dto.Design = result; Database.Update(dto); } } else { var result = _masterPageHelper.CreateMasterPage(template, this, true); if (result != entity.Content) { entity.Content = result; //re-persist it... though we don't really care about the templates in the db do we??!! dto.Design = result; Database.Update(dto); } } template.ResetDirtyProperties(); // ensure that from now on, content is lazy-loaded if (template.GetFileContent == null) { template.GetFileContent = file => GetFileContent((Template)file, false); } }