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);


        }
        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);
        }
        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.");
            
            
        }
        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);
            }
        }
        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.");
            }
        }
        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());
        }
        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);

        }
        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);
        }
        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);
        }
        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);
                });
            });
        }
        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
                };
            });
        }
        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());
        }
        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);
        }
        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);
            });
        }
        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));
                });
            });
        }
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var webAppModelHost = modelHost.WithAssertAndCast<WebApplicationModelHost>("modelHost", value => value.RequireNotNull());
            var siteModel = model.WithAssertAndCast<SiteDefinition>("model", value => value.RequireNotNull());

            DeploySite(webAppModelHost, webAppModelHost.HostWebApplication, siteModel);
        }
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var farmModelHost = modelHost.WithAssertAndCast<FarmModelHost>("modelHost", value => value.RequireNotNull());
            var managedAccountDefinition = model.WithAssertAndCast<ManagedAccountDefinition>("model", value => value.RequireNotNull());

            DeployManagedAccount(modelHost, farmModelHost.HostFarm, managedAccountDefinition);
        }
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var list = ExtractListFromHost(modelHost);
            var hideContentTypeLinksDefinition = model.WithAssertAndCast<RemoveContentTypeLinksDefinition>("model", value => value.RequireNotNull());

            DeployHideContentTypeLinks(modelHost, list, hideContentTypeLinksDefinition);
        }
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var webModelHost = modelHost.WithAssertAndCast<WebModelHost>("modelHost", value => value.RequireNotNull());
            var navigationModel = model.WithAssertAndCast<WebNavigationSettingsDefinition>("model", value => value.RequireNotNull());

            DeployNavigationSettings(modelHost, webModelHost, navigationModel);
        }
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var modelHostContext = modelHost.WithAssertAndCast<ModelHostContext>("modelHost", value => value.RequireNotNull());
            var fieldlinkModel = model.WithAssertAndCast<ContentTypeFieldLinkDefinition>("model", value => value.RequireNotNull());

            var site = modelHostContext.Site;
            var contentType = modelHostContext.ContentType;

            var context = site.Context;

            context.Load(contentType, ct => ct.FieldLinks);
            context.ExecuteQuery();

            var spFieldLink = FindFieldLinkById(contentType.FieldLinks, fieldlinkModel.FieldId);

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

                // assert base properties
                traceScope.WithTraceIndent(trace =>
                {
                    trace.WriteLine(string.Format("Validate FieldId: model:[{0}] ct field link:[{1}]", fieldlinkModel.FieldId, spFieldLink.Id));
                    Assert.AreEqual(fieldlinkModel.FieldId, spFieldLink.Id);
                });
            });
        }
        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<ClientWebPartDefinition>("model", value => value.RequireNotNull());

            //var pageItem = listItemModelHost.HostListItem;

            WithExistingWebPart(listItemModelHost.HostFile, definition, spObject =>
            {
                var assert = ServiceFactory.AssertService
                                           .NewAssert(model, definition, spObject)
                                                 .ShouldNotBeNull(spObject);

                // some of the properties can actually be validated
                // http://stackoverflow.com/questions/11814829/how-to-read-webpart-content-using-sharepoint-client-om
                // asmx calls are required to get additional information about the current web parts

                assert
                    .SkipProperty(m => m.ZoneIndex, "Property is not available in CSOM. Skipping.")

                    .SkipProperty(m => m.Id, "Property is not available in CSOM. Skipping.")
                    .SkipProperty(m => m.ZoneId, "Property is not available in CSOM. Skipping.")

                    .SkipProperty(m => m.WebpartFileName, "Property is not available in CSOM. Skipping.")
                    .SkipProperty(m => m.WebpartType, "Property is not available in CSOM. Skipping.")
                    .SkipProperty(m => m.WebpartXmlTemplate, "Property is not available in CSOM. Skipping.")

                    .ShouldBeEqual(m => m.Title, o => o.Title);
            });
        }
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var list = modelHost.WithAssertAndCast<SPList>("modelHost", value => value.RequireNotNull());
            var listItemModel = model.WithAssertAndCast<ListItemDefinition>("model", value => value.RequireNotNull());

            DeployInternall(list, listItemModel);
        }
        public override void WithResolvingModelHost(object modelHost, DefinitionBase model, Type childModelType, Action<object> action)
        {
            var folderModelHost = modelHost.WithAssertAndCast<FolderModelHost>("modelHost", value => value.RequireNotNull());
            var folderModel = model.WithAssertAndCast<FolderDefinition>("model", value => value.RequireNotNull());

            if (folderModelHost.CurrentLibrary != null)
            {
                var currentFolder = EnsureLibraryFolder(folderModelHost, folderModel);

                var newContext = new FolderModelHost
                {
                    CurrentLibrary = folderModelHost.CurrentLibrary,
                    CurrentLibraryFolder = currentFolder
                };

                action(newContext);
            }
            else if (folderModelHost.CurrentList != null)
            {
                var currentListItem = EnsureListFolder(folderModelHost, folderModel);

                var newContext = new FolderModelHost
                {
                    CurrentList = folderModelHost.CurrentList,
                    CurrentListItem = currentListItem
                };

                action(newContext);
            }
        }
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var typedModelHost = modelHost.WithAssertAndCast<WebModelHost>("modelHost", value => value.RequireNotNull());
            var typedDefinition = model.WithAssertAndCast<DeleteTopNavigationNodesDefinition>("model", value => value.RequireNotNull());

            DeployDefinition(modelHost, typedModelHost, typedDefinition);
        }
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var webModelHost = modelHost.WithAssertAndCast<WebModelHost>("modelHost", value => value.RequireNotNull());
            var definition = model.WithAssertAndCast<RegionalSettingsDefinition>("model", value => value.RequireNotNull());

            DeployRegionalSettings(modelHost, webModelHost.HostWeb, definition);
        }
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var folder = ExtractFolderFromModelHost(modelHost);
            var welcomePgaeModel = model.WithAssertAndCast<WelcomePageDefinition>("model", value => value.RequireNotNull());

            DeployWelcomePage(modelHost, model, folder, welcomePgaeModel);
        }
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var siteModelHost = modelHost.WithAssertAndCast<TermStoreModelHost>("modelHost", value => value.RequireNotNull());
            var groupModel = model.WithAssertAndCast<TaxonomyTermGroupDefinition>("model", value => value.RequireNotNull());

            DeployTaxonomyGroup(modelHost, siteModelHost, groupModel);
        }
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var farmModelHost = modelHost.WithAssertAndCast<FarmModelHost>("modelHost", value => value.RequireNotNull());
            var solutionModel = model.WithAssertAndCast<FarmSolutionDefinition>("model", value => value.RequireNotNull());

            DeploySolution(farmModelHost, solutionModel);
        }
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var folder = modelHost.WithAssertAndCast<SPFolder>("modelHost", value => value.RequireNotNull());
            var moduleFile = model.WithAssertAndCast<ModuleFileDefinition>("model", value => value.RequireNotNull());

            ProcessFile(modelHost, folder, moduleFile);
        }
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var workflowAssociationModel = model.WithAssertAndCast<WorkflowAssociationDefinition>("model", value => value.RequireNotNull());

            if (modelHost is ListModelHost)
            {
                var listModelHost = (modelHost as ListModelHost);
                var list = listModelHost.HostList;

                DeployListWorkflowAssociationDefinition(listModelHost, list, workflowAssociationModel);
            }
            else if (modelHost is WebModelHost)
            {
                var webModelHost = (modelHost as WebModelHost);
                var web = webModelHost.HostWeb;

                DeployWebWorkflowAssociationDefinition(webModelHost, web, workflowAssociationModel);
            }
            else if (modelHost is ModelHostContext)
            {
                var contentType = (modelHost as ModelHostContext).ContentType;

                DeployContentTypeWorkflowAssociationDefinition(modelHost, contentType, workflowAssociationModel);
            }
            else
            {
                throw new SPMeta2NotSupportedException("model host should be of type ListModelHost or WebModelHost");
            }
        }