Exemplo n.º 1
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;
             }
         }
     }
 }
Exemplo n.º 2
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;
             }
         }
     }
 }
Exemplo n.º 3
0
 private void Provision(string siteUrl, Guid siteId, Guid webId, bool provisionContentType, bool provisionList, SPModelListProvisionOptions listOptions, ProvisionResult result)
 {
     try {
         if (provisionContentType)
         {
             CheckFieldConsistency();
             ProvisionContentType(siteUrl, siteId, true, true, listOptions != SPModelListProvisionOptions.Default ? null : result.ProvisionedLists);
         }
         if (provisionList && (listOptions != SPModelListProvisionOptions.Default || !String.IsNullOrEmpty(listAttribute.Url)))
         {
             ProvisionList(siteUrl, siteId, webId, listOptions, result.ProvisionedLists);
         }
     } catch (Exception ex) {
         result.Exception = ex;
         SPDiagnosticsService.Local.WriteTrace(TraceCategory.ModelProvision, ex);
         SPDiagnosticsService.Local.WriteTrace(TraceCategory.ModelProvision, String.Concat("[Invocation site ", result.StackTrace, "]"));
     }
 }
Exemplo n.º 4
0
        public SPModelUsageCollection Provision(SPWeb targetWeb, SPModelProvisionOptions options, SPModelListProvisionOptions listOptions)
        {
            CommonHelper.ConfirmNotNull(targetWeb, "targetWeb");
            CommonHelper.ConfirmNotNull(listOptions, "listOptions");
            if (contentTypeAttribute == null || !contentTypeAttribute.ExternalContentType)
            {
                bool provisionContentType = options.HasFlag(SPModelProvisionOptions.ForceProvisionContentType) || provisionedSites.TryAdd(targetWeb.Site.ID, true);
                bool provisionList        = !options.HasFlag(SPModelProvisionOptions.SuppressListCreation);
                if (provisionContentType || provisionList)
                {
                    string          siteUrl = targetWeb.Site.Url;
                    Guid            siteId  = targetWeb.Site.ID;
                    Guid            webId   = targetWeb.ID;
                    ProvisionResult result  = new ProvisionResult();

                    Thread thread = new Thread(() => Provision(siteUrl, siteId, webId, provisionContentType, provisionList, listOptions, result));
                    thread.Start();
                    if (!options.HasFlag(SPModelProvisionOptions.Asynchronous))
                    {
                        thread.Join();
                        if (result.Exception != null)
                        {
                            throw result.Exception.Rethrow();
                        }
                        return(new SPModelUsageCollection(targetWeb.Site, result.ProvisionedLists.ToArray()));
                    }
                }
            }
            return(new SPModelUsageCollection(targetWeb.Site, new SPModelUsage[0]));
        }
Exemplo n.º 5
0
 public SPModelUsageCollection Provision(SPWeb targetWeb, SPModelListProvisionOptions listOptions)
 {
     return(Provision(targetWeb, SPModelProvisionOptions.None, listOptions));
 }