internal SPListAttribute Clone(string url) { SPListAttribute other = this.Clone(); other.Url = url; return(other); }
internal SPListAttribute Clone(SPList list) { SPListAttribute other = this.Clone(); other.Url = list.RootFolder.Url; if (this.Url == null || !this.Url.Equals(other.Url, StringComparison.OrdinalIgnoreCase)) { other.Title = list.Title; } return(other); }
private void ProvisionList(string siteUrl, Guid siteId, Guid webId, SPModelListProvisionOptions listOptions, HashSet <SPModelUsage> deferredListUrls) { if (checksum == null) { checksum = ComputeCheckSum(); } using (SPModelProvisionHelper helper = new SPModelProvisionHelper(siteId, GetProvisionEventReceiver(true))) { SPList targetList = null; if (listOptions.TargetListId != Guid.Empty) { targetList = helper.ObjectCache.GetList(listOptions.TargetWebId, listOptions.TargetListId); if (targetList == null) { return; } helper.UpdateList(targetList, listAttribute.Clone(targetList), contentTypeAttribute, fieldAttributes, hiddenFields.ToArray(), new SPContentTypeId[0], checksum); } else { SPListAttribute implListAttribute = listOptions.ListAttributeOverrides ?? listAttribute; if (listOptions.TargetListUrl != null) { implListAttribute = implListAttribute.Clone(listOptions.TargetListUrl); } else { implListAttribute = implListAttribute.Clone(); } if (listOptions.TargetListTitle != null) { implListAttribute.Title = listOptions.TargetListTitle; } List <SPContentTypeId> contentTypes; targetList = helper.EnsureList(helper.ObjectCache.GetWeb(webId), implListAttribute, out contentTypes); helper.UpdateList(targetList, implListAttribute, contentTypeAttribute, fieldAttributes, hiddenFields.ToArray(), contentTypes, checksum); } foreach (SPContentType ct in targetList.ContentTypes) { if (ct.Id.Parent == contentTypeAttribute.ContentTypeId) { deferredListUrls.Add(SPModelUsage.Create(targetList, ct.Id).GetWithoutList()); break; } } } }
private void ProvisionList(string siteUrl, Guid siteId, Guid webId, SPModelListProvisionOptions listOptions, HashSet <SPModelUsage> deferredListUrls) { using (SPModelProvisionHelper helper = new SPModelProvisionHelper(siteId, GetProvisionEventReceiver(true))) { SPList targetList = null; if (listOptions.TargetListId != Guid.Empty) { targetList = helper.TargetSite.AllWebs[listOptions.TargetWebId].Lists[listOptions.TargetListId]; } SPListAttribute implListAttribute = listOptions.ListAttributeOverrides ?? listAttribute; if (targetList != null) { implListAttribute = listAttribute.Clone(targetList.RootFolder.Url); helper.UpdateList(targetList, implListAttribute, contentTypeAttribute, fieldAttributes, hiddenFields.ToArray(), new SPContentTypeId[0]); } else { if (listOptions.TargetListUrl != null) { implListAttribute = implListAttribute.Clone(listOptions.TargetListUrl); } else { implListAttribute = implListAttribute.Clone(); } if (listOptions.TargetListTitle != null) { implListAttribute.Title = listOptions.TargetListTitle; } using (SPWeb targetWeb = helper.TargetSite.OpenWeb(webId)) { List <SPContentTypeId> contentTypes; targetList = helper.EnsureList(targetWeb, implListAttribute, out contentTypes); helper.UpdateList(targetList, implListAttribute, contentTypeAttribute, fieldAttributes, hiddenFields.ToArray(), contentTypes); } } foreach (SPContentType ct in targetList.ContentTypes) { if (ct.Id.Parent == contentTypeAttribute.ContentTypeId) { deferredListUrls.Add(SPModelUsage.Create(targetList, ct.Id).GetWithoutList()); break; } } } }
public SPModelListProvisionOptions(SPListAttribute attribute) { CommonHelper.ConfirmNotNull(attribute, "attribute"); this.ListAttributeOverrides = attribute.Clone(); }
private SPModelDescriptor(Type targetType, SPModelDefaultsAttribute defaultsAttribute) { this.ModelType = targetType; TargetTypeDictionary.TryAdd(targetType, this); TargetTypeDictionary.TryGetValue(targetType.BaseType, out this.Parent); if (this.Parent is SPModelInterfaceTypeDescriptor) { this.Parent = null; } this.contentTypeAttribute = targetType.GetCustomAttribute <SPContentTypeAttribute>(false); ResolveContentTypeId(contentTypeAttribute, targetType); ContentTypeDictionary.Add(contentTypeAttribute.ContentTypeId, this); this.defaultManagerType = GetDefaultManagerType(targetType); this.provisionEventReceiverType = contentTypeAttribute.ProvisionEventReceiverType; this.hasExplicitListAttribute = targetType.GetCustomAttribute <SPListAttribute>(false) != null; this.listAttribute = targetType.GetCustomAttribute <SPListAttribute>(true) ?? new SPListAttribute(); this.fieldAttributes = SPModelFieldAssociationCollection.EnumerateFieldAttributes(this, targetType).ToArray(); if (contentTypeAttribute.Group == null && defaultsAttribute != null) { contentTypeAttribute.Group = defaultsAttribute.DefaultContentTypeGroup; } foreach (SPFieldAttribute attribute in fieldAttributes) { if (attribute.Group == null) { if (this.Parent != null) { SPFieldAttribute baseAttribute = this.Parent.fieldAttributes.FirstOrDefault(v => v.InternalName == attribute.InternalName); if (baseAttribute != null) { attribute.Group = baseAttribute.Group; continue; } } if (defaultsAttribute != null) { attribute.Group = defaultsAttribute.DefaultFieldGroup; } } } if (contentTypeAttribute.ContentTypeId.IsChildOf(ContentTypeId.Page)) { this.ItemType = SPModelItemType.PublishingPage; } else if (contentTypeAttribute.ContentTypeId.IsChildOf(SPBuiltInContentTypeId.DocumentSet)) { this.ItemType = SPModelItemType.DocumentSet; } else if (contentTypeAttribute.ContentTypeId.IsChildOf(SPBuiltInContentTypeId.Folder)) { this.ItemType = SPModelItemType.Folder; } else if (contentTypeAttribute.ContentTypeId.IsChildOf(SPBuiltInContentTypeId.Document)) { this.ItemType = SPModelItemType.File; } if (this.ItemType == SPModelItemType.GenericItem) { this.baseType = SPBaseType.GenericList; } else if (contentTypeAttribute.ContentTypeId.IsChildOf(SPBuiltInContentTypeId.Issue)) { this.baseType = SPBaseType.Issue; } else { this.baseType = SPBaseType.DocumentLibrary; } if (this.Parent != null) { this.Parent.Children.Add(this); this.fieldAttributes = fieldAttributes.Concat(this.Parent.fieldAttributes).Distinct().ToArray(); if (provisionEventReceiverType == null) { this.provisionEventReceiverType = this.Parent.provisionEventReceiverType; } } foreach (SPFieldAttribute v in fieldAttributes) { AddRequiredViewField(v); } foreach (Type interfaceType in targetType.GetInterfaces()) { if (!interfaceType.IsDefined(typeof(SPModelIgnoreAttribute), true)) { SPModelInterfaceTypeDescriptor interfaceDescriptor = (SPModelInterfaceTypeDescriptor)TargetTypeDictionary.EnsureKeyValue(interfaceType, SPModelInterfaceTypeDescriptor.Create); interfaceDescriptor.AddImplementedType(this); this.Interfaces.Add(interfaceDescriptor); } } if (targetType.BaseType != typeof(SPModel) && targetType.BaseType.GetCustomAttribute <SPContentTypeAttribute>(false) == null) { SPModelInterfaceTypeDescriptor interfaceDescriptor = (SPModelInterfaceTypeDescriptor)TargetTypeDictionary.EnsureKeyValue(targetType.BaseType, SPModelInterfaceTypeDescriptor.Create); interfaceDescriptor.AddImplementedType(this); this.Interfaces.Add(interfaceDescriptor); } if (!targetType.IsAbstract) { instanceType = new Lazy <Type>(() => targetType); } else { instanceType = new Lazy <Type>(() => SPModel.BuildTypeFromAbstractBaseType(targetType), LazyThreadSafetyMode.ExecutionAndPublication); } }
private void ProvisionContentType(string siteUrl, Guid siteId, bool provisionParent, bool provisionChildren, bool matchChecksum, HashSet <SPModelUsage> deferredListUrls) { if (provisionParent && this.Parent != null) { this.Parent.ProvisionContentType(siteUrl, siteId, true, false, matchChecksum, null); } if (contentTypeAttribute != null) { if (TryLockSite(siteId)) { provisionedSites.TryAdd(siteId, true); try { if (checksum == null) { checksum = ComputeCheckSum(); } SPModelProvisionEventReceiver eventReceiver = GetProvisionEventReceiver(true); using (SPModelProvisionHelper helper = new SPModelProvisionHelper(siteId, eventReceiver)) { SPContentType contentType = helper.EnsureContentType(contentTypeAttribute); if (!matchChecksum || helper.GetContentTypeChecksum(contentType) != checksum) { helper.UpdateContentType(contentType, contentTypeAttribute, fieldAttributes, checksum); } SaveAssemblyName(helper.TargetSite, contentTypeAttribute.ContentTypeId, this.ModelType.Assembly); foreach (SPModelUsage usage in GetUsages(helper.TargetSite.RootWeb)) { if (usage.ContentTypeId.Parent == contentTypeAttribute.ContentTypeId) { using (SPModelProvisionHelper helper2 = new SPModelProvisionHelper(siteId, eventReceiver)) { SPList list = helper2.ObjectCache.GetList(usage.WebId, usage.ListId); if (list == null) { continue; } SPContentType listContentType = list.ContentTypes[usage.ContentTypeId]; if (listContentType == null) { continue; } if (!matchChecksum || helper2.GetContentTypeChecksum(listContentType) != checksum) { helper2.UpdateContentType(listContentType, contentTypeAttribute, fieldAttributes, checksum); } if (!matchChecksum || helper2.GetContentTypeChecksum(list, contentTypeAttribute.ContentTypeId) != checksum) { SPListAttribute listAttributeClone = listAttribute.Clone(list); helper2.UpdateList(list, listAttributeClone, contentTypeAttribute, fieldAttributes, hiddenFields.ToArray(), new SPContentTypeId[0], checksum); } } if (deferredListUrls != null) { deferredListUrls.Add(usage.GetWithoutList()); } } } } } catch (Exception ex) { bool dummy; provisionedSites.TryRemove(siteId, out dummy); throw new SPModelProvisionException(String.Format("Unable to provision for type '{0}'. {1}. {2}", this.ModelType.Name, siteUrl, ex.Message), ex); } finally { EventWaitHandle handle; if (provisionedSitesLocks.TryRemove(siteId, out handle)) { handle.Set(); handle.Close(); } } } } if (provisionChildren) { foreach (SPModelDescriptor child in this.Children) { if (!child.hasExplicitListAttribute) { child.ProvisionContentType(siteUrl, siteId, false, true, matchChecksum, deferredListUrls); } } } }