protected File GetWikiPageFile(List list, WikiPageDefinition wikiPageModel) { var newWikiPageUrl = string.Empty; var result = GetWikiPageFile(list, wikiPageModel, out newWikiPageUrl); return result; }
protected string GetSafeWikiPageFileName(WikiPageDefinition wikiPageModel) { var pageName = wikiPageModel.FileName; if (!pageName.EndsWith(".aspx")) pageName += ".aspx"; return pageName; }
private void DeployWikiPage(List list, WikiPageDefinition wikiPageModel) { var context = list.Context; var newWikiPageUrl = string.Empty; var file = GetWikiPageFile(list, wikiPageModel, out newWikiPageUrl); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = file, ObjectType = typeof(File), ObjectDefinition = wikiPageModel, ModelHost = list }); if (file == null) { var newPageFile = list.RootFolder.Files.AddTemplateFile(newWikiPageUrl, TemplateFileType.WikiPage); context.Load(newPageFile); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = newPageFile, ObjectType = typeof(File), ObjectDefinition = wikiPageModel, ModelHost = list }); context.ExecuteQuery(); } else { // TODO,override if force InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = file, ObjectType = typeof(File), ObjectDefinition = wikiPageModel, ModelHost = list }); } }
public override ModelNode ReverseSingleHost(object reverseHost, ReverseOptions options) { var item = (reverseHost as WikiPageReverseHost).HostWikiPageFile; var def = new WikiPageDefinition(); def.FileName = item.Name; def.Content = ConvertUtils.ToString(item.ListItemAllFields[BuiltInInternalFieldNames.WikiField]); def.NeedOverride = true; return new WikiPageModelNode { Options = { RequireSelfProcessing = true }, Value = def }; }
protected File GetWikiPageFile(List list, WikiPageDefinition wikiPageModel, out string newWikiPageUrl) { var context = list.Context; //if (!string.IsNullOrEmpty(wikiPageModel.FolderUrl)) // throw new Exception("FolderUrl property is not supported yet!"); var pageName = GetSafeWikiPageFileName(wikiPageModel); context.Load(list, l => l.RootFolder.ServerRelativeUrl); context.ExecuteQuery(); newWikiPageUrl = list.RootFolder.ServerRelativeUrl + "/" + pageName; var file = list.ParentWeb.GetFileByServerRelativeUrl(newWikiPageUrl); context.Load(file, f => f.Exists); context.ExecuteQuery(); if (file.Exists) return file; return null; }
public static ModelNode AddWikiPage(this ModelNode model, WikiPageDefinition definition, Action<ModelNode> action) { return model.AddDefinitionNode(definition, action); }
private void DeployWikiPage(Web web, Folder folder, WikiPageDefinition wikiPageModel) { var context = folder.Context; var newWikiPageUrl = string.Empty; var file = GetWikiPageFile(web, folder, wikiPageModel, out newWikiPageUrl); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = file, ObjectType = typeof(File), ObjectDefinition = wikiPageModel, ModelHost = folder }); if (file == null) { TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new wiki page"); var newPageFile = folder.Files.AddTemplateFile(newWikiPageUrl, TemplateFileType.WikiPage); context.Load(newPageFile); var currentListItem = newPageFile.ListItemAllFields; context.Load(currentListItem); context.ExecuteQueryWithTrace(); currentListItem[BuiltInInternalFieldNames.WikiField] = wikiPageModel.Content ?? String.Empty; currentListItem.Update(); context.ExecuteQueryWithTrace(); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = newPageFile, ObjectType = typeof(File), ObjectDefinition = wikiPageModel, ModelHost = folder }); context.ExecuteQueryWithTrace(); } else { // TODO,override if force TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing wiki page"); if (wikiPageModel.NeedOverride) { TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "NeedOverride = true. Updating wiki page content."); var currentListItem = file.ListItemAllFields; context.Load(currentListItem); context.ExecuteQueryWithTrace(); currentListItem[BuiltInInternalFieldNames.WikiField] = wikiPageModel.Content ?? String.Empty; currentListItem.Update(); } else { TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "NeedOverride = false. Skipping Updating wiki page content."); } InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = file, ObjectType = typeof(File), ObjectDefinition = wikiPageModel, ModelHost = folder }); context.ExecuteQueryWithTrace(); } }
protected File GetWikiPageFile(Web web, Folder folder, WikiPageDefinition wikiPageModel, out string newWikiPageUrl) { var context = folder.Context; //if (!string.IsNullOrEmpty(wikiPageModel.FolderUrl)) // throw new Exception("FolderUrl property is not supported yet!"); var pageName = GetSafeWikiPageFileName(wikiPageModel); context.Load(folder, l => l.ServerRelativeUrl); context.ExecuteQueryWithTrace(); newWikiPageUrl = folder.ServerRelativeUrl + "/" + pageName; TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Resolving file with URL: [{0}]", newWikiPageUrl); var file = web.GetFileByServerRelativeUrl(newWikiPageUrl); context.Load(file, f => f.Exists); context.ExecuteQueryWithTrace(); if (file.Exists) { TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Returning existing file"); return file; } TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "File does not exist. Returning NULL"); return null; }
protected File GetWikiPageFile(Web web, Folder folder, WikiPageDefinition wikiPageModel) { var newWikiPageUrl = string.Empty; var result = GetWikiPageFile(web, folder, wikiPageModel, out newWikiPageUrl); return result; }
public void Deploy_WikiPage() { // Step 1, define security groups var aboutPage = new WikiPageDefinition { Title = "About", FileName = "about.aspx" }; var contactPage = new WikiPageDefinition { Title = "Contact", FileName = "contact.aspx" }; var faqPage = new WikiPageDefinition { Title = "FAQ", FileName = "faq.aspx" }; // Step 2, define web model and artifact relationships - add security groups t the web var model = SPMeta2Model .NewWebModel(web => { web .AddList(BuiltInListDefinitions.SitePages, list => { list .AddWikiPage(aboutPage) .AddWikiPage(contactPage) .AddWikiPage(faqPage); }); }); // Step 3, deploy model DeployWebModel(model); }
protected string GetSafeWikiPageUrl(SPFolder folder, WikiPageDefinition wikiPageModel) { // TODO, fix +/ to SPUtility return folder.ServerRelativeUrl + "/" + GetSafeWikiPageFileName(wikiPageModel); }
protected SPListItem FindWikiPageItem(SPFolder folder, WikiPageDefinition wikiPageModel) { var file = folder.ParentWeb.GetFile(GetSafeWikiPageUrl(folder, wikiPageModel)); return file.Exists ? file.Item : null; }
private void DeployWikiPage(Web web, List list, Folder folder, WikiPageDefinition definition) { var context = folder.Context; var newWikiPageUrl = string.Empty; var contentTypeId = string.Empty; // pre load content type if (!string.IsNullOrEmpty(definition.ContentTypeId)) { contentTypeId = definition.ContentTypeId; } else if (!string.IsNullOrEmpty(definition.ContentTypeName)) { contentTypeId = ContentTypeLookupService .LookupContentTypeByName(list, definition.ContentTypeName) .Id.ToString(); } var file = GetWikiPageFile(web, folder, definition, out newWikiPageUrl); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = file, ObjectType = typeof(File), ObjectDefinition = definition, ModelHost = folder }); if (file == null) { TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new wiki page"); var newPageFile = folder.Files.AddTemplateFile(newWikiPageUrl, TemplateFileType.WikiPage); context.Load(newPageFile); var currentListItem = newPageFile.ListItemAllFields; context.Load(currentListItem); context.ExecuteQueryWithTrace(); FieldLookupService.EnsureDefaultValues(currentListItem, definition.DefaultValues); if (!string.IsNullOrEmpty(contentTypeId)) currentListItem[BuiltInInternalFieldNames.ContentTypeId] = contentTypeId; currentListItem[BuiltInInternalFieldNames.WikiField] = definition.Content ?? String.Empty; FieldLookupService.EnsureValues(currentListItem, definition.Values, true); currentListItem.Update(); context.ExecuteQueryWithTrace(); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = newPageFile, ObjectType = typeof(File), ObjectDefinition = definition, ModelHost = folder }); context.ExecuteQueryWithTrace(); } else { // TODO,override if force TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing wiki page"); if (definition.NeedOverride) { TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "NeedOverride = true. Updating wiki page content."); var currentListItem = file.ListItemAllFields; context.Load(currentListItem); context.ExecuteQueryWithTrace(); FieldLookupService.EnsureDefaultValues(currentListItem, definition.DefaultValues); if (!string.IsNullOrEmpty(contentTypeId)) currentListItem[BuiltInInternalFieldNames.ContentTypeId] = contentTypeId; currentListItem[BuiltInInternalFieldNames.WikiField] = definition.Content ?? String.Empty; currentListItem.Update(); } else { TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "NeedOverride = false. Skipping Updating wiki page content."); } InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = file, ObjectType = typeof(File), ObjectDefinition = definition, ModelHost = folder }); context.ExecuteQueryWithTrace(); } }
public static ModelNode AddHostWikiPage(this ModelNode model, WikiPageDefinition definition) { return AddHostWikiPage(model, definition, null); }
protected string GetSafeWikiPageFileName(WikiPageDefinition wikiPageModel) { return GetSafeWikiPageFileName(wikiPageModel.FileName); }
public static ModelNode AddHostWikiPage(this ModelNode model, WikiPageDefinition definition, Action<ModelNode> action) { return model.AddDefinitionNodeWithOptions(definition, action, ModelNodeOptions.New().NoSelfProcessing()); }
protected SPListItem FindWikiPage(SPList pageList, WikiPageDefinition wikiPageModel) { var file = pageList.ParentWeb.GetFile(GetSafeWikiPageUrl(pageList, wikiPageModel)); return file.Exists ? file.Item : null; }