Пример #1
0
 public void Add(SPModelProvisionEventReceiver eventReceiver)
 {
     if (eventReceiver != SPModelProvisionEventReceiver.Default)
     {
         SPModelProvisionMulticastEventReceiver multicastReceiver = eventReceiver as SPModelProvisionMulticastEventReceiver;
         if (multicastReceiver != null)
         {
             eventReceivers.AddRange(multicastReceiver.eventReceivers);
         }
         else
         {
             eventReceivers.Add(eventReceiver);
         }
     }
 }
Пример #2
0
        private void ProvisionContentType(string siteUrl, Guid siteId, bool provisionParent, bool provisionChildren, HashSet <SPModelUsage> deferredListUrls)
        {
            if (provisionParent && this.Parent != null)
            {
                this.Parent.ProvisionContentType(siteUrl, siteId, true, false, null);
            }
            if (contentTypeAttribute != null)
            {
                if (TryLockSite(siteId))
                {
                    provisionedSites.TryAdd(siteId, true);
                    try {
                        SPModelProvisionEventReceiver eventReceiver = GetProvisionEventReceiver(true);
                        using (SPModelProvisionHelper helper = new SPModelProvisionHelper(siteId, eventReceiver)) {
                            SPContentType contentType = helper.EnsureContentType(contentTypeAttribute);
                            helper.UpdateContentType(contentType, contentTypeAttribute, fieldAttributes);
                            SaveAssemblyName(helper.TargetSite, contentTypeAttribute.ContentTypeId, this.ModelType.Assembly);

                            foreach (SPContentTypeUsage usage in SPContentTypeUsage.GetUsages(contentType))
                            {
                                if (usage.Id.Parent == contentType.Id && usage.IsUrlToList)
                                {
                                    using (SPSite listParentSite = new SPSite(helper.TargetSite.MakeFullUrl(usage.Url), SPUserToken.SystemAccount)) {
                                        using (SPWeb listParentWeb = listParentSite.OpenWeb()) {
                                            SPList list;
                                            try {
                                                list = listParentWeb.GetListSafe(usage.Url);
                                            } catch (FileNotFoundException) {
                                                continue;
                                            }
                                            SPContentType listContentType = list.ContentTypes[usage.Id];
                                            if (listContentType != null)
                                            {
                                                using (SPModelProvisionHelper helper2 = new SPModelProvisionHelper(siteId, eventReceiver)) {
                                                    helper2.UpdateContentType(listContentType, contentTypeAttribute, fieldAttributes);
                                                    helper2.UpdateList(list, listAttribute.Clone(list.RootFolder.Url), contentTypeAttribute, fieldAttributes, hiddenFields.ToArray(), new SPContentTypeId[0]);
                                                    if (deferredListUrls != null)
                                                    {
                                                        deferredListUrls.Add(SPModelUsage.Create(list, usage.Id).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, deferredListUrls);
                    }
                }
            }
        }
Пример #3
0
        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);
                    }
                }
            }
        }