当前位置: 首页>>代码示例>>C#>>正文


C# DefinitionBase.WithAssertAndCast方法代码示例

本文整理汇总了C#中SPMeta2.Definitions.DefinitionBase.WithAssertAndCast方法的典型用法代码示例。如果您正苦于以下问题:C# DefinitionBase.WithAssertAndCast方法的具体用法?C# DefinitionBase.WithAssertAndCast怎么用?C# DefinitionBase.WithAssertAndCast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SPMeta2.Definitions.DefinitionBase的用法示例。


在下文中一共展示了DefinitionBase.WithAssertAndCast方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DeployModel

        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var definition = model.WithAssertAndCast<FieldDefinition>("model", value => value.RequireNotNull());
            var spObject = GetField(modelHost, definition);

            var assert = ServiceFactory.AssertService.NewAssert(model, definition, spObject);

            ValidateField(assert, spObject, definition);

            var textField = spObject as SPFieldNumber;
            var textDefinition = model.WithAssertAndCast<NumberFieldDefinition>("model", value => value.RequireNotNull());

            var typedFieldAssert = ServiceFactory.AssertService.NewAssert(model, textDefinition, textField);

            typedFieldAssert.ShouldBeEqual(m => m.MaximumValue, o => o.MaximumValue);
            typedFieldAssert.ShouldBeEqual(m => m.MinimumValue, o => o.MinimumValue);
            typedFieldAssert.ShouldBeEqual(m => m.ShowAsPercentage, o => o.ShowAsPercentage);


            if (!string.IsNullOrEmpty(textDefinition.DisplayFormat))
                typedFieldAssert.ShouldBeEqual(m => m.DisplayFormat, o => o.GetDisplayFormat());
            else
                typedFieldAssert.SkipProperty(m => m.DisplayFormat);


        }
开发者ID:karayakar,项目名称:spmeta2,代码行数:26,代码来源:NumberFieldDefinitionValidator.cs

示例2: DeployModel

        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var definition = model.WithAssertAndCast<FieldDefinition>("model", value => value.RequireNotNull());
            var spObject = GetField(modelHost, definition);

            var assert = ServiceFactory.AssertService.NewAssert(model, definition, spObject);

            ValidateField(assert, spObject, definition);

            var textField = spObject as SPFieldMultiLineText;
            var textDefinition = model.WithAssertAndCast<NoteFieldDefinition>("model", value => value.RequireNotNull());

            var textFieldAssert = ServiceFactory.AssertService.NewAssert(model, textDefinition, textField);

            textFieldAssert.ShouldBeEqual(m => m.NumberOfLines, o => o.NumberOfLines);
            textFieldAssert.ShouldBeEqual(m => m.RichText, o => o.RichText);
            textFieldAssert.ShouldBeEqual(m => m.AppendOnly, o => o.AppendOnly);

            textFieldAssert.ShouldBeEqual(m => m.RichText, o => o.RichText);
            textFieldAssert.ShouldBeEqual(m => m.UnlimitedLengthInDocumentLibrary, o => o.UnlimitedLengthInDocumentLibrary);

            if (!string.IsNullOrEmpty(textDefinition.RichTextMode))
                textFieldAssert.ShouldBeEqual(m => m.RichTextMode, o => o.GetRichTextMode());
            else
                textFieldAssert.SkipProperty(m => m.RichTextMode);
        }
开发者ID:karayakar,项目名称:spmeta2,代码行数:26,代码来源:NoteFieldDefinitionValidator.cs

示例3: DeployModel

        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var definition = model.WithAssertAndCast<FieldDefinition>("model", value => value.RequireNotNull());
            var spObject = GetField(modelHost, definition);

            var assert = ServiceFactory.AssertService.NewAssert(model, definition, spObject);

            ValidateField(assert, spObject, definition);

            var textField = spObject.Context.CastTo<FieldDateTime>(spObject);
            var textDefinition = model.WithAssertAndCast<DateTimeFieldDefinition>("model", value => value.RequireNotNull());

            var textFieldAssert = ServiceFactory.AssertService.NewAssert(model, textDefinition, textField);

            if (!string.IsNullOrEmpty(textDefinition.CalendarType))
                textFieldAssert.ShouldBeEqual(m => m.CalendarType, o => o.GetCalendarType());
            else
                textFieldAssert.SkipProperty(m => m.CalendarType, "CalendarType is null or empty. Skipping.");

            if (!string.IsNullOrEmpty(textDefinition.FriendlyDisplayFormat))
                textFieldAssert.ShouldBeEqual(m => m.FriendlyDisplayFormat, o => o.GetFriendlyDisplayFormat());
            else
                textFieldAssert.SkipProperty(m => m.FriendlyDisplayFormat, "FriendlyDisplayFormat is null or empty. Skipping.");

            if (!string.IsNullOrEmpty(textDefinition.DisplayFormat))
                textFieldAssert.ShouldBeEqual(m => m.DisplayFormat, o => o.GetDisplayFormat());
            else
                textFieldAssert.SkipProperty(m => m.DisplayFormat, "FriendlyDisplayFormat is null or empty. Skipping.");
            
            
        }
开发者ID:karayakar,项目名称:spmeta2,代码行数:31,代码来源:DateTimeFieldDefinitionValidator.cs

示例4: DeployModel

        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            if (modelHost is WebModelHost)
            {
                var workflowWebSubscriptionModelHost = modelHost.WithAssertAndCast<WebModelHost>("modelHost", value => value.RequireNotNull());
                var definition = model.WithAssertAndCast<SP2013WorkflowSubscriptionDefinition>("model", value => value.RequireNotNull());

                var web = workflowWebSubscriptionModelHost.HostWeb;

                var spObject = GetCurrentWebWorkflowSubscriptioBySourceId(workflowWebSubscriptionModelHost,
                       web,
                       web.ID,
                       definition);

                ValidateWorkflowSubscription(modelHost, workflowWebSubscriptionModelHost.HostWeb, spObject, definition);
            }

            if (modelHost is ListModelHost)
            {
                var workflowSubscriptionModelHost = modelHost.WithAssertAndCast<ListModelHost>("modelHost", value => value.RequireNotNull());
                var definition = model.WithAssertAndCast<SP2013WorkflowSubscriptionDefinition>("model", value => value.RequireNotNull());

                var list = workflowSubscriptionModelHost.HostList;
                var web = list.ParentWeb;

                var spObject = GetCurrentWebWorkflowSubscriptioBySourceId(workflowSubscriptionModelHost,
                      web,
                      list.ID,
                      definition);

                ValidateWorkflowSubscription(modelHost, web, spObject, definition);
            }
        }
开发者ID:karayakar,项目名称:spmeta2,代码行数:33,代码来源:SP2013WorkflowSubscriptionDefinitionValidator.cs

示例5: DeployModel

        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var definition = model.WithAssertAndCast<FieldDefinition>("model", value => value.RequireNotNull());
            var spObject = GetField(modelHost, definition);

            var assert = ServiceFactory.AssertService.NewAssert(model, definition, spObject);

            ValidateField(assert, spObject, definition);

            var typedField = spObject.Context.CastTo<FieldUser>(spObject);
            var typedDefinition = model.WithAssertAndCast<UserFieldDefinition>("model", value => value.RequireNotNull());

            var typedFieldAssert = ServiceFactory.AssertService.NewAssert(model, typedDefinition, typedField);

            typedFieldAssert.ShouldBeEqual(m => m.AllowMultipleValues, o => o.AllowMultipleValues);
            typedFieldAssert.ShouldBeEqual(m => m.AllowDisplay, o => o.AllowDisplay);
            typedFieldAssert.ShouldBeEqual(m => m.Presence, o => o.Presence);
            typedFieldAssert.ShouldBeEqual(m => m.SelectionMode, o => o.GetSelectionMode());

            if (typedDefinition.SelectionGroup.HasValue)
            {
                typedFieldAssert.ShouldBeEqual(m => m.SelectionGroup, o => o.SelectionGroup);
            }
            else
            {
                typedFieldAssert.SkipProperty(m => m.SelectionGroup, "SelectionGroup is NULL. Skipping.");
            }

            if (!string.IsNullOrEmpty(typedDefinition.SelectionGroupName))
            {
                var web = ExtractWebFromHost(modelHost);
                var context = web.Context;

                var group = web.SiteGroups.GetByName(typedDefinition.SelectionGroupName);

                context.Load(group);
                context.ExecuteQueryWithTrace();

                typedFieldAssert.ShouldBeEqual((p, s, d) =>
                {
                    var srcProp = s.GetExpressionValue(m => m.SelectionGroupName);
                    var isValid = typedField.SelectionGroup == group.Id;

                    return new PropertyValidationResult
                    {
                        Tag = p.Tag,
                        Src = srcProp,
                        Dst = null,
                        IsValid = isValid
                    };
                });
            }
            else
            {
                typedFieldAssert.SkipProperty(m => m.SelectionGroupName, "SelectionGroupName is NULL. Skipping.");
            }
        }
开发者ID:Uolifry,项目名称:spmeta2,代码行数:57,代码来源:UserFieldDefinitionValidator.cs

示例6: DeployModel

        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            base.DeployModel(modelHost, model);

            var definition = model.WithAssertAndCast<FieldDefinition>("model", value => value.RequireNotNull());
            var spObject = GetField(modelHost, definition);

            var textField = spObject.Context.CastTo<FieldChoice>(spObject);
            var textDefinition = model.WithAssertAndCast<ChoiceFieldDefinition>("model", value => value.RequireNotNull());

            var textFieldAssert = ServiceFactory.AssertService.NewAssert(model, textDefinition, textField);

            textFieldAssert.ShouldBeEqual(m => m.EditFormat, o => o.GetEditFormat());
        }
开发者ID:Uolifry,项目名称:spmeta2,代码行数:14,代码来源:ChoiceFieldDefinitionValidator.cs

示例7: DeployModel

        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var definition = model.WithAssertAndCast<FieldDefinition>("model", value => value.RequireNotNull());
            var spObject = GetField(modelHost, definition);

            var assert = ServiceFactory.AssertService.NewAssert(model, definition, spObject);

            ValidateField(assert, spObject, definition);

            var textField = spObject as SPFieldBoolean;
            var textDefinition = model.WithAssertAndCast<BooleanFieldDefinition>("model", value => value.RequireNotNull());

            var textFieldAssert = ServiceFactory.AssertService.NewAssert(model, textDefinition, textField);

        }
开发者ID:karayakar,项目名称:spmeta2,代码行数:15,代码来源:BooleanFieldDefinitionValidator.cs

示例8: DeployModel

        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var siteModelHost = modelHost.WithAssertAndCast<AdminSiteModelHost>("modelHost", value => value.RequireNotNull());
            var o365SiteModel = model.WithAssertAndCast<O365SiteDefinition>("model", value => value.RequireNotNull());

            DeployO365SiteCollection(modelHost, siteModelHost.HostClientContext, o365SiteModel);
        }
开发者ID:Uolifry,项目名称:spmeta2,代码行数:7,代码来源:O365SiteDefinitionModelHandler.cs

示例9: DeployModel

        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var securableObject = ExtractSecurableObject(modelHost);
            var breakRoleInheritanceModel = model.WithAssertAndCast<BreakRoleInheritanceDefinition>("model", value => value.RequireNotNull());

            ProcessRoleInheritance(modelHost, securableObject, breakRoleInheritanceModel);
        }
开发者ID:karayakar,项目名称:spmeta2,代码行数:7,代码来源:BreakRoleInheritanceModelHandler.cs

示例10: DeployModelInternal

        protected override void DeployModelInternal(object modelHost, DefinitionBase model)
        {
            var siteModelHost = modelHost.WithAssertAndCast<SiteModelHost>("modelHost", value => value.RequireNotNull());
            var definitionModel = model.WithAssertAndCast<ContentTypeDefinition>("model", value => value.RequireNotNull());

            var site = siteModelHost.HostSite;
            var rootWeb = site.RootWeb;

            var contentTypes = rootWeb.AvailableContentTypes;

            var spModel = contentTypes[definitionModel.Name];

            TraceUtils.WithScope(traceScope =>
            {
                Trace.WriteLine(string.Format("Validate model: {0} ContentType:{1}", definitionModel, spModel));

                // assert base properties
                traceScope.WithTraceIndent(trace =>
                {
                    trace.WriteLine(string.Format("Validate Name: model:[{0}] ct:[{1}]", definitionModel.Name, spModel.Name));
                    Assert.AreEqual(definitionModel.Name, spModel.Name);

                    trace.WriteLine(string.Format("Validate Description: model:[{0}] ct:[{1}]", definitionModel.Description, spModel.Description));
                    Assert.AreEqual(definitionModel.Description, spModel.Description);

                    trace.WriteLine(string.Format("Validate Id: model:[{0}] ct:[{1}]", definitionModel.GetContentTypeId(), spModel.Id));
                    Assert.AreEqual(new SPContentTypeId(definitionModel.GetContentTypeId()), spModel.Id);

                    trace.WriteLine(string.Format("Validate Group: model:[{0}] ct:[{1}]", definitionModel.Group, spModel.Group));
                    Assert.AreEqual(definitionModel.Group, spModel.Group);
                });
            });
        }
开发者ID:nklychnikov,项目名称:spmeta2,代码行数:33,代码来源:ContentTypeDefinitionValidator.cs

示例11: DeployModel

        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var securableObject = ExtractSecurableObject(modelHost);
            var definition = model.WithAssertAndCast<ResetRoleInheritanceDefinition>("model", value => value.RequireNotNull());

            var context = securableObject.Context;

            if (!securableObject.IsObjectPropertyInstantiated("HasUniqueRoleAssignments"))
            {
                context.Load(securableObject, s => s.HasUniqueRoleAssignments);
                context.ExecuteQueryWithTrace();
            }

            var assert = ServiceFactory.AssertService
                                      .NewAssert(definition, securableObject)
                                            .ShouldNotBeNull(securableObject);

            assert.ShouldBeEqual((p, s, d) =>
            {
                var dstProp = d.GetExpressionValue(m => m.HasUniqueRoleAssignments);

                return new PropertyValidationResult
                {
                    Tag = p.Tag,
                    Src = null,
                    Dst = dstProp,
                    IsValid = d.HasUniqueRoleAssignments == false
                };
            });
        }
开发者ID:karayakar,项目名称:spmeta2,代码行数:30,代码来源:ClientResetRoleInheritanceDefinitionValidator.cs

示例12: DeployModel

        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var definition = model.WithAssertAndCast<EventReceiverDefinition>("model", value => value.RequireNotNull());
            Microsoft.SharePoint.Client.EventReceiverDefinition spObject = null;

            if (modelHost is ListModelHost)
                spObject = FindEventReceiverDefinition((modelHost as ListModelHost).HostList.EventReceivers, definition);
            else if (modelHost is WebModelHost)
                spObject = FindEventReceiverDefinition((modelHost as WebModelHost).HostWeb.EventReceivers, definition);
            else if (modelHost is SiteModelHost)
                spObject = FindEventReceiverDefinition((modelHost as SiteModelHost).HostSite.EventReceivers, definition);
            else
            {
                throw new SPMeta2UnsupportedModelHostException("model host should be ListModelHost or WebModelHost");
            }

            var assert = ServiceFactory.AssertService
                               .NewAssert(definition, spObject)
                                     .ShouldNotBeNull(spObject)
                                     .ShouldBeEqual(m => m.Name, o => o.ReceiverName)
                                     .ShouldBeEqual(m => m.Class, o => o.ReceiverClass)
                                     .ShouldBeEqual(m => m.Assembly, o => o.ReceiverAssembly)
                                     .SkipProperty(m => m.Data, "Data property is not supported by CSOM. SKipping.")
                                     .ShouldBeEqual(m => m.SequenceNumber, o => o.SequenceNumber)
                                     .ShouldBeEqual(m => m.Synchronization, o => o.GetSynchronization())
                                     .ShouldBeEqual(m => m.Type, o => o.GetEventReceiverType());
        }
开发者ID:Uolifry,项目名称:spmeta2,代码行数:27,代码来源:ClientEventReceiverDefinitionValidator.cs

示例13: DeployModel

        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var webAppModelHost = modelHost.WithAssertAndCast<WebApplicationModelHost>("modelHost", value => value.RequireNotNull());
            var definition = model.WithAssertAndCast<PeoplePickerSettingsDefinition>("model", value => value.RequireNotNull());

            DeployPeoplePickerSettings(modelHost, webAppModelHost.HostWebApplication, definition);
        }
开发者ID:avishnyakov,项目名称:spmeta2,代码行数:7,代码来源:PeoplePickerSettingsModelHandler.cs

示例14: DeployModel

        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            // base validation
            base.DeployModel(modelHost, model);

            // web specific validation
            var host = modelHost.WithAssertAndCast<WebpartPageModelHost>("modelHost", value => value.RequireNotNull());
            var definition = model.WithAssertAndCast<PageViewerWebPartDefinition>("model", value => value.RequireNotNull());

            var item = host.PageListItem;

            WebPartExtensions.WithExistingWebPart(item, definition, (spWebPartManager, spObject) =>
            {
                var web = spWebPartManager.Web;
                var typedObject = spObject as PageViewerWebPart;

                var assert = ServiceFactory.AssertService
                    .NewAssert(definition, typedObject)
                    .ShouldNotBeNull(typedObject);

                if (!string.IsNullOrEmpty(definition.ContentLink))
                    assert.ShouldBeEqual(m => m.ContentLink, o => o.ContentLink);
                else
                    assert.SkipProperty(m => m.ContentLink);

                if (!string.IsNullOrEmpty(definition.SourceType))
                    assert.ShouldBeEqual(m => m.SourceType, o => o.GetSourceType());
                else
                    assert.SkipProperty(m => m.SourceType);
            });
        }
开发者ID:Uolifry,项目名称:spmeta2,代码行数:31,代码来源:PageViewerWebPartDefinitionValidator.cs

示例15: DeployModel

        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var securableObject = modelHost.WithAssertAndCast<SecurableObject>("modelHost", value => value.RequireNotNull());
            var securityGroupLinkModel = model.WithAssertAndCast<SecurityGroupLinkDefinition>("model", value => value.RequireNotNull());

            var web = GetWebFromSPSecurableObject(securableObject);

            var context = web.Context;

            context.Load(web, w => w.SiteGroups);
            context.Load(securableObject, s => s.RoleAssignments.Include(r => r.Member));

            context.ExecuteQuery();

            var securityGroup = WebExtensions.FindGroupByName(web.SiteGroups, securityGroupLinkModel.SecurityGroupName);

            TraceUtils.WithScope(traceScope =>
            {
                traceScope.WriteLine(string.Format("Validate model:[{0}] securableObject:[{1}]", securityGroupLinkModel, securityGroup));

                traceScope.WithTraceIndent(trace =>
                {
                    // asserting it exists
                    trace.WriteLine(string.Format("Validating existance..."));

                    var existingRoleAssignments = FindClientRoleRoleAssignment(securableObject.RoleAssignments, securityGroup);

                    Assert.IsNotNull(existingRoleAssignments);

                    trace.WriteLine(string.Format("RoleAssignments for security group link [{0}] exists.", securityGroupLinkModel.SecurityGroupName));
                });
            });
        }
开发者ID:nklychnikov,项目名称:spmeta2,代码行数:33,代码来源:ClientSecurityGroupLinkDefinitionValidator.cs


注:本文中的SPMeta2.Definitions.DefinitionBase.WithAssertAndCast方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。