From 1bcd984481b79cfc782d8e2a0e575d8b9c98527e Mon Sep 17 00:00:00 2001 From: Rylov Roman Date: Tue, 8 Mar 2016 21:32:53 +0300 Subject: [PATCH] Fix compatibility with 2010 Workflows --- TemplatePackageFix/Fixer.cs | 29 ++++++----- TemplatePackageFix/Helpers/Extensions.cs | 4 -- TemplatePackageFix/Models/Solution.cs | 3 -- TemplatePackageFix/Packer.cs | 4 -- TemplatePackageFix/Program.cs | 9 +--- TemplatePackageFix/Properties/app.manifest | 54 ++++++++++++++++++++ TemplatePackageFix/TemplatePackageFix.csproj | 15 ++++-- 7 files changed, 85 insertions(+), 33 deletions(-) create mode 100644 TemplatePackageFix/Properties/app.manifest diff --git a/TemplatePackageFix/Fixer.cs b/TemplatePackageFix/Fixer.cs index fac22a2..daa2fe0 100644 --- a/TemplatePackageFix/Fixer.cs +++ b/TemplatePackageFix/Fixer.cs @@ -1,23 +1,21 @@ -using System; +using Plumsail.TemplatePackageFix.Helpers; +using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Linq.Expressions; -using System.Text; -using System.Threading.Tasks; -using System.Xml; using System.Xml.Linq; -using Plumsail.TemplatePackageFix.Helpers; namespace Plumsail.TemplatePackageFix { public sealed class Fixer { #region Declarations - readonly XNamespace ns = "http://schemas.microsoft.com/sharepoint/"; + readonly string BasePath; + readonly XNamespace ns = "http://schemas.microsoft.com/sharepoint/"; readonly string WFPackSolutionID = "64283c6e-6aea-4a86-a881-042359b3521a"; readonly string WFFeaturePath = "SP2013Workflows"; - readonly string BasePath; + readonly List WFPackFeatures = new List { "{9a5d1295-65c0-4c8e-a926-968da90d2ef9}", "{d7891031-e7f5-4734-8077-9189dd35551c}" }; private XDocument wfFeature; private XDocument wfElements; @@ -86,7 +84,7 @@ internal void ProcessFeature(string featureFile) internal void CreateWorkflowFeature() { wfFeatureDir = Path.Combine(BasePath, WFFeaturePath); - System.IO.Directory.CreateDirectory(wfFeatureDir); + Directory.CreateDirectory(wfFeatureDir); wfFeature = new XDocument( new XElement(ns + "Feature", new XAttribute("Id", Guid.NewGuid().ToString()), @@ -141,8 +139,7 @@ private void RemoveDependentFeatures(XDocument feature, XDocument elements, stri var onetFilePath = Path.Combine(featureDir, onet.Attribute("Location").Value); var onetDocument = XDocument.Load(onetFilePath); var features = onetDocument.Descendants(ns + "Feature") - .Where(el => el.Attribute("ID").Value == "{9a5d1295-65c0-4c8e-a926-968da90d2ef9}" - || el.Attribute("ID").Value == "{d7891031-e7f5-4734-8077-9189dd35551c}"); + .Where(el => WFPackFeatures.Contains(el.Attribute("ID").Value)); if (features.Count() < 1) return; @@ -166,8 +163,8 @@ private void RemoveCustomActions(XDocument feature, XDocument elements, string f private void RemoveModules(XDocument feature, XDocument elements, string featureDir) { var workflowFiles = - feature.Descendants(ns + "ElementFile") - .Where(el => el.Attribute("Location").Value.Contains("\\Workflows\\")); + feature.Descendants(ns + "ElementFile").Where(ActionsFilter); + if (workflowFiles.Count() < 1) return; @@ -200,6 +197,14 @@ private void RemoveModules(XDocument feature, XDocument elements, string feature workflowFiles.Remove(); } + private bool ActionsFilter(XElement el) + { + var location = el.Attribute("Location").Value; + var ext = Path.GetExtension(location); + + return location.Contains("\\Workflows\\") && (ext == ".xaml" || ext == ".actions4"); + } + private void RemovePackageDependency(XDocument manifest) { var dependencyNode = manifest.Descendants(ns + "ActivationDependency") diff --git a/TemplatePackageFix/Helpers/Extensions.cs b/TemplatePackageFix/Helpers/Extensions.cs index 8a29d8a..5cb324b 100644 --- a/TemplatePackageFix/Helpers/Extensions.cs +++ b/TemplatePackageFix/Helpers/Extensions.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Xml; using System.Xml.Linq; diff --git a/TemplatePackageFix/Models/Solution.cs b/TemplatePackageFix/Models/Solution.cs index d407155..bd0c2a0 100644 --- a/TemplatePackageFix/Models/Solution.cs +++ b/TemplatePackageFix/Models/Solution.cs @@ -1,8 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Plumsail.TemplatePackageFix.Models { diff --git a/TemplatePackageFix/Packer.cs b/TemplatePackageFix/Packer.cs index 3a2ce5b..e47480b 100644 --- a/TemplatePackageFix/Packer.cs +++ b/TemplatePackageFix/Packer.cs @@ -1,11 +1,7 @@ using Microsoft.Deployment.Compression; using Microsoft.Deployment.Compression.Cab; using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Plumsail.TemplatePackageFix { diff --git a/TemplatePackageFix/Program.cs b/TemplatePackageFix/Program.cs index 63f16fa..67b5719 100644 --- a/TemplatePackageFix/Program.cs +++ b/TemplatePackageFix/Program.cs @@ -1,15 +1,10 @@ using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Plumsail.TemplatePackageFix { - class Program + public class Program { - static void Main(string[] args) + public static void Main(string[] args) { if (args.Length < 1) { diff --git a/TemplatePackageFix/Properties/app.manifest b/TemplatePackageFix/Properties/app.manifest new file mode 100644 index 0000000..7776278 --- /dev/null +++ b/TemplatePackageFix/Properties/app.manifest @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TemplatePackageFix/TemplatePackageFix.csproj b/TemplatePackageFix/TemplatePackageFix.csproj index 3c1ec03..376e3a2 100644 --- a/TemplatePackageFix/TemplatePackageFix.csproj +++ b/TemplatePackageFix/TemplatePackageFix.csproj @@ -55,10 +55,19 @@ TemplatePackageFix_TemporaryKey.pfx - true + false - true + false + + + LocalIntranet + + + Properties\app.manifest + + + false @@ -101,7 +110,7 @@ - +