protected virtual void ContentTypeHandler_OnUnProvisioned(ContentTypeProvisionHandler <TContext, TEntity> handler, ContentType contentType) { Debug.WriteLine($"ContentType '{contentType.Name}' has been provisioned on {handler.ContentType.Level}."); if (_contentTypes != null && _contentTypes.ContainsKey(handler)) { _contentTypes.Remove(handler); } }
private void RetrieveHandlers() { ProvisionHandlers = new List <SpProvisionHandler <TContext, TEntity> >(); var contentTypes = AttributeHelper.GetCustomAttributes <TEntity, ContentTypeAttribute>(true); var list = AttributeHelper.GetCustomAttributes <TEntity, ListAttribute>(false).FirstOrDefault(); var fields = AttributeHelper.GetFieldAttributes <TEntity, FieldAttribute>().Concat(AttributeHelper.GetPropertyAttributes <TEntity, FieldAttribute>()).OrderBy(f => f.Value.Order); if (list != null) { var listHandler = new ListProvisionHandler <TContext, TEntity>(list, this); listHandler.OnProvisioning += ListHandler_OnProvisioning; listHandler.OnProvisioned += ListHandler_OnProvisioned; ProvisionHandlers.Add(listHandler); } foreach (var contentType in contentTypes) { if (contentType != null) { var contentTypeHandler = new ContentTypeProvisionHandler <TContext, TEntity>(contentType, list, this); contentTypeHandler.OnProvisioned += ContentTypeHandler_OnProvisioned; contentTypeHandler.OnProvisioning += ContentTypeHandler_OnProvisioning; ProvisionHandlers.Add(contentTypeHandler); } } foreach (var field in fields.OrderBy(f => typeof(CalculatedFieldAttribute).IsAssignableFrom(f.Value.GetType()) ? 1 : 0)) { if (typeof(DependentLookupFieldAttribute).IsAssignableFrom(field.Value.GetType())) { continue; } //if (typeof(LookupFieldAttribute).IsAssignableFrom(field.Value.GetType())) //{ //} Type valueType = null; if (field.Key is PropertyInfo) { valueType = (field.Key as PropertyInfo).PropertyType; } else if (field.Key is FieldInfo) { valueType = (field.Key as FieldInfo).FieldType; } var fieldHandler = new FieldProvisionHandler <TContext, TEntity>(field.Value, AttributeHelper.GetCustomAttributes <TEntity, ContentTypeAttribute>(false).FirstOrDefault(), list, this, valueType); fieldHandler.OnProvisioned += FieldHandler_OnProvisioned; fieldHandler.OnProvisioning += FieldHandler_OnProvisioning; ProvisionHandlers.Add(fieldHandler); } }
private void SetContentTypeToList(ContentType contentType, ContentTypeProvisionHandler <TContext, TEntity> contentTypeHandler, ListProvisionHandler <TContext, TEntity> listHandler, ProvisionLevel level, Comparison <string> comparison) { if ((contentTypeHandler.ContentType.Level == ProvisionLevel.Web || level == ProvisionLevel.Web) && _list != null && listHandler != null && listHandler.List.Behavior != ProvisionBehavior.None) { string ctName; string ctId = contentType.Id.StringValue; var listContentTypes = _list.Context.LoadQuery(_list.ContentTypes.Where(ct => ct.Id.StringValue == ctId || ct.Parent.Id.StringValue == ctId)); ContentType listContentType; try { _list.Context.ExecuteQuery(); listContentType = listContentTypes.FirstOrDefault(); if (listContentType != null) { ctName = listContentType.Name; } } catch { listContentType = null; } if (listContentType == null) { listContentType = _list.ContentTypes.AddExistingContentType(contentType); _list.Context.Load(listContentType); _list.Context.ExecuteQuery(); if (_fields != null) { SetFieldLinks(contentType, _fields.Values, comparison); } } } }
private void RetrieveHandlers() { ProvisionHandlers = new List <SpProvisionHandler <TContext, TEntity> >(); var contentTypes = AttributeHelper.GetCustomAttributes <TEntity, ContentTypeAttribute>(true); var list = AttributeHelper.GetCustomAttributes <TEntity, ListAttribute>(false).FirstOrDefault(); var fields = AttributeHelper.GetFieldAttributes <TEntity, FieldAttribute>().Concat(AttributeHelper.GetPropertyAttributes <TEntity, FieldAttribute>()).OrderBy(f => f.Value.Order); if (list != null && list.Behavior != ProvisionBehavior.None) { var listHandler = new ListProvisionHandler <TContext, TEntity>(list, this); listHandler.OnProvisioning += ListHandler_OnProvisioning; listHandler.OnProvisioned += ListHandler_OnProvisioned; listHandler.OnUnProvisioning += ListHandler_OnUnProvisioning; listHandler.OnUnProvisioned += ListHandler_OnUnProvisioned; ProvisionHandlers.Add(listHandler); } foreach (var contentType in contentTypes) { if (contentType != null && contentType.Behavior != ProvisionBehavior.None) { var contentTypeHandler = new ContentTypeProvisionHandler <TContext, TEntity>(contentType, list, this); contentTypeHandler.OnProvisioned += ContentTypeHandler_OnProvisioned; contentTypeHandler.OnProvisioning += ContentTypeHandler_OnProvisioning; contentTypeHandler.OnUnProvisioned += ContentTypeHandler_OnUnProvisioned; contentTypeHandler.OnUnProvisioning += ContentTypeHandler_OnUnProvisioning; ProvisionHandlers.Add(contentTypeHandler); } } foreach (var field in fields.OrderBy(f => typeof(CalculatedFieldAttribute).IsAssignableFrom(f.Value.GetType()) ? 1 : 0)) { if (field.Value.Behavior == ProvisionBehavior.None) { continue; } if (typeof(DependentLookupFieldAttribute).IsAssignableFrom(field.Value.GetType())) { continue; } //if (typeof(LookupFieldAttribute).IsAssignableFrom(field.Value.GetType())) //{ //} Type valueType = null; if (field.Key is PropertyInfo) { valueType = (field.Key as PropertyInfo).PropertyType; } else if (field.Key is FieldInfo) { valueType = (field.Key as FieldInfo).FieldType; } if (field.Value.DataType == FieldType.Lookup) { if (/*!typeof(IListItemEntity).IsAssignableFrom(valueType) &&*/ !typeof(ISpEntityLookup).IsAssignableFrom(valueType) && !typeof(ISpEntityLookupCollection).IsAssignableFrom(valueType)) { continue; } } var duplicateField = ProvisionHandlers.OfType <FieldProvisionHandler <TContext, TEntity> >().FirstOrDefault(f => f.Field.Name == field.Value.Name); if (duplicateField != null) { throw new Exception($"Duplicate field: {duplicateField.Field}."); } var fieldHandler = new FieldProvisionHandler <TContext, TEntity>(field.Value, AttributeHelper.GetCustomAttributes <TEntity, ContentTypeAttribute>(true).LastOrDefault(), list, this, valueType); fieldHandler.OnProvisioned += FieldHandler_OnProvisioned; fieldHandler.OnProvisioning += FieldHandler_OnProvisioning; fieldHandler.OnUnProvisioned += FieldHandler_OnUnProvisioned; fieldHandler.OnUnProvisioning += FieldHandler_OnUnProvisioning; ProvisionHandlers.Add(fieldHandler); } }
protected virtual void ContentTypeHandler_OnUnProvisioning(ContentTypeProvisionHandler <TContext, TEntity> handler, ContentType contentType) { }
protected virtual void ContentTypeHandler_OnProvisioned(ContentTypeProvisionHandler <TContext, TEntity> handler, ContentType contentType) { Debug.WriteLine($"ContentType '{contentType.Name}' has been provisioned on {handler.ContentType.Level}."); _contentTypes.Add(handler, contentType); }
protected virtual void ContentTypeHandler_OnProvisioned(ContentTypeProvisionHandler <TContext, TEntity> handler, ContentType contentType) { _contentTypes.Add(contentType, handler); }