{"action":"created","comment":{"url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/pulls/comments/63635166","id":63635166,"diff_hunk":"@@ -0,0 +1,490 @@\n+﻿// Copyright (c) .NET Foundation. All rights reserved.\n+// Licensed under the MIT License. See License.txt in the project root for license information.\n+\n+using System;\n+using System.Collections.Generic;\n+using System.Collections.ObjectModel;\n+using System.Globalization;\n+using System.IO;\n+using System.Linq;\n+using System.Management.Automation;\n+using System.Management.Automation.Runspaces;\n+using System.Net.Http;\n+using System.Text;\n+using System.Text.RegularExpressions;\n+using System.Threading.Tasks;\n+using Microsoft.Azure.WebJobs.Host;\n+using Microsoft.Azure.WebJobs.Host.Bindings.Runtime;\n+using Microsoft.Azure.WebJobs.Script.Binding;\n+using Microsoft.Azure.WebJobs.Script.Description.PowerShell;\n+using Microsoft.Azure.WebJobs.Script.Diagnostics;\n+\n+namespace Microsoft.Azure.WebJobs.Script.Description\n+{\n+    public class PowerShellFunctionInvoker : FunctionInvokerBase\n+    {\n+        private readonly ScriptHost _host;\n+        private readonly string _scriptFilePath;\n+        private readonly string _functionName;\n+\n+        private readonly Collection<FunctionBinding> _inputBindings;\n+        private readonly Collection<FunctionBinding> _outputBindings;\n+        private readonly IMetricsLogger _metrics;\n+\n+        private string _script;\n+        private List<string> _moduleFiles;\n+        private Dictionary<string, string> _environmentVariables;\n+        private Action _reloadScript;\n+\n+        private static readonly string[] WatchedFileTypes = { \".ps1\", \".psm1\", \".dll\", \".psd1\" };\n+\n+        internal PowerShellFunctionInvoker(ScriptHost host, FunctionMetadata functionMetadata,\n+            Collection<FunctionBinding> inputBindings, Collection<FunctionBinding> outputBindings) : base(host, functionMetadata)\n+        {\n+            _host = host;\n+            _scriptFilePath = functionMetadata.Source;\n+            _functionName = functionMetadata.Name;\n+            _inputBindings = inputBindings;\n+            _outputBindings = outputBindings;\n+            _metrics = host.ScriptConfig.HostConfig.GetService<IMetricsLogger>();\n+            _environmentVariables = new Dictionary<string, string>();\n+            InitializeFileWatcherIfEnabled();\n+            _reloadScript = ReloadScript;\n+            _reloadScript = _reloadScript.Debounce();\n+        }\n+\n+        public override async Task Invoke(object[] parameters)\n+        {\n+            object input = parameters[0];\n+            TraceWriter traceWriter = (TraceWriter)parameters[1];\n+            IBinderEx binder = (IBinderEx)parameters[2];\n+            ExecutionContext functionExecutionContext = (ExecutionContext)parameters[3];\n+            string invocationId = functionExecutionContext.InvocationId.ToString();\n+\n+            FunctionStartedEvent startedEvent = new FunctionStartedEvent(functionExecutionContext.InvocationId, Metadata);\n+            _metrics.BeginEvent(startedEvent);\n+\n+            try\n+            {\n+                object convertedInput = input;","path":"src/WebJobs.Script/Description/PowerShell/PowerShellFunctionInvoker.cs","position":69,"original_position":69,"commit_id":"cc5d21094ebdec31783d4111d8d480a59a178076","original_commit_id":"cc5d21094ebdec31783d4111d8d480a59a178076","user":{"login":"mathewc","id":1056548,"avatar_url":"https://avatars.githubusercontent.com/u/1056548?v=3","gravatar_id":"","url":"https://api.github.com/users/mathewc","html_url":"https://github.com/mathewc","followers_url":"https://api.github.com/users/mathewc/followers","following_url":"https://api.github.com/users/mathewc/following{/other_user}","gists_url":"https://api.github.com/users/mathewc/gists{/gist_id}","starred_url":"https://api.github.com/users/mathewc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mathewc/subscriptions","organizations_url":"https://api.github.com/users/mathewc/orgs","repos_url":"https://api.github.com/users/mathewc/repos","events_url":"https://api.github.com/users/mathewc/events{/privacy}","received_events_url":"https://api.github.com/users/mathewc/received_events","type":"User","site_admin":false},"body":"It's a TODO on me to refactor some of this common code out so it is shared rather than duplicated across the various providers (PowerShell and Script).","created_at":"2016-05-18T01:57:08Z","updated_at":"2016-05-18T01:57:08Z","html_url":"https://github.com/Azure/azure-webjobs-sdk-script/pull/357#discussion_r63635166","pull_request_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/pulls/357","_links":{"self":{"href":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/pulls/comments/63635166"},"html":{"href":"https://github.com/Azure/azure-webjobs-sdk-script/pull/357#discussion_r63635166"},"pull_request":{"href":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/pulls/357"}}},"pull_request":{"url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/pulls/357","id":70437571,"html_url":"https://github.com/Azure/azure-webjobs-sdk-script/pull/357","diff_url":"https://github.com/Azure/azure-webjobs-sdk-script/pull/357.diff","patch_url":"https://github.com/Azure/azure-webjobs-sdk-script/pull/357.patch","issue_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/issues/357","number":357,"state":"open","locked":false,"title":"PowerShell Implementation","user":{"login":"tohling","id":14911331,"avatar_url":"https://avatars.githubusercontent.com/u/14911331?v=3","gravatar_id":"","url":"https://api.github.com/users/tohling","html_url":"https://github.com/tohling","followers_url":"https://api.github.com/users/tohling/followers","following_url":"https://api.github.com/users/tohling/following{/other_user}","gists_url":"https://api.github.com/users/tohling/gists{/gist_id}","starred_url":"https://api.github.com/users/tohling/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tohling/subscriptions","organizations_url":"https://api.github.com/users/tohling/orgs","repos_url":"https://api.github.com/users/tohling/repos","events_url":"https://api.github.com/users/tohling/events{/privacy}","received_events_url":"https://api.github.com/users/tohling/received_events","type":"User","site_admin":false},"body":"Updated functions support for PowerShell.  Added features include:\r\n\r\n1.\tRunning PowerShell in-process\r\n2.\tRunning PowerShell custom modules – We will support script (*.psm1), binary(*.dll), and manifest (*.psd1) modules.  This would be the most common 3 out of 4 module types.\r\n3.\tPrinting output and errors in real-time.\r\n4.\tRunning Azure PowerShell cmdlets.","created_at":"2016-05-17T21:55:57Z","updated_at":"2016-05-18T01:57:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/pulls/357/commits","review_comments_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/pulls/357/comments","review_comment_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/issues/357/comments","statuses_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/statuses/cc5d21094ebdec31783d4111d8d480a59a178076","head":{"label":"tohling:dev","ref":"dev","sha":"cc5d21094ebdec31783d4111d8d480a59a178076","user":{"login":"tohling","id":14911331,"avatar_url":"https://avatars.githubusercontent.com/u/14911331?v=3","gravatar_id":"","url":"https://api.github.com/users/tohling","html_url":"https://github.com/tohling","followers_url":"https://api.github.com/users/tohling/followers","following_url":"https://api.github.com/users/tohling/following{/other_user}","gists_url":"https://api.github.com/users/tohling/gists{/gist_id}","starred_url":"https://api.github.com/users/tohling/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tohling/subscriptions","organizations_url":"https://api.github.com/users/tohling/orgs","repos_url":"https://api.github.com/users/tohling/repos","events_url":"https://api.github.com/users/tohling/events{/privacy}","received_events_url":"https://api.github.com/users/tohling/received_events","type":"User","site_admin":false},"repo":{"id":58666863,"name":"azure-webjobs-sdk-script","full_name":"tohling/azure-webjobs-sdk-script","owner":{"login":"tohling","id":14911331,"avatar_url":"https://avatars.githubusercontent.com/u/14911331?v=3","gravatar_id":"","url":"https://api.github.com/users/tohling","html_url":"https://github.com/tohling","followers_url":"https://api.github.com/users/tohling/followers","following_url":"https://api.github.com/users/tohling/following{/other_user}","gists_url":"https://api.github.com/users/tohling/gists{/gist_id}","starred_url":"https://api.github.com/users/tohling/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tohling/subscriptions","organizations_url":"https://api.github.com/users/tohling/orgs","repos_url":"https://api.github.com/users/tohling/repos","events_url":"https://api.github.com/users/tohling/events{/privacy}","received_events_url":"https://api.github.com/users/tohling/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tohling/azure-webjobs-sdk-script","description":"Scripting the Azure WebJobs SDK","fork":true,"url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script","forks_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/forks","keys_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/teams","hooks_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/hooks","issue_events_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/issues/events{/number}","events_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/events","assignees_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/assignees{/user}","branches_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/branches{/branch}","tags_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/tags","blobs_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/git/refs{/sha}","trees_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/statuses/{sha}","languages_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/languages","stargazers_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/stargazers","contributors_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/contributors","subscribers_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/subscribers","subscription_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/subscription","commits_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/commits{/sha}","git_commits_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/git/commits{/sha}","comments_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/comments{/number}","issue_comment_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/issues/comments{/number}","contents_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/contents/{+path}","compare_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/merges","archive_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/downloads","issues_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/issues{/number}","pulls_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/pulls{/number}","milestones_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/milestones{/number}","notifications_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/labels{/name}","releases_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/releases{/id}","deployments_url":"https://api.github.com/repos/tohling/azure-webjobs-sdk-script/deployments","created_at":"2016-05-12T18:32:42Z","updated_at":"2016-05-12T18:32:43Z","pushed_at":"2016-05-17T21:52:40Z","git_url":"git://github.com/tohling/azure-webjobs-sdk-script.git","ssh_url":"git@github.com:tohling/azure-webjobs-sdk-script.git","clone_url":"https://github.com/tohling/azure-webjobs-sdk-script.git","svn_url":"https://github.com/tohling/azure-webjobs-sdk-script","homepage":"","size":14845,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"dev"}},"base":{"label":"Azure:dev","ref":"dev","sha":"b8d82fddf301453cfb280f2ed722713da81e3ae1","user":{"login":"Azure","id":6844498,"avatar_url":"https://avatars.githubusercontent.com/u/6844498?v=3","gravatar_id":"","url":"https://api.github.com/users/Azure","html_url":"https://github.com/Azure","followers_url":"https://api.github.com/users/Azure/followers","following_url":"https://api.github.com/users/Azure/following{/other_user}","gists_url":"https://api.github.com/users/Azure/gists{/gist_id}","starred_url":"https://api.github.com/users/Azure/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Azure/subscriptions","organizations_url":"https://api.github.com/users/Azure/orgs","repos_url":"https://api.github.com/users/Azure/repos","events_url":"https://api.github.com/users/Azure/events{/privacy}","received_events_url":"https://api.github.com/users/Azure/received_events","type":"Organization","site_admin":false},"repo":{"id":42548553,"name":"azure-webjobs-sdk-script","full_name":"Azure/azure-webjobs-sdk-script","owner":{"login":"Azure","id":6844498,"avatar_url":"https://avatars.githubusercontent.com/u/6844498?v=3","gravatar_id":"","url":"https://api.github.com/users/Azure","html_url":"https://github.com/Azure","followers_url":"https://api.github.com/users/Azure/followers","following_url":"https://api.github.com/users/Azure/following{/other_user}","gists_url":"https://api.github.com/users/Azure/gists{/gist_id}","starred_url":"https://api.github.com/users/Azure/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Azure/subscriptions","organizations_url":"https://api.github.com/users/Azure/orgs","repos_url":"https://api.github.com/users/Azure/repos","events_url":"https://api.github.com/users/Azure/events{/privacy}","received_events_url":"https://api.github.com/users/Azure/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Azure/azure-webjobs-sdk-script","description":"Scripting the Azure WebJobs SDK","fork":false,"url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script","forks_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/forks","keys_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/teams","hooks_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/hooks","issue_events_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/issues/events{/number}","events_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/events","assignees_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/assignees{/user}","branches_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/branches{/branch}","tags_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/tags","blobs_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/git/refs{/sha}","trees_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/statuses/{sha}","languages_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/languages","stargazers_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/stargazers","contributors_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/contributors","subscribers_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/subscribers","subscription_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/subscription","commits_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/commits{/sha}","git_commits_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/git/commits{/sha}","comments_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/comments{/number}","issue_comment_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/issues/comments{/number}","contents_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/contents/{+path}","compare_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/merges","archive_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/downloads","issues_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/issues{/number}","pulls_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/pulls{/number}","milestones_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/milestones{/number}","notifications_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/labels{/name}","releases_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/releases{/id}","deployments_url":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/deployments","created_at":"2015-09-15T21:48:19Z","updated_at":"2016-05-17T23:43:58Z","pushed_at":"2016-05-18T00:11:39Z","git_url":"git://github.com/Azure/azure-webjobs-sdk-script.git","ssh_url":"git@github.com:Azure/azure-webjobs-sdk-script.git","clone_url":"https://github.com/Azure/azure-webjobs-sdk-script.git","svn_url":"https://github.com/Azure/azure-webjobs-sdk-script","homepage":"","size":15106,"stargazers_count":54,"watchers_count":54,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":31,"mirror_url":null,"open_issues_count":78,"forks":31,"open_issues":78,"watchers":54,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/pulls/357"},"html":{"href":"https://github.com/Azure/azure-webjobs-sdk-script/pull/357"},"issue":{"href":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/issues/357"},"comments":{"href":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/issues/357/comments"},"review_comments":{"href":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/pulls/357/comments"},"review_comment":{"href":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/pulls/357/commits"},"statuses":{"href":"https://api.github.com/repos/Azure/azure-webjobs-sdk-script/statuses/cc5d21094ebdec31783d4111d8d480a59a178076"}}}}