From 18f9a2f0d20359b099eeed4631228cfeb7fa9347 Mon Sep 17 00:00:00 2001 From: Ondrej Valenta Date: Wed, 4 Jul 2018 11:56:58 +0200 Subject: [PATCH] #15 CreateTermSet and CreateTerm --- .../FluentlySharePoint/Extensions/Taxonomy.cs | 25 +++- FluentlySharepoint/TestConsole/Assignee.cs | 12 ++ .../TestConsole/Models/WorkflowModels.cs | 116 ++++++++++++++++++ FluentlySharepoint/TestConsole/Program.cs | 111 +---------------- FluentlySharepoint/TestConsole/Stage.cs | 11 ++ 5 files changed, 163 insertions(+), 112 deletions(-) create mode 100644 FluentlySharepoint/TestConsole/Assignee.cs create mode 100644 FluentlySharepoint/TestConsole/Models/WorkflowModels.cs create mode 100644 FluentlySharepoint/TestConsole/Stage.cs diff --git a/FluentlySharepoint/FluentlySharePoint/Extensions/Taxonomy.cs b/FluentlySharepoint/FluentlySharePoint/Extensions/Taxonomy.cs index bae85d3..a4decd9 100644 --- a/FluentlySharepoint/FluentlySharePoint/Extensions/Taxonomy.cs +++ b/FluentlySharepoint/FluentlySharePoint/Extensions/Taxonomy.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using KeenMate.FluentlySharePoint.Models; using Microsoft.SharePoint.Client.Taxonomy; @@ -42,9 +43,29 @@ public static CSOMOperation CreateTermGroup(this CSOMOperation operation, string return operation; } - public static CSOMOperation CreateTermSet(this CSOMOperation operation, string name, Guid? guid = null) + public static CSOMOperation CreateTermSet(this CSOMOperation operation, string name, Guid? guid = null, int lcid = 1033) { - throw new NotImplementedException(); + var op = operation.TaxonomyOperation; + + op.LastTermSet = op.LastTermGroup.CreateTermSet(name, guid??Guid.NewGuid(), lcid); + + return operation; + } + + public static CSOMOperation CreateTerm(this CSOMOperation operation, string name + , Guid? guid = null, int lcid = 1033, IEnumerable> descriptions = null) + { + var op = operation.TaxonomyOperation; + + op.LastTerm = op.LastTermSet.CreateTerm(name, lcid, guid ?? Guid.NewGuid()); + + if (descriptions != null) + foreach (var description in descriptions) + { + op.LastTerm.SetDescription(description.Item1, description.Item2); + } + + return operation; } } diff --git a/FluentlySharepoint/TestConsole/Assignee.cs b/FluentlySharepoint/TestConsole/Assignee.cs new file mode 100644 index 0000000..b67c26a --- /dev/null +++ b/FluentlySharepoint/TestConsole/Assignee.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; +using System.Xml.Serialization; + +namespace TestConsole +{ + [XmlRoot(ElementName = "Assignee", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] + public class Assignee + { + [XmlElement(ElementName = "Person", Namespace = "http://schemas.microsoft.com/office/infopath/2007/PartnerControls")] + public List Person { get; set; } + } +} \ No newline at end of file diff --git a/FluentlySharepoint/TestConsole/Models/WorkflowModels.cs b/FluentlySharepoint/TestConsole/Models/WorkflowModels.cs new file mode 100644 index 0000000..282e4f2 --- /dev/null +++ b/FluentlySharepoint/TestConsole/Models/WorkflowModels.cs @@ -0,0 +1,116 @@ +using System.Collections.Generic; +using System.Xml.Serialization; + +namespace TestConsole.WorkflowModels +{ + [XmlRoot(ElementName = "Person", Namespace = "http://schemas.microsoft.com/office/infopath/2007/PartnerControls")] + public class Person + { + [XmlElement(ElementName = "DisplayName", Namespace = "http://schemas.microsoft.com/office/infopath/2007/PartnerControls")] + public string DisplayName { get; set; } + [XmlElement(ElementName = "AccountId", Namespace = "http://schemas.microsoft.com/office/infopath/2007/PartnerControls")] + public string AccountId { get; set; } + [XmlElement(ElementName = "AccountType", Namespace = "http://schemas.microsoft.com/office/infopath/2007/PartnerControls")] + public string AccountType { get; set; } + } + + [XmlRoot(ElementName = "Assignee", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] + public class Assignee + { + [XmlElement(ElementName = "Person", Namespace = "http://schemas.microsoft.com/office/infopath/2007/PartnerControls")] + public List Person { get; set; } + } + + [XmlRoot(ElementName = "Stage", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] + public class Stage + { + [XmlAttribute(AttributeName = "nil", Namespace = "http://www.w3.org/2001/XMLSchema-instance")] + public string Nil { get; set; } + } + + [XmlRoot(ElementName = "Assignment", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] + public class Assignment + { + [XmlElement(ElementName = "Assignee", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] + public Assignee Assignee { get; set; } + [XmlElement(ElementName = "Stage", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] + public Stage Stage { get; set; } + [XmlElement(ElementName = "AssignmentType", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] + public string AssignmentType { get; set; } + } + + [XmlRoot(ElementName = "Reviewers", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] + public class Reviewers + { + [XmlElement(ElementName = "Assignment", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] + public Assignment Assignment { get; set; } + } + + [XmlRoot(ElementName = "DueDateforAllTasks", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] + public class DueDateforAllTasks + { + [XmlAttribute(AttributeName = "nil", Namespace = "http://www.w3.org/2001/XMLSchema-instance")] + public string Nil { get; set; } + } + + [XmlRoot(ElementName = "CC", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] + public class CC + { + [XmlElement(ElementName = "Person", Namespace = "http://schemas.microsoft.com/office/infopath/2007/PartnerControls")] + public Person Person { get; set; } + } + + [XmlRoot(ElementName = "SharePointListItem_RW", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] + public class SharePointListItem_RW + { + [XmlElement(ElementName = "Reviewers", + Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] + public Reviewers Reviewers { get; set; } = new Reviewers(); + [XmlElement(ElementName = "ExpandGroups", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] + public string ExpandGroups { get; set; } + [XmlElement(ElementName = "NotificationMessage", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] + public string NotificationMessage { get; set; } + [XmlElement(ElementName = "DueDateforAllTasks", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] + public DueDateforAllTasks DueDateforAllTasks { get; set; } = new DueDateforAllTasks(); + [XmlElement(ElementName = "DurationforSerialTasks", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] + public string DurationforSerialTasks { get; set; } + [XmlElement(ElementName = "DurationUnits", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] + public string DurationUnits { get; set; } + [XmlElement(ElementName = "CC", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] + public CC CC { get; set; } = new CC(); + [XmlElement(ElementName = "CancelonChange", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] + public string CancelonChange { get; set; } + } + + [XmlRoot(ElementName = "dataFields", Namespace = "http://schemas.microsoft.com/office/infopath/2003/dataFormSolution")] + public class DataFields + { + [XmlElement(ElementName = "SharePointListItem_RW", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] + public SharePointListItem_RW SharePointListItem_RW { get; set; } = new SharePointListItem_RW(); + } + + [XmlRoot(ElementName = "myFields", Namespace = "http://schemas.microsoft.com/office/infopath/2003/dataFormSolution")] + public class MyFields + { + [XmlElement(ElementName = "queryFields", Namespace = "http://schemas.microsoft.com/office/infopath/2003/dataFormSolution")] + public string QueryFields { get; set; } + [XmlElement(ElementName = "dataFields", Namespace = "http://schemas.microsoft.com/office/infopath/2003/dataFormSolution")] + public DataFields DataFields { get; set; } = new DataFields(); + [XmlAttribute(AttributeName = "xsd", Namespace = "http://www.w3.org/2000/xmlns/")] + public string Xsd { get; set; } + [XmlAttribute(AttributeName = "dms", Namespace = "http://www.w3.org/2000/xmlns/")] + public string Dms { get; set; } + [XmlAttribute(AttributeName = "dfs", Namespace = "http://www.w3.org/2000/xmlns/")] + public string Dfs { get; set; } + [XmlAttribute(AttributeName = "q", Namespace = "http://www.w3.org/2000/xmlns/")] + public string Q { get; set; } + [XmlAttribute(AttributeName = "d", Namespace = "http://www.w3.org/2000/xmlns/")] + public string D { get; set; } + [XmlAttribute(AttributeName = "ma", Namespace = "http://www.w3.org/2000/xmlns/")] + public string Ma { get; set; } + [XmlAttribute(AttributeName = "pc", Namespace = "http://www.w3.org/2000/xmlns/")] + public string Pc { get; set; } + [XmlAttribute(AttributeName = "xsi", Namespace = "http://www.w3.org/2000/xmlns/")] + public string Xsi { get; set; } + } +} \ No newline at end of file diff --git a/FluentlySharepoint/TestConsole/Program.cs b/FluentlySharepoint/TestConsole/Program.cs index 8a8375d..e0dc0fc 100644 --- a/FluentlySharepoint/TestConsole/Program.cs +++ b/FluentlySharepoint/TestConsole/Program.cs @@ -208,114 +208,5 @@ private static void StartStandardWorkflow() } - [XmlRoot(ElementName = "Person", Namespace = "http://schemas.microsoft.com/office/infopath/2007/PartnerControls")] - public class Person - { - [XmlElement(ElementName = "DisplayName", Namespace = "http://schemas.microsoft.com/office/infopath/2007/PartnerControls")] - public string DisplayName { get; set; } - [XmlElement(ElementName = "AccountId", Namespace = "http://schemas.microsoft.com/office/infopath/2007/PartnerControls")] - public string AccountId { get; set; } - [XmlElement(ElementName = "AccountType", Namespace = "http://schemas.microsoft.com/office/infopath/2007/PartnerControls")] - public string AccountType { get; set; } - } - - [XmlRoot(ElementName = "Assignee", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] - public class Assignee - { - [XmlElement(ElementName = "Person", Namespace = "http://schemas.microsoft.com/office/infopath/2007/PartnerControls")] - public List Person { get; set; } - } - - [XmlRoot(ElementName = "Stage", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] - public class Stage - { - [XmlAttribute(AttributeName = "nil", Namespace = "http://www.w3.org/2001/XMLSchema-instance")] - public string Nil { get; set; } - } - - [XmlRoot(ElementName = "Assignment", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] - public class Assignment - { - [XmlElement(ElementName = "Assignee", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] - public Assignee Assignee { get; set; } - [XmlElement(ElementName = "Stage", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] - public Stage Stage { get; set; } - [XmlElement(ElementName = "AssignmentType", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] - public string AssignmentType { get; set; } - } - - [XmlRoot(ElementName = "Reviewers", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] - public class Reviewers - { - [XmlElement(ElementName = "Assignment", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] - public Assignment Assignment { get; set; } - } - - [XmlRoot(ElementName = "DueDateforAllTasks", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] - public class DueDateforAllTasks - { - [XmlAttribute(AttributeName = "nil", Namespace = "http://www.w3.org/2001/XMLSchema-instance")] - public string Nil { get; set; } - } - - [XmlRoot(ElementName = "CC", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] - public class CC - { - [XmlElement(ElementName = "Person", Namespace = "http://schemas.microsoft.com/office/infopath/2007/PartnerControls")] - public Person Person { get; set; } - } - - [XmlRoot(ElementName = "SharePointListItem_RW", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] - public class SharePointListItem_RW - { - [XmlElement(ElementName = "Reviewers", - Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] - public Reviewers Reviewers { get; set; } = new Reviewers(); - [XmlElement(ElementName = "ExpandGroups", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] - public string ExpandGroups { get; set; } - [XmlElement(ElementName = "NotificationMessage", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] - public string NotificationMessage { get; set; } - [XmlElement(ElementName = "DueDateforAllTasks", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] - public DueDateforAllTasks DueDateforAllTasks { get; set; } = new DueDateforAllTasks(); - [XmlElement(ElementName = "DurationforSerialTasks", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] - public string DurationforSerialTasks { get; set; } - [XmlElement(ElementName = "DurationUnits", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] - public string DurationUnits { get; set; } - [XmlElement(ElementName = "CC", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] - public CC CC { get; set; } = new CC(); - [XmlElement(ElementName = "CancelonChange", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] - public string CancelonChange { get; set; } - } - - [XmlRoot(ElementName = "dataFields", Namespace = "http://schemas.microsoft.com/office/infopath/2003/dataFormSolution")] - public class DataFields - { - [XmlElement(ElementName = "SharePointListItem_RW", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] - public SharePointListItem_RW SharePointListItem_RW { get; set; } = new SharePointListItem_RW(); - } - - [XmlRoot(ElementName = "myFields", Namespace = "http://schemas.microsoft.com/office/infopath/2003/dataFormSolution")] - public class MyFields - { - [XmlElement(ElementName = "queryFields", Namespace = "http://schemas.microsoft.com/office/infopath/2003/dataFormSolution")] - public string QueryFields { get; set; } - [XmlElement(ElementName = "dataFields", Namespace = "http://schemas.microsoft.com/office/infopath/2003/dataFormSolution")] - public DataFields DataFields { get; set; } = new DataFields(); - [XmlAttribute(AttributeName = "xsd", Namespace = "http://www.w3.org/2000/xmlns/")] - public string Xsd { get; set; } - [XmlAttribute(AttributeName = "dms", Namespace = "http://www.w3.org/2000/xmlns/")] - public string Dms { get; set; } - [XmlAttribute(AttributeName = "dfs", Namespace = "http://www.w3.org/2000/xmlns/")] - public string Dfs { get; set; } - [XmlAttribute(AttributeName = "q", Namespace = "http://www.w3.org/2000/xmlns/")] - public string Q { get; set; } - [XmlAttribute(AttributeName = "d", Namespace = "http://www.w3.org/2000/xmlns/")] - public string D { get; set; } - [XmlAttribute(AttributeName = "ma", Namespace = "http://www.w3.org/2000/xmlns/")] - public string Ma { get; set; } - [XmlAttribute(AttributeName = "pc", Namespace = "http://www.w3.org/2000/xmlns/")] - public string Pc { get; set; } - [XmlAttribute(AttributeName = "xsi", Namespace = "http://www.w3.org/2000/xmlns/")] - public string Xsi { get; set; } - } + } diff --git a/FluentlySharepoint/TestConsole/Stage.cs b/FluentlySharepoint/TestConsole/Stage.cs new file mode 100644 index 0000000..1cd7219 --- /dev/null +++ b/FluentlySharepoint/TestConsole/Stage.cs @@ -0,0 +1,11 @@ +using System.Xml.Serialization; + +namespace TestConsole +{ + [XmlRoot(ElementName = "Stage", Namespace = "http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields")] + public class Stage + { + [XmlAttribute(AttributeName = "nil", Namespace = "http://www.w3.org/2001/XMLSchema-instance")] + public string Nil { get; set; } + } +} \ No newline at end of file