public override void WithResolvingModelHost(object modelHost, DefinitionBase model, Type childModelType, Action <object> action) { var folderModelHost = modelHost.WithAssertAndCast <FolderModelHost>("modelHost", value => value.RequireNotNull()); var wikiPageModel = model.WithAssertAndCast <WikiPageDefinition>("model", value => value.RequireNotNull()); var folder = folderModelHost.CurrentLibraryFolder; var targetPage = FindWikiPageItem(folder, wikiPageModel); ModuleFileModelHandler.WithSafeFileOperation(folderModelHost.CurrentLibrary, folder, targetPage.Url, GetWikiPageName(wikiPageModel), Encoding.UTF8.GetBytes(PublishingPageTemplates.RedirectionPageMarkup), false, null, afterFile => { using (var webPartManager = afterFile.GetLimitedWebPartManager(PersonalizationScope.Shared)) { var webpartPageHost = new WebpartPageModelHost { HostFile = afterFile, PageListItem = targetPage, SPLimitedWebPartManager = webPartManager }; action(webpartPageHost); // targetPage.Update(); } }); }
private SPListItem CreateObject(object modelHost, SPFolder folder, MasterPageDefinition definition) { var pageName = GetSafePageFileName(definition); var fileContent = definition.Content; ModuleFileModelHandler.DeployModuleFile(folder, SPUrlUtility.CombineUrl(folder.ServerRelativeUrl, pageName), pageName, fileContent, true, null, null); return(GetCurrentObject(folder, definition)); }
private SPListItem GetOrCreateNewWebPartPage(object modelHost, SPFolder folder, WebPartPageDefinition webpartPageModel) { var targetPage = FindWebPartPage(folder, webpartPageModel); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = targetPage == null ? null : targetPage.File, ObjectType = typeof(SPFile), ObjectDefinition = webpartPageModel, ModelHost = modelHost }); if (targetPage == null || webpartPageModel.NeedOverride) { if (webpartPageModel.NeedOverride) { TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing web part page"); TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "NeedOverride = true. Replacing web part page."); } else { TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new web part page"); } var webPartPageName = GetSafeWebPartPageFileName(webpartPageModel); byte[] fileContent = null; if (!string.IsNullOrEmpty(webpartPageModel.CustomPageLayout)) { fileContent = Encoding.UTF8.GetBytes(webpartPageModel.CustomPageLayout); } else { fileContent = Encoding.UTF8.GetBytes(GetWebPartTemplateContent(webpartPageModel)); } ModuleFileModelHandler.DeployModuleFile(folder, SPUrlUtility.CombineUrl(folder.ServerRelativeUrl, webPartPageName), webPartPageName, fileContent, true, file => { InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = file, ObjectType = typeof(SPFile), ObjectDefinition = webpartPageModel, ModelHost = modelHost }); }, null); targetPage = FindWebPartPage(folder, webpartPageModel); } else { TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing web part page"); TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "NeedOverride = false. Skipping replacing web part page."); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = targetPage == null ? null : targetPage.File, ObjectType = typeof(SPFile), ObjectDefinition = webpartPageModel, ModelHost = modelHost }); targetPage.Update(); } return(targetPage); }
private SPFile GetOrCreateNewWebPartFile(object modelHost, SPFolder folder, WebPartPageDefinition definition) { var list = folder.DocumentLibrary; var targetFile = FindWebPartPage(folder, definition); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = targetFile, ObjectType = typeof(SPFile), ObjectDefinition = definition, ModelHost = modelHost }); if (targetFile == null || definition.NeedOverride) { if (definition.NeedOverride) { TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing web part page"); TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "NeedOverride = true. Replacing web part page."); } else { TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new web part page"); } var webPartPageName = GetSafeWebPartPageFileName(definition); byte[] fileContent = null; if (!string.IsNullOrEmpty(definition.CustomPageLayout)) { fileContent = Encoding.UTF8.GetBytes(definition.CustomPageLayout); } else { fileContent = Encoding.UTF8.GetBytes(GetWebPartPageTemplateContent(definition)); } ModuleFileModelHandler.DeployModuleFile(folder, SPUrlUtility.CombineUrl(folder.ServerRelativeUrl, webPartPageName), webPartPageName, fileContent, true, file => { }, after => { FieldLookupService.EnsureDefaultValues(after.ListItemAllFields, definition.DefaultValues); if (!string.IsNullOrEmpty(definition.ContentTypeId) || !string.IsNullOrEmpty(definition.ContentTypeName)) { if (!string.IsNullOrEmpty(definition.ContentTypeId)) { after.ListItemAllFields["ContentTypeId"] = ContentTypeLookupService.LookupListContentTypeById(list, definition.ContentTypeId); } if (!string.IsNullOrEmpty(definition.ContentTypeName)) { after.ListItemAllFields["ContentTypeId"] = ContentTypeLookupService.LookupContentTypeByName(list, definition.ContentTypeName); } } FieldLookupService.EnsureValues(after.ListItemAllFields, definition.Values, true); if (definition.DefaultValues.Any() || definition.Values.Any() || !string.IsNullOrEmpty(definition.ContentTypeId) || !string.IsNullOrEmpty(definition.ContentTypeName)) { after.ListItemAllFields.Update(); } InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = after, ObjectType = typeof(SPFile), ObjectDefinition = definition, ModelHost = modelHost }); }); targetFile = FindWebPartPage(folder, definition); } else { FieldLookupService.EnsureDefaultValues(targetFile.ListItemAllFields, definition.DefaultValues); if (!string.IsNullOrEmpty(definition.ContentTypeId) || !string.IsNullOrEmpty(definition.ContentTypeName)) { if (!string.IsNullOrEmpty(definition.ContentTypeId)) { targetFile.ListItemAllFields["ContentTypeId"] = ContentTypeLookupService.LookupListContentTypeById(list, definition.ContentTypeId); } if (!string.IsNullOrEmpty(definition.ContentTypeName)) { targetFile.ListItemAllFields["ContentTypeId"] = ContentTypeLookupService.LookupContentTypeByName(list, definition.ContentTypeName); } } TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing web part page"); TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "NeedOverride = false. Skipping replacing web part page."); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = targetFile, ObjectType = typeof(SPFile), ObjectDefinition = definition, ModelHost = modelHost }); targetFile.Update(); } return(targetFile); }
private void DeployPage(object modelHost, SPList list, SPFolder folder, MasterPageDefinition definition) { var web = list.ParentWeb; var targetPage = GetCurrentObject(folder, definition); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = targetPage == null ? null : targetPage.File, ObjectType = typeof(SPFile), ObjectDefinition = definition, ModelHost = modelHost }); if (targetPage == null) { targetPage = CreateObject(modelHost, folder, definition); } InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = targetPage.File, ObjectType = typeof(SPFile), ObjectDefinition = definition, ModelHost = modelHost }); ModuleFileModelHandler.WithSafeFileOperation(list, folder, targetPage.Url, GetSafePageFileName(definition), definition.Content, definition.NeedOverride, null, afterFile => { var pageItem = afterFile.Properties; //pageItem[BuiltInInternalFieldNames.Title] = definition.Title; pageItem["vti_title"] = definition.Title; pageItem["MasterPageDescription"] = definition.Description; pageItem[BuiltInInternalFieldNames.ContentTypeId] = BuiltInContentTypeId.MasterPage; if (definition.UIVersion.Count > 0) { var value = new SPFieldMultiChoiceValue(); foreach (var v in definition.UIVersion) { value.Add(v); } pageItem["UIVersion"] = value.ToString(); } pageItem["DefaultCssFile"] = definition.DefaultCSSFile; //pageItem.Update(); //pageItem.SystemUpdate(); }); }