From d6dbef6d4e863c546d269c852ae8097defdbfde9 Mon Sep 17 00:00:00 2001 From: David O'Brien Date: Thu, 10 Nov 2016 00:48:44 -0800 Subject: [PATCH 01/23] Change GetModuleFilePaths() to include a modules directory in root of Function App --- .../PowerShell/PowerShellFunctionInvoker.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs index ccc000af09..2613ffef52 100644 --- a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs +++ b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs @@ -261,6 +261,7 @@ internal static List GetModuleFilePaths(string rootScriptPath, string fu { List modulePaths = new List(); string functionFolder = Path.Combine(rootScriptPath, functionName); + string rootModuleDirectory = Path.Combine(rootScriptPath, PowerShellConstants.ModulesFolderName); string moduleDirectory = Path.Combine(functionFolder, PowerShellConstants.ModulesFolderName); if (Directory.Exists(moduleDirectory)) { @@ -272,6 +273,16 @@ internal static List GetModuleFilePaths(string rootScriptPath, string fu PowerShellConstants.ModulesScriptFileExtensionPattern)); } + if (Directory.Exists(rootModuleDirectory)) + { + modulePaths.AddRange(Directory.GetFiles(rootModuleDirectory, + PowerShellConstants.ModulesManifestFileExtensionPattern)); + modulePaths.AddRange(Directory.GetFiles(rootModuleDirectory, + PowerShellConstants.ModulesBinaryFileExtensionPattern)); + modulePaths.AddRange(Directory.GetFiles(rootModuleDirectory, + PowerShellConstants.ModulesScriptFileExtensionPattern)); + } + return modulePaths; } } From 96a3616ad0df1002698511a3139188542703481b Mon Sep 17 00:00:00 2001 From: David O'Brien Date: Thu, 10 Nov 2016 10:49:10 -0800 Subject: [PATCH 02/23] Create AddToModulePaths() method to avoid code duplication. --- .../PowerShell/PowerShellFunctionInvoker.cs | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs index 2613ffef52..9b414752d7 100644 --- a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs +++ b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs @@ -263,27 +263,24 @@ internal static List GetModuleFilePaths(string rootScriptPath, string fu string functionFolder = Path.Combine(rootScriptPath, functionName); string rootModuleDirectory = Path.Combine(rootScriptPath, PowerShellConstants.ModulesFolderName); string moduleDirectory = Path.Combine(functionFolder, PowerShellConstants.ModulesFolderName); - if (Directory.Exists(moduleDirectory)) - { - modulePaths.AddRange(Directory.GetFiles(moduleDirectory, - PowerShellConstants.ModulesManifestFileExtensionPattern)); - modulePaths.AddRange(Directory.GetFiles(moduleDirectory, - PowerShellConstants.ModulesBinaryFileExtensionPattern)); - modulePaths.AddRange(Directory.GetFiles(moduleDirectory, - PowerShellConstants.ModulesScriptFileExtensionPattern)); - } + modulePaths.AddRange(AddToModulePaths(rootModuleDirectory)); + modulePaths.AddRange(AddToModulePaths(moduleDirectory)); + return modulePaths; + } - if (Directory.Exists(rootModuleDirectory)) + internal static List AddToModulePaths(string directory) + { + List paths = new List(); + if (Directory.Exists(directory)) { - modulePaths.AddRange(Directory.GetFiles(rootModuleDirectory, + paths.AddRange(Directory.GetFiles(directory, PowerShellConstants.ModulesManifestFileExtensionPattern)); - modulePaths.AddRange(Directory.GetFiles(rootModuleDirectory, + paths.AddRange(Directory.GetFiles(directory, PowerShellConstants.ModulesBinaryFileExtensionPattern)); - modulePaths.AddRange(Directory.GetFiles(rootModuleDirectory, + paths.AddRange(Directory.GetFiles(directory, PowerShellConstants.ModulesScriptFileExtensionPattern)); } - - return modulePaths; + return paths; } } } From a478b40eff5cee4cb8552fbed8662eb4dc9d10e7 Mon Sep 17 00:00:00 2001 From: David O'Brien Date: Fri, 11 Nov 2016 00:04:55 -0800 Subject: [PATCH 03/23] Change AddToModulePaths() to accept array of strings to further reduce calling method. --- .../PowerShell/PowerShellFunctionInvoker.cs | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs index 9b414752d7..6084aa09d9 100644 --- a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs +++ b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs @@ -263,22 +263,27 @@ internal static List GetModuleFilePaths(string rootScriptPath, string fu string functionFolder = Path.Combine(rootScriptPath, functionName); string rootModuleDirectory = Path.Combine(rootScriptPath, PowerShellConstants.ModulesFolderName); string moduleDirectory = Path.Combine(functionFolder, PowerShellConstants.ModulesFolderName); - modulePaths.AddRange(AddToModulePaths(rootModuleDirectory)); - modulePaths.AddRange(AddToModulePaths(moduleDirectory)); + string[] searchDirectories = new string[] { rootModuleDirectory, moduleDirectory }; + modulePaths.AddRange(AddToModulePaths(searchDirectories)); + return modulePaths; } - internal static List AddToModulePaths(string directory) + internal static List AddToModulePaths(string[] directories) { List paths = new List(); - if (Directory.Exists(directory)) + for (int i = 0; i < directories.Length; i++) { - paths.AddRange(Directory.GetFiles(directory, - PowerShellConstants.ModulesManifestFileExtensionPattern)); - paths.AddRange(Directory.GetFiles(directory, - PowerShellConstants.ModulesBinaryFileExtensionPattern)); - paths.AddRange(Directory.GetFiles(directory, - PowerShellConstants.ModulesScriptFileExtensionPattern)); + string currentDirectory = directories[i]; + if (Directory.Exists(currentDirectory)) + { + paths.AddRange(Directory.GetFiles(currentDirectory, + PowerShellConstants.ModulesManifestFileExtensionPattern)); + paths.AddRange(Directory.GetFiles(currentDirectory, + PowerShellConstants.ModulesBinaryFileExtensionPattern)); + paths.AddRange(Directory.GetFiles(currentDirectory, + PowerShellConstants.ModulesScriptFileExtensionPattern)); + } } return paths; } From e69dd067adee2b2ccff738939d4e836e919f7d1c Mon Sep 17 00:00:00 2001 From: David O'Brien Date: Sat, 12 Nov 2016 10:26:38 -0800 Subject: [PATCH 04/23] Change AddToModulePaths so that it searches the modules folder recursively --- .../Description/PowerShell/PowerShellFunctionInvoker.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs index 6084aa09d9..a844058c2a 100644 --- a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs +++ b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs @@ -278,11 +278,14 @@ internal static List AddToModulePaths(string[] directories) if (Directory.Exists(currentDirectory)) { paths.AddRange(Directory.GetFiles(currentDirectory, - PowerShellConstants.ModulesManifestFileExtensionPattern)); + PowerShellConstants.ModulesManifestFileExtensionPattern, + SearchOption.AllDirectories)); paths.AddRange(Directory.GetFiles(currentDirectory, - PowerShellConstants.ModulesBinaryFileExtensionPattern)); + PowerShellConstants.ModulesBinaryFileExtensionPattern, + SearchOption.AllDirectories)); paths.AddRange(Directory.GetFiles(currentDirectory, - PowerShellConstants.ModulesScriptFileExtensionPattern)); + PowerShellConstants.ModulesScriptFileExtensionPattern, + SearchOption.AllDirectories)); } } return paths; From 07818474d6e538d23860f3cd82db3e0f86a7cc11 Mon Sep 17 00:00:00 2001 From: David O'Brien Date: Thu, 10 Nov 2016 00:48:44 -0800 Subject: [PATCH 05/23] Change GetModuleFilePaths() to include a modules directory in root of Function App --- .../PowerShell/PowerShellFunctionInvoker.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs index ccc000af09..2613ffef52 100644 --- a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs +++ b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs @@ -261,6 +261,7 @@ internal static List GetModuleFilePaths(string rootScriptPath, string fu { List modulePaths = new List(); string functionFolder = Path.Combine(rootScriptPath, functionName); + string rootModuleDirectory = Path.Combine(rootScriptPath, PowerShellConstants.ModulesFolderName); string moduleDirectory = Path.Combine(functionFolder, PowerShellConstants.ModulesFolderName); if (Directory.Exists(moduleDirectory)) { @@ -272,6 +273,16 @@ internal static List GetModuleFilePaths(string rootScriptPath, string fu PowerShellConstants.ModulesScriptFileExtensionPattern)); } + if (Directory.Exists(rootModuleDirectory)) + { + modulePaths.AddRange(Directory.GetFiles(rootModuleDirectory, + PowerShellConstants.ModulesManifestFileExtensionPattern)); + modulePaths.AddRange(Directory.GetFiles(rootModuleDirectory, + PowerShellConstants.ModulesBinaryFileExtensionPattern)); + modulePaths.AddRange(Directory.GetFiles(rootModuleDirectory, + PowerShellConstants.ModulesScriptFileExtensionPattern)); + } + return modulePaths; } } From f1aacf930c051507b7b729e1ba2ca3f666d52a98 Mon Sep 17 00:00:00 2001 From: David O'Brien Date: Thu, 10 Nov 2016 10:49:10 -0800 Subject: [PATCH 06/23] Create AddToModulePaths() method to avoid code duplication. --- .../PowerShell/PowerShellFunctionInvoker.cs | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs index 2613ffef52..9b414752d7 100644 --- a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs +++ b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs @@ -263,27 +263,24 @@ internal static List GetModuleFilePaths(string rootScriptPath, string fu string functionFolder = Path.Combine(rootScriptPath, functionName); string rootModuleDirectory = Path.Combine(rootScriptPath, PowerShellConstants.ModulesFolderName); string moduleDirectory = Path.Combine(functionFolder, PowerShellConstants.ModulesFolderName); - if (Directory.Exists(moduleDirectory)) - { - modulePaths.AddRange(Directory.GetFiles(moduleDirectory, - PowerShellConstants.ModulesManifestFileExtensionPattern)); - modulePaths.AddRange(Directory.GetFiles(moduleDirectory, - PowerShellConstants.ModulesBinaryFileExtensionPattern)); - modulePaths.AddRange(Directory.GetFiles(moduleDirectory, - PowerShellConstants.ModulesScriptFileExtensionPattern)); - } + modulePaths.AddRange(AddToModulePaths(rootModuleDirectory)); + modulePaths.AddRange(AddToModulePaths(moduleDirectory)); + return modulePaths; + } - if (Directory.Exists(rootModuleDirectory)) + internal static List AddToModulePaths(string directory) + { + List paths = new List(); + if (Directory.Exists(directory)) { - modulePaths.AddRange(Directory.GetFiles(rootModuleDirectory, + paths.AddRange(Directory.GetFiles(directory, PowerShellConstants.ModulesManifestFileExtensionPattern)); - modulePaths.AddRange(Directory.GetFiles(rootModuleDirectory, + paths.AddRange(Directory.GetFiles(directory, PowerShellConstants.ModulesBinaryFileExtensionPattern)); - modulePaths.AddRange(Directory.GetFiles(rootModuleDirectory, + paths.AddRange(Directory.GetFiles(directory, PowerShellConstants.ModulesScriptFileExtensionPattern)); } - - return modulePaths; + return paths; } } } From 7f148f82256ef954d1fabf7dd56e22b6fbd79238 Mon Sep 17 00:00:00 2001 From: David O'Brien Date: Fri, 11 Nov 2016 00:04:55 -0800 Subject: [PATCH 07/23] Change AddToModulePaths() to accept array of strings to further reduce calling method. --- .../PowerShell/PowerShellFunctionInvoker.cs | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs index 9b414752d7..6084aa09d9 100644 --- a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs +++ b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs @@ -263,22 +263,27 @@ internal static List GetModuleFilePaths(string rootScriptPath, string fu string functionFolder = Path.Combine(rootScriptPath, functionName); string rootModuleDirectory = Path.Combine(rootScriptPath, PowerShellConstants.ModulesFolderName); string moduleDirectory = Path.Combine(functionFolder, PowerShellConstants.ModulesFolderName); - modulePaths.AddRange(AddToModulePaths(rootModuleDirectory)); - modulePaths.AddRange(AddToModulePaths(moduleDirectory)); + string[] searchDirectories = new string[] { rootModuleDirectory, moduleDirectory }; + modulePaths.AddRange(AddToModulePaths(searchDirectories)); + return modulePaths; } - internal static List AddToModulePaths(string directory) + internal static List AddToModulePaths(string[] directories) { List paths = new List(); - if (Directory.Exists(directory)) + for (int i = 0; i < directories.Length; i++) { - paths.AddRange(Directory.GetFiles(directory, - PowerShellConstants.ModulesManifestFileExtensionPattern)); - paths.AddRange(Directory.GetFiles(directory, - PowerShellConstants.ModulesBinaryFileExtensionPattern)); - paths.AddRange(Directory.GetFiles(directory, - PowerShellConstants.ModulesScriptFileExtensionPattern)); + string currentDirectory = directories[i]; + if (Directory.Exists(currentDirectory)) + { + paths.AddRange(Directory.GetFiles(currentDirectory, + PowerShellConstants.ModulesManifestFileExtensionPattern)); + paths.AddRange(Directory.GetFiles(currentDirectory, + PowerShellConstants.ModulesBinaryFileExtensionPattern)); + paths.AddRange(Directory.GetFiles(currentDirectory, + PowerShellConstants.ModulesScriptFileExtensionPattern)); + } } return paths; } From f680ed62772e158ed41239278161e86b006a34a3 Mon Sep 17 00:00:00 2001 From: David O'Brien Date: Sat, 12 Nov 2016 10:26:38 -0800 Subject: [PATCH 08/23] Change AddToModulePaths so that it searches the modules folder recursively --- .../Description/PowerShell/PowerShellFunctionInvoker.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs index 6084aa09d9..a844058c2a 100644 --- a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs +++ b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs @@ -278,11 +278,14 @@ internal static List AddToModulePaths(string[] directories) if (Directory.Exists(currentDirectory)) { paths.AddRange(Directory.GetFiles(currentDirectory, - PowerShellConstants.ModulesManifestFileExtensionPattern)); + PowerShellConstants.ModulesManifestFileExtensionPattern, + SearchOption.AllDirectories)); paths.AddRange(Directory.GetFiles(currentDirectory, - PowerShellConstants.ModulesBinaryFileExtensionPattern)); + PowerShellConstants.ModulesBinaryFileExtensionPattern, + SearchOption.AllDirectories)); paths.AddRange(Directory.GetFiles(currentDirectory, - PowerShellConstants.ModulesScriptFileExtensionPattern)); + PowerShellConstants.ModulesScriptFileExtensionPattern, + SearchOption.AllDirectories)); } } return paths; From 25f7fa03198eff19f00b34a680e571a866cae333 Mon Sep 17 00:00:00 2001 From: David O'Brien Date: Thu, 10 Nov 2016 00:48:44 -0800 Subject: [PATCH 09/23] Change GetModuleFilePaths() to include a modules directory in root of Function App --- .../PowerShell/PowerShellFunctionInvoker.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs index ccc000af09..2613ffef52 100644 --- a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs +++ b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs @@ -261,6 +261,7 @@ internal static List GetModuleFilePaths(string rootScriptPath, string fu { List modulePaths = new List(); string functionFolder = Path.Combine(rootScriptPath, functionName); + string rootModuleDirectory = Path.Combine(rootScriptPath, PowerShellConstants.ModulesFolderName); string moduleDirectory = Path.Combine(functionFolder, PowerShellConstants.ModulesFolderName); if (Directory.Exists(moduleDirectory)) { @@ -272,6 +273,16 @@ internal static List GetModuleFilePaths(string rootScriptPath, string fu PowerShellConstants.ModulesScriptFileExtensionPattern)); } + if (Directory.Exists(rootModuleDirectory)) + { + modulePaths.AddRange(Directory.GetFiles(rootModuleDirectory, + PowerShellConstants.ModulesManifestFileExtensionPattern)); + modulePaths.AddRange(Directory.GetFiles(rootModuleDirectory, + PowerShellConstants.ModulesBinaryFileExtensionPattern)); + modulePaths.AddRange(Directory.GetFiles(rootModuleDirectory, + PowerShellConstants.ModulesScriptFileExtensionPattern)); + } + return modulePaths; } } From e54f4ad3ddf62331cba56ed7f9dc36d168f6e981 Mon Sep 17 00:00:00 2001 From: David O'Brien Date: Thu, 10 Nov 2016 10:49:10 -0800 Subject: [PATCH 10/23] Create AddToModulePaths() method to avoid code duplication. --- .../PowerShell/PowerShellFunctionInvoker.cs | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs index 2613ffef52..9b414752d7 100644 --- a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs +++ b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs @@ -263,27 +263,24 @@ internal static List GetModuleFilePaths(string rootScriptPath, string fu string functionFolder = Path.Combine(rootScriptPath, functionName); string rootModuleDirectory = Path.Combine(rootScriptPath, PowerShellConstants.ModulesFolderName); string moduleDirectory = Path.Combine(functionFolder, PowerShellConstants.ModulesFolderName); - if (Directory.Exists(moduleDirectory)) - { - modulePaths.AddRange(Directory.GetFiles(moduleDirectory, - PowerShellConstants.ModulesManifestFileExtensionPattern)); - modulePaths.AddRange(Directory.GetFiles(moduleDirectory, - PowerShellConstants.ModulesBinaryFileExtensionPattern)); - modulePaths.AddRange(Directory.GetFiles(moduleDirectory, - PowerShellConstants.ModulesScriptFileExtensionPattern)); - } + modulePaths.AddRange(AddToModulePaths(rootModuleDirectory)); + modulePaths.AddRange(AddToModulePaths(moduleDirectory)); + return modulePaths; + } - if (Directory.Exists(rootModuleDirectory)) + internal static List AddToModulePaths(string directory) + { + List paths = new List(); + if (Directory.Exists(directory)) { - modulePaths.AddRange(Directory.GetFiles(rootModuleDirectory, + paths.AddRange(Directory.GetFiles(directory, PowerShellConstants.ModulesManifestFileExtensionPattern)); - modulePaths.AddRange(Directory.GetFiles(rootModuleDirectory, + paths.AddRange(Directory.GetFiles(directory, PowerShellConstants.ModulesBinaryFileExtensionPattern)); - modulePaths.AddRange(Directory.GetFiles(rootModuleDirectory, + paths.AddRange(Directory.GetFiles(directory, PowerShellConstants.ModulesScriptFileExtensionPattern)); } - - return modulePaths; + return paths; } } } From 98629d027a7aa2521f169b1295466c9a42daf9a0 Mon Sep 17 00:00:00 2001 From: David O'Brien Date: Fri, 11 Nov 2016 00:04:55 -0800 Subject: [PATCH 11/23] Change AddToModulePaths() to accept array of strings to further reduce calling method. --- .../PowerShell/PowerShellFunctionInvoker.cs | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs index 9b414752d7..6084aa09d9 100644 --- a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs +++ b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs @@ -263,22 +263,27 @@ internal static List GetModuleFilePaths(string rootScriptPath, string fu string functionFolder = Path.Combine(rootScriptPath, functionName); string rootModuleDirectory = Path.Combine(rootScriptPath, PowerShellConstants.ModulesFolderName); string moduleDirectory = Path.Combine(functionFolder, PowerShellConstants.ModulesFolderName); - modulePaths.AddRange(AddToModulePaths(rootModuleDirectory)); - modulePaths.AddRange(AddToModulePaths(moduleDirectory)); + string[] searchDirectories = new string[] { rootModuleDirectory, moduleDirectory }; + modulePaths.AddRange(AddToModulePaths(searchDirectories)); + return modulePaths; } - internal static List AddToModulePaths(string directory) + internal static List AddToModulePaths(string[] directories) { List paths = new List(); - if (Directory.Exists(directory)) + for (int i = 0; i < directories.Length; i++) { - paths.AddRange(Directory.GetFiles(directory, - PowerShellConstants.ModulesManifestFileExtensionPattern)); - paths.AddRange(Directory.GetFiles(directory, - PowerShellConstants.ModulesBinaryFileExtensionPattern)); - paths.AddRange(Directory.GetFiles(directory, - PowerShellConstants.ModulesScriptFileExtensionPattern)); + string currentDirectory = directories[i]; + if (Directory.Exists(currentDirectory)) + { + paths.AddRange(Directory.GetFiles(currentDirectory, + PowerShellConstants.ModulesManifestFileExtensionPattern)); + paths.AddRange(Directory.GetFiles(currentDirectory, + PowerShellConstants.ModulesBinaryFileExtensionPattern)); + paths.AddRange(Directory.GetFiles(currentDirectory, + PowerShellConstants.ModulesScriptFileExtensionPattern)); + } } return paths; } From 9c742aa1ec08bc83df5c1cb589d270bb7e0dfb57 Mon Sep 17 00:00:00 2001 From: David O'Brien Date: Sat, 12 Nov 2016 10:26:38 -0800 Subject: [PATCH 12/23] Change AddToModulePaths so that it searches the modules folder recursively --- .../Description/PowerShell/PowerShellFunctionInvoker.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs index 6084aa09d9..a844058c2a 100644 --- a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs +++ b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs @@ -278,11 +278,14 @@ internal static List AddToModulePaths(string[] directories) if (Directory.Exists(currentDirectory)) { paths.AddRange(Directory.GetFiles(currentDirectory, - PowerShellConstants.ModulesManifestFileExtensionPattern)); + PowerShellConstants.ModulesManifestFileExtensionPattern, + SearchOption.AllDirectories)); paths.AddRange(Directory.GetFiles(currentDirectory, - PowerShellConstants.ModulesBinaryFileExtensionPattern)); + PowerShellConstants.ModulesBinaryFileExtensionPattern, + SearchOption.AllDirectories)); paths.AddRange(Directory.GetFiles(currentDirectory, - PowerShellConstants.ModulesScriptFileExtensionPattern)); + PowerShellConstants.ModulesScriptFileExtensionPattern, + SearchOption.AllDirectories)); } } return paths; From ea7f4098bc5490ab24b93f02bc57bc129dc9f78d Mon Sep 17 00:00:00 2001 From: David O'Brien Date: Thu, 10 Nov 2016 00:48:44 -0800 Subject: [PATCH 13/23] Change GetModuleFilePaths() to include a modules directory in root of Function App --- .../PowerShell/PowerShellFunctionInvoker.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs index a844058c2a..e43096000c 100644 --- a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs +++ b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs @@ -266,6 +266,16 @@ internal static List GetModuleFilePaths(string rootScriptPath, string fu string[] searchDirectories = new string[] { rootModuleDirectory, moduleDirectory }; modulePaths.AddRange(AddToModulePaths(searchDirectories)); + if (Directory.Exists(rootModuleDirectory)) + { + modulePaths.AddRange(Directory.GetFiles(rootModuleDirectory, + PowerShellConstants.ModulesManifestFileExtensionPattern)); + modulePaths.AddRange(Directory.GetFiles(rootModuleDirectory, + PowerShellConstants.ModulesBinaryFileExtensionPattern)); + modulePaths.AddRange(Directory.GetFiles(rootModuleDirectory, + PowerShellConstants.ModulesScriptFileExtensionPattern)); + } + return modulePaths; } From da355016eab8ea4d67c1d75d3ca581e14d9a475f Mon Sep 17 00:00:00 2001 From: David O'Brien Date: Thu, 10 Nov 2016 10:49:10 -0800 Subject: [PATCH 14/23] Create AddToModulePaths() method to avoid code duplication. --- .../PowerShell/PowerShellFunctionInvoker.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs index e43096000c..2f120cdc7a 100644 --- a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs +++ b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs @@ -265,18 +265,24 @@ internal static List GetModuleFilePaths(string rootScriptPath, string fu string moduleDirectory = Path.Combine(functionFolder, PowerShellConstants.ModulesFolderName); string[] searchDirectories = new string[] { rootModuleDirectory, moduleDirectory }; modulePaths.AddRange(AddToModulePaths(searchDirectories)); + modulePaths.AddRange(AddToModulePaths(rootModuleDirectory)); + modulePaths.AddRange(AddToModulePaths(moduleDirectory)); + return modulePaths; + } - if (Directory.Exists(rootModuleDirectory)) + internal static List AddToModulePaths(string directory) + { + List paths = new List(); + if (Directory.Exists(directory)) { - modulePaths.AddRange(Directory.GetFiles(rootModuleDirectory, + paths.AddRange(Directory.GetFiles(directory, PowerShellConstants.ModulesManifestFileExtensionPattern)); - modulePaths.AddRange(Directory.GetFiles(rootModuleDirectory, + paths.AddRange(Directory.GetFiles(directory, PowerShellConstants.ModulesBinaryFileExtensionPattern)); - modulePaths.AddRange(Directory.GetFiles(rootModuleDirectory, + paths.AddRange(Directory.GetFiles(directory, PowerShellConstants.ModulesScriptFileExtensionPattern)); } - - return modulePaths; + return paths; } internal static List AddToModulePaths(string[] directories) From 3fb418776a6cfbaceed0f7c0873ae4eaa9d33b3e Mon Sep 17 00:00:00 2001 From: David O'Brien Date: Fri, 11 Nov 2016 00:04:55 -0800 Subject: [PATCH 15/23] Change AddToModulePaths() to accept array of strings to further reduce calling method. --- .../PowerShell/PowerShellFunctionInvoker.cs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs index 2f120cdc7a..7f6a8007e0 100644 --- a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs +++ b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs @@ -265,25 +265,9 @@ internal static List GetModuleFilePaths(string rootScriptPath, string fu string moduleDirectory = Path.Combine(functionFolder, PowerShellConstants.ModulesFolderName); string[] searchDirectories = new string[] { rootModuleDirectory, moduleDirectory }; modulePaths.AddRange(AddToModulePaths(searchDirectories)); - modulePaths.AddRange(AddToModulePaths(rootModuleDirectory)); - modulePaths.AddRange(AddToModulePaths(moduleDirectory)); return modulePaths; } - internal static List AddToModulePaths(string directory) - { - List paths = new List(); - if (Directory.Exists(directory)) - { - paths.AddRange(Directory.GetFiles(directory, - PowerShellConstants.ModulesManifestFileExtensionPattern)); - paths.AddRange(Directory.GetFiles(directory, - PowerShellConstants.ModulesBinaryFileExtensionPattern)); - paths.AddRange(Directory.GetFiles(directory, - PowerShellConstants.ModulesScriptFileExtensionPattern)); - } - return paths; - } internal static List AddToModulePaths(string[] directories) { From fae756bb36c21b90eb31e0c6c230cc9d5e919b91 Mon Sep 17 00:00:00 2001 From: David O'Brien Date: Fri, 18 Nov 2016 17:02:35 +1100 Subject: [PATCH 16/23] Change GetModuleFilePaths() from for loop to foreach. --- .../PowerShell/PowerShellFunctionInvoker.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs index 5b90c5af6e..1b411d5ec0 100644 --- a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs +++ b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs @@ -271,18 +271,17 @@ internal static List GetModuleFilePaths(string rootScriptPath, string fu internal static List AddToModulePaths(string[] directories) { List paths = new List(); - for (int i = 0; i < directories.Length; i++) + foreach (string directory in directories) { - string currentDirectory = directories[i]; - if (Directory.Exists(currentDirectory)) + if (Directory.Exists(directory)) { - paths.AddRange(Directory.GetFiles(currentDirectory, + paths.AddRange(Directory.GetFiles(directory, PowerShellConstants.ModulesManifestFileExtensionPattern, SearchOption.AllDirectories)); - paths.AddRange(Directory.GetFiles(currentDirectory, + paths.AddRange(Directory.GetFiles(directory, PowerShellConstants.ModulesBinaryFileExtensionPattern, SearchOption.AllDirectories)); - paths.AddRange(Directory.GetFiles(currentDirectory, + paths.AddRange(Directory.GetFiles(directory, PowerShellConstants.ModulesScriptFileExtensionPattern, SearchOption.AllDirectories)); } From 7bc6206f17c618fab0df05a8187392b0504f6b88 Mon Sep 17 00:00:00 2001 From: David Date: Sun, 27 Nov 2016 00:08:49 +1100 Subject: [PATCH 17/23] Add test for modules dir in root --- .../PowerShellInvokerTests.cs | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/test/WebJobs.Script.Tests/PowerShellInvokerTests.cs b/test/WebJobs.Script.Tests/PowerShellInvokerTests.cs index 3fef3a7a17..c5d3f340ac 100644 --- a/test/WebJobs.Script.Tests/PowerShellInvokerTests.cs +++ b/test/WebJobs.Script.Tests/PowerShellInvokerTests.cs @@ -100,7 +100,14 @@ public Fixture() "manifest-module.psd1" }; - TestModulesPath = CreateModuleFiles(TestModulesRoot, TestModules); + RootTestModules = new string[] + { + "root-script-module.psm1", + "root-binary-module.dll", + "root-manifest-module.psd1" + }; + + TestModulesPath = CreateModuleFiles(TestModulesRoot, RootTestModules, TestModules); } public string TestFunctionRoot { get; private set; } @@ -154,13 +161,20 @@ public string CreateScriptFile(string scriptRoot) return path; } - public List CreateModuleFiles(string moduleRoot, string[] modules) + public List CreateModuleFiles(string moduleRoot, string[] rootModules, string[] modules) { if (!Directory.Exists(moduleRoot)) { Directory.CreateDirectory(moduleRoot); } + string moduleDirinRoot = TestFunctionRoot + "\\modules"; + + if (!Directory.Exists(moduleDirinRoot)) + { + Directory.CreateDirectory(moduleDirinRoot); + } + List modulesPath = new List(); foreach (var module in modules) { @@ -177,6 +191,21 @@ public List CreateModuleFiles(string moduleRoot, string[] modules) modulesPath.Add(path); } + foreach (var module in rootModules) + { + string path = Path.Combine(moduleDirinRoot, module); + if (!File.Exists(path)) + { + // Create a file to write to. + using (StreamWriter sw = File.CreateText(path)) + { + sw.WriteLine(string.Format("This is a {0} file.", module)); + } + } + + modulesPath.Add(path); + } + return modulesPath; } } From 8d579e0cecb6f1cc8da03ff7cdd3fc75466485cf Mon Sep 17 00:00:00 2001 From: David Date: Sun, 27 Nov 2016 01:32:40 +1100 Subject: [PATCH 18/23] Set reference to RootTestModules in current scope --- test/WebJobs.Script.Tests/PowerShellInvokerTests.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/WebJobs.Script.Tests/PowerShellInvokerTests.cs b/test/WebJobs.Script.Tests/PowerShellInvokerTests.cs index c5d3f340ac..39ad6cf7a9 100644 --- a/test/WebJobs.Script.Tests/PowerShellInvokerTests.cs +++ b/test/WebJobs.Script.Tests/PowerShellInvokerTests.cs @@ -122,6 +122,8 @@ public Fixture() public string[] TestModules { get; private set; } + public string[] RootTestModules { get; private set; } + public string TestModulesRoot { get; private set; } public List TestModulesPath { get; set; } From e996fb82d508925df11ff6ac7d6eba8fe479e3a0 Mon Sep 17 00:00:00 2001 From: David Date: Sun, 27 Nov 2016 20:00:58 +1100 Subject: [PATCH 19/23] Change AddToModulePaths method input to accept params to make calling code cleaner. --- .../Description/PowerShell/PowerShellFunctionInvoker.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs index 1b411d5ec0..ce6f91443a 100644 --- a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs +++ b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs @@ -263,12 +263,11 @@ internal static List GetModuleFilePaths(string rootScriptPath, string fu string functionFolder = Path.Combine(rootScriptPath, functionName); string rootModuleDirectory = Path.Combine(rootScriptPath, PowerShellConstants.ModulesFolderName); string moduleDirectory = Path.Combine(functionFolder, PowerShellConstants.ModulesFolderName); - string[] searchDirectories = new string[] { rootModuleDirectory, moduleDirectory }; - modulePaths.AddRange(AddToModulePaths(searchDirectories)); + modulePaths.AddRange(AddToModulePaths(rootModuleDirectory, moduleDirectory)); return modulePaths; } - internal static List AddToModulePaths(string[] directories) + internal static List AddToModulePaths(params string[] directories) { List paths = new List(); foreach (string directory in directories) From 8d170b18a50360172f764ad701837d38dde33bd2 Mon Sep 17 00:00:00 2001 From: = Date: Tue, 6 Dec 2016 11:57:53 +1100 Subject: [PATCH 20/23] Add code to identify duplicate modules and ignore duplicates by name --- .../PowerShell/PowerShellFunctionInvoker.cs | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs index ce6f91443a..d3ba3bfa32 100644 --- a/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs +++ b/src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs @@ -87,7 +87,9 @@ private async Task> InvokePowerShellScript(Diction System.Management.Automation.PowerShell.Create()) { powerShellInstance.Runspace = runspace; - _moduleFiles = GetModuleFilePaths(_host.ScriptConfig.RootScriptPath, _functionName); + _moduleFiles = FindDuplicateModules(GetModuleFilePaths(_host.ScriptConfig.RootScriptPath, _functionName), _host.ScriptConfig.RootScriptPath, _functionName); + // Remove duplicates from _moduleFiles and only keep the ones closest to the Function in moduleDirectory + if (_moduleFiles.Any()) { powerShellInstance.AddCommand("Import-Module").AddArgument(_moduleFiles); @@ -287,5 +289,32 @@ internal static List AddToModulePaths(params string[] directories) } return paths; } + + internal static List FindDuplicateModules(List foundModules, string rootScriptPath, string functionName) + { + List moduleFileNames = new List(); + string functionFolder = Path.Combine(rootScriptPath, functionName); + string rootModuleDirectory = Path.Combine(rootScriptPath, PowerShellConstants.ModulesFolderName); + string moduleDirectory = Path.Combine(functionFolder, PowerShellConstants.ModulesFolderName); + + foreach (string entry in foundModules) + { + moduleFileNames.Add(Path.GetFileName(entry)); + } + + List distinctModuleFiles = moduleFileNames.Distinct().ToList(); + + foreach (string distinctModuleFile in distinctModuleFiles) + { + string potentialModule = Path.Combine(moduleDirectory, distinctModuleFile); + string result = foundModules.SingleOrDefault(s => s == potentialModule); + if (result != null) + { + foundModules.Remove(Path.Combine(rootModuleDirectory, distinctModuleFile)); + } + } + return foundModules; + } + } } From 75e915ec0fdaa29a52ba3b47cf862aa667c2ed6e Mon Sep 17 00:00:00 2001 From: = Date: Tue, 6 Dec 2016 12:01:01 +1100 Subject: [PATCH 21/23] Add tests for FindDuplicateModules() --- .../PowerShell/PowerShellInvokerTests.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/test/WebJobs.Script.Tests/Description/PowerShell/PowerShellInvokerTests.cs b/test/WebJobs.Script.Tests/Description/PowerShell/PowerShellInvokerTests.cs index f8fb66bcaf..260ec3e8ee 100644 --- a/test/WebJobs.Script.Tests/Description/PowerShell/PowerShellInvokerTests.cs +++ b/test/WebJobs.Script.Tests/Description/PowerShell/PowerShellInvokerTests.cs @@ -37,6 +37,17 @@ public void GetModuleFilePaths() } } + [Fact] + public void FindDuplicateModules() + { + List actualModules = PowerShellFunctionInvoker.FindDuplicateModules(PowerShellFunctionInvoker.GetModuleFilePaths(_fixture.TestRootScriptPath, _fixture.TestFunctionName), _fixture.TestRootScriptPath, _fixture.TestFunctionName); + Assert.Equal(_fixture.ExpectedNumberOfImportedModules, actualModules.Count); + foreach (var actualModule in actualModules) + { + Assert.True(_fixture.TestModulesPath.Contains(actualModule)); + } + } + [Fact] public void GetRelativePath() { @@ -90,6 +101,9 @@ public Fixture() TestRootScriptPath = Path.Combine(TestHelpers.FunctionsTestDirectory, "Functions"); TestFunctionRoot = Path.Combine(TestRootScriptPath, TestFunctionName); TestModulesRoot = Path.Combine(TestFunctionRoot, "modules"); + // The number of imported modules is expected to be 6, as the "manifest-module.psd1" in RootTestModules + // should be ignored when importing. So the 7 available modules should end up being 6. + ExpectedNumberOfImportedModules = 6; TestScriptPath = CreateScriptFile(TestFunctionRoot); @@ -104,7 +118,8 @@ public Fixture() { "root-script-module.psm1", "root-binary-module.dll", - "root-manifest-module.psd1" + "root-manifest-module.psd1", + "manifest-module.psd1" }; TestModulesPath = CreateModuleFiles(TestModulesRoot, RootTestModules, TestModules); @@ -127,6 +142,7 @@ public Fixture() public string TestModulesRoot { get; private set; } public List TestModulesPath { get; set; } + public int ExpectedNumberOfImportedModules { get; set; } public void Dispose() { From b61a4beced8ee32f6a926bbf687ef54f562fb9df Mon Sep 17 00:00:00 2001 From: David OBrien Date: Wed, 7 Dec 2016 11:06:40 +1100 Subject: [PATCH 22/23] Merge dev into feature/powershell_module_root --- README.md | 4 +--- .../Binding/ServiceBusScriptBindingProvider.cs | 6 ++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 20a5361481..96c460c426 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,4 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope ### Questions -See the [getting help](https://github.com/Azure/azure-webjobs-sdk-script/wiki#getting-help) section in the wiki. - - +See the [getting help](https://github.com/Azure/azure-webjobs-sdk-script/wiki#getting-help) section in the wiki. \ No newline at end of file diff --git a/src/WebJobs.Script/Binding/ServiceBusScriptBindingProvider.cs b/src/WebJobs.Script/Binding/ServiceBusScriptBindingProvider.cs index 91f40c2f74..9a2f90c668 100644 --- a/src/WebJobs.Script/Binding/ServiceBusScriptBindingProvider.cs +++ b/src/WebJobs.Script/Binding/ServiceBusScriptBindingProvider.cs @@ -3,6 +3,7 @@ using System; using System.Collections.ObjectModel; +using System.Globalization; using System.IO; using System.Reflection; using Microsoft.Azure.WebJobs.Host; @@ -56,6 +57,11 @@ public override void Initialize() serviceBusConfig.MessageOptions.MaxConcurrentCalls = (int)value; } + if (configSection.TryGetValue("autoRenewTimeout", StringComparison.OrdinalIgnoreCase, out value)) + { + serviceBusConfig.MessageOptions.AutoRenewTimeout = TimeSpan.Parse((string)value, CultureInfo.InvariantCulture); + } + if (configSection.TryGetValue("prefetchCount", StringComparison.OrdinalIgnoreCase, out value)) { serviceBusConfig.PrefetchCount = (int)value; From 5e757d2307d9f97e28c860f12f24258902d34a55 Mon Sep 17 00:00:00 2001 From: David OBrien Date: Wed, 7 Dec 2016 15:24:21 +1100 Subject: [PATCH 23/23] CreateModuleFiles() now supports modules Dir in root of App so that GetModuleFilePaths() now passes again. --- .../Description/PowerShell/PowerShellInvokerTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/WebJobs.Script.Tests/Description/PowerShell/PowerShellInvokerTests.cs b/test/WebJobs.Script.Tests/Description/PowerShell/PowerShellInvokerTests.cs index 260ec3e8ee..2231333b71 100644 --- a/test/WebJobs.Script.Tests/Description/PowerShell/PowerShellInvokerTests.cs +++ b/test/WebJobs.Script.Tests/Description/PowerShell/PowerShellInvokerTests.cs @@ -186,7 +186,7 @@ public List CreateModuleFiles(string moduleRoot, string[] rootModules, s Directory.CreateDirectory(moduleRoot); } - string moduleDirinRoot = TestFunctionRoot + "\\modules"; + string moduleDirinRoot = TestRootScriptPath + "\\modules"; if (!Directory.Exists(moduleDirinRoot)) { @@ -209,15 +209,15 @@ public List CreateModuleFiles(string moduleRoot, string[] rootModules, s modulesPath.Add(path); } - foreach (var module in rootModules) + foreach (var rootModule in rootModules) { - string path = Path.Combine(moduleDirinRoot, module); + string path = Path.Combine(moduleDirinRoot, rootModule); if (!File.Exists(path)) { // Create a file to write to. using (StreamWriter sw = File.CreateText(path)) { - sw.WriteLine(string.Format("This is a {0} file.", module)); + sw.WriteLine(string.Format("This is a {0} file.", rootModule)); } }