Skip to content

Commit cd3fe04

Browse files
author
Anthony Staples
committed
Refactor strings to constants
1 parent bbf56b3 commit cd3fe04

File tree

6 files changed

+24
-18
lines changed

6 files changed

+24
-18
lines changed

src/Microsoft.Azure.Functions.PowerShellWorker.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,4 @@ Licensed under the MIT license. See LICENSE file in the project root for full li
3535
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3636
</Content>
3737
</ItemGroup>
38-
39-
<ItemGroup>
40-
<Folder Include="Messaging\protobuf\" />
41-
</ItemGroup>
4238
</Project>

src/RequestProcessor.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ internal class RequestProcessor
3232

3333
// Holds the exception if an issue is encountered while processing the function app dependencies.
3434
private Exception _initTerminatingError;
35-
36-
// Indicate whether the dependencies have been installed
37-
private bool _areDependenciesInstalled;
35+
36+
// Indicate whether the FunctionApp has been initialized.
37+
private bool _isFunctionAppInitialized;
3838

3939
private Dictionary<StreamingMessage.ContentOneofCase, Func<StreamingMessage, StreamingMessage>> _requestHandlers =
4040
new Dictionary<StreamingMessage.ContentOneofCase, Func<StreamingMessage, StreamingMessage>>();
@@ -182,7 +182,6 @@ internal StreamingMessage ProcessFunctionLoadRequest(StreamingMessage request)
182182
stopwatch.Start();
183183

184184
FunctionLoadRequest functionLoadRequest = request.FunctionLoadRequest;
185-
string lrs = System.Text.Json.JsonSerializer.Serialize<FunctionLoadRequest>(functionLoadRequest);
186185

187186
StreamingMessage response = NewStreamingMessageTemplate(
188187
request.RequestId,
@@ -215,14 +214,14 @@ internal StreamingMessage ProcessFunctionLoadRequest(StreamingMessage request)
215214
// 'FunctionLoadRequest' comes in. Therefore, we run initialization here.
216215
// Also, we receive a FunctionLoadRequest when a proxy is configured. Proxies don't have the Metadata.Directory set
217216
// which would cause initialization issues with the PSModulePath. Since they don't have that set, we skip over them.
218-
if (!_areDependenciesInstalled && !functionLoadRequest.Metadata.IsProxy)
217+
if (!_isFunctionAppInitialized && !functionLoadRequest.Metadata.IsProxy)
219218
{
220219
try
221220
{
222221
var rpcLogger = new RpcLogger(_msgStream);
223222
rpcLogger.SetContext(request.RequestId, null);
224223

225-
_areDependenciesInstalled = true;
224+
_isFunctionAppInitialized = true;
226225

227226
var managedDependenciesPath = _dependencyManager.Initialize(request, rpcLogger);
228227

@@ -264,7 +263,6 @@ internal StreamingMessage ProcessInvocationRequest(StreamingMessage request)
264263
{
265264
try
266265
{
267-
string ins = System.Text.Json.JsonSerializer.Serialize<InvocationRequest>(request.InvocationRequest);
268266
var stopwatch = new FunctionInvocationPerformanceStopwatch();
269267
stopwatch.OnStart();
270268

src/WorkerIndexing/BindingInformation.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ namespace Microsoft.Azure.Functions.PowerShellWorker.WorkerIndexing
88
{
99
internal class BindingInformation
1010
{
11+
private const string BindingNameKey = "name";
12+
private const string BindingDirectionKey = "direction";
13+
private const string BindingTypeKey = "type";
1114
public enum Directions
1215
{
1316
Unknown = -1,
@@ -25,18 +28,18 @@ internal string ConvertToRpcRawBinding(out BindingInfo bindingInfo)
2528
{
2629
string rawBinding = string.Empty;
2730
JObject rawBindingObject = new JObject();
28-
rawBindingObject.Add("name", Name);
31+
rawBindingObject.Add(BindingNameKey, Name);
2932
BindingInfo outInfo = new BindingInfo();
3033

3134

3235
if (Direction == Directions.Unknown)
3336
{
34-
throw new Exception("The bindingInfo's Direction is not valid");
37+
throw new Exception(PowerShellWorkerStrings.InvalidBindingInfoDirection);
3538
}
3639
outInfo.Direction = (BindingInfo.Types.Direction)Direction;
37-
rawBindingObject.Add("direction", Enum.GetName(typeof(BindingInfo.Types.Direction), outInfo.Direction).ToLower());
40+
rawBindingObject.Add(BindingDirectionKey, Enum.GetName(typeof(BindingInfo.Types.Direction), outInfo.Direction).ToLower());
3841
outInfo.Type = Type;
39-
rawBindingObject.Add("type", Type);
42+
rawBindingObject.Add(BindingTypeKey, Type);
4043

4144
foreach (KeyValuePair<string, Object> pair in otherInformation)
4245
{

src/WorkerIndexing/FunctionInformation.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ namespace Microsoft.Azure.Functions.PowerShellWorker.WorkerIndexing
55
{
66
internal class FunctionInformation
77
{
8+
private const string FunctionLanguagePowerShell = "powershell";
9+
810
public string Directory { get; set; } = "";
911
public string ScriptFile { get; set; } = "";
1012
public string Name { get; set; } = "";
@@ -20,7 +22,7 @@ internal RpcFunctionMetadata ConvertToRpc()
2022
returnMetadata.EntryPoint = EntryPoint;
2123
returnMetadata.Name = Name;
2224
returnMetadata.ScriptFile = ScriptFile;
23-
returnMetadata.Language = "powershell";
25+
returnMetadata.Language = FunctionLanguagePowerShell;
2426
foreach(BindingInformation binding in Bindings)
2527
{
2628
string rawBinding = binding.ConvertToRpcRawBinding(out BindingInfo bindingInfo);

src/WorkerIndexing/WorkerIndexingHelper.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace Microsoft.Azure.Functions.PowerShellWorker.WorkerIndexing
1414
{
1515
internal class WorkerIndexingHelper
1616
{
17+
const string GetFunctionsMetadataCmdletName = "Get-FunctionsMetadata";
1718
internal static IEnumerable<RpcFunctionMetadata> IndexFunctions(string baseDir)
1819
{
1920
List<RpcFunctionMetadata> indexedFunctions = new List<RpcFunctionMetadata>();
@@ -24,13 +25,13 @@ internal static IEnumerable<RpcFunctionMetadata> IndexFunctions(string baseDir)
2425
System.Management.Automation.PowerShell ps = System.Management.Automation.PowerShell.Create();
2526
ps.Runspace = runspace;
2627

27-
ps.AddCommand("Get-FunctionsMetadata").AddArgument(baseDir);
28+
ps.AddCommand(GetFunctionsMetadataCmdletName).AddArgument(baseDir);
2829
string outputString = string.Empty;
2930
foreach (PSObject rawMetadata in ps.Invoke())
3031
{
3132
if (outputString != string.Empty)
3233
{
33-
throw new Exception("Multiple results from metadata cmdlet");
34+
throw new Exception(PowerShellWorkerStrings.GetFunctionsMetadataMultipleResultsError);
3435
}
3536
outputString = rawMetadata.ToString();
3637
//Console.WriteLine(rawMetadata.ToString());

src/resources/PowerShellWorkerStrings.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,4 +352,10 @@
352352
<data name="DependencySnapshotDoesNotContainAcceptableModuleVersions" xml:space="preserve">
353353
<value>Dependency snapshot '{0}' does not contain acceptable module versions.</value>
354354
</data>
355+
<data name="GetFunctionsMetadataMultipleResultsError" xml:space="preserve">
356+
<value>Multiple results from metadata cmdlet</value>
357+
</data>
358+
<data name="InvalidBindingInfoDirection" xml:space="preserve">
359+
<value>The bindingInfo's Direction is not valid</value>
360+
</data>
355361
</root>

0 commit comments

Comments
 (0)