gleono commented on code in PR #92:
URL: 
https://github.com/apache/openwhisk-runtime-dotnet/pull/92#discussion_r1796216613


##########
core/net6.0/proxy/Apache.OpenWhisk.Runtime.Common/Init.cs:
##########
@@ -54,58 +53,52 @@ public async Task<Run> HandleRequest(HttpContext 
httpContext)
                 {
                     await httpContext.Response.WriteError("Cannot initialize 
the action more than once.");
                     Console.Error.WriteLine("Cannot initialize the action more 
than once.");
-                    return (new Run(Type, Method, Constructor, 
AwaitableMethod));
+                    return new Run(_type, _method, _constructor, 
_awaitableMethod);
                 }
 
-                string body = await new 
StreamReader(httpContext.Request.Body).ReadToEndAsync();
+                using StreamReader reader = new(httpContext.Request.Body);
+                string body = await reader.ReadToEndAsync();
                 JObject inputObject = JObject.Parse(body);
-                if (!inputObject.ContainsKey("value"))
+                if (!inputObject.TryGetValue("value", out JToken? message) || 
message is not JObject valueObj)
                 {
                     await httpContext.Response.WriteError("Missing main/no 
code to execute.");
-                    return (null);
+                    return null;
                 }
 
-                JToken message = inputObject["value"];
+                string main = valueObj.TryGetValue("main", out JToken? 
mainToken) ? mainToken.ToString() : string.Empty;
+                string code = valueObj.TryGetValue("code", out JToken? 
codeToken) ? codeToken.ToString() : string.Empty;
+                bool binary = valueObj.TryGetValue("binary", out JToken? 
binaryToken) && binaryToken.ToObject<bool>();
 
-                if (message["main"] == null || message["binary"] == null || 
message["code"] == null)
+                if (string.IsNullOrWhiteSpace(main) || 
string.IsNullOrWhiteSpace(code))
                 {
                     await httpContext.Response.WriteError("Missing main/no 
code to execute.");
-                    return (null);
+                    return null;
                 }
 
-                string main = message["main"].ToString();
-
-                bool binary = message["binary"].ToObject<bool>();
-
                 if (!binary)
                 {
                     await httpContext.Response.WriteError("code must be binary 
(zip file).");
-                    return (null);
+                    return null;
                 }
 
                 string[] mainParts = main.Split("::");
                 if (mainParts.Length != 3)
                 {
                     await httpContext.Response.WriteError("main required 
format is \"Assembly::Type::Function\".");
-                    return (null);
+                    return null;
                 }
 
                 string tempPath = Path.Combine(Environment.CurrentDirectory, 
Guid.NewGuid().ToString());
-                string base64Zip = message["code"].ToString();
                 try
                 {
-                    using (MemoryStream stream = new 
MemoryStream(Convert.FromBase64String(base64Zip)))
-                    {
-                        using (ZipArchive archive = new ZipArchive(stream))
-                        {
-                            archive.ExtractToDirectory(tempPath);
-                        }
-                    }
+                    using MemoryStream stream = 
new(Convert.FromBase64String(code));

Review Comment:
   No need to nest `using`s anymore.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to