protected TermStore FindTermStore(SiteModelHost siteModelHost, TaxonomyTermStoreDefinition termStoreModel) { return TaxonomyTermStoreModelHandler.FindTermStore(siteModelHost, termStoreModel.Name, termStoreModel.Id, termStoreModel.UseDefaultSiteCollectionTermStore); }
internal static TermStore FindTermStore(SiteModelHost siteModelHost, string termStoreName, Guid? termStoreId, bool? useDefaultSiteCollectionTermStore) { return FindTermStore(siteModelHost.HostSite, termStoreName, termStoreId, useDefaultSiteCollectionTermStore); }
protected FeatureCollection LoadSiteFeatures(SiteModelHost siteModelHost) { var site = siteModelHost.HostSite; var context = site.Context; context.Load(site, w => w.Features); context.ExecuteQuery(); return site.Features; }
protected UserCustomAction GetCustomAction(SiteModelHost modelHost, UserCustomActionDefinition model) { var site = modelHost.HostSite; var context = site.Context; context.Load(site, s => s.UserCustomActions); context.ExecuteQuery(); return site.UserCustomActions.FirstOrDefault(a => a.Name == model.Name); }
private void ValidateSiteField(SiteModelHost siteModelHost, FieldDefinition model) { var spObject = FindSiteField(siteModelHost, model); TraceUtils.WithScope(traceScope => { var pair = new ComparePair<FieldDefinition, Field>(model, spObject); traceScope.WriteLine(string.Format("Validating model:[{0}] field:[{1}]", model, spObject)); traceScope.WithTraceIndent(trace => pair .ShouldBeEqual(trace, m => m.Title, o => o.Title) .ShouldBeEqual(trace, m => m.InternalName, o => o.InternalName) .ShouldBeEqual(trace, m => m.Id, o => o.Id) .ShouldBeEqual(trace, m => m.Description, o => o.Description) .ShouldBeEqual(trace, m => m.Group, o => o.Group)); }); }
private void ValidateModel(SiteModelHost siteModelHost, UserCustomActionDefinition customActionModel) { var customAction = GetCustomAction(siteModelHost, customActionModel); TraceUtils.WithScope(traceScope => { var pair = new ComparePair<UserCustomActionDefinition, UserCustomAction>(customActionModel, customAction); traceScope.WriteLine(string.Format("Validating model:[{0}] custom action:[{1}]", customActionModel, customAction)); traceScope.WithTraceIndent(trace => pair .ShouldBeEqual(trace, m => m.Title, o => o.Title) .ShouldBeEqual(trace, m => m.Description, o => o.Description) .ShouldBeEqual(trace, m => m.Group, o => o.Group) .ShouldBeEqual(trace, m => m.Name, o => o.Name) .ShouldBeEqual(trace, m => m.Sequence, o => o.Sequence) .ShouldBeEqual(trace, m => m.Location, o => o.Location)); }); }
private void DeploySiteCustomAction(SiteModelHost modelHost, UserCustomActionDefinition model) { var site = modelHost.HostSite; var context = site.Context; var existingAction = GetCustomAction(modelHost, model); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = null, ObjectType = typeof(UserCustomAction), ObjectDefinition = model, ModelHost = modelHost }); if (existingAction == null) existingAction = site.UserCustomActions.Add(); MapCustomAction(existingAction, model); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = existingAction, ObjectType = typeof(UserCustomAction), ObjectDefinition = model, ModelHost = modelHost }); existingAction.Update(); context.ExecuteQuery(); }
public static TermSet LookupTermSet( SiteModelHost currentSiteModelHost, TermStore termStore, TaxonomyFieldDefinition taxFieldModel) { var storeContext = currentSiteModelHost.HostClientContext; return LookupTermSet(storeContext, currentSiteModelHost.HostSite, termStore, taxFieldModel); }
public static TermStore LookupTermStore(SiteModelHost currentSiteModelHost, TaxonomyFieldDefinition taxFieldModel, bool raiseNullRefException) { var termStore = TaxonomyTermStoreModelHandler.FindTermStore(currentSiteModelHost, taxFieldModel.SspName, taxFieldModel.SspId, taxFieldModel.UseDefaultSiteCollectionTermStore); if (termStore == null && raiseNullRefException) throw new ArgumentNullException("termStore is NULL. Please define SspName, SspId or ensure there is a default term store for the giving site."); if (termStore != null) { var storeContext = currentSiteModelHost.HostClientContext; storeContext.Load(termStore, s => s.Id); storeContext.ExecuteQueryWithTrace(); } return termStore; }
private void DeploySiteEventReceiver(object modelHost, SiteModelHost siteModelHost, EventReceiverDefinition definition) { DeployEventReceiver(modelHost, siteModelHost.HostSite.EventReceivers, definition); }
private void DeploySiteDependentLookup(object modelHost, SiteModelHost siteModelHost, DependentLookupFieldDefinition definition) { DeployDependentLookupField(modelHost, siteModelHost.HostSite.RootWeb.Fields, definition); }
private Field DeploySiteField(SiteModelHost siteModelHost, FieldDefinition fieldModel) { TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Deploying site field"); var site = siteModelHost.HostSite; var context = site.Context; var field = GetField(siteModelHost, fieldModel); return EnsureField(context, field, site.RootWeb.Fields, fieldModel); }
private Field DeploySiteField(SiteModelHost siteModelHost, FieldDefinition fieldModel) { var site = siteModelHost.HostSite; var context = site.Context; var rootWeb = site.RootWeb; context.Load(rootWeb, tmpWeb => tmpWeb.Fields); context.ExecuteQuery(); return EnsureField(context, rootWeb.Fields, fieldModel); }
public static Term LookupTerm(SiteModelHost currentSiteModelHost, TermStore termStore, TaxonomyFieldDefinition termModel) { var context = currentSiteModelHost.HostClientContext; Term result = null; if (termModel.TermId.HasValue) { var scope = new ExceptionHandlingScope(context); using (scope.StartScope()) { using (scope.StartTry()) { result = termStore.GetTerm(termModel.TermId.Value); context.Load(result); } using (scope.StartCatch()) { } } context.ExecuteQueryWithTrace(); } else if (!string.IsNullOrEmpty(termModel.TermName)) { var terms = termStore.GetTerms(new LabelMatchInformation(context) { Lcid = termModel.TermLCID, TermLabel = termModel.TermName, TrimUnavailable = false }); context.Load(terms); context.ExecuteQueryWithTrace(); result = terms.FirstOrDefault(); } if (result != null && result.ServerObjectIsNull == false) { context.Load(result); context.ExecuteQueryWithTrace(); return result; } return null; }
private void DeploySiteGroup(object modelHost, SiteModelHost siteModelHost, DefinitionBase model) { var webModelHost = modelHost.WithAssertAndCast<SiteModelHost>("modelHost", value => value.RequireNotNull()); var web = webModelHost.HostSite.RootWeb; var securityGroupModel = model.WithAssertAndCast<SecurityGroupDefinition>("model", value => value.RequireNotNull()); var context = web.Context; // well, this should be pulled up to the site handler and init Load/Exec query context.Load(web, tmpWeb => tmpWeb.SiteGroups, g => g.Id, g => g.Title); context.ExecuteQueryWithTrace(); Principal groupOwner = null; if (!string.IsNullOrEmpty(securityGroupModel.Owner) && (securityGroupModel.Owner.ToUpper() != securityGroupModel.Name.ToUpper())) { groupOwner = ResolvePrincipal(context, web, securityGroupModel.Owner); if (groupOwner == null) throw new SPMeta2Exception(string.Format("Cannot resolve Principal by string value: [{0}]", securityGroupModel.Owner)); } var currentGroup = FindSecurityGroupByTitle(web.SiteGroups, securityGroupModel.Name); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = currentGroup, ObjectType = typeof(Principal), ObjectDefinition = model, ModelHost = modelHost }); if (currentGroup == null) { TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new security group"); currentGroup = web.SiteGroups.Add(new GroupCreationInformation { Title = securityGroupModel.Name, Description = securityGroupModel.Description ?? string.Empty, }); currentGroup.Update(); context.ExecuteQueryWithTrace(); // updating the owner or leave as default // Enhance 'SecurityGroupDefinition' provision - add self-owner support #516 // https://github.com/SubPointSolutions/spmeta2/issues/516 if (!string.IsNullOrEmpty(securityGroupModel.Owner)) { groupOwner = ResolvePrincipal(context, web, securityGroupModel.Owner); currentGroup.Owner = groupOwner; currentGroup.Update(); context.ExecuteQueryWithTrace(); } context.Load(currentGroup); context.ExecuteQueryWithTrace(); } else { TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing security group"); } currentGroup.Title = securityGroupModel.Name; currentGroup.Description = securityGroupModel.Description ?? string.Empty; currentGroup.OnlyAllowMembersViewMembership = securityGroupModel.OnlyAllowMembersViewMembership; if (securityGroupModel.AllowMembersEditMembership.HasValue) currentGroup.AllowMembersEditMembership = securityGroupModel.AllowMembersEditMembership.Value; if (securityGroupModel.AllowRequestToJoinLeave.HasValue) currentGroup.AllowRequestToJoinLeave = securityGroupModel.AllowRequestToJoinLeave.Value; if (securityGroupModel.AutoAcceptRequestToJoinLeave.HasValue) currentGroup.AutoAcceptRequestToJoinLeave = securityGroupModel.AutoAcceptRequestToJoinLeave.Value; if (groupOwner != null) currentGroup.Owner = groupOwner; InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = currentGroup, ObjectType = typeof(Principal), ObjectDefinition = model, ModelHost = modelHost }); currentGroup.Update(); context.ExecuteQueryWithTrace(); }
private void DeployImageRenditionSettings(object modelHost, SiteModelHost siteModelHost, ImageRenditionDefinition imageRenditionModel) { var context = siteModelHost.HostSite.Context; var renditions = SiteImageRenditions.GetRenditions(siteModelHost.HostSite.Context); context.ExecuteQueryWithTrace(); var currentRendition = GetCurrentImageRendition(renditions, imageRenditionModel); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = currentRendition, ObjectType = typeof(ImageRendition), ObjectDefinition = imageRenditionModel, ModelHost = modelHost }); if (currentRendition == null) { TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new Image Rendition"); var newRendition = new ImageRendition { Name = imageRenditionModel.Name, Width = imageRenditionModel.Width, Height = imageRenditionModel.Height }; InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = newRendition, ObjectType = typeof(ImageRendition), ObjectDefinition = imageRenditionModel, ModelHost = modelHost }); renditions.Add(newRendition); SiteImageRenditions.SetRenditions(context, renditions); context.ExecuteQueryWithTrace(); } else { TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing existing Image Rendition"); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = currentRendition, ObjectType = typeof(ImageRendition), ObjectDefinition = imageRenditionModel, ModelHost = modelHost }); } }
protected File FindExistingSolutionFile(SiteModelHost siteModelHost, SandboxSolutionDefinition sandboxSolutionDefinition) { TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Resolving sandbox solution by FileName: [{0}]", sandboxSolutionDefinition.FileName); var site = siteModelHost.HostSite; var context = site.Context; var solutionGallery = site.GetCatalog((int)ListTemplateType.SolutionCatalog); var files = solutionGallery.GetItems(CamlQuery.CreateAllItemsQuery()); context.Load(files); context.ExecuteQueryWithTrace(); var fileItem = files.ToList().FirstOrDefault(f => f["FileLeafRef"].ToString() == sandboxSolutionDefinition.FileName); return fileItem != null ? fileItem.File : null; }
private void DeploySandboxSolution(object modelHost, SiteModelHost siteModelHost, SandboxSolutionDefinition sandboxSolutionDefinition) { var site = siteModelHost.HostSite; var context = site.Context; var existingSolutionFile = FindExistingSolutionFile(siteModelHost, sandboxSolutionDefinition); var existingSolution = FindExistingSolution(siteModelHost, sandboxSolutionDefinition); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = existingSolutionFile, ObjectType = typeof(File), ObjectDefinition = sandboxSolutionDefinition, ModelHost = modelHost }); if (existingSolution != null) { TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing sandbox solution"); var fileItem = existingSolution.ListItemAllFields; context.Load(fileItem); context.ExecuteQueryWithTrace(); var currentFileName = fileItem["FileLeafRef"].ToString(); if (!currentFileName.Contains(sandboxSolutionDefinition.FileName)) { currentFileName = currentFileName.Replace(string.Format("-v{0}.{1}.wsp", 1, 0), string.Empty); } else { currentFileName = sandboxSolutionDefinition.FileName; } var info = new DesignPackageInfo { PackageGuid = sandboxSolutionDefinition.SolutionId, MajorVersion = 1, MinorVersion = 0, PackageName = Path.GetFileNameWithoutExtension(currentFileName) }; // deactivate and remove TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Deleting existing sandbox solution via DesignPackage.UnInstall()"); DesignPackage.UnInstall(context, site, info); context.ExecuteQueryWithTrace(); } //var solutionGallery = site.RootWeb.Lists.GetByTitle("Site Assets"); //var folder = solutionGallery.RootFolder; var folder = site.RootWeb.RootFolder; context.Load(folder); context.ExecuteQueryWithTrace(); var fileCreatingInfo = new FileCreationInformation { Url = sandboxSolutionDefinition.FileName, Overwrite = true }; if (sandboxSolutionDefinition.Content.Length < 1024 * 1024 * 1.5) { fileCreatingInfo.Content = sandboxSolutionDefinition.Content; } else { fileCreatingInfo.ContentStream = new System.IO.MemoryStream(sandboxSolutionDefinition.Content); } var newFile = folder.Files.Add(fileCreatingInfo); context.Load(newFile); context.Load(newFile, f => f.ServerRelativeUrl); TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Uploading new sandbox solution to root site folder"); context.ExecuteQueryWithTrace(); if (sandboxSolutionDefinition.Activate) { var info = new DesignPackageInfo { PackageGuid = sandboxSolutionDefinition.SolutionId, MajorVersion = 1, MinorVersion = 0, PackageName = Path.GetFileNameWithoutExtension(sandboxSolutionDefinition.FileName) }; // activate and remove TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Activating sandbox solution via DesignPackage.Install()"); DesignPackage.Install(context, site, info, newFile.ServerRelativeUrl); context.ExecuteQueryWithTrace(); // clean up the file TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Deleting sandbox file from root site folder"); newFile.DeleteObject(); context.ExecuteQueryWithTrace(); } InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = newFile, ObjectType = typeof(File), ObjectDefinition = sandboxSolutionDefinition, ModelHost = modelHost }); }
protected Field FindExistingSiteField(SiteModelHost siteHost, FieldDefinition fieldDefinition) { var id = fieldDefinition.Id; var rootWeb = siteHost.HostSite.RootWeb; TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "FindExistingSiteField with Id: [{0}]", id); var context = rootWeb.Context; var scope = new ExceptionHandlingScope(context); Field field = null; using (scope.StartScope()) { using (scope.StartTry()) { rootWeb.Fields.GetById(id); } using (scope.StartCatch()) { } } TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "ExecuteQuery()"); context.ExecuteQueryWithTrace(); if (!scope.HasException) { field = rootWeb.Fields.GetById(id); context.Load(field); TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Found site field with Id: [{0}]", id); TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "ExecuteQuery()"); context.ExecuteQueryWithTrace(); } else { TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Cannot find site field with Id: [{0}]", id); } return field; }
public static Term LookupTerm(SiteModelHost currentSiteModelHost, TermStore termStore, TermSet termSet, TaxonomyFieldDefinition termModel) { return LookupTerm(currentSiteModelHost.HostClientContext, termStore, termSet, termModel); }
protected Field FindSiteField(SiteModelHost siteModelHost, FieldDefinition fieldModel) { var site = siteModelHost.HostSite; var context = site.Context; var rootWeb = site.RootWeb; context.Load(rootWeb, tmpWeb => tmpWeb.Fields); context.ExecuteQuery(); return FindExistingField(rootWeb.Fields, fieldModel.InternalName); }
public static TermStore LookupTermStore(SiteModelHost currentSiteModelHost, TaxonomyFieldDefinition taxFieldModel) { return LookupTermStore(currentSiteModelHost, taxFieldModel, false); }
public static Term LookupTerm(SiteModelHost currentSiteModelHost, TermStore termStore, TaxonomyFieldDefinition termModel) { var context = currentSiteModelHost.HostClientContext; var site = currentSiteModelHost.HostSite; Term result = null; TermGroup currenGroup = null; var termGroupName = termModel.TermGroupName; var termGroupId = termModel.TermGroupId; var isSiteCollectionGroup = termModel.IsSiteCollectionGroup; if (!string.IsNullOrEmpty(termGroupName)) { currenGroup = termStore.Groups.GetByName(termGroupName); context.Load(currenGroup); context.ExecuteQueryWithTrace(); } else if (termGroupId != null && termGroupId.HasGuidValue()) { currenGroup = termStore.Groups.GetById(termGroupId.Value); context.Load(currenGroup); context.ExecuteQueryWithTrace(); } else if (isSiteCollectionGroup == true) { currenGroup = termStore.GetSiteCollectionGroup(site, false); context.Load(currenGroup); context.ExecuteQueryWithTrace(); } if (currenGroup != null) { if (termModel.TermId.HasValue) { // by ID, the only one match var scope = new ExceptionHandlingScope(context); using (scope.StartScope()) { using (scope.StartTry()) { result = termStore.GetTerm(termModel.TermId.Value); context.Load(result); } using (scope.StartCatch()) { } } context.ExecuteQueryWithTrace(); } else if (!string.IsNullOrEmpty(termModel.TermName)) { var terms = termStore.GetTerms(new LabelMatchInformation(context) { Lcid = termModel.TermLCID, TermLabel = termModel.TermName, TrimUnavailable = false }); context.Load(terms, t => t.Include( i => i.Id, i => i.Name, i => i.TermSet, i => i.TermSet.Group, i => i.TermSet.Group.Name )); context.ExecuteQueryWithTrace(); result = terms.FirstOrDefault(t => t.TermSet.Group.Name == currenGroup.Name); } } else { if (termModel.TermId.HasValue) { var scope = new ExceptionHandlingScope(context); using (scope.StartScope()) { using (scope.StartTry()) { result = termStore.GetTerm(termModel.TermId.Value); context.Load(result); } using (scope.StartCatch()) { } } context.ExecuteQueryWithTrace(); } else if (!string.IsNullOrEmpty(termModel.TermName)) { var terms = termStore.GetTerms(new LabelMatchInformation(context) { Lcid = termModel.TermLCID, TermLabel = termModel.TermName, TrimUnavailable = false }); context.Load(terms); context.ExecuteQueryWithTrace(); result = terms.FirstOrDefault(); } } if (result != null && result.ServerObjectIsNull == false) { context.Load(result); context.ExecuteQueryWithTrace(); return result; } return null; }