public override ModelNode ReverseSingleHost(object reverseHost, ReverseOptions options) { var typedHost = (reverseHost as ListReverseHost); var item = typedHost.HostList; var listContentTypes = item.ContentTypes.ToArray(); var def = new UniqueContentTypeOrderDefinition(); if (item.RootFolder.UniqueContentTypeOrder != null) { foreach (var ct in item.RootFolder.UniqueContentTypeOrder.ToArray()) { var sourceContentType = listContentTypes.FirstOrDefault(c => c.StringId == ct.StringValue); if (sourceContentType == null) { throw new SPMeta2ReverseException( string.Format("Cannot find list content type by ID:[{0}]", ct.StringValue)); } def.ContentTypes.Add(new ContentTypeLinkValue { ContentTypeName = sourceContentType.Name }); } } return(new UniqueContentTypeOrderModelNode { Options = { RequireSelfProcessing = true }, Value = def }); }
private void DeployContentTypeOrder(object modelHost, List list, Folder folder, UniqueContentTypeOrderDefinition contentTypeOrderDefinition) { var context = folder.Context; TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Fetching list content types and the order"); context.Load(list, l => l.ContentTypes); context.Load(folder, f => f.ContentTypeOrder); context.ExecuteQueryWithTrace(); var oldContentTypeOrder = folder.ContentTypeOrder; var newContentTypeOrder = new List <ContentTypeId>(); var listContentTypes = list.ContentTypes.ToList(); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = folder, ObjectType = typeof(Folder), ObjectDefinition = contentTypeOrderDefinition, ModelHost = modelHost }); // re-order foreach (var srcContentTypeDef in contentTypeOrderDefinition.ContentTypes) { ContentType listContentType = null; if (!string.IsNullOrEmpty(srcContentTypeDef.ContentTypeName)) { listContentType = listContentTypes.FirstOrDefault(c => c.Name.ToUpper() == srcContentTypeDef.ContentTypeName.ToUpper()); if (listContentType != null) { TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, string.Format("Found content type by name:[{0}]", srcContentTypeDef.ContentTypeName)); } } #if !NET35 if (listContentType == null && !string.IsNullOrEmpty(srcContentTypeDef.ContentTypeId)) { listContentType = listContentTypes.FirstOrDefault(c => c.Id.ToString().ToUpper().StartsWith(srcContentTypeDef.ContentTypeId.ToUpper())); if (listContentType != null) { TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, string.Format("Found content type by matching ID start:[{0}]", srcContentTypeDef.ContentTypeId)); } } #endif if (listContentType != null && !newContentTypeOrder.Contains(listContentType.Id)) { TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, string.Format("Adding content type to new ordering")); newContentTypeOrder.Add(listContentType.Id); } } // filling up gapes foreach (var oldCt in oldContentTypeOrder) { #if !NET35 if (newContentTypeOrder.Count(c => c.StringValue.ToString().ToUpper().StartsWith(oldCt.StringValue.ToUpper())) == 0) { newContentTypeOrder.Add(oldCt); } #endif #if NET35 // .ToString() should return .StringValue of the content type ID if (newContentTypeOrder.Count(c => c.ToString().ToUpper().StartsWith(oldCt.ToString().ToUpper())) == 0) { newContentTypeOrder.Add(oldCt); } #endif } if (newContentTypeOrder.Count() > 0) { folder.UniqueContentTypeOrder = newContentTypeOrder; } InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = folder, ObjectType = typeof(Folder), ObjectDefinition = contentTypeOrderDefinition, ModelHost = modelHost }); folder.Update(); context.ExecuteQueryWithTrace(); }
public static TModelNode AddUniqueContentTypeOrder <TModelNode>(this TModelNode model, UniqueContentTypeOrderDefinition definition, Action <UniqueContentTypeOrderModelNode> action) where TModelNode : ModelNode, IListModelNode, new() { return(model.AddTypedDefinitionNode(definition, action)); }
public static TModelNode AddUniqueContentTypeOrder <TModelNode>(this TModelNode model, UniqueContentTypeOrderDefinition definition) where TModelNode : ModelNode, IListModelNode, new() { return(AddUniqueContentTypeOrder(model, definition, null)); }
private void DeployContentTypeOrder(object modelHost, SPList list, SPFolder folder, UniqueContentTypeOrderDefinition contentTypeOrderDefinition) { var oldContentTypeOrder = folder.ContentTypeOrder; var newContentTypeOrder = new List <SPContentType>(); var listContentTypes = list.ContentTypes.OfType <SPContentType>().ToList(); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = folder, ObjectType = typeof(SPFolder), ObjectDefinition = contentTypeOrderDefinition, ModelHost = modelHost }); // re-order foreach (var srcContentTypeDef in contentTypeOrderDefinition.ContentTypes) { SPContentType listContentType = null; if (!string.IsNullOrEmpty(srcContentTypeDef.ContentTypeName)) { listContentType = listContentTypes.FirstOrDefault(c => c.Name.ToUpper() == srcContentTypeDef.ContentTypeName.ToUpper()); if (listContentType != null) { TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, string.Format("Found content type by name:[{0}]", srcContentTypeDef.ContentTypeName)); } } if (listContentType == null && !string.IsNullOrEmpty(srcContentTypeDef.ContentTypeId)) { var spContentTypeId = new SPContentTypeId(srcContentTypeDef.ContentTypeId); listContentType = listContentTypes.FirstOrDefault(c => c.Parent.Id == spContentTypeId); if (listContentType != null) { TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, string.Format("Found content type by matching parent ID:[{0}]", srcContentTypeDef.ContentTypeId)); } } if (listContentType != null && !newContentTypeOrder.Contains(listContentType)) { TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, string.Format("Adding content type to new ordering")); newContentTypeOrder.Add(listContentType); } } // filling up gapes foreach (var oldCt in oldContentTypeOrder) { if (newContentTypeOrder.Count(c => c.Name == oldCt.Name || c.Id.ToString().ToUpper().StartsWith(oldCt.Id.ToString().ToUpper())) == 0) { newContentTypeOrder.Add(oldCt); } } if (newContentTypeOrder.Count() > 0) { folder.UniqueContentTypeOrder = newContentTypeOrder; } InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = folder, ObjectType = typeof(SPFolder), ObjectDefinition = contentTypeOrderDefinition, ModelHost = modelHost }); folder.Update(); }
public static ModelNode AddUniqueContentTypeOrder(this ModelNode model, UniqueContentTypeOrderDefinition definition, Action <ModelNode> action) { return(model.AddDefinitionNode(definition, action)); }
public static ModelNode AddUniqueContentTypeOrder(this ModelNode model, UniqueContentTypeOrderDefinition definition) { return(AddUniqueContentTypeOrder(model, definition, null)); }
private void DeployContentTypeOrder(object modelHost, List list, Folder folder, UniqueContentTypeOrderDefinition contentTypeOrderDefinition) { var context = folder.Context; context.Load(list, l => l.ContentTypes); context.Load(folder, f => f.ContentTypeOrder); context.ExecuteQueryWithTrace(); var oldContentTypeOrder = folder.ContentTypeOrder; var newContentTypeOrder = new List <ContentTypeId>(); var listContentTypes = list.ContentTypes.ToList(); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = folder, ObjectType = typeof(Folder), ObjectDefinition = contentTypeOrderDefinition, ModelHost = modelHost }); // re-order foreach (var srcContentTypeDef in contentTypeOrderDefinition.ContentTypes) { ContentType listContentType = null; if (!string.IsNullOrEmpty(srcContentTypeDef.ContentTypeName)) { listContentType = listContentTypes.FirstOrDefault(c => c.Name == srcContentTypeDef.ContentTypeName); } if (listContentType == null && !string.IsNullOrEmpty(srcContentTypeDef.ContentTypeId)) { listContentType = listContentTypes.FirstOrDefault(c => c.Id.ToString().ToUpper().StartsWith(srcContentTypeDef.ContentTypeId.ToUpper())); } if (listContentType != null && !newContentTypeOrder.Contains(listContentType.Id)) { newContentTypeOrder.Add(listContentType.Id); } } // filling up gapes foreach (var oldCt in oldContentTypeOrder) { if (newContentTypeOrder.Count(c => c.StringValue.ToString().ToUpper().StartsWith(oldCt.StringValue.ToUpper())) == 0) { newContentTypeOrder.Add(oldCt); } } if (newContentTypeOrder.Count() > 0) { folder.UniqueContentTypeOrder = newContentTypeOrder; } InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = folder, ObjectType = typeof(Folder), ObjectDefinition = contentTypeOrderDefinition, ModelHost = modelHost }); folder.Update(); context.ExecuteQueryWithTrace(); }