Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue #376 #379

Open
wants to merge 1 commit into
base: spkl_dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions spkl/SparkleXrm.Tasks/PluginRegistraton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public PluginRegistraton(IOrganizationService service, OrganizationServiceContex
/// </summary>
public string SolutionUniqueName { get; set; }

public void RegisterWorkflowActivities(string path)
public void RegisterWorkflowActivities(string path, string publisherPrefix = "")
{
var assemblyFilePath = new FileInfo(path);
if (Reflection.IgnoredAssemblies.Contains(assemblyFilePath.Name))
if (Reflection.IgnoreAssembly(assemblyFilePath, publisherPrefix))
return;
// Load each assembly
Assembly assembly = Reflection.LoadAssembly(assemblyFilePath.FullName);
Expand Down Expand Up @@ -148,11 +148,11 @@ private void AddStepToSolution(string solutionName, SdkMessageProcessingStep sdk
_service.Execute(addToSolution);
}

public void RegisterPlugin(string file, bool excludePluginSteps = false)
public void RegisterPlugin(string file, bool excludePluginSteps = false, string publisherPrefix = "")
{
var assemblyFilePath = new FileInfo(file);

if (assemblyFilePath.Name.StartsWith("System.") || Reflection.IgnoredAssemblies.Contains(assemblyFilePath.Name))
if (Reflection.IgnoreAssembly(assemblyFilePath, publisherPrefix))
return;

// Load each assembly
Expand Down
23 changes: 23 additions & 0 deletions spkl/SparkleXrm.Tasks/Reflection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace SparkleXrm.Tasks
Expand All @@ -28,6 +29,8 @@ public class Reflection
"Microsoft.Rest.ClientRuntime.dll"
};

private static Regex _ignoredPublisherRegEx = new Regex("^system|microsoft|newtonsoft|sparklexrm.*/.dll");

public static Assembly LoadAssembly(string path)
{
Assembly assembly = null;
Expand All @@ -43,6 +46,26 @@ public static Assembly LoadAssembly(string path)
return assembly;
}

public static bool IgnoreAssembly(FileInfo assemblyFilePath, string publisherPrefix = "", bool onlyPublisherAssemblies = false)
{
var assemblyName = assemblyFilePath.Name.ToLower();

// if publisher prefix is specified we consider assemblies starting with this prefix OK to deploy
if (!string.IsNullOrEmpty(publisherPrefix))
{
if (assemblyName.StartsWith(publisherPrefix.ToLower()))
{
return false;
}
else if (onlyPublisherAssemblies)
{
return true; // ignore other assemblies if the corresponding flag is raised
}
}

return _ignoredPublisherRegEx.IsMatch(assemblyName);
}

public static IEnumerable<Type> GetTypesImplementingInterface(Assembly assembly, Type interfaceName)
{
var types = assembly.ExportedTypes.Where(p => p.GetInterfaces().FirstOrDefault(a => a.Name == interfaceName.Name) != null);
Expand Down
4 changes: 3 additions & 1 deletion spkl/SparkleXrm.Tasks/Tasks/DeployPluginsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class DeployPluginsTask : BaseTask
{
public bool ExcludePluginSteps { get; set; }

public string PublisherPrefix { get; set; }

public DeployPluginsTask(IOrganizationService service, ITrace trace) : base(service, trace)
{

Expand Down Expand Up @@ -57,7 +59,7 @@ private void DeployPlugins(OrganizationServiceContext ctx, ConfigFile config)
{
try
{
pluginRegistration.RegisterPlugin(assemblyFilePath, ExcludePluginSteps);
pluginRegistration.RegisterPlugin(assemblyFilePath, ExcludePluginSteps, PublisherPrefix);
}

catch (ReflectionTypeLoadException ex)
Expand Down
4 changes: 3 additions & 1 deletion spkl/SparkleXrm.Tasks/Tasks/DeployWorkflowActivitiesTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace SparkleXrm.Tasks
{
public class DeployWorkflowActivitiesTask : BaseTask
{
public string PublisherPrefix { get; set; }

public DeployWorkflowActivitiesTask(IOrganizationService service, ITrace trace) : base(service, trace)
{
}
Expand Down Expand Up @@ -49,7 +51,7 @@ private void DeployWorkflowActivities(OrganizationServiceContext ctx, ConfigFile
{
try
{
pluginRegistration.RegisterWorkflowActivities(assemblyFilePath);
pluginRegistration.RegisterWorkflowActivities(assemblyFilePath, PublisherPrefix);
}
catch (ReflectionTypeLoadException ex)
{
Expand Down
10 changes: 8 additions & 2 deletions spkl/spkl/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,18 @@ private static void RunTask(CommandLineArgs arguments, IOrganizationService serv
case "plugins":
trace.WriteLine("Deploying Plugins");
task = new DeployPluginsTask(service, trace)
{ ExcludePluginSteps = arguments.ExcludePluginSteps };
{
ExcludePluginSteps = arguments.ExcludePluginSteps,
PublisherPrefix = arguments.Prefix
};
break;

case "workflow":
trace.WriteLine("Deploying Custom Workflow Activities");
task = new DeployWorkflowActivitiesTask(service, trace);
task = new DeployWorkflowActivitiesTask(service, trace)
{
PublisherPrefix = arguments.Prefix
};
break;

case "webresources":
Expand Down