Skip to content

Commit

Permalink
+ .AddWorkflowAssociation() should support list scoped content types #…
Browse files Browse the repository at this point in the history
…980

+ CSOM support
  • Loading branch information
SubPointSupport committed Mar 20, 2017
1 parent f42fa6d commit 7c18ecf
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 15 deletions.
32 changes: 18 additions & 14 deletions SPMeta2/SPMeta2.CSOM/ModelHandlers/ContentTypeLinkModelHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
using SPMeta2.ModelHandlers;
using SPMeta2.Services;
using SPMeta2.Utils;
using SPMeta2.CSOM.ModelHosts;
using SPMeta2.CSOM.ModelHosts;
using SPMeta2.ModelHosts;

namespace SPMeta2.CSOM.ModelHandlers
{
Expand All @@ -20,8 +21,8 @@ public override Type TargetType
}

public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
{
var modelHost = modelHostContext.ModelHost;
{
var modelHost = modelHostContext.ModelHost as CSOMModelHostBase;
var model = modelHostContext.Model;
var childModelType = modelHostContext.ChildModelType;
var action = modelHostContext.Action;
Expand All @@ -33,18 +34,21 @@ public override void WithResolvingModelHost(ModelHostResolveContext modelHostCon
var context = list.Context;

context.Load(list, l => l.ContentTypes);
context.ExecuteQueryWithTrace();

var listContentType = FindListContentType(list, contentTypeLinkModel);

action(new ModelHostContext
{
Site = listModelHost.HostSite,
Web = listModelHost.HostWeb,
ContentType = listContentType
});
context.ExecuteQueryWithTrace();

var contentType = FindListContentType(list, contentTypeLinkModel);

var contentTypeLinkHost = ModelHostBase.Inherit<ContentTypeLinkModelHost>(modelHost, host =>
{
host.HostContentType = contentType;
host.HostList = list;
});

action(contentTypeLinkHost);

if (!contentTypeLinkHost.ShouldUpdateHost)
contentType.Update(false);

listContentType.Update(false);
context.ExecuteQueryWithTrace();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ public override void DeployModel(object modelHost, DefinitionBase model)

DeployContentTypeWorkflowAssociationDefinition(modelHost, contentType, workflowAssociationModel);
}
else if (modelHost is ContentTypeLinkModelHost)
{
var contentTypeLinkModelHost = (modelHost as ContentTypeLinkModelHost);

// don't update content type link within list
if (contentTypeLinkModelHost.HostList != null)
contentTypeLinkModelHost.ShouldUpdateHost = false;

var contentType = contentTypeLinkModelHost.HostContentType;
var web = contentTypeLinkModelHost.HostWeb;

if (contentTypeLinkModelHost.HostList != null)
contentTypeLinkModelHost.ShouldUpdateHost = false;

DeployContentTypeWorkflowAssociationDefinition(modelHost, contentType, workflowAssociationModel);
}
else
{
throw new SPMeta2NotSupportedException("model host should be of type ListModelHost or WebModelHost");
Expand All @@ -77,6 +93,14 @@ private Web GetWebFromModelHost(object modelHost)
return (modelHost as ModelHostContext).Web;
}

if (modelHost is ContentTypeLinkModelHost)
{
var listContentTypeHost = (modelHost as ContentTypeLinkModelHost);


return listContentTypeHost.HostWeb;
}

throw new SPMeta2NotSupportedException("model host should be of type ListModelHost or WebModelHost");
}

Expand Down Expand Up @@ -121,6 +145,19 @@ protected WorkflowAssociation FindExistringWorkflowAssotiation(object modelHost,
return res.FirstOrDefault();
}

if (modelHost is ContentTypeLinkModelHost)
{
var list = (modelHost as ContentTypeLinkModelHost).HostList;
var context = list.Context;

var defName = def.Name;

var res = context.LoadQuery(list.WorkflowAssociations.Where(w => w.Name == defName));
context.ExecuteQueryWithTrace();

return res.FirstOrDefault();
}

throw new SPMeta2NotSupportedException("model host should be of type ListModelHost or WebModelHost");
}

Expand Down
24 changes: 24 additions & 0 deletions SPMeta2/SPMeta2.CSOM/ModelHosts/ContentTypeLinkModelHost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.SharePoint;
using Microsoft.SharePoint.Client;

namespace SPMeta2.CSOM.ModelHosts
{
public class ContentTypeLinkModelHost : ListModelHost
{
#region constructors


#endregion

#region properties

public ContentType HostContentType { get; set; }

#endregion
}
}
2 changes: 1 addition & 1 deletion SPMeta2/SPMeta2.CSOM/ModelHosts/ListModelHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace SPMeta2.CSOM.ModelHosts
{
public class ListModelHost : CSOMModelHostBase
public class ListModelHost : WebModelHost
{
#region properties

Expand Down
1 change: 1 addition & 0 deletions SPMeta2/SPMeta2.CSOM/SPMeta2.CSOM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@
<Compile Include="ModelHandlers\WorkflowAssociationModelHandler.cs" />
<Compile Include="ModelHandlers\WikiPageModelHandler.cs" />
<Compile Include="ModelHandlers\Webparts\XsltListViewWebPartModelHandler.cs" />
<Compile Include="ModelHosts\ContentTypeLinkModelHost.cs" />
<Compile Include="ModelHosts\ListItemFieldValueModelHost.cs" />
<Compile Include="ModelHosts\ListItemModelHost.cs" />
<Compile Include="ModelHosts\ModuleFileModelHost.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public void CanDeploy_WorkflowAssociation_UnderContentTypeLink()
{
def.Hidden = true;
def.TemplateType = BuiltInListTemplateTypeId.Tasks;
def.ContentTypesEnabled = true;
});

var historyList = ModelGeneratorService.GetRandomDefinition<ListDefinition>(def =>
Expand Down

0 comments on commit 7c18ecf

Please sign in to comment.