Ejemplo n.º 1
0
        public virtual SPModelUsageCollection GetUsages(SPList list)
        {
            CommonHelper.ConfirmNotNull(list, "list");
            List <SPModelUsage> collection = new List <SPModelUsage>();

            foreach (SPContentType ct in list.ContentTypes)
            {
                if (this.ContentTypeIds.Any(v => v.IsParentOf(ct.Id)))
                {
                    collection.Add(SPModelUsage.Create(list, ct.Id));
                }
            }
            return(new SPModelUsageCollection(list.ParentWeb.Site, collection));
        }
Ejemplo n.º 2
0
 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;
             }
         }
     }
 }
Ejemplo n.º 3
0
 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;
             }
         }
     }
 }
Ejemplo n.º 4
0
        public virtual SPModelUsageCollection GetUsages(SPWeb web)
        {
            CommonHelper.ConfirmNotNull(web, "web");
            List <SPModelUsage> collection = new List <SPModelUsage>();
            string startUrl = web.ServerRelativeUrl;

            if (listAttribute.RootWebOnly)
            {
                startUrl = web.Site.ServerRelativeUrl;
            }
            startUrl = startUrl.TrimEnd('/');
            foreach (SPContentTypeUsage usage in GetContentTypeUsages(web, contentTypeAttribute.ContentTypeId))
            {
                if (usage.IsUrlToList && IsUrlInScope(startUrl, usage.Url))
                {
                    collection.Add(SPModelUsage.Create(web.Site, usage));
                }
            }
            return(new SPModelUsageCollection(web.Site, collection));
        }
Ejemplo n.º 5
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);
                    }
                }
            }
        }