private void DeployHideContentTypeLinks(object modelHost, SPList list, RemoveContentTypeLinksDefinition contentTypeOrderDefinition) { var listContentTypes = list.ContentTypes.OfType <SPContentType>().ToList(); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = list, ObjectType = typeof(SPList), 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 == srcContentTypeDef.ContentTypeName); } if (listContentType == null && !string.IsNullOrEmpty(srcContentTypeDef.ContentTypeId)) { listContentType = listContentTypes.FirstOrDefault(c => c.Id.ToString().ToUpper().StartsWith(srcContentTypeDef.ContentTypeId.ToUpper())); } if (listContentType != null) { try { list.ContentTypes.Delete(listContentType.Id); } catch (Exception) { // TODO } } } InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = list, ObjectType = typeof(SPList), ObjectDefinition = contentTypeOrderDefinition, ModelHost = modelHost }); }
private void DeployHideContentTypeLinks(object modelHost, List list, RemoveContentTypeLinksDefinition contentTypeOrderDefinition) { var context = list.Context; TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Fetching list content types"); context.Load(list, l => l.ContentTypes); context.ExecuteQueryWithTrace(); var listContentTypes = list.ContentTypes.ToList(); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = list, ObjectType = typeof(List), 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 (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)); } } if (listContentType != null) { try { TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, string.Format("Deleting list content type")); listContentType.DeleteObject(); } catch (Exception e) { TraceService.Error((int)LogEventId.ModelProvisionCoreCall, e); } } } InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = list, ObjectType = typeof(List), ObjectDefinition = contentTypeOrderDefinition, ModelHost = modelHost }); context.ExecuteQueryWithTrace(); }
public static ModelNode AddRemoveContentTypeLinks(this ModelNode model, RemoveContentTypeLinksDefinition definition, Action <ModelNode> action) { return(model.AddDefinitionNode(definition, action)); }
public static ModelNode AddRemoveContentTypeLinks(this ModelNode model, RemoveContentTypeLinksDefinition definition) { return(AddRemoveContentTypeLinks(model, definition, null)); }
private void DeployHideContentTypeLinks(object modelHost, SPList list, RemoveContentTypeLinksDefinition contentTypeOrderDefinition) { var listContentTypes = list.ContentTypes.OfType <SPContentType>().ToList(); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = list, ObjectType = typeof(SPList), 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) { try { TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, string.Format("Deleting list content type")); list.ContentTypes.Delete(listContentType.Id); } catch (Exception e) { TraceService.Error((int)LogEventId.ModelProvisionCoreCall, e); } } } InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = list, ObjectType = typeof(SPList), ObjectDefinition = contentTypeOrderDefinition, ModelHost = modelHost }); }
public static TModelNode AddRemoveContentTypeLinks <TModelNode>(this TModelNode model, RemoveContentTypeLinksDefinition definition, Action <RemoveContentTypeLinksModelNode> action) where TModelNode : ModelNode, IListModelNode, new() { return(model.AddTypedDefinitionNode(definition, action)); }
public static TModelNode AddRemoveContentTypeLinks <TModelNode>(this TModelNode model, RemoveContentTypeLinksDefinition definition) where TModelNode : ModelNode, IListModelNode, new() { return(AddRemoveContentTypeLinks(model, definition, null)); }