public override void DeployModel(object modelHost, DefinitionBase model) { base.DeployModel(modelHost, model); var typedModelHost = modelHost.WithAssertAndCast <SiteModelHost>("modelHost", value => value.RequireNotNull()); var definition = model.WithAssertAndCast <TaxonomyFieldDefinition>("model", value => value.RequireNotNull()); var site = typedModelHost.HostSite; var spObject = GetField(modelHost, definition) as TaxonomyField; var assert = ServiceFactory.AssertService .NewAssert(definition, spObject) .ShouldNotBeNull(spObject) .ShouldBeEqual(m => m.IsMulti, o => o.AllowMultipleValues); if (definition.CreateValuesInEditForm.HasValue) { assert.ShouldBeEqual(m => m.CreateValuesInEditForm, o => o.CreateValuesInEditForm); } else { assert.SkipProperty(m => m.CreateValuesInEditForm, "CreateValuesInEditForm is null. Skipping property."); } if (definition.Open.HasValue) { assert.ShouldBeEqual(m => m.Open, o => o.Open); } else { assert.SkipProperty(m => m.Open, "Open is null. Skipping property."); } if (definition.IsPathRendered.HasValue) { assert.ShouldBeEqual(m => m.IsPathRendered, o => o.IsPathRendered); } else { assert.SkipProperty(m => m.IsPathRendered, "IsPathRendered is null. Skipping property."); } // SSP if (definition.SspId.HasValue) { assert.ShouldBeEqual(m => m.SspId, o => o.SspId); } else { assert.SkipProperty(m => m.SspId, "SspId is null. Skipping property."); } if (!string.IsNullOrEmpty(definition.SspName)) { // TODO } else { assert.SkipProperty(m => m.SspName, "SspName is null. Skipping property."); } if (definition.UseDefaultSiteCollectionTermStore == true) { var taxSession = new TaxonomySession(site); var termStore = taxSession.DefaultSiteCollectionTermStore; var isValid = termStore.Id == spObject.SspId; assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.UseDefaultSiteCollectionTermStore); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.UseDefaultSiteCollectionTermStore, "UseDefaultSiteCollectionTermStore is null. Skipping property."); } // term set if (definition.TermSetId.HasValue) { assert.ShouldBeEqual(m => m.TermSetId, o => o.TermSetId); } else { assert.SkipProperty(m => m.TermSetId, "TermSetId is null. Skipping property."); } if (!string.IsNullOrEmpty(definition.TermSetName)) { var termStore = TaxonomyFieldModelHandler.LookupTermStore(site, definition); var termSet = TaxonomyFieldModelHandler.LookupTermSet(termStore, definition); var isValid = spObject.TermSetId == termSet.Id; assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.TermSetName); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.TermSetName, "TermSetName is null. Skipping property."); } /// term if (definition.TermId.HasValue) { assert.ShouldBeEqual(m => m.TermId, o => o.AnchorId); } else { assert.SkipProperty(m => m.TermId, "TermId is null. Skipping property."); } if (!string.IsNullOrEmpty(definition.TermName)) { var termStore = TaxonomyFieldModelHandler.LookupTermStore(site, definition); var term = TaxonomyFieldModelHandler.LookupTerm(termStore, definition); var isValid = spObject.AnchorId == term.Id; assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.TermName); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.TermName, "TermName is null. Skipping property."); } // etc assert.SkipProperty(m => m.TermLCID, "TermLCID. Skipping property."); assert.SkipProperty(m => m.TermSetLCID, "TermSetLCID. Skipping property."); }
private void DeployNavigationSettings(object modelHost, WebModelHost webModelHost, WebNavigationSettingsDefinition navigationModel) { var site = webModelHost.HostWeb.Site; var web = webModelHost.HostWeb; var thisWebNavSettings = GetWebNavigationSettings(webModelHost, navigationModel); var shouldUpdateWeb = false; var allProperties = web.AllProperties; InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = thisWebNavSettings, ObjectType = typeof(WebNavigationSettings), ObjectDefinition = navigationModel, ModelHost = modelHost }); if (!string.IsNullOrEmpty(navigationModel.GlobalNavigationSource) || !string.IsNullOrEmpty(navigationModel.CurrentNavigationSource)) { if (!string.IsNullOrEmpty(navigationModel.GlobalNavigationSource)) { var globalSource = (StandardNavigationSource)Enum.Parse(typeof(StandardNavigationSource), navigationModel.GlobalNavigationSource); thisWebNavSettings.GlobalNavigation.Source = globalSource; if (globalSource == StandardNavigationSource.TaxonomyProvider) { var globalTermStore = TaxonomyTermStoreModelHandler.FindTermStore(site, navigationModel.GlobalNavigationTermStoreName, navigationModel.GlobalNavigationTermStoreId, navigationModel.GlobalNavigationUseDefaultSiteCollectionTermStore); var globalTermSet = TaxonomyFieldModelHandler.LookupTermSet(globalTermStore, null, null, null, null, navigationModel.GlobalNavigationTermSetName, navigationModel.GlobalNavigationTermSetId, navigationModel.GlobalNavigationTermSetLCID); thisWebNavSettings.GlobalNavigation.TermStoreId = globalTermStore.Id; thisWebNavSettings.GlobalNavigation.TermSetId = globalTermSet.Id; } else { int?globalNavigationIncludeTypes = GetGlobalNavigationIncludeTypes(navigationModel, ConvertUtils.ToInt(allProperties[BuiltInWebPropertyId.GlobalNavigationIncludeTypes])); if (globalNavigationIncludeTypes != null) { allProperties[BuiltInWebPropertyId.GlobalNavigationIncludeTypes] = globalNavigationIncludeTypes.Value; shouldUpdateWeb = true; } if (navigationModel.GlobalNavigationMaximumNumberOfDynamicItems.HasValue) { allProperties[BuiltInWebPropertyId.GlobalDynamicChildLimit] = navigationModel.GlobalNavigationMaximumNumberOfDynamicItems.Value; shouldUpdateWeb = true; } } } if (!string.IsNullOrEmpty(navigationModel.CurrentNavigationSource)) { var currentSource = (StandardNavigationSource)Enum.Parse(typeof(StandardNavigationSource), navigationModel.CurrentNavigationSource); thisWebNavSettings.CurrentNavigation.Source = currentSource; if (currentSource == StandardNavigationSource.TaxonomyProvider) { var currentTermStore = TaxonomyTermStoreModelHandler.FindTermStore(site, navigationModel.CurrentNavigationTermStoreName, navigationModel.CurrentNavigationTermStoreId, navigationModel.CurrentNavigationUseDefaultSiteCollectionTermStore); var currentTermSet = TaxonomyFieldModelHandler.LookupTermSet(currentTermStore, null, null, null, null, navigationModel.CurrentNavigationTermSetName, navigationModel.CurrentNavigationTermSetId, navigationModel.CurrentNavigationTermSetLCID); thisWebNavSettings.CurrentNavigation.TermStoreId = currentTermStore.Id; thisWebNavSettings.CurrentNavigation.TermSetId = currentTermSet.Id; } else { int?currentNavigationIncludeTypes = GetCurrentNavigationIncludeTypes(navigationModel, ConvertUtils.ToInt(allProperties[BuiltInWebPropertyId.CurrentNavigationIncludeTypes])); if (currentNavigationIncludeTypes != null) { allProperties[BuiltInWebPropertyId.CurrentNavigationIncludeTypes] = currentNavigationIncludeTypes.Value; shouldUpdateWeb = true; } if (navigationModel.CurrentNavigationMaximumNumberOfDynamicItems.HasValue) { allProperties[BuiltInWebPropertyId.CurrentDynamicChildLimit] = navigationModel.CurrentNavigationMaximumNumberOfDynamicItems.Value; shouldUpdateWeb = true; } } } } if (navigationModel.AddNewPagesToNavigation.HasValue) { thisWebNavSettings.AddNewPagesToNavigation = navigationModel.AddNewPagesToNavigation.Value; } if (navigationModel.CreateFriendlyUrlsForNewPages.HasValue) { thisWebNavSettings.CreateFriendlyUrlsForNewPages = navigationModel.CreateFriendlyUrlsForNewPages.Value; } if (navigationModel.DisplayShowHideRibbonAction.HasValue) { allProperties[BuiltInWebPropertyId.DisplayShowHideRibbonActionId] = navigationModel.DisplayShowHideRibbonAction.ToString(); shouldUpdateWeb = true; } InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = thisWebNavSettings, ObjectType = typeof(WebNavigationSettings), ObjectDefinition = navigationModel, ModelHost = modelHost }); if (shouldUpdateWeb) { web.Update(); } if (!string.IsNullOrEmpty(navigationModel.GlobalNavigationSource) || !string.IsNullOrEmpty(navigationModel.CurrentNavigationSource)) { thisWebNavSettings.Update(null); } }
private void DeployNavigationSettings(object modelHost, WebModelHost webModelHost, WebNavigationSettingsDefinition navigationModel) { var shouldUpdateWeb = false; var site = webModelHost.HostSite; var web = webModelHost.HostWeb; var context = web.Context; var thisWebNavSettings = GetWebNavigationSettings(webModelHost, navigationModel); StandardNavigationSource?globalSource = null; StandardNavigationSource?currentSource = null; if (!string.IsNullOrEmpty(navigationModel.GlobalNavigationSource)) { globalSource = (StandardNavigationSource)Enum.Parse(typeof(StandardNavigationSource), navigationModel.GlobalNavigationSource); } if (!string.IsNullOrEmpty(navigationModel.CurrentNavigationSource)) { currentSource = (StandardNavigationSource)Enum.Parse(typeof(StandardNavigationSource), navigationModel.CurrentNavigationSource); } TermStore currentTermStore = null; TermSet currentTermSet = null; if (currentSource == StandardNavigationSource.TaxonomyProvider) { currentTermStore = TaxonomyTermStoreModelHandler.FindTermStore(site, navigationModel.CurrentNavigationTermStoreName, navigationModel.CurrentNavigationTermStoreId, navigationModel.CurrentNavigationUseDefaultSiteCollectionTermStore); currentTermSet = TaxonomyFieldModelHandler.LookupTermSet(currentTermStore.Context, currentTermStore, site, null, null, null, navigationModel.CurrentNavigationTermSetName, navigationModel.CurrentNavigationTermSetId, navigationModel.CurrentNavigationTermSetLCID); } TermStore globalTermStore = null; TermSet globalTermSet = null; if (globalSource == StandardNavigationSource.TaxonomyProvider) { globalTermStore = TaxonomyTermStoreModelHandler.FindTermStore(site, navigationModel.GlobalNavigationTermStoreName, navigationModel.GlobalNavigationTermStoreId, navigationModel.GlobalNavigationUseDefaultSiteCollectionTermStore); globalTermSet = TaxonomyFieldModelHandler.LookupTermSet(site.Context, globalTermStore, site, null, null, null, navigationModel.GlobalNavigationTermSetName, navigationModel.GlobalNavigationTermSetId, navigationModel.GlobalNavigationTermSetLCID); } InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = thisWebNavSettings, ObjectType = typeof(WebNavigationSettings), ObjectDefinition = navigationModel, ModelHost = modelHost }); if (!string.IsNullOrEmpty(navigationModel.GlobalNavigationSource) || !string.IsNullOrEmpty(navigationModel.CurrentNavigationSource)) { if (globalSource.HasValue) { TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Setting GlobalNavigation to: [{0}]", navigationModel.GlobalNavigationSource); thisWebNavSettings.GlobalNavigation.Source = globalSource.Value; if (globalTermStore != null) { thisWebNavSettings.GlobalNavigation.TermStoreId = globalTermStore.Id; thisWebNavSettings.GlobalNavigation.TermSetId = globalTermSet.Id; } else { int?globalNavigationIncludeTypes = GetGlobalNavigationIncludeTypes(navigationModel); if (globalNavigationIncludeTypes != null) { TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Setting GlobalNavigationIncludeTypes to: [{0}]", globalNavigationIncludeTypes); web.AllProperties[BuiltInWebPropertyId.GlobalNavigationIncludeTypes] = globalNavigationIncludeTypes; shouldUpdateWeb = true; } if (navigationModel.GlobalNavigationMaximumNumberOfDynamicItems.HasValue) { TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Setting GlobalDynamicChildLimit to: [{0}]", navigationModel.GlobalNavigationMaximumNumberOfDynamicItems.Value); web.AllProperties[BuiltInWebPropertyId.GlobalDynamicChildLimit] = navigationModel.GlobalNavigationMaximumNumberOfDynamicItems.Value; shouldUpdateWeb = true; } } } if (currentSource.HasValue) { TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Setting CurrentNavigation to: [{0}]", navigationModel.CurrentNavigationSource); thisWebNavSettings.CurrentNavigation.Source = currentSource.Value; if (currentTermStore != null) { thisWebNavSettings.CurrentNavigation.TermStoreId = currentTermStore.Id; thisWebNavSettings.CurrentNavigation.TermSetId = currentTermSet.Id; } else { int?currentNavigationIncludeTypes = GetCurrentNavigationIncludeTypes(navigationModel); if (currentNavigationIncludeTypes != null) { TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Setting CurrentNavigationIncludeTypes to: [{0}]", currentNavigationIncludeTypes); web.AllProperties[BuiltInWebPropertyId.CurrentNavigationIncludeTypes] = currentNavigationIncludeTypes; shouldUpdateWeb = true; } if (navigationModel.CurrentNavigationMaximumNumberOfDynamicItems.HasValue) { TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Setting CurrentDynamicChildLimit to: [{0}]", navigationModel.CurrentNavigationMaximumNumberOfDynamicItems.Value); web.AllProperties[BuiltInWebPropertyId.CurrentDynamicChildLimit] = navigationModel.CurrentNavigationMaximumNumberOfDynamicItems.Value; shouldUpdateWeb = true; } } } } if (navigationModel.DisplayShowHideRibbonAction.HasValue) { web.AllProperties["__DisplayShowHideRibbonActionId"] = navigationModel.DisplayShowHideRibbonAction.ToString(); shouldUpdateWeb = true; } InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = thisWebNavSettings, ObjectType = typeof(WebNavigationSettings), ObjectDefinition = navigationModel, ModelHost = modelHost }); if (!string.IsNullOrEmpty(navigationModel.GlobalNavigationSource) || !string.IsNullOrEmpty(navigationModel.CurrentNavigationSource)) { TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Updating navigation settings"); thisWebNavSettings.Update(null); context.ExecuteQueryWithTrace(); } // update include types if (shouldUpdateWeb) { TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Updating web"); web.Update(); context.ExecuteQueryWithTrace(); } }
public override void DeployModel(object modelHost, DefinitionBase model) { base.DeployModel(modelHost, model); var typedModelHost = modelHost.WithAssertAndCast <SiteModelHost>("modelHost", value => value.RequireNotNull()); var definition = model.WithAssertAndCast <TaxonomyFieldDefinition>("model", value => value.RequireNotNull()); var context = typedModelHost.HostClientContext; var site = typedModelHost.HostSite; var spObjectTmp = GetField(modelHost, definition); var spObject = spObjectTmp.Context.CastTo <TaxonomyField>(spObjectTmp); var assert = ServiceFactory.AssertService .NewAssert(definition, spObject) .ShouldNotBeNull(spObject) .ShouldBeEqual(m => m.IsMulti, o => o.AllowMultipleValues); if (definition.CreateValuesInEditForm.HasValue) { assert.ShouldBeEqual(m => m.CreateValuesInEditForm, o => o.CreateValuesInEditForm); } else { assert.SkipProperty(m => m.CreateValuesInEditForm, "CreateValuesInEditForm is null. Skipping property."); } if (definition.Open.HasValue) { assert.ShouldBeEqual(m => m.Open, o => o.Open); } else { assert.SkipProperty(m => m.Open, "Open is null. Skipping property."); } if (definition.IsPathRendered.HasValue) { assert.ShouldBeEqual(m => m.IsPathRendered, o => o.IsPathRendered); } else { assert.SkipProperty(m => m.IsPathRendered, "IsPathRendered is null. Skipping property."); } // SSP if (definition.SspId.HasValue) { assert.ShouldBeEqual(m => m.SspId, o => o.SspId); } else { assert.SkipProperty(m => m.SspId, "SspId is null. Skipping property."); } if (definition.UseDefaultSiteCollectionTermStore.HasValue && definition.UseDefaultSiteCollectionTermStore.Value) { var termStore = TaxonomyFieldModelHandler.LookupTermStore(typedModelHost, definition); var isValid = termStore.Id == spObject.SspId; assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.UseDefaultSiteCollectionTermStore); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.UseDefaultSiteCollectionTermStore, "UseDefaultSiteCollectionTermStore is null. Skipping property."); } if (!string.IsNullOrEmpty(definition.SspName)) { // TODO } else { assert.SkipProperty(m => m.SspName, "SspName is null. Skipping property."); } // is site collectiongroup if (definition.IsSiteCollectionGroup.HasValue && definition.IsSiteCollectionGroup.Value) { var termStore = TaxonomyFieldModelHandler.LookupTermStore(typedModelHost, definition); TermGroup group = null; // cause binding might be only by group AND (termset || term) var termSet = TaxonomyFieldModelHandler.LookupTermSet(context, context.Site, termStore, definition); var term = TaxonomyFieldModelHandler.LookupTerm(typedModelHost, termStore, definition); if (termSet != null) { group = termSet.Group; } else if (term != null) { group = term.TermSet.Group; } context.Load(group); context.ExecuteQuery(); var isValid = group.IsSiteCollectionGroup; assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.IsSiteCollectionGroup); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.IsSiteCollectionGroup, "IsSiteCollectionGroup is null. Skipping property."); } // term group if (definition.TermGroupId.HasValue) { var termStore = TaxonomyFieldModelHandler.LookupTermStore(typedModelHost, definition); TermGroup group = null; // cause binding might be only by group AND (termset || term) var termSet = TaxonomyFieldModelHandler.LookupTermSet(context, context.Site, termStore, definition); var term = TaxonomyFieldModelHandler.LookupTerm(typedModelHost, termStore, definition); if (termSet != null) { group = termSet.Group; } else if (term != null) { group = term.TermSet.Group; } context.Load(group); context.ExecuteQuery(); var isValid = group.Id == definition.TermGroupId; assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.TermGroupId); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.TermGroupId, "TermGroupId is null. Skipping property."); } if (!string.IsNullOrEmpty(definition.TermGroupName)) { var termStore = TaxonomyFieldModelHandler.LookupTermStore(typedModelHost, definition); TermGroup group = null; // cause binding might be only by group AND (termset || term) var termSet = TaxonomyFieldModelHandler.LookupTermSet(context, context.Site, termStore, definition); var term = TaxonomyFieldModelHandler.LookupTerm(typedModelHost, termStore, definition); if (termSet != null) { group = termSet.Group; } else if (term != null) { group = term.TermSet.Group; } context.Load(group); context.ExecuteQuery(); var isValid = group.Name == definition.TermGroupName; assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.TermGroupName); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.TermGroupName, "TermGroupName is null. Skipping property."); } // term set if (definition.TermSetId.HasValue) { assert.ShouldBeEqual(m => m.TermSetId, o => o.TermSetId); } else { assert.SkipProperty(m => m.TermSetId, "TermSetId is null. Skipping property."); } if (!string.IsNullOrEmpty(definition.TermSetName)) { var termStore = TaxonomyFieldModelHandler.LookupTermStore(typedModelHost, definition); var termSet = TaxonomyFieldModelHandler.LookupTermSet(typedModelHost, termStore, definition); var isValid = spObject.TermSetId == termSet.Id; assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.TermSetName); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.TermSetName, "TermSetName is null. Skipping property."); } if (definition.TermId.HasValue) { assert.ShouldBeEqual(m => m.TermId, o => o.AnchorId); } else { assert.SkipProperty(m => m.TermId, "TermId is null. Skipping property."); } if (!string.IsNullOrEmpty(definition.TermName)) { var termStore = TaxonomyFieldModelHandler.LookupTermStore(typedModelHost, definition); var term = TaxonomyFieldModelHandler.LookupTerm(typedModelHost, termStore, definition); var isValid = spObject.AnchorId == term.Id; assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.TermName); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.TermName, "TermName is null. Skipping property."); } // etc assert.SkipProperty(m => m.TermLCID, "TermLCID. Skipping property."); assert.SkipProperty(m => m.TermSetLCID, "TermSetLCID. Skipping property."); }