Skip to content

Commit e395476

Browse files
added a bunch of comments
1 parent 91b2bf8 commit e395476

File tree

16 files changed

+254
-237
lines changed

16 files changed

+254
-237
lines changed

examples/PSCoreApp/MyHttpTrigger/function.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"disabled": false,
3-
"entryPoint":"FunctionName",
43
"bindings": [
54
{
65
"authLevel": "function",
@@ -15,7 +14,7 @@
1514
{
1615
"type": "http",
1716
"direction": "out",
18-
"name": "$return"
17+
"name": "res"
1918
}
2019
]
2120
}
Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
function FunctionName {
2-
$global:res = $req.GetHttpResponseContext()
3-
"hello verbose"
4-
$res.Json('{"Hello":"World"}')
5-
$res.SetHeader("foo", "bar")
1+
$name = 'World'
2+
if($req.Query.Name) {
3+
$name = $req.Query.Name
4+
}
5+
6+
Write-Verbose "Hello $name" -Verbose
7+
Write-Warning "Warning $name"
8+
9+
$res = [HttpResponseContext]@{
10+
Body = @{ Hello = $name }
11+
ContentType = 'application/json'
612
}

src/Azure.Functions.PowerShell.Worker.Messaging/FunctionMessagingClient.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public FunctionMessagingClient(string host, int port)
2121
public async Task WriteAsync(StreamingMessage message)
2222
{
2323
if(isDisposed) return;
24+
25+
// Wait for the handle to be released because we can't have
26+
// more than one message being sent at the same time
2427
await _writeStreamHandle.WaitAsync();
2528
try
2629
{

src/Azure.Functions.PowerShell.Worker/Function/FunctionInfo.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ public FunctionInfo(RpcFunctionMetadata metadata)
2424
{
2525
Bindings.Add(binding.Key, binding.Value);
2626

27+
// Only add Out and InOut bindings to the OutputBindings
2728
if (binding.Value.Direction != BindingInfo.Types.Direction.In)
2829
{
2930
if(binding.Value.Type == "http")
30-
{
31-
HttpOutputName = binding.Key;
32-
}if(binding.Value.Type == "http")
3331
{
3432
HttpOutputName = binding.Key;
3533
}

src/Azure.Functions.PowerShell.Worker/Http/HttpRequestContext.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,5 @@ public class HttpRequestContext
1313
public MapField<string, string> Params {get; set;}
1414
public object Body {get; set;}
1515
public object RawBody {get; set;}
16-
17-
public HttpResponseContext GetHttpResponseContext()
18-
{
19-
return new HttpResponseContext();
20-
}
2116
}
2217
}
Lines changed: 4 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,15 @@
1+
using System.Collections;
12
using Google.Protobuf.Collections;
23
using Microsoft.Azure.WebJobs.Script.Grpc.Messages;
34

45
namespace Microsoft.Azure.Functions.PowerShellWorker
56
{
67
public class HttpResponseContext
78
{
8-
#region properties
99
public string StatusCode {get; set;} = "200";
10-
public MapField<string, string> Headers {get; set;} = new MapField<string,string>();
11-
public TypedData Body {get; set;} = new TypedData { String = "" };
10+
public Hashtable Headers {get; set;} = new Hashtable();
11+
public object Body {get; set;}
12+
public string ContentType {get; set;} = "text/plain";
1213
public bool EnableContentNegotiation {get; set;} = false;
13-
#endregion
14-
#region Helper functions for user to use to set data
15-
public HttpResponseContext Header(string field, string value) =>
16-
SetHeader(field, value);
17-
public HttpResponseContext SetHeader(string field, string value)
18-
{
19-
Headers.Add(field, value);
20-
return this;
21-
}
22-
23-
public string GetHeader(string field) =>
24-
Headers[field];
25-
26-
public HttpResponseContext RemoveHeader(string field)
27-
{
28-
Headers.Remove(field);
29-
return this;
30-
}
31-
32-
public HttpResponseContext Status(int statusCode) =>
33-
SetStatus(statusCode);
34-
public HttpResponseContext Status(string statusCode) =>
35-
SetStatus(statusCode);
36-
public HttpResponseContext SetStatus(int statusCode) =>
37-
SetStatus(statusCode);
38-
public HttpResponseContext SetStatus(string statusCode)
39-
{
40-
StatusCode = statusCode;
41-
return this;
42-
}
43-
44-
public HttpResponseContext Type(string type) =>
45-
SetHeader("content-type", type);
46-
public HttpResponseContext SetContentType(string type) =>
47-
SetHeader("content-type", type);
48-
49-
public HttpResponseContext Send(int val)
50-
{
51-
Body = new TypedData
52-
{
53-
Int = val
54-
};
55-
return this;
56-
}
57-
public HttpResponseContext Send(double val)
58-
{
59-
Body = new TypedData
60-
{
61-
Double = val
62-
};
63-
return this;
64-
}
65-
public HttpResponseContext Send(string val)
66-
{
67-
Body = new TypedData
68-
{
69-
String = val
70-
};
71-
return this;
72-
}
73-
public HttpResponseContext Json(string val) {
74-
Body = new TypedData
75-
{
76-
Json = val
77-
};
78-
return Type("application/json");
79-
}
80-
#endregion
8114
}
8215
}

src/Azure.Functions.PowerShell.Worker/PowerShell/Host/Host.cs renamed to src/Azure.Functions.PowerShell.Worker/PowerShell/Host/AzureFunctionsHost.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ namespace Microsoft.Azure.Functions.PowerShellWorker.PowerShell.Host
1010
/// applications. Not all members are implemented. Those that aren't throw a
1111
/// NotImplementedException.
1212
/// </summary>
13-
internal class Host : PSHost
13+
internal class AzureFunctionsHost : PSHost
1414
{
15+
/// <summary>
16+
/// The private reference of the logger.
17+
/// </summary>
1518
private RpcLogger _logger;
1619

1720
/// <summary>
@@ -80,23 +83,22 @@ internal class Host : PSHost
8083
/// </summary>
8184
public override Version Version => new Version(1, 0, 0, 0);
8285

83-
public Host(RpcLogger logger)
86+
public AzureFunctionsHost(RpcLogger logger)
8487
{
8588
_logger = logger;
86-
8789
HostUI = new HostUserInterface(logger);
8890
}
8991

9092
/// <summary>
91-
/// Not implemented by this example class. The call fails with an exception.
93+
/// Not implemented by this class. The call fails with an exception.
9294
/// </summary>
9395
public override void EnterNestedPrompt()
9496
{
9597
throw new NotImplementedException("The method or operation is not implemented.");
9698
}
9799

98100
/// <summary>
99-
/// Not implemented by this example class. The call fails with an exception.
101+
/// Not implemented by this class. The call fails with an exception.
100102
/// </summary>
101103
public override void ExitNestedPrompt()
102104
{
@@ -106,7 +108,7 @@ public override void ExitNestedPrompt()
106108
/// <summary>
107109
/// This API is called before an external application process is started. Typically
108110
/// it's used to save state that the child process may alter so the parent can
109-
/// restore that state when the child exits. In this sample, we don't need this so
111+
/// restore that state when the child exits. In this, we don't need this so
110112
/// the method simple returns.
111113
/// </summary>
112114
public override void NotifyBeginApplication()
@@ -116,8 +118,8 @@ public override void NotifyBeginApplication()
116118

117119
/// <summary>
118120
/// This API is called after an external application process finishes. Typically
119-
/// it's used to restore state that the child process may have altered. In this
120-
/// sample, we don't need this so the method simple returns.
121+
/// it's used to restore state that the child process may have altered. In this,
122+
/// we don't need this so the method simple returns.
121123
/// </summary>
122124
public override void NotifyEndApplication()
123125
{

src/Azure.Functions.PowerShell.Worker/PowerShell/Host/HostUserInterface.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ namespace Microsoft.Azure.Functions.PowerShellWorker.PowerShell.Host
1515
/// </summary>
1616
internal class HostUserInterface : PSHostUserInterface
1717
{
18+
/// <summary>
19+
/// The private reference of the logger.
20+
/// </summary>
1821
private RpcLogger _logger;
1922

2023
/// <summary>
@@ -40,7 +43,7 @@ public HostUserInterface(RpcLogger logger)
4043
/// <param name="message">The text of the prompt.</param>
4144
/// <param name="descriptions">A collection of FieldDescription objects that
4245
/// describe each field of the prompt.</param>
43-
/// <returns>Throws a NotImplementedException exception.</returns>
46+
/// <returns>Throws a NotImplementedException exception because we don't need a prompt.</returns>
4447
public override Dictionary<string, PSObject> Prompt(string caption, string message, System.Collections.ObjectModel.Collection<FieldDescription> descriptions)
4548
{
4649
throw new NotImplementedException("The method or operation is not implemented.");
@@ -55,7 +58,7 @@ public override Dictionary<string, PSObject> Prompt(string caption, string messa
5558
/// each choice.</param>
5659
/// <param name="defaultChoice">The index of the label in the Choices parameter
5760
/// collection. To indicate no default choice, set to -1.</param>
58-
/// <returns>Throws a NotImplementedException exception.</returns>
61+
/// <returns>Throws a NotImplementedException exception because we don't need a prompt.</returns>
5962
public override int PromptForChoice(string caption, string message, System.Collections.ObjectModel.Collection<ChoiceDescription> choices, int defaultChoice)
6063
{
6164
throw new NotImplementedException("The method or operation is not implemented.");
@@ -69,7 +72,7 @@ public override int PromptForChoice(string caption, string message, System.Colle
6972
/// <param name="message">The text of the message.</param>
7073
/// <param name="userName">The user name whose credential is to be prompted for.</param>
7174
/// <param name="targetName">The name of the target for which the credential is collected.</param>
72-
/// <returns>Throws a NotImplementedException exception.</returns>
75+
/// <returns>Throws a NotImplementedException exception because we don't need a prompt.</returns>
7376
public override PSCredential PromptForCredential(string caption, string message, string userName, string targetName)
7477
{
7578
throw new NotImplementedException("The method or operation is not implemented.");
@@ -88,7 +91,7 @@ public override PSCredential PromptForCredential(string caption, string message,
8891
/// identifies the type of credentials that can be returned.</param>
8992
/// <param name="options">A PSCredentialUIOptions constant that identifies the UI
9093
/// behavior when it gathers the credentials.</param>
91-
/// <returns>Throws a NotImplementedException exception.</returns>
94+
/// <returns>Throws a NotImplementedException exception because we don't need a prompt.</returns>
9295
public override PSCredential PromptForCredential(string caption, string message, string userName, string targetName, PSCredentialTypes allowedCredentialTypes, PSCredentialUIOptions options)
9396
{
9497
throw new NotImplementedException("The method or operation is not implemented.");
@@ -98,7 +101,7 @@ public override PSCredential PromptForCredential(string caption, string message,
98101
/// Reads characters that are entered by the user until a newline
99102
/// (carriage return) is encountered.
100103
/// </summary>
101-
/// <returns>The characters that are entered by the user.</returns>
104+
/// <returns>Throws a NotImplemented exception because we are in a non-interactive experience.</returns>
102105
public override string ReadLine()
103106
{
104107
throw new NotImplementedException("The method or operation is not implemented.");
@@ -108,7 +111,7 @@ public override string ReadLine()
108111
/// Reads characters entered by the user until a newline (carriage return)
109112
/// is encountered and returns the characters as a secure string.
110113
/// </summary>
111-
/// <returns>Throws a NotImplemented exception.</returns>
114+
/// <returns>Throws a NotImplemented exception because we are in a non-interactive experience.</returns>
112115
public override System.Security.SecureString ReadLineAsSecureString()
113116
{
114117
throw new NotImplementedException("The method or operation is not implemented.");
@@ -161,7 +164,7 @@ public override void WriteErrorLine(string value)
161164
/// </summary>
162165
public override void WriteLine()
163166
{
164-
//do nothing
167+
//do nothing because we don't need to log empty lines
165168
}
166169

167170
/// <summary>
@@ -203,7 +206,6 @@ public override void WriteProgress(long sourceId, ProgressRecord record)
203206
/// <param name="message">The verbose message that is displayed.</param>
204207
public override void WriteVerboseLine(string message)
205208
{
206-
//Console.WriteLine(String.Format(CultureInfo.CurrentCulture, "VERBOSE: {0}", message));
207209
_logger.LogTrace(String.Format(CultureInfo.CurrentCulture, "VERBOSE: {0}", message));
208210
}
209211

@@ -213,7 +215,6 @@ public override void WriteVerboseLine(string message)
213215
/// <param name="message">The warning message that is displayed.</param>
214216
public override void WriteWarningLine(string message)
215217
{
216-
//Console.WriteLine(String.Format(CultureInfo.CurrentCulture, "WARNING: {0}", message));
217218
_logger.LogWarning(String.Format(CultureInfo.CurrentCulture, "WARNING: {0}", message));
218219
}
219220
}

0 commit comments

Comments
 (0)