protected StepOrTransformCallerBase(TypeCaster typeCaster, DefinitionBase definition) { CompiledRegex = definition.Regex; DelegateToInvoke = definition.Action; InputParameterTypes = definition.InputParamsTypes.ToArray(); this.typeCaster = typeCaster; }
public static ModelNode AddDefinitionNodeWithOptions(this ModelNode node, DefinitionBase definition, Action<ModelNode> action, ModelNodeOptions options) { var modelNode = new ModelNode { Value = definition }; // TODO, should be extend later if (options != null) { modelNode.Options = options; //definition.RequireSelfProcessing = options.RequireSelfProcessing; } node.ChildModels.Add(modelNode); if (action != null) action(modelNode); return node; }
public virtual void WithResolvingModelHost(object modelHost, DefinitionBase model, Type childModelType, Action <object> action) { action(modelHost); }
public override void DeployModel(object modelHost, DefinitionBase model) { // CSOM provision for DependentLookupFieldDefinition does not update these props // seems to be a by design SharePoin issue // https://github.com/SubPointSolutions/spmeta2/issues/753 this.SkipAllowMultipleValuesValidation = true; this.SkipFieldTypeValidation = true; this.SkipLookupFieldValidation = true; this.ModelHost = modelHost; base.DeployModel(modelHost, model); var definition = model.WithAssertAndCast <FieldDefinition>("model", value => value.RequireNotNull()); var spObject = GetField(modelHost, definition); var typedField = spObject.Context.CastTo <FieldLookup>(spObject); var typedDefinition = model.WithAssertAndCast <DependentLookupFieldDefinition>("model", value => value.RequireNotNull()); var typedFieldAssert = ServiceFactory.AssertService.NewAssert(model, typedDefinition, typedField); var context = spObject.Context; typedFieldAssert.SkipProperty(m => m.RelationshipDeleteBehavior, "DependentLookupFieldDefinition"); // binding var fields = FieldLookupService.GetFieldCollection(this.ModelHost); FieldLookup primaryLookupField = null; if (typedDefinition.PrimaryLookupFieldId.HasGuidValue()) { primaryLookupField = FieldLookupService.GetFieldAs <FieldLookup>(fields, typedDefinition.PrimaryLookupFieldId.Value, null, null); typedFieldAssert.ShouldNotBeNull(primaryLookupField); typedFieldAssert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.PrimaryLookupFieldId); var isValid = primaryLookupField.Id == new Guid(typedField.PrimaryFieldId); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { typedFieldAssert.SkipProperty(m => m.PrimaryLookupFieldId, "PrimaryLookupFieldId is NULL. Skipping."); } if (!string.IsNullOrEmpty(typedDefinition.PrimaryLookupFieldInternalName)) { primaryLookupField = FieldLookupService.GetFieldAs <FieldLookup>(fields, null, typedDefinition.PrimaryLookupFieldInternalName, null); typedFieldAssert.ShouldNotBeNull(primaryLookupField); typedFieldAssert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.PrimaryLookupFieldInternalName); var isValid = primaryLookupField.Id == new Guid(typedField.PrimaryFieldId); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { typedFieldAssert.SkipProperty(m => m.PrimaryLookupFieldInternalName, "PrimaryLookupFieldInternalName is NULL. Skipping."); } if (!string.IsNullOrEmpty(typedDefinition.PrimaryLookupFieldTitle)) { primaryLookupField = FieldLookupService.GetFieldAs <FieldLookup>(fields, null, null, typedDefinition.PrimaryLookupFieldTitle); typedFieldAssert.ShouldNotBeNull(primaryLookupField); typedFieldAssert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.PrimaryLookupFieldTitle); var isValid = primaryLookupField.Id == new Guid(typedField.PrimaryFieldId); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { typedFieldAssert.SkipProperty(m => m.PrimaryLookupFieldTitle, "PrimaryLookupFieldInternalName is NULL. Skipping."); } }
public static ModelNode AddDefinitionNode(this ModelNode node, DefinitionBase definition, Action<ModelNode> action) { return AddDefinitionNodeWithOptions(node, definition, action, null); }
public override void DeployModel(object modelHost, DefinitionBase model) { var securableObject = ExtractSecurableObject(modelHost); var definition = model.WithAssertAndCast <SecurityGroupLinkDefinition>("model", value => value.RequireNotNull()); var web = GetWebFromSPSecurableObject(securableObject); var spObject = ResolveSecurityGroup(web, definition); var assert = ServiceFactory.AssertService .NewAssert(definition, spObject) .ShouldNotBeNull(spObject); if (!string.IsNullOrEmpty(definition.SecurityGroupName)) { assert.ShouldBeEqual(m => m.SecurityGroupName, o => o.Name); } else { assert.SkipProperty(m => m.SecurityGroupName, "SecurityGroupName is null or empty. Skipping."); } if (definition.IsAssociatedMemberGroup) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.IsAssociatedMemberGroup); var dstProp = d.GetExpressionValue(o => o.GetAssociatedMemberGroup()); var isValid = spObject.ID == web.AssociatedMemberGroup.ID; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.IsAssociatedMemberGroup, "IsAssociatedMemberGroup is false. Skipping."); } if (definition.IsAssociatedOwnerGroup) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.IsAssociatedOwnerGroup); var dstProp = d.GetExpressionValue(o => o.GetAssociatedOwnerGroup()); var isValid = spObject.ID == web.AssociatedOwnerGroup.ID; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.IsAssociatedOwnerGroup, "IsAssociatedOwnerGroup is false. Skipping."); } if (definition.IsAssociatedVisitorGroup) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.IsAssociatedVisitorGroup); var dstProp = d.GetExpressionValue(o => o.GetAssociatedVisitorGroup()); var isValid = spObject.ID == web.AssociatedVisitorGroup.ID; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.IsAssociatedVisitorGroup, "IsAssociatedVisitorsGroup is false. Skipping."); } }
public override void DeployModel(object modelHost, DefinitionBase model) { // TODO }
public override void DeployModel(object modelHost, DefinitionBase model) { var securityGroupModelHost = modelHost.WithAssertAndCast <SecurityGroupModelHost>("modelHost", value => value.RequireNotNull()); var definition = model.WithAssertAndCast <SecurityRoleLinkDefinition>("model", value => value.RequireNotNull()); var securableObject = securityGroupModelHost.SecurableObject; var securityGroup = securityGroupModelHost.SecurityGroup; var securityRole = ResolveSecurityRole(ExtractWeb(securableObject), definition); var securityRoleContext = securityRole.Context; securityRoleContext.Load(securityRole); securityRoleContext.ExecuteQueryWithTrace(); var roleAssignments = securableObject.RoleAssignments; securityRoleContext.Load(roleAssignments, d => d.Include(c => c.Member)); securityRoleContext.ExecuteQueryWithTrace(); var spObject = roleAssignments.ToArray() .FirstOrDefault(r => r.Member.Id == securityGroup.Id); if (definition.RegIsMustBeSingleItem()) { if (roleAssignments.Count != 1) { throw new SPMeta2Exception("There must be only one RoleAssignments. RegIsMustBeSingleItem() == true"); } } var context = spObject.Context; context.Load(spObject, o => o.RoleDefinitionBindings); context.ExecuteQueryWithTrace(); var assert = ServiceFactory.AssertService.NewAssert(definition, spObject); assert .ShouldNotBeNull(spObject); if (!string.IsNullOrEmpty(definition.SecurityRoleName)) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.SecurityRoleName); var dstProp = d.GetExpressionValue(o => o.RoleDefinitionBindings.ToString()); var hasRoleDefinitionBinding = spObject.RoleDefinitionBindings .FirstOrDefault(b => b.Id == securityRole.Id) != null; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = hasRoleDefinitionBinding }); }); } else { assert.SkipProperty(m => m.SecurityRoleName, "SecurityRoleName is null or empty. Skipping."); } if (!string.IsNullOrEmpty(definition.SecurityRoleType)) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.SecurityRoleType); var dstProp = d.GetExpressionValue(o => o.RoleDefinitionBindings.ToString()); var hasRoleDefinitionBinding = spObject.RoleDefinitionBindings .FirstOrDefault(b => b.Id == securityRole.Id) != null; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = hasRoleDefinitionBinding }); }); } else { assert.SkipProperty(m => m.SecurityRoleType, "SecurityRoleType is null or empty. Skipping."); } if (definition.SecurityRoleId > 0) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.SecurityRoleId); var dstProp = d.GetExpressionValue(o => o.RoleDefinitionBindings.ToString()); var hasRoleDefinitionBinding = spObject.RoleDefinitionBindings .FirstOrDefault(b => b.Id == securityRole.Id) != null; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = hasRoleDefinitionBinding }); }); } else { assert.SkipProperty(m => m.SecurityRoleId, "SecurityRoleId == 0. Skipping."); } }
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."); } // is site collectiongroup if (definition.IsSiteCollectionGroup.HasValue && definition.IsSiteCollectionGroup.Value) { var termStore = TaxonomyFieldModelHandler.LookupTermStore(site, definition); Group group = null; // cause binding might be only by group AND (termset || term) var termSet = TaxonomyFieldModelHandler.LookupTermSet(site, termStore, definition); var term = TaxonomyFieldModelHandler.LookupTerm(site, termStore, definition); if (termSet != null) { group = termSet.Group; } else if (term != null) { group = term.TermSet.Group; } 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(site, definition); Group group = null; // cause binding might be only by group AND (termset || term) var termSet = TaxonomyFieldModelHandler.LookupTermSet(site, termStore, definition); var term = TaxonomyFieldModelHandler.LookupTerm(site, termStore, definition); if (termSet != null) { group = termSet.Group; } else if (term != null) { group = term.TermSet.Group; } 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(site, definition); Group group = null; // cause binding might be only by group AND (termset || term) var termSet = TaxonomyFieldModelHandler.LookupTermSet(site, termStore, definition); var term = TaxonomyFieldModelHandler.LookupTerm(site, termStore, definition); if (termSet != null) { group = termSet.Group; } else if (term != null) { group = term.TermSet.Group; } 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(site, definition); var termSet = TaxonomyFieldModelHandler.LookupTermSet(site, 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(site, 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."); }
public override void DeployModel(object modelHost, DefinitionBase model) { var listModelHost = modelHost.WithAssertAndCast <ListModelHost>("modelHost", value => value.RequireNotNull()); var contentTypeLinkModel = model.WithAssertAndCast <ContentTypeLinkDefinition>("model", value => value.RequireNotNull()); var list = listModelHost.HostList; var context = list.Context; context.Load(list, l => l.ContentTypesEnabled); context.ExecuteQueryWithTrace(); if (list.ContentTypesEnabled) { TraceService.Information((int)LogEventId.ModelProvisionCoreCall, "ContentTypesEnabled is TRUE. Processing content type link"); var web = list.ParentWeb; // context.Load(web, w => w.AvailableContentTypes); context.Load(list, l => l.ContentTypes); context.ExecuteQueryWithTrace(); var targetContentType = web.AvailableContentTypes.GetById(contentTypeLinkModel.ContentTypeId); var listContentType = FindListContentType(list, contentTypeLinkModel); context.Load(targetContentType); context.ExecuteQueryWithTrace(); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = listContentType, ObjectType = typeof(ContentType), ObjectDefinition = model, ModelHost = modelHost }); if (targetContentType != null && listContentType == null) { TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new list content type link"); var ct = list.ContentTypes.Add(new ContentTypeCreationInformation { Description = targetContentType.Description, Group = targetContentType.Group, Name = targetContentType.Name, ParentContentType = targetContentType, }); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = ct, ObjectType = typeof(ContentType), ObjectDefinition = model, ModelHost = modelHost }); TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "list.Update()"); list.Update(); context.ExecuteQueryWithTrace(); } else { TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing list content type link"); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = listContentType, ObjectType = typeof(ContentType), ObjectDefinition = model, ModelHost = modelHost }); TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "listContentType.Update(false)"); // no update is required for content type link // besides, CTH wouldn't work // .AddContentTypeLink() should work well with the read-only content types (Content Type Hub) // https://github.com/SubPointSolutions/spmeta2/issues/745 // listContentType.Update(false); // context.ExecuteQueryWithTrace(); } } else { TraceService.Information((int)LogEventId.ModelProvisionCoreCall, "ContentTypesEnabled is FALSE. Provision might break."); } }
public override void DeployModel(object modelHost, DefinitionBase model) { base.DeployModel(modelHost, model); var listItemModelHost = modelHost.WithAssertAndCast <ListItemModelHost>("modelHost", value => value.RequireNotNull()); var definition = model.WithAssertAndCast <ContentByQueryWebPartDefinition>("model", value => value.RequireNotNull()); var pageItem = listItemModelHost.HostListItem; WithExistingWebPart(listItemModelHost.HostFile, definition, spObject => { var assert = ServiceFactory.AssertService .NewAssert(model, definition, spObject) .ShouldNotBeNull(spObject); if (!string.IsNullOrEmpty(definition.ContentTypeBeginsWithId)) { throw new NotImplementedException(); } else { assert.SkipProperty(m => m.ContentTypeBeginsWithId, "ContentTypeBeginsWithId is null or empty, skipping."); } // mappings if (!string.IsNullOrEmpty(definition.DataMappings)) { throw new NotImplementedException(); } else { assert.SkipProperty(m => m.DataMappings, "DataMappings is null or empty, skipping."); } if (!string.IsNullOrEmpty(definition.DataMappingViewFields)) { throw new NotImplementedException(); } else { assert.SkipProperty(m => m.DataMappingViewFields, "DataMappingViewFields is null or empty, skipping."); } // filter display values if (!string.IsNullOrEmpty(definition.FilterDisplayValue1)) { throw new NotImplementedException(); } else { assert.SkipProperty(m => m.FilterDisplayValue1, "FilterDisplayValue1 is null or empty, skipping."); } if (!string.IsNullOrEmpty(definition.FilterDisplayValue2)) { throw new NotImplementedException(); } else { assert.SkipProperty(m => m.FilterDisplayValue2, "FilterDisplayValue2 is null or empty, skipping."); } if (!string.IsNullOrEmpty(definition.FilterDisplayValue3)) { throw new NotImplementedException(); } else { assert.SkipProperty(m => m.FilterDisplayValue3, "FilterDisplayValue3 is null or empty, skipping."); } // filter operator if (!string.IsNullOrEmpty(definition.FilterOperator1)) { throw new NotImplementedException(); } else { assert.SkipProperty(m => m.FilterOperator1, "FilterOperator1 is null or empty, skipping."); } if (!string.IsNullOrEmpty(definition.FilterOperator2)) { throw new NotImplementedException(); } else { assert.SkipProperty(m => m.FilterOperator2, "FilterOperator2 is null or empty, skipping."); } if (!string.IsNullOrEmpty(definition.FilterOperator3)) { throw new NotImplementedException(); } else { assert.SkipProperty(m => m.FilterOperator3, "FilterOperator3 is null or empty, skipping."); } // filter types if (!string.IsNullOrEmpty(definition.FilterType1)) { throw new NotImplementedException(); } else { assert.SkipProperty(m => m.FilterType1, "FilterType1 is null or empty, skipping."); } if (!string.IsNullOrEmpty(definition.FilterType2)) { throw new NotImplementedException(); } else { assert.SkipProperty(m => m.FilterType2, "FilterType2 is null or empty, skipping."); } if (!string.IsNullOrEmpty(definition.FilterType3)) { throw new NotImplementedException(); } else { assert.SkipProperty(m => m.FilterType3, "FilterType3 is null or empty, skipping."); } if (!string.IsNullOrEmpty(definition.SortBy)) { // TODO } else { assert.SkipProperty(m => m.SortBy, "SortBy is null or empty, skipping."); } if (!string.IsNullOrEmpty(definition.SortByFieldType)) { // TODO } else { assert.SkipProperty(m => m.SortByFieldType, "SortByFieldType is null or empty, skipping."); } if (!string.IsNullOrEmpty(definition.SortByDirection)) { // TODO } else { assert.SkipProperty(m => m.SortByDirection, "SortByDirection is null or empty, skipping."); } // filter values if (!string.IsNullOrEmpty(definition.FilterValue1)) { throw new NotImplementedException(); } else { assert.SkipProperty(m => m.FilterValue1, "FilterValue1 is null or empty, skipping."); } if (!string.IsNullOrEmpty(definition.FilterValue2)) { throw new NotImplementedException(); } else { assert.SkipProperty(m => m.FilterValue2, "FilterValue2 is null or empty, skipping."); } if (!string.IsNullOrEmpty(definition.FilterValue3)) { throw new NotImplementedException(); } else { assert.SkipProperty(m => m.FilterValue3, "FilterValue3 is null or empty, skipping."); } // styles if (!string.IsNullOrEmpty(definition.GroupStyle)) { throw new NotImplementedException(); } else { assert.SkipProperty(m => m.GroupStyle, "GroupStyle is null or empty, skipping."); } if (!string.IsNullOrEmpty(definition.ItemStyle)) { throw new NotImplementedException(); } else { assert.SkipProperty(m => m.ItemStyle, "ItemStyle is null or empty, skipping."); } if (!string.IsNullOrEmpty(definition.ItemXslLink)) { throw new NotImplementedException(); } else { assert.SkipProperty(m => m.ItemXslLink, "ItemXslLink is null or empty, skipping."); } if (!string.IsNullOrEmpty(definition.MainXslLink)) { throw new NotImplementedException(); } else { assert.SkipProperty(m => m.MainXslLink, "MainXslLink is null or empty, skipping."); } // list bindings if (!string.IsNullOrEmpty(definition.WebUrl)) { throw new NotImplementedException(); } else { assert.SkipProperty(m => m.WebUrl, "WebUrl is null or empty, skipping."); } if (definition.ListGuid.HasGuidValue()) { throw new NotImplementedException(); } else { assert.SkipProperty(m => m.ListGuid, "ListGuid is null or empty, skipping."); } if (!string.IsNullOrEmpty(definition.ListName)) { throw new NotImplementedException(); } else { assert.SkipProperty(m => m.ListName, "ListName is null or empty, skipping."); } if (!string.IsNullOrEmpty(definition.ListUrl)) { throw new NotImplementedException(); } else { assert.SkipProperty(m => m.ListUrl, "ListUrl is null or empty, skipping."); } // misc if (definition.ServerTemplate.HasValue) { throw new NotImplementedException(); } else { assert.SkipProperty(m => m.ServerTemplate, "ServerTemplate is null or empty, skipping."); } if (definition.ItemLimit.HasValue) { throw new NotImplementedException(); } else { assert.SkipProperty(m => m.ItemLimit, "ItemLimit is null or empty, skipping."); } if (definition.PlayMediaInBrowser.HasValue) { throw new NotImplementedException(); } else { assert.SkipProperty(m => m.PlayMediaInBrowser, "PlayMediaInBrowser is null or empty, skipping."); } if (definition.ShowUntargetedItems.HasValue) { throw new NotImplementedException(); } else { assert.SkipProperty(m => m.ShowUntargetedItems, "ShowUntargetedItems is null or empty, skipping."); } if (definition.UseCopyUtil.HasValue) { throw new NotImplementedException(); } else { assert.SkipProperty(m => m.UseCopyUtil, "UseCopyUtil is null or empty, skipping."); } }); }
public override void DeployModel(object modelHost, DefinitionBase model) { var webModelHost = modelHost.WithAssertAndCast <SiteModelHost>("modelHost", value => value.RequireNotNull()); var web = webModelHost.HostSite.RootWeb; var securityRoleModel = model.WithAssertAndCast <SecurityRoleDefinition>("model", value => value.RequireNotNull()); var context = web.Context; var roleDefinitions = web.RoleDefinitions; context.Load(roleDefinitions); context.ExecuteQueryWithTrace(); var currentRoleDefinition = FindRoleDefinition(roleDefinitions, securityRoleModel.Name); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = currentRoleDefinition, ObjectType = typeof(RoleDefinition), ObjectDefinition = model, ModelHost = modelHost }); var basePermissions = new BasePermissions(); foreach (var permissionString in securityRoleModel.BasePermissions) { basePermissions.Set((PermissionKind)Enum.Parse(typeof(PermissionKind), permissionString)); } if (currentRoleDefinition == null) { TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new security role"); currentRoleDefinition = roleDefinitions.Add(new RoleDefinitionCreationInformation { Name = securityRoleModel.Name, BasePermissions = basePermissions, Description = securityRoleModel.Description ?? string.Empty }); } else { TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing security role"); } // SPBug, // something wrong with setting up BasePermissions.Set() method up // so, a new object has to be assigned every time currentRoleDefinition.BasePermissions = basePermissions; InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = currentRoleDefinition, ObjectType = typeof(RoleDefinition), ObjectDefinition = model, ModelHost = modelHost }); currentRoleDefinition.Update(); context.ExecuteQueryWithTrace(); }
public override void DeployModel(object modelHost, DefinitionBase model) { var folderHost = modelHost.WithAssertAndCast <FolderModelHost>("modelHost", value => value.RequireNotNull()); var definition = model.WithAssertAndCast <ModuleFileDefinition>("model", value => value.RequireNotNull()); var stringCustomContentType = string.Empty; if (!string.IsNullOrEmpty(definition.ContentTypeName) || !string.IsNullOrEmpty(definition.ContentTypeId)) { stringCustomContentType = ResolveContentTypeId(folderHost, definition); } var folder = folderHost.CurrentListFolder; var spObject = GetFile(folderHost, definition); if (folderHost.CurrentList != null) { if (!spObject.IsObjectPropertyInstantiated("ListItemAllFields")) { spObject.Context.Load(spObject, o => o.ListItemAllFields); } } if (!spObject.IsObjectPropertyInstantiated("Name")) { spObject.Context.Load(spObject, o => o.Name); } if (!spObject.IsObjectPropertyInstantiated("ServerRelativeUrl")) { spObject.Context.Load(spObject, o => o.ServerRelativeUrl); } spObject.Context.ExecuteQueryWithTrace(); var assert = ServiceFactory.AssertService .NewAssert(definition, spObject) .ShouldNotBeNull(spObject) .ShouldBeEqual(m => m.FileName, o => o.Name); if (!string.IsNullOrEmpty(definition.ContentTypeId)) { // TODO } else { assert.SkipProperty(m => m.ContentTypeId, "ContentTypeId is null or empty. Skipping."); } if (!string.IsNullOrEmpty(definition.ContentTypeName)) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.ContentTypeName); var currentContentTypeName = d.ListItemAllFields["ContentTypeId"].ToString(); var isValis = stringCustomContentType == currentContentTypeName; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValis }); }); } else { assert.SkipProperty(m => m.ContentTypeName, "ContentTypeName is null or empty. Skipping."); } if (definition.DefaultValues.Count > 0) { assert.ShouldBeEqual((p, s, d) => { var isValid = true; foreach (var srcValue in s.DefaultValues) { // big TODO here for == != if (!string.IsNullOrEmpty(srcValue.FieldName)) { if (d.ListItemAllFields[srcValue.FieldName].ToString() != srcValue.Value.ToString()) { isValid = false; } } if (!isValid) { break; } } var srcProp = s.GetExpressionValue(def => def.DefaultValues); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.DefaultValues, "DefaultValues.Count == 0. Skipping."); } // skip all templates if (definition.FileName.ToUpper().EndsWith("DOTX")) { assert.SkipProperty(m => m.Content, "DOTX file is detected. Skipping."); } else { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.Content); //var dstProp = d.GetExpressionValue(ct => ct.GetId()); var isContentValid = false; byte[] dstContent = null; using (var stream = File.OpenBinaryDirect(folderHost.HostClientContext, spObject.ServerRelativeUrl).Stream) dstContent = ModuleFileUtils.ReadFully(stream); isContentValid = dstContent.SequenceEqual(definition.Content); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, // Dst = dstProp, IsValid = isContentValid }); }); } }
public override void DeployModel(object modelHost, DefinitionBase model) { if (modelHost is SiteModelHost) { var webModelHost = modelHost.WithAssertAndCast <SiteModelHost>("modelHost", value => value.RequireNotNull()); var web = webModelHost.HostSite.RootWeb; var definition = model as SecurityGroupDefinition; 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); context.ExecuteQueryWithTrace(); var spObject = FindSecurityGroupByTitle(web.SiteGroups, definition.Name); var assert = ServiceFactory.AssertService .NewAssert(definition, spObject) .ShouldNotBeNull(spObject) .ShouldBeEqual(m => m.Name, o => o.Title) .ShouldBeEqual(m => m.OnlyAllowMembersViewMembership, o => o.OnlyAllowMembersViewMembership) .ShouldBeEqualIfNotNullOrEmpty(m => m.Description, o => o.Description) .ShouldBeEqualIfHasValue(m => m.AllowMembersEditMembership, o => o.AllowMembersEditMembership) .ShouldBeEqualIfHasValue(m => m.AllowRequestToJoinLeave, o => o.AllowRequestToJoinLeave) .ShouldBeEqualIfHasValue(m => m.AutoAcceptRequestToJoinLeave, o => o.AutoAcceptRequestToJoinLeave) .ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.Owner); var dstProp = d.GetExpressionValue(ct => ct.GetOwnerLogin()); var isValid = dstProp.Value.ToString().ToUpper().Replace("\\", "/").EndsWith( srcProp.Value.ToString().ToUpper().Replace("\\", "/")); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValid }); }) .SkipProperty(m => m.DefaultUser, "DefaultUser cannot be setup via CSOM API. Skipping."); } else if (modelHost is SecurityGroupModelHost) { // skip everything, just check if the group is therw var securityGroupModelHost = modelHost.WithAssertAndCast <SecurityGroupModelHost>("modelHost", value => value.RequireNotNull()); var definition = model.WithAssertAndCast <SecurityGroupDefinition>("model", value => value.RequireNotNull()); var context = securityGroupModelHost.HostClientContext; var currentGroup = securityGroupModelHost.SecurityGroup; var subGroup = securityGroupModelHost.HostWeb.EnsureUser(definition.Name); context.Load(subGroup); context.Load(currentGroup, g => g.Users); context.ExecuteQueryWithTrace(); var spObject = currentGroup.Users.FirstOrDefault(u => u.Id == subGroup.Id); var assert = ServiceFactory.AssertService.NewAssert(definition, spObject); assert .ShouldNotBeNull(spObject) .SkipProperty(m => m.Name) .SkipProperty(m => m.AllowMembersEditMembership) .SkipProperty(m => m.AllowRequestToJoinLeave) .SkipProperty(m => m.AutoAcceptRequestToJoinLeave) .SkipProperty(m => m.DefaultUser) .SkipProperty(m => m.Description) .SkipProperty(m => m.IsAssociatedMemberGroup) .SkipProperty(m => m.IsAssociatedVisitorsGroup) .SkipProperty(m => m.IsAssociatedOwnerGroup) .SkipProperty(m => m.OnlyAllowMembersViewMembership) .SkipProperty(m => m.Owner); } else { throw new SPMeta2UnsupportedModelHostException("modelHost"); } //assert.ShouldBeEqual((p, s, d) => //{ // var srcProp = s.GetExpressionValue(def => def.DefaultUser); // var dstProp = d.GetExpressionValue(ct => ct.GetDefaultUserLoginName()); // var isValid = srcProp.Value.ToString().Replace("\\", "/") == // dstProp.Value.ToString().Replace("\\", "/"); // return new PropertyValidationResult // { // Tag = p.Tag, // Src = srcProp, // Dst = dstProp, // IsValid = isValid // }; //}); }
public override void DeployModel(object modelHost, DefinitionBase model) { base.DeployModel(modelHost, model); var listModelHost = modelHost.WithAssertAndCast <FolderModelHost>("modelHost", value => value.RequireNotNull()); var definition = model.WithAssertAndCast <ControlDisplayTemplateDefinition>("model", value => value.RequireNotNull()); var folder = listModelHost.CurrentLibraryFolder; var spObject = GetCurrentObject(folder, definition); var file = spObject.File; var assert = ServiceFactory.AssertService .NewAssert(definition, spObject); #region crawler xslt file if (!string.IsNullOrEmpty(definition.CrawlerXSLFileURL)) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.CrawlerXSLFileURL); var isValid = d.GetCrawlerXSLFile().Url == s.CrawlerXSLFileURL; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.CrawlerXSLFileURL, "PreviewURL is NULL. Skipping"); } if (!string.IsNullOrEmpty(definition.CrawlerXSLFileDescription)) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.CrawlerXSLFileDescription); var isValid = d.GetCrawlerXSLFile().Description == s.CrawlerXSLFileDescription; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.CrawlerXSLFileDescription, "PreviewDescription is NULL. Skipping"); } #endregion assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.Content); //var dstProp = d.GetExpressionValue(ct => ct.GetId()); var isContentValid = false; var srcStringContent = Encoding.UTF8.GetString(s.Content); var dstStringContent = Encoding.UTF8.GetString(file.GetContent()); isContentValid = dstStringContent.Contains(srcStringContent); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, // Dst = dstProp, IsValid = isContentValid }); }); }
public override void DeployModel(object modelHost, DefinitionBase model) { var webModel = model.WithAssertAndCast <SupportedUICultureDefinition>("model", value => value.RequireNotNull()); var typedHost = modelHost.WithAssertAndCast <WebModelHost>("model", value => value.RequireNotNull()); var web = typedHost.HostWeb; var context = web.Context; context.Load(web); context.Load(web, w => w.SupportedUILanguageIds); context.ExecuteQuery(); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = web, ObjectType = typeof(Web), ObjectDefinition = model, ModelHost = modelHost }); var shouldUpdate = false; var currentLanguages = web.SupportedUILanguageIds; if (!currentLanguages.Contains(webModel.LCID)) { // if running nice CSOM, so that method is there and a few web's props var supportedRuntime = ReflectionUtils.HasProperty(web, "IsMultilingual") && ReflectionUtils.HasMethod(web, "AddSupportedUILanguage"); if (supportedRuntime) { // TODO, wrap up into extensions // that's the trick to get all working on CSOM SP2013 SP1+ // once props are there, we setup them // if not, giving critical messages in logs // pushing IsMultilingual to true if false var objectData = GetPropertyValue(web, "ObjectData"); var objectProperties = GetPropertyValue(objectData, "Properties") as Dictionary <string, object>; var isMultilingual = Convert.ToBoolean(objectProperties["IsMultilingual"]); if (!isMultilingual) { ClientRuntimeQueryService.SetProperty(web, "IsMultilingual", true); } // adding languages ClientRuntimeQueryService.InvokeMethod(web, "AddSupportedUILanguage", webModel.LCID); // upating the web web.Update(); shouldUpdate = true; } else { TraceService.Critical((int)LogEventId.ModelProvisionCoreCall, "CSOM runtime doesn't have Web.IsMultilingual and Web.AddSupportedUILanguage() methods support. Update CSOM runtime to a new version. SupportedUILanguage provision is skipped"); } } InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = web, ObjectType = typeof(Web), ObjectDefinition = model, ModelHost = modelHost }); if (shouldUpdate) { context.ExecuteQueryWithTrace(); } }
public SpellStart(DefinitionBase pDefinition) { definition = pDefinition; //definition.InitLog(); }
public override void DeployModel(object modelHost, DefinitionBase model) { var definition = model.WithAssertAndCast <UserCustomActionDefinition>("model", value => value.RequireNotNull()); var spObject = GetCurrentCustomUserAction(modelHost, definition); var assert = ServiceFactory.AssertService .NewAssert(definition, definition, spObject) .ShouldBeEqual(m => m.Name, o => o.Name) .ShouldBeEqual(m => m.Title, o => o.Title) .ShouldBeEqual(m => m.Description, o => o.Description) .ShouldBeEqual(m => m.Group, o => o.Group) .ShouldBeEqual(m => m.Location, o => o.Location) .ShouldBeEqual(m => m.ScriptSrc, o => o.ScriptSrc) .ShouldBeEqual(m => m.ScriptBlock, o => o.ScriptBlock) .ShouldBeEqual(m => m.Sequence, o => o.Sequence) .ShouldBeEqual(m => m.Url, o => o.Url) //.ShouldBeEqual(m => m.RegistrationId, o => o.RegistrationId) .ShouldBeEqual(m => m.RegistrationType, o => o.GetRegistrationType()); var context = spObject.Context; var registrationIdIsGuid = ConvertUtils.ToGuid(spObject.RegistrationId); if (registrationIdIsGuid.HasValue) { // this is list scoped user custom action reg // skipping validation assert.SkipProperty(m => m.RegistrationId, "RegistrationId is GUID. List scope user custom action. Skipping validation."); } else { assert.ShouldBeEqual(m => m.RegistrationId, o => o.RegistrationId); } if (!string.IsNullOrEmpty(definition.CommandUIExtension)) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.CommandUIExtension); var dstProp = d.GetExpressionValue(ct => ct.CommandUIExtension); var isValid = GetCommandUIString(srcProp.Value.ToString()) == GetCommandUIString(dstProp.Value.ToString()); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.CommandUIExtension, "CommandUIExtension is null or empty. Skipping."); } assert .ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.Rights); var dstProp = d.GetExpressionValue(ct => ct.Rights); var hasCorrectRights = true; foreach (var srcRight in s.Rights) { var srcPermission = (PermissionKind)Enum.Parse(typeof(PermissionKind), srcRight); var tmpRight = d.Rights.Has(srcPermission); if (tmpRight == false) { hasCorrectRights = false; } } return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = hasCorrectRights }); }); var supportsLocalization = ReflectionUtils.HasProperties(spObject, new[] { "TitleResource", "DescriptionResource", "CommandUIExtensionResource" }); if (supportsLocalization) { if (definition.TitleResource.Any()) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.TitleResource); var isValid = true; foreach (var userResource in s.TitleResource) { var culture = LocalizationService.GetUserResourceCultureInfo(userResource); var resourceObject = ReflectionUtils.GetPropertyValue(spObject, "TitleResource"); var value = ReflectionUtils.GetMethod(resourceObject, "GetValueForUICulture") .Invoke(resourceObject, new[] { culture.Name }) as ClientResult <string>; context.ExecuteQuery(); isValid = userResource.Value == value.Value; if (!isValid) { break; } } return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.TitleResource, "TitleResource is NULL or empty. Skipping."); } if (definition.DescriptionResource.Any()) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.DescriptionResource); var isValid = true; foreach (var userResource in s.DescriptionResource) { var culture = LocalizationService.GetUserResourceCultureInfo(userResource); var resourceObject = ReflectionUtils.GetPropertyValue(spObject, "DescriptionResource"); var value = ReflectionUtils.GetMethod(resourceObject, "GetValueForUICulture") .Invoke(resourceObject, new[] { culture.Name }) as ClientResult <string>; context.ExecuteQuery(); isValid = userResource.Value == value.Value; if (!isValid) { break; } } return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.DescriptionResource, "DescriptionResource is NULL or empty. Skipping."); } if (definition.CommandUIExtensionResource.Any()) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.CommandUIExtensionResource); var isValid = true; foreach (var userResource in s.CommandUIExtensionResource) { var culture = LocalizationService.GetUserResourceCultureInfo(userResource); var resourceObject = ReflectionUtils.GetPropertyValue(spObject, "CommandUIExtensionResource"); var value = ReflectionUtils.GetMethod(resourceObject, "GetValueForUICulture") .Invoke(resourceObject, new[] { culture.Name }) as ClientResult <string>; context.ExecuteQuery(); isValid = GetCommandUIString(userResource.Value) == GetCommandUIString(value.Value); if (!isValid) { break; } } return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.CommandUIExtensionResource, "DescriptionResource is NULL or empty. Skipping."); } } else { TraceService.Critical((int)LogEventId.ModelProvisionCoreCall, "CSOM runtime doesn't have Web.TitleResource and Web.DescriptionResource() methods support. Skipping validation."); assert.SkipProperty(m => m.TitleResource, "TitleResource is null or empty. Skipping."); assert.SkipProperty(m => m.DescriptionResource, "DescriptionResource is null or empty. Skipping."); assert.SkipProperty(m => m.CommandUIExtensionResource, "CommandUIExtensionResource is null or empty. Skipping."); } }
/// <summary> /// Handles model provision under particular modelHost. /// </summary> /// <param name="modelHost"></param> /// <param name="model"></param> public virtual void DeployModel(object modelHost, DefinitionBase model) { }
public override void DeployModel(object modelHost, DefinitionBase model) { var siteModelHost = modelHost.WithAssertAndCast <SiteModelHost>("modelHost", value => value.RequireNotNull()); var definition = model.WithAssertAndCast <TaxonomyTermStoreDefinition>("model", value => value.RequireNotNull()); var site = siteModelHost.HostSite; var spObject = FindTermStore(siteModelHost, definition); var assert = ServiceFactory.AssertService .NewAssert(definition, spObject) .ShouldNotBeNull(spObject); if (definition.Id.HasValue) { assert.ShouldBeEqual(m => m.Id, o => o.Id); } else { assert.SkipProperty(m => m.Id, "ID is NULL. Skipping."); } if (!string.IsNullOrEmpty(definition.Name)) { assert.ShouldBeEqual(m => m.Name, o => o.Name); } else { assert.SkipProperty(m => m.Name, "Name is NULL. Skipping."); } if (definition.UseDefaultSiteCollectionTermStore.HasValue) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.UseDefaultSiteCollectionTermStore); var session = TaxonomySession.GetTaxonomySession(siteModelHost.HostClientContext); var client = siteModelHost.HostClientContext; var termStore = session.GetDefaultSiteCollectionTermStore(); client.Load(termStore, t => t.Id); client.Load(termStore, t => t.Name); siteModelHost.HostClientContext.ExecuteQueryWithTrace(); var isValid = termStore.Id == spObject.Id; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.UseDefaultSiteCollectionTermStore, "UseDefaultSiteCollectionTermStore is NULL. Skipping."); } }
public override void DeployModel(object modelHost, DefinitionBase model) { base.DeployModel(modelHost, model); var listItemModelHost = modelHost.WithAssertAndCast <ListItemModelHost>("modelHost", value => value.RequireNotNull()); var definition = model.WithAssertAndCast <ListViewWebPartDefinition>("model", value => value.RequireNotNull()); var context = listItemModelHost.HostClientContext; WithExistingWebPart(listItemModelHost.HostFile, definition, spObject => { var assert = ServiceFactory.AssertService .NewAssert(model, definition, spObject) .ShouldNotBeNull(spObject); var typedDefinition = definition; if (typedDefinition.WebId.HasGuidValue()) { // TODO } else { assert.SkipProperty(m => m.WebId, "WebId is NULL. Skipping."); } if (!string.IsNullOrEmpty(typedDefinition.WebUrl)) { // TODO } else { assert.SkipProperty(m => m.WebUrl, "WebUrl is NULL. Skipping."); } // list if (!string.IsNullOrEmpty(definition.ListTitle)) { var listId = new Guid(CurrentWebPartXml.GetListViewWebPartProperty("ListId")); var list = LookupList(listItemModelHost, definition); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.ListTitle); var isValid = list.Id == listId; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.ListTitle, "ListTitle is null or empty. Skipping."); } if (!string.IsNullOrEmpty(definition.ListUrl)) { var listId = new Guid(CurrentWebPartXml.GetListViewWebPartProperty("ListId")); var list = LookupList(listItemModelHost, definition); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.ListUrl); var isValid = list.Id == listId; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.ListUrl, "ListUrl is null or empty. Skipping."); } if (definition.ListId.HasGuidValue()) { var listId = new Guid(CurrentWebPartXml.GetListViewWebPartProperty("ListId")); var list = LookupList(listItemModelHost, definition); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.ListId); var isValid = list.Id == listId; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.ListId, "ListId is null or empty. Skipping."); } if (definition.ViewId.HasGuidValue()) { var list = LookupList(listItemModelHost, definition); var bindContext = LookupBindContext(listItemModelHost, definition); var viewBindingXml = XDocument.Parse(CurrentWebPartXml.GetListViewWebPartProperty("ListViewXml")); var viewId = new Guid(viewBindingXml.Root.GetAttributeValue("Name")); var bindedView = list.Views.GetById(viewId); var targetView = list.Views.GetById(definition.ViewId.Value); context.Load(bindedView, l => l.ViewFields, l => l.ViewQuery, l => l.RowLimit); context.Load(targetView, l => l.ViewFields, l => l.ViewQuery, l => l.RowLimit); context.ExecuteQueryWithTrace(); var isValid = false; // these are two different views, just CAML and field count isValid = (bindedView.ViewFields.Count == targetView.ViewFields.Count) && (bindedView.ViewQuery == targetView.ViewQuery) && (bindedView.RowLimit == targetView.RowLimit); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.ViewId); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.ViewId, "ViewId is null or empty. Skipping."); } if (!string.IsNullOrEmpty(definition.ViewName)) { var list = LookupList(listItemModelHost, definition); var bindContext = LookupBindContext(listItemModelHost, definition); var viewBindingXml = XDocument.Parse(CurrentWebPartXml.GetListViewWebPartProperty("ListViewXml")); var viewId = new Guid(viewBindingXml.Root.GetAttributeValue("Name")); var bindedView = list.Views.GetById(viewId); var targetView = list.Views.GetByTitle(definition.ViewName); context.Load(bindedView, l => l.ViewFields, l => l.ViewQuery, l => l.RowLimit); context.Load(targetView, l => l.ViewFields, l => l.ViewQuery, l => l.RowLimit); context.ExecuteQueryWithTrace(); var isValid = false; // these are two different views, just CAML and field count isValid = (bindedView.ViewFields.Count == targetView.ViewFields.Count) && (bindedView.ViewQuery == targetView.ViewQuery) && (bindedView.RowLimit == targetView.RowLimit); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.ViewName); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.ViewName, "ViewName is null or empty. Skipping."); } // skip it, it will be part of the .Toolbar validation assert.SkipProperty(m => m.ToolbarShowAlways, ""); if (!string.IsNullOrEmpty(definition.Toolbar)) { assert.ShouldBeEqual((p, s, d) => { var targetWeb = listItemModelHost.HostWeb; if (typedDefinition.WebId.HasGuidValue() || !string.IsNullOrEmpty(typedDefinition.WebUrl)) { targetWeb = new LookupFieldModelHandler() .GetTargetWeb(this.CurrentClientContext.Site, typedDefinition.WebUrl, typedDefinition.WebId); } var list = XsltListViewWebPartModelHandler.LookupList(targetWeb, typedDefinition.ListUrl, typedDefinition.ListTitle, typedDefinition.WebId); var xmlDefinition = ConvertUtils.ToString( CurrentWebPartXml.Root.Descendants( ((XNamespace)"http://schemas.microsoft.com/WebPart/v2/ListView") + "ListViewXml") .First().Value); var xmlDefinitionDoc = XDocument.Parse(xmlDefinition); var viewId = new Guid(xmlDefinitionDoc.Root.GetAttributeValue("Name")); var hiddenView = list.Views.GetById(viewId); context.Load(hiddenView, v => v.HtmlSchemaXml); context.ExecuteQueryWithTrace(); var htmlSchemaXml = XDocument.Parse(hiddenView.HtmlSchemaXml); var useShowAlwaysValue = (typedDefinition.Toolbar.ToUpper() == BuiltInToolbarType.Standard.ToUpper()) && typedDefinition.ToolbarShowAlways.HasValue && typedDefinition.ToolbarShowAlways.Value; var toolbarNode = htmlSchemaXml.Root .Descendants("Toolbar") .FirstOrDefault(); // NONE? the node might not be there if ((typedDefinition.Toolbar.ToUpper() == BuiltInToolbarType.None.ToUpper()) && (toolbarNode == null)) { var srcProp = s.GetExpressionValue(m => m.Toolbar); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = true }); } else { var toolBarValue = toolbarNode.GetAttributeValue("Type"); var srcProp = s.GetExpressionValue(m => m.Toolbar); var isValid = toolBarValue.ToUpper() == definition.Toolbar.ToUpper(); if (useShowAlwaysValue) { var showAlwaysValue = toolbarNode.GetAttributeValue("ShowAlways"); isValid = isValid && (showAlwaysValue.ToUpper() == "TRUE"); } return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); } }); } else { assert.SkipProperty(m => m.Toolbar); } }); }
public override void DeployModel(object modelHost, DefinitionBase model) { var webModelHost = modelHost.WithAssertAndCast <SiteModelHost>("modelHost", value => value.RequireNotNull()); var web = webModelHost.HostSite.RootWeb; var definition = model as SecurityGroupDefinition; 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); context.ExecuteQuery(); var spObject = FindSecurityGroupByTitle(web.SiteGroups, definition.Name); var assert = ServiceFactory.AssertService .NewAssert(definition, spObject) .ShouldNotBeNull(spObject) .ShouldBeEqual(m => m.Name, o => o.Title) .ShouldBeEqual(m => m.OnlyAllowMembersViewMembership, o => o.OnlyAllowMembersViewMembership); //.ShouldBeEqual(m => m.Description, o => o.Description); if (!string.IsNullOrEmpty(definition.Description)) { assert.ShouldBeEqual(m => m.Description, o => o.Description); } else { assert.SkipProperty(m => m.Description, "Description is NULL. Skipping."); } if (definition.AllowMembersEditMembership.HasValue) { assert.ShouldBeEqual(m => m.AllowMembersEditMembership, o => o.AllowMembersEditMembership); } else { assert.SkipProperty(m => m.AllowMembersEditMembership, "AllowMembersEditMembership is NULL. Skipping."); } if (definition.AllowRequestToJoinLeave.HasValue) { assert.ShouldBeEqual(m => m.AllowRequestToJoinLeave, o => o.AllowRequestToJoinLeave); } else { assert.SkipProperty(m => m.AllowRequestToJoinLeave, "AllowRequestToJoinLeave is NULL. Skipping."); } if (definition.AutoAcceptRequestToJoinLeave.HasValue) { assert.ShouldBeEqual(m => m.AutoAcceptRequestToJoinLeave, o => o.AutoAcceptRequestToJoinLeave); } else { assert.SkipProperty(m => m.AutoAcceptRequestToJoinLeave, "AutoAcceptRequestToJoinLeave is NULL. Skipping."); } assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.Owner); var dstProp = d.GetExpressionValue(ct => ct.GetOwnerLogin()); var isValid = dstProp.Value.ToString().ToUpper().Replace("\\", "/").EndsWith( srcProp.Value.ToString().ToUpper().Replace("\\", "/")); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValid }); }); assert.SkipProperty(m => m.DefaultUser, "DefaultUser cannot be setup via CSOM API. Skipping."); //assert.ShouldBeEqual((p, s, d) => //{ // var srcProp = s.GetExpressionValue(def => def.DefaultUser); // var dstProp = d.GetExpressionValue(ct => ct.GetDefaultUserLoginName()); // var isValid = srcProp.Value.ToString().Replace("\\", "/") == // dstProp.Value.ToString().Replace("\\", "/"); // return new PropertyValidationResult // { // Tag = p.Tag, // Src = srcProp, // Dst = dstProp, // IsValid = isValid // }; //}); }
public override void DeployModel(object modelHost, DefinitionBase model) { var site = ExtractSite(modelHost); var web = ExtractWeb(modelHost); var contentTypeModel = model.WithAssertAndCast <ContentTypeDefinition>("model", value => value.RequireNotNull()); var context = web.Context; var contentTypeId = contentTypeModel.GetContentTypeId(); var tmpContentType = context.LoadQuery(web.ContentTypes.Where(ct => ct.StringId == contentTypeId)); context.ExecuteQueryWithTrace(); var tmp = tmpContentType.FirstOrDefault(); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = tmp, ObjectType = typeof(ContentType), ObjectDefinition = model, ModelHost = modelHost }); ContentType currentContentType = null; if (tmp == null || tmp.ServerObjectIsNull == null || tmp.ServerObjectIsNull.Value) { TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new content type"); currentContentType = web.ContentTypes.Add(new ContentTypeCreationInformation { Name = contentTypeModel.Name, Description = string.IsNullOrEmpty(contentTypeModel.Description) ? string.Empty : contentTypeModel.Description, Group = contentTypeModel.Group, Id = contentTypeId, ParentContentType = null }); } else { TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing content type"); currentContentType = tmp; } currentContentType.Hidden = contentTypeModel.Hidden; currentContentType.Name = contentTypeModel.Name; currentContentType.Description = string.IsNullOrEmpty(contentTypeModel.Description) ? string.Empty : contentTypeModel.Description; currentContentType.Group = contentTypeModel.Group; if (!string.IsNullOrEmpty(contentTypeModel.DocumentTemplate)) { var serverRelativeFolderUrl = ExtractResourceFolderServerRelativeUrl(web, context, currentContentType); var processedDocumentTemplateUrl = TokenReplacementService.ReplaceTokens(new TokenReplacementContext { Value = contentTypeModel.DocumentTemplate, Context = context }).Value; // resource related path if (!processedDocumentTemplateUrl.Contains('/') && !processedDocumentTemplateUrl.Contains('\\')) { processedDocumentTemplateUrl = UrlUtility.CombineUrl(new string[] { serverRelativeFolderUrl, processedDocumentTemplateUrl }); } currentContentType.DocumentTemplate = processedDocumentTemplateUrl; } ProcessLocalization(currentContentType, contentTypeModel); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = currentContentType, ObjectType = typeof(ContentType), ObjectDefinition = model, ModelHost = modelHost }); TraceService.Information((int)LogEventId.ModelProvisionCoreCall, "Calling currentContentType.Update(true)"); currentContentType.Update(true); context.ExecuteQueryWithTrace(); }
public override void DeployModel(object modelHost, DefinitionBase model) { var modelHostWrapper = modelHost.WithAssertAndCast <ModelHostContext>("modelHost", value => value.RequireNotNull()); var contentTypeFieldLinkModel = model.WithAssertAndCast <ContentTypeFieldLinkDefinition>("model", value => value.RequireNotNull()); //var site = modelHostWrapper.Site; var web = modelHostWrapper.Web; var contentType = modelHostWrapper.ContentType; var context = contentType.Context; TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Getting content type field link by ID: [{0}]", contentTypeFieldLinkModel.FieldId); FieldLink fieldLink = FindExistingFieldLink(contentType, contentTypeFieldLinkModel); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = fieldLink, ObjectType = typeof(FieldLink), ObjectDefinition = model, ModelHost = modelHost }); if (fieldLink == null) { TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new content type field link"); var targetField = FindAvailableField(web, contentTypeFieldLinkModel); fieldLink = contentType.FieldLinks.Add(new FieldLinkCreationInformation { Field = targetField }); } else { TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing content type field link"); } if (contentTypeFieldLinkModel.Required.HasValue) { fieldLink.Required = contentTypeFieldLinkModel.Required.Value; } if (contentTypeFieldLinkModel.Hidden.HasValue) { fieldLink.Hidden = contentTypeFieldLinkModel.Hidden.Value; } if (!string.IsNullOrEmpty(contentTypeFieldLinkModel.DisplayName)) { // CSOM limitation - DisplayName is not available yet. // https://officespdev.uservoice.com/forums/224641-general/suggestions/7024931-enhance-fieldlink-class-with-additional-properties // fieldLink.DisplayName = contentTypeFieldLinkModel.DisplayName; // Enhance FieldLinkDefinition - DisplayName, ReadOnly, ShowInDisplayForm #892 // https://github.com/SubPointSolutions/spmeta2/issues/892 if (ReflectionUtils.HasProperty(fieldLink, "DisplayName")) { if (!string.IsNullOrEmpty(contentTypeFieldLinkModel.DisplayName)) { ClientRuntimeQueryService.SetProperty(fieldLink, "DisplayName", contentTypeFieldLinkModel.DisplayName); } } else { TraceService.Critical((int)LogEventId.ModelProvisionCoreCall, "CSOM runtime doesn't have FieldLink.DisplayName. Update CSOM runtime to a new version. Provision is skipped"); } } InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = fieldLink, ObjectType = typeof(FieldLink), ObjectDefinition = model, ModelHost = modelHost }); contentType.Update(true); context.ExecuteQueryWithTrace(); }
public override void DeployModel(object modelHost, DefinitionBase model) { var modelHostContext = modelHost.WithAssertAndCast <ModelHostContext>("modelHost", value => value.RequireNotNull()); var definition = model.WithAssertAndCast <ContentTypeFieldLinkDefinition>("model", value => value.RequireNotNull()); var site = modelHostContext.Site; var contentType = modelHostContext.ContentType; var context = site.Context; var spObject = FindExistingFieldLink(contentType, definition); var assert = ServiceFactory.AssertService .NewAssert(definition, spObject) .ShouldNotBeNull(spObject); if (!string.IsNullOrEmpty(definition.FieldInternalName)) { assert.ShouldBeEqual(m => m.FieldInternalName, o => o.Name); } else { assert.SkipProperty(m => m.FieldInternalName, "FieldInternalName is NULL or empty. Skipping."); } if (definition.FieldId.HasGuidValue()) { assert.ShouldBeEqual(m => m.FieldId, o => o.Id); } else { assert.SkipProperty(m => m.FieldId, "FieldId is NULL. Skipping."); } if (!string.IsNullOrEmpty(definition.DisplayName)) { // DisplayName is notsupported by CSOM yet // https://officespdev.uservoice.com/forums/224641-general/suggestions/7024931-enhance-fieldlink-class-with-additional-properties // assert.ShouldBeEqual(m => m.DisplayName, o => o.DisplayName); assert.SkipProperty(m => m.DisplayName, "DisplayName is not supported by CSOM yet. Skipping."); } else { assert.SkipProperty(m => m.DisplayName, "DisplayName is NULL or empty. Skipping."); } if (definition.Required.HasValue) { assert.ShouldBeEqual(m => m.Required, o => o.Required); } else { assert.SkipProperty(m => m.Required, "Required is NULL. Skipping."); } if (definition.Hidden.HasValue) { assert.ShouldBeEqual(m => m.Hidden, o => o.Hidden); } else { assert.SkipProperty(m => m.Hidden, "Hidden is NULL. Skipping."); } }
public override void DeployModel(object modelHost, DefinitionBase model) { var webModelHost = modelHost.WithAssertAndCast <WebModelHost>("modelHost", value => value.RequireNotNull()); var web = webModelHost.HostWeb; var listModel = model.WithAssertAndCast <ListDefinition>("model", value => value.RequireNotNull()); var context = web.Context; context.Load(web, w => w.ServerRelativeUrl); context.ExecuteQueryWithTrace(); List currentList = null; var loadedList = LoadCurrentList(web, listModel); if (loadedList != null) { currentList = loadedList; } InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = null, ObjectType = typeof(List), ObjectDefinition = model, ModelHost = modelHost }); // gosh! //currentList = FindListByUrl(lists, listModel.GetListUrl()); if (currentList == null) { TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new list"); // no support for the TemplateName yet var listInfo = new ListCreationInformation { Title = listModel.Title, Description = listModel.Description ?? string.Empty, #pragma warning disable 618 Url = listModel.GetListUrl() #pragma warning restore 618 }; if (listModel.TemplateType > 0) { TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Creating list by TemplateType: [{0}]", listModel.TemplateType); listInfo.TemplateType = listModel.TemplateType; } else if (!string.IsNullOrEmpty(listModel.TemplateName)) { TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Creating list by TemplateName: [{0}]", listModel.TemplateName); var listTemplate = ResolveListTemplate(webModelHost, listModel); listInfo.TemplateFeatureId = listTemplate.FeatureId; listInfo.TemplateType = listTemplate.ListTemplateTypeKind; } else { TraceService.Error((int)LogEventId.ModelProvisionCoreCall, "Either TemplateType or TemplateName has to be specified. Throwing SPMeta2Exception"); throw new SPMeta2Exception("Either TemplateType or TemplateName has to be specified."); } var newList = web.Lists.Add(listInfo); currentList = newList; currentList.Update(); context.ExecuteQueryWithTrace(); currentList = LoadCurrentList(web, listModel); } else { TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing list"); } MapListProperties(modelHost, currentList, listModel); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = currentList, ObjectType = typeof(List), ObjectDefinition = model, ModelHost = modelHost }); TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Calling currentList.Update()"); currentList.Update(); context.ExecuteQueryWithTrace(); }
public override void DeployModel(object modelHost, DefinitionBase model) { var listItemModelHost = modelHost.WithAssertAndCast <ListItemModelHost>("modelHost", value => value.RequireNotNull()); var definition = model.WithAssertAndCast <WebPartDefinition>("model", value => value.RequireNotNull()); var pageFile = listItemModelHost.HostFile; var context = pageFile.Context; context.Load(pageFile); context.ExecuteQueryWithTrace(); var siteServerUrl = listItemModelHost.HostSite.ServerRelativeUrl; var webUrl = listItemModelHost.HostWeb.Url; var serverUrl = context.Url; if (siteServerUrl != "/") { serverUrl = context.Url.Split(new string[] { siteServerUrl }, StringSplitOptions.RemoveEmptyEntries)[0]; } var absItemUrl = UrlUtility.CombineUrl(serverUrl, pageFile.ServerRelativeUrl); WithExistingWebPart(pageFile, definition, (spObject, spObjectDefintion) => { var webpartExportUrl = UrlUtility.CombineUrl(new[] { webUrl, "_vti_bin/exportwp.aspx?pageurl=" + absItemUrl + "&" + "guidstring=" + spObjectDefintion.Id.ToString() }); var assert = ServiceFactory.AssertService .NewAssert(model, definition, spObject) .ShouldNotBeNull(spObject); var webClient = new WebClient(); if (context.Credentials != null) { webClient.Credentials = context.Credentials; webClient.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f"); } else { webClient.UseDefaultCredentials = true; } var webPartXmlString = webClient.DownloadString(webpartExportUrl); CurrentWebPartXml = WebpartXmlExtensions.LoadWebpartXmlDocument(webPartXmlString); assert.ShouldBeEqual(m => m.Title, o => o.Title); // checking the web part type, shoul be as expected // Add regression on 'expected' web part type #690 var currentType = CurrentWebPartXml.GetWebPartAssemblyQualifiedName(); var currentClassName = currentType.Split(',').First().Trim(); var expectedTypeAttr = (definition.GetType().GetCustomAttributes(typeof(ExpectWebpartType)) .FirstOrDefault() as ExpectWebpartType); // NULL can be on generic web part // test should not care about that case, there other tests to enfore that attr usage if (expectedTypeAttr != null) { var expectedType = expectedTypeAttr.WebPartType; var expectedClassName = expectedType.Split(',').First().Trim(); assert.ShouldBeEqual((p, s, d) => { var isValid = true; isValid = currentClassName.ToUpper() == expectedClassName.ToUpper(); return(new PropertyValidationResult { Tag = p.Tag, Src = null, Dst = null, IsValid = isValid }); }); } // props if (definition.Properties.Count > 0) { assert.ShouldBeEqual((p, s, d) => { var isValid = true; foreach (var prop in definition.Properties) { // returns correct one depending on the V2/V3 var value = CurrentWebPartXml.GetProperty(prop.Name); // that True / true issue give a pain // toLower for the time being isValid = value.ToLower() == prop.Value.ToLower(); if (!isValid) { break; } } var srcProp = s.GetExpressionValue(m => m.Properties); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.Properties, "Properties are empty. Skipping."); } if (!string.IsNullOrEmpty(definition.ExportMode)) { var value = CurrentWebPartXml.GetExportMode(); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.ExportMode); var isValid = definition.ExportMode == value; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.ExportMode, "ExportMode is null or empty. Skipping."); } if (!string.IsNullOrEmpty(definition.ChromeState)) { var value = CurrentWebPartXml.GetChromeState(); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.ChromeState); var isValid = definition.ChromeState == value; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.ChromeState, "ChromeState is null or empty. Skipping."); } if (!string.IsNullOrEmpty(definition.ChromeType)) { // returns correct one depending on the V2/V3 var value = CurrentWebPartXml.GetChromeType(); var chromeType = string.Empty; if (CurrentWebPartXml.IsV3version()) { chromeType = WebPartChromeTypesConvertService.NormilizeValueToPartChromeTypes(definition.ChromeType); } else if (CurrentWebPartXml.IsV2version()) { chromeType = WebPartChromeTypesConvertService.NormilizeValueToFrameTypes(definition.ChromeType); } assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.ChromeType); var isValid = chromeType == value; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.ChromeType, "ChromeType is null or empty. Skipping."); } if (!string.IsNullOrEmpty(definition.Description)) { var value = CurrentWebPartXml.GetProperty("Description"); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.Description); var isValid = (srcProp.Value as string) == value; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.Description, "Description is null or empty. Skipping."); } if (definition.Height.HasValue) { var value = ConvertUtils.ToInt(CurrentWebPartXml.GetProperty("Height").Replace("px", string.Empty)); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.Height); var isValid = definition.Height == value; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.Height, "Height is null or empty. Skipping."); } if (definition.Width.HasValue) { var value = ConvertUtils.ToInt(CurrentWebPartXml.GetProperty("Width").Replace("px", string.Empty)); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.Width); var isValid = definition.Width == value; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.Width, "Width is NULL, skipping"); } if (!string.IsNullOrEmpty(definition.ImportErrorMessage)) { var value = CurrentWebPartXml.GetImportErrorMessage(); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.ImportErrorMessage); var isValid = definition.ImportErrorMessage == value; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.ImportErrorMessage, "ImportErrorMessage is null or empty. Skipping."); } if (!string.IsNullOrEmpty(definition.TitleIconImageUrl)) { var value = CurrentWebPartXml.GetTitleIconImageUrl(); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.TitleIconImageUrl); var isValid = definition.TitleIconImageUrl == value; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.TitleIconImageUrl, "TitleIconImageUrl is null or empty. Skipping."); } if (!string.IsNullOrEmpty(definition.TitleUrl)) { var value = CurrentWebPartXml.GetTitleUrl(); var defValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext { Context = listItemModelHost, Value = value }).Value; var isValid = defValue.ToUpper() == value.ToUpper(); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.TitleUrl); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.TitleUrl, "TitleUrl is null or empty. Skipping."); } assert.SkipProperty(m => m.WebpartFileName, "WebpartFileName is null or empty. Skipping."); assert.SkipProperty(m => m.WebpartType, "WebpartType is null or empty. Skipping."); assert.SkipProperty(m => m.WebpartXmlTemplate, "WebpartXmlTemplate is null or empty. Skipping."); assert.SkipProperty(m => m.ZoneId, "ZoneId is null or empty. Skipping."); assert.SkipProperty(m => m.ZoneIndex, "ZoneIndex is null or empty. Skipping."); assert.SkipProperty(m => m.Id, "Id is null or empty. Skipping."); if (definition.ParameterBindings.Count == 0) { assert.SkipProperty(m => m.ParameterBindings, "ParameterBindings is null or empty. Skipping."); } else { // TODO } if (!string.IsNullOrEmpty(definition.AuthorizationFilter)) { var value = CurrentWebPartXml.GetProperty("AuthorizationFilter"); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.AuthorizationFilter); var isValid = (srcProp.Value as string) == value; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.AuthorizationFilter, "AuthorizationFilter is null or empty. Skipping."); } }); }
public static ModelNode AddDefinitionNode(this ModelNode node, DefinitionBase definition) { return AddDefinitionNode(node, definition, null); }
public override void DeployModel(object modelHost, DefinitionBase model) { var definition = model.WithAssertAndCast <RootWebDefinition>("model", value => value.RequireNotNull()); var spObject = GetCurrentObject(modelHost, definition); Site site = null; if (modelHost is SiteModelHost) { site = (modelHost as SiteModelHost).HostSite; } else if (modelHost is WebModelHost) { site = (modelHost as WebModelHost).HostSite; } var assert = ServiceFactory.AssertService .NewAssert(definition, spObject) .ShouldNotBeNull(spObject); if (string.IsNullOrEmpty(definition.Title)) { assert.SkipProperty(m => m.Title, "Title is null or empty"); } else { assert.ShouldBeEqual(m => m.Title, o => o.Title); } if (string.IsNullOrEmpty(definition.Description)) { assert.SkipProperty(m => m.Description, "Description is null or empty"); } else { assert.ShouldBeEqual(m => m.Description, o => o.Description); } assert.ShouldBeEqual((p, s, d) => { var context = d.Context; if (!d.IsPropertyAvailable("ServerRelativeUrl")) { context.Load(d, o => o.ServerRelativeUrl); context.ExecuteQuery(); } if (!site.IsPropertyAvailable("ServerRelativeUrl")) { site.Context.Load(site, o => o.ServerRelativeUrl); site.Context.ExecuteQuery(); } var isValid = d.ServerRelativeUrl.ToUpper() == site.ServerRelativeUrl.ToUpper(); return(new PropertyValidationResult { Tag = p.Tag, Src = null, Dst = null, IsValid = isValid, Message = "Checking if IsRootWeb == TRUE" }); }); }
public virtual void UpdateAuraInfo(DefinitionBase def) { }
public override void WithResolvingModelHost(object modelHost, DefinitionBase model, Type childModelType, Action <object> action) { var webModelHost = modelHost.WithAssertAndCast <WebModelHost>("modelHost", value => value.RequireNotNull()); var web = webModelHost.HostWeb; var listDefinition = model as ListDefinition; if (web != null && listDefinition != null) { // This is very important line -> adding new 'fake list' // // Nintex workflow deployment web service updates the list, so that version of the list becomes +4 // Current SPWeb has not been updated, current list will be 4 versions behind so you will have 'Save conflict' exception // // We try to add new list, so SPListCollection is invalidated. // Surely, we won't save this list. try { var tmpListId = web.Lists.Add(Guid.NewGuid().ToString(), string.Empty, Microsoft.SharePoint.SPListTemplateType.GenericList); var tmpList = web.Lists[tmpListId]; tmpList.Delete(); } catch (Exception) { } var list = web.GetList(SPUtility.ConcatUrls(web.ServerRelativeUrl, listDefinition.GetListUrl())); var listModelHost = new ListModelHost { HostList = list }; if (childModelType == typeof(ModuleFileDefinition)) { var folderModelHost = new FolderModelHost { CurrentLibrary = list as SPDocumentLibrary, CurrentLibraryFolder = list.RootFolder, CurrentList = (list as SPDocumentLibrary != null) ? null : list, CurrentListItem = null, }; action(folderModelHost); } else if (childModelType == typeof(FolderDefinition)) { var folderModelHost = new FolderModelHost { CurrentLibrary = list as SPDocumentLibrary, CurrentLibraryFolder = list.RootFolder, CurrentList = (list as SPDocumentLibrary != null) ? null : list, CurrentListItem = null, }; action(folderModelHost); } else if (typeof(PageDefinitionBase).IsAssignableFrom(childModelType)) { var folderModelHost = new FolderModelHost { CurrentLibrary = list as SPDocumentLibrary, CurrentLibraryFolder = list.RootFolder, CurrentList = (list as SPDocumentLibrary != null) ? null : list, CurrentListItem = null, }; action(folderModelHost); } else { action(listModelHost); } if (listModelHost.ShouldUpdateHost) { list.Update(); } } else { action(modelHost); } }
/// <summary> /// Handles model retraction under particular model host. /// </summary> /// <param name="modelHost"></param> /// <param name="model"></param> public virtual void RetractModel(object modelHost, DefinitionBase model) { }
public override void DeployModel(object modelHost, DefinitionBase model) { var webModelHost = modelHost.WithAssertAndCast <WebModelHost>("modelHost", value => value.RequireNotNull()); var definition = model.WithAssertAndCast <MasterPageSettingsDefinition>("model", value => value.RequireNotNull()); var spObject = webModelHost.HostWeb; var assert = ServiceFactory.AssertService .NewAssert(model, definition, spObject) .ShouldNotBeNull(spObject); if (!string.IsNullOrEmpty(definition.SiteMasterPageUrl)) { if (definition.SiteMasterPageUrl.StartsWith("/")) { assert.ShouldBeEndOf(m => m.SiteMasterPageUrl, o => o.CustomMasterUrl); } else { // check for ~site/~sitecollection tokens var url = ResolveUrlWithTokens(webModelHost.HostWeb, definition.SiteMasterPageUrl); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.SiteMasterPageUrl); var dstProp = d.GetExpressionValue(def => def.CustomMasterUrl); var isValid = ((string)dstProp.Value).EndsWith((string)url); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValid }); }); } } else { assert.SkipProperty(m => m.SiteMasterPageUrl, "SiteMasterPageUrl is NULL or empty"); } if (!string.IsNullOrEmpty(definition.SystemMasterPageUrl)) { if (definition.SystemMasterPageUrl.StartsWith("/")) { assert.ShouldBeEndOf(m => m.SystemMasterPageUrl, o => o.MasterUrl); } else { // check for ~site/~sitecollection tokens var url = ResolveUrlWithTokens(webModelHost.HostWeb, definition.SystemMasterPageUrl); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.SystemMasterPageUrl); var dstProp = d.GetExpressionValue(def => def.MasterUrl); var isValid = ((string)dstProp.Value).EndsWith((string)url); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValid }); }); } } else { assert.SkipProperty(m => m.SystemMasterPageUrl, "SiteMasterPageUrl is NULL or empty"); } }
public override void DeployModel(object modelHost, DefinitionBase model) { var listModelHost = modelHost.WithAssertAndCast <ListModelHost>("modelHost", value => value.RequireNotNull()); var definition = model.WithAssertAndCast <ListViewDefinition>("model", value => value.RequireNotNull()); var list = listModelHost.HostList; var context = list.Context; context.Load(list, l => l.Fields); context.Load(list, l => l.Views.Include( v => v.ViewFields, v => v.Title, v => v.DefaultView, v => v.ViewQuery, v => v.RowLimit, v => v.Paged, v => v.Scope, v => v.Hidden, v => v.JSLink, v => v.ServerRelativeUrl, v => v.DefaultViewForContentType, v => v.ContentTypeId, v => v.AggregationsStatus, v => v.Aggregations, v => v.ViewType, v => v.ViewData)); context.ExecuteQueryWithTrace(); var spObject = FindViewByTitle(list.Views, definition.Title); var assert = ServiceFactory.AssertService .NewAssert(definition, spObject); assert .ShouldNotBeNull(spObject) .ShouldBeEqual(m => m.Title, o => o.Title) .ShouldBeEqual(m => m.IsDefault, o => o.DefaultView) .ShouldBeEqual(m => m.Hidden, o => o.Hidden) .ShouldBeEqual(m => m.RowLimit, o => (int)o.RowLimit) .ShouldBeEqual(m => m.IsPaged, o => o.Paged); if (!string.IsNullOrEmpty(definition.Scope)) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.Scope); var dstProp = d.GetExpressionValue(o => o.Scope); var scopeValue = ListViewScopeTypesConvertService.NormilizeValueToCSOMType(definition.Scope); var isValid = scopeValue == d.Scope.ToString(); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.Scope); } if (!string.IsNullOrEmpty(definition.ViewData)) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.ViewData); var dstProp = d.GetExpressionValue(o => o.ViewData); var srcViewDate = assert.Src.ViewData.Replace(System.Environment.NewLine, string.Empty).Replace(" /", "/"); var dstViewDate = assert.Dst.ViewData.Replace(System.Environment.NewLine, string.Empty).Replace(" /", "/"); var isValid = srcViewDate.ToUpper() == dstViewDate.ToUpper(); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.ViewData); } if (!string.IsNullOrEmpty(definition.Type)) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.Type); var dstProp = d.GetExpressionValue(o => o.ViewType); var isValid = srcProp.Value.ToString().ToUpper() == dstProp.Value.ToString().ToUpper(); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.Type); } assert.SkipProperty(m => m.ViewStyleId, "ViewStyleId unsupported by SP CSOM API yet. Skipping."); assert.SkipProperty(m => m.TabularView, "TabularView unsupported by SP CSOM API yet. Skipping."); assert.SkipProperty(m => m.InlineEdit, "InlineEdit unsupported by SP CSOM API yet. Skipping."); assert.ShouldBeEqualIfNotNullOrEmpty(m => m.JSLink, o => o.JSLink); if (!string.IsNullOrEmpty(definition.Query)) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.Query); var dstProp = d.GetExpressionValue(o => o.ViewQuery); var srcViewDate = assert.Src.Query.Replace(System.Environment.NewLine, string.Empty).Replace(" /", "/"); var dstViewDate = assert.Dst.ViewQuery.Replace(System.Environment.NewLine, string.Empty).Replace(" /", "/"); var isValid = srcViewDate.ToUpper() == dstViewDate.ToUpper(); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.Query, "Query is null or empty. Skipping."); } assert.ShouldBeEqualIfHasValue(m => m.DefaultViewForContentType, o => o.DefaultViewForContentType); if (string.IsNullOrEmpty(definition.ContentTypeName)) { assert.SkipProperty(m => m.ContentTypeName, "ContentTypeName is null or empty. Skipping."); } else { var contentTypeId = LookupListContentTypeByName(list, definition.ContentTypeName); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.ContentTypeName); var dstProp = d.GetExpressionValue(ct => ct.ContentTypeId); var isValis = contentTypeId.StringValue == d.ContentTypeId.StringValue; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValis }); }); } if (string.IsNullOrEmpty(definition.ContentTypeId)) { assert.SkipProperty(m => m.ContentTypeId, "ContentTypeId is null or empty. Skipping."); } else { var contentTypeId = LookupListContentTypeById(list, definition.ContentTypeId); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.ContentTypeId); var dstProp = d.GetExpressionValue(ct => ct.ContentTypeId); var isValis = contentTypeId.StringValue == d.ContentTypeId.StringValue; return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = isValis }); }); } if (string.IsNullOrEmpty(definition.AggregationsStatus)) { assert.SkipProperty(m => m.AggregationsStatus, "Aggregationsstatus is null or empty. Skipping."); } else { assert.ShouldBeEqual(m => m.AggregationsStatus, o => o.AggregationsStatus); } if (string.IsNullOrEmpty(definition.Aggregations)) { assert.SkipProperty(m => m.Aggregations, "Aggregations is null or empty. Skipping."); } else { assert.ShouldBeEqual(m => m.Aggregations, o => o.Aggregations); } assert.ShouldBePartOfIfNotNullOrEmpty(m => m.Url, o => o.ServerRelativeUrl); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.Fields); var dstProp = d.GetExpressionValue(ct => ct.ViewFields); var hasAllFields = true; foreach (var srcField in s.Fields) { var listField = list.Fields.ToList().FirstOrDefault(f => f.StaticName == srcField); // if list-scoped field we need to check by internal name // internal name is changed for list scoped-fields // that's why to check by BOTH, definition AND real internal name if (!d.ViewFields.ToList().Contains(srcField) && !d.ViewFields.ToList().Contains(listField.InternalName)) { hasAllFields = false; } } return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = hasAllFields }); }); var supportsLocalization = ReflectionUtils.HasProperties(spObject, new[] { "TitleResource" }); if (supportsLocalization) { if (definition.TitleResource.Any()) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.TitleResource); var isValid = true; foreach (var userResource in s.TitleResource) { var culture = LocalizationService.GetUserResourceCultureInfo(userResource); var resourceObject = ReflectionUtils.GetPropertyValue(spObject, "TitleResource"); var value = ReflectionUtils.GetMethod(resourceObject, "GetValueForUICulture") .Invoke(resourceObject, new[] { culture.Name }) as ClientResult <string>; context.ExecuteQuery(); isValid = userResource.Value == value.Value; if (!isValid) { break; } } return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(m => m.TitleResource, "TitleResource is NULL or empty. Skipping."); } } else { TraceService.Critical((int)LogEventId.ModelProvisionCoreCall, "CSOM runtime doesn't have Web.TitleResource and Web.DescriptionResource() methods support. Skipping validation."); assert.SkipProperty(m => m.TitleResource, "TitleResource is null or empty. Skipping."); } }
public override void UpdateAuraInfo(DefinitionBase def) { if (IsValidForUnitDataCapture()) { if (def is PACKETPARSERMAX20.CORE.DEFINITIONS.SMSG_AURA_UPDATE_DEF) { var _def = (PACKETPARSERMAX20.CORE.DEFINITIONS.SMSG_AURA_UPDATE_DEF)def; var list = _def.validauraupdatelist; if (list.Count > 0) { if (_creature_template_addon == null) { _creature_template_addon = new creature_template_addon(); _creature_template_addon.entry = ENTRY; } foreach (var item in list) { if (GlobalCache.IsValidInitialAura(ENTRY, item.Value.id)) { if (!AuraSpellIdList.Contains(item.Value.id)) { AuraSpellIdList.Add(item.Value.id); byte eff = GlobalCache.ValidAuraSpellIDEffectList[item.Value.id]; for (int i = 0; i <= eff; i++) { if (_creature_template_addon.auras == null) { _creature_template_addon.auras = item.Value.id.ToString() + " " + i.ToString(); } else { _creature_template_addon.auras += " " + item.Value.id.ToString() + " " + i.ToString(); ; } } } } } } } } }
protected override void DeployModelInternal(object modelHost, DefinitionBase model) { var siteModelHost = modelHost.WithAssertAndCast <SiteModelHost>("modelHost", value => value.RequireNotNull()); var site = siteModelHost.HostSite; var web = site.RootWeb; var securityRoleModel = model.WithAssertAndCast <SecurityRoleDefinition>("model", value => value.RequireNotNull()); var currentRoleDefinition = (SPRoleDefinition)null; var permissions = SPBasePermissions.EmptyMask; foreach (var permissionString in securityRoleModel.BasePermissions) { permissions = permissions | (SPBasePermissions)Enum.Parse(typeof(SPBasePermissions), permissionString); } try { currentRoleDefinition = web.RoleDefinitions[securityRoleModel.Name]; InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = currentRoleDefinition, ObjectType = typeof(SPRoleDefinition), ObjectDefinition = securityRoleModel, ModelHost = modelHost }); } catch (SPException) { InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = null, ObjectType = typeof(SPRoleDefinition), ObjectDefinition = securityRoleModel, ModelHost = modelHost }); web.RoleDefinitions.Add(new SPRoleDefinition { Name = securityRoleModel.Name, Description = securityRoleModel.Description, BasePermissions = permissions }); currentRoleDefinition = web.RoleDefinitions[securityRoleModel.Name]; } currentRoleDefinition.Description = securityRoleModel.Description; currentRoleDefinition.BasePermissions = permissions; InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = currentRoleDefinition, ObjectType = typeof(SPRoleDefinition), ObjectDefinition = securityRoleModel, ModelHost = modelHost }); currentRoleDefinition.Update(); }
protected ElementBase(DefinitionBase parent, IO.XmlStream s) { Name = string.Empty; s.ReadAttributeOpt("name", ref Name); s.ReadAttribute("declType", ref DeclarationType); }
public override void DeployModel(object modelHost, DefinitionBase model) { var webModelHost = modelHost.WithAssertAndCast <WebModelHost>("modelHost", value => value.RequireNotNull()); var definition = model.WithAssertAndCast <WebNavigationSettingsDefinition>("model", value => value.RequireNotNull()); var spObject = GetWebNavigationSettings(webModelHost, definition); var web = webModelHost.HostWeb; var assert = ServiceFactory.AssertService .NewAssert(definition, spObject) .ShouldNotBeNull(spObject); var publishingWeb = PublishingWeb.GetPublishingWeb(web); // web??/_layouts/15/AreaNavigationSettings.aspx // extra protection, downbloading HTML page and making sure checkboxes are there :) //<input name="ctl00$PlaceHolderMain$globalNavSection$ctl02$globalIncludeSubSites" type="checkbox" id="ctl00_PlaceHolderMain_globalNavSection_ctl02_globalIncludeSubSites" checked="checked"> //<input name="ctl00$PlaceHolderMain$globalNavSection$ctl02$globalIncludePages" type="checkbox" id="ctl00_PlaceHolderMain_globalNavSection_ctl02_globalIncludePages" disabled="disabled"> //<input name="ctl00$PlaceHolderMain$currentNavSection$ctl02$currentIncludeSubSites" type="checkbox" id="ctl00_PlaceHolderMain_currentNavSection_ctl02_currentIncludeSubSites"> //<input name="ctl00$PlaceHolderMain$currentNavSection$ctl02$currentIncludePages" type="checkbox" id="ctl00_PlaceHolderMain_currentNavSection_ctl02_currentIncludePages" disabled="disabled"> var pageUrl = UrlUtility.CombineUrl(web.Url, "/_layouts/15/AreaNavigationSettings.aspx"); var client = new WebClient(); client.UseDefaultCredentials = true; var pageContent = client.DownloadString(new Uri(pageUrl)); CQ j = pageContent; // so not only API, but also real checboxed on browser page check var globalSubSites = j.Select("input[id$='globalIncludeSubSites']").First(); var globalSubSitesValue = globalSubSites.Attr("checked") == "checked"; var globalIncludePages = j.Select("input[id$='globalIncludePages']").First(); var globalIncludePagesValue = globalIncludePages.Attr("checked") == "checked"; var currentIncludeSubSites = j.Select("input[id$='currentIncludeSubSites']").First(); var currentIncludeSubSitesValue = currentIncludeSubSites.Attr("checked") == "checked"; var currentIncludePages = j.Select("input[id$='currentIncludePages']").First(); var currentIncludePagesValue = currentIncludePages.Attr("checked") == "checked"; if (definition.GlobalNavigationShowSubsites.HasValue) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.GlobalNavigationShowSubsites); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = (publishingWeb.Navigation.GlobalIncludeSubSites && globalSubSitesValue) == s.GlobalNavigationShowSubsites }); }); } else { assert.SkipProperty(m => m.GlobalNavigationShowSubsites, "GlobalNavigationShowSubsites is null"); } if (definition.GlobalNavigationShowPages.HasValue) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.GlobalNavigationShowPages); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = (publishingWeb.Navigation.GlobalIncludePages && globalIncludePagesValue) == s.GlobalNavigationShowPages }); }); } else { assert.SkipProperty(m => m.GlobalNavigationShowPages, "GlobalNavigationShowPages is null"); } if (definition.CurrentNavigationShowSubsites.HasValue) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.CurrentNavigationShowSubsites); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = (publishingWeb.Navigation.CurrentIncludeSubSites && currentIncludeSubSitesValue) == s.CurrentNavigationShowSubsites }); }); } else { assert.SkipProperty(m => m.CurrentNavigationShowSubsites, "CurrentNavigationShowSubsites is null"); } if (definition.CurrentNavigationShowPages.HasValue) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.CurrentNavigationShowPages); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = (publishingWeb.Navigation.CurrentIncludePages && currentIncludePagesValue) == s.CurrentNavigationShowPages }); }); } else { assert.SkipProperty(m => m.CurrentNavigationShowPages, "CurrentNavigationShowPages is null"); } // items count if (definition.GlobalNavigationMaximumNumberOfDynamicItems.HasValue) { var globalDynamicChildLimitValue = ConvertUtils.ToInt(web.AllProperties[BuiltInWebPropertyId.GlobalDynamicChildLimit]); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.GlobalNavigationMaximumNumberOfDynamicItems); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = s.GlobalNavigationMaximumNumberOfDynamicItems == globalDynamicChildLimitValue }); }); } else { assert.SkipProperty(d => d.GlobalNavigationMaximumNumberOfDynamicItems, "GlobalNavigationMaximumNumberOfDynamicItems is null or empty"); } if (definition.CurrentNavigationMaximumNumberOfDynamicItems.HasValue) { var currentDynamicChildLimitValue = ConvertUtils.ToInt(web.AllProperties[BuiltInWebPropertyId.CurrentDynamicChildLimit]); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.CurrentNavigationMaximumNumberOfDynamicItems); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = s.CurrentNavigationMaximumNumberOfDynamicItems == currentDynamicChildLimitValue }); }); } else { assert.SkipProperty(d => d.CurrentNavigationMaximumNumberOfDynamicItems, "CurrentNavigationMaximumNumberOfDynamicItems is null or empty"); } // nav sources if (!string.IsNullOrEmpty(definition.GlobalNavigationSource)) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.GlobalNavigationSource); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = s.GlobalNavigationSource == spObject.GlobalNavigation.Source.ToString() }); }); } else { assert.SkipProperty(d => d.GlobalNavigationSource, "GlobalNavigationSource is null or empty"); } if (!string.IsNullOrEmpty(definition.CurrentNavigationSource)) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(m => m.CurrentNavigationSource); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = s.CurrentNavigationSource == spObject.CurrentNavigation.Source.ToString() }); }); } else { assert.SkipProperty(d => d.CurrentNavigationSource, "CurrentNavigationSource is null or empty"); } }