From 5b13df42b1dfae0f31e19bdcf46b3611b99103d0 Mon Sep 17 00:00:00 2001 From: Rob Chambers Date: Thu, 28 Mar 2024 12:08:06 -0700 Subject: [PATCH] nullable stuff --- src/ai/Program_AI.cs | 8 ++--- src/ai/commands/chat_command.cs | 4 ++- src/ai/commands/dev_command.cs | 2 +- src/ai/commands/eval_command.cs | 2 +- src/ai/commands/init_command.cs | 2 +- src/ai/commands/language_command.cs | 2 +- .../commands/parsers/chat_command_parser.cs | 2 +- src/ai/commands/parsers/dev_command_parser.cs | 2 +- .../commands/parsers/init_command_parser.cs | 2 +- .../parsers/language_command_parser.cs | 2 +- .../parsers/scenario_wizard_command_parser.cs | 2 +- .../commands/parsers/search_command_parser.cs | 2 +- .../parsers/service_command_parser.cs | 2 +- .../commands/parsers/speech_command_parser.cs | 2 +- .../commands/parsers/test_command_parser.cs | 2 +- .../commands/parsers/tool_command_parser.cs | 2 +- .../commands/parsers/update_command_parser.cs | 2 +- .../parsers/version_command_parser.cs | 2 +- .../commands/parsers/vision_command_parser.cs | 2 +- src/ai/commands/scenario_wizard_command.cs | 2 +- src/ai/commands/search_command.cs | 2 +- src/ai/commands/service_command.cs | 2 +- src/ai/commands/speech_command.cs | 2 +- src/ai/commands/test_command.cs | 2 +- src/ai/commands/tool_command.cs | 2 +- src/ai/commands/version_command.cs | 2 +- src/ai/commands/vision_command.cs | 2 +- src/clis/vz/commands/image_command.cs | 5 ++- src/common/Program.cs | 4 +-- src/common/details/commands/command.cs | 6 ++-- .../commands/parsers/command_parser.cs | 8 ++--- .../commands/parsers/help_command_parser.cs | 2 +- src/common/details/helpers/file_helpers.cs | 4 +-- src/common/details/helpers/http_helpers.cs | 4 +-- .../details/named_values/named_values.cs | 20 ++++++++--- .../commands/batch_command.cs | 6 ++-- .../custom_speech_recognition_command.cs | 6 ++-- .../commands/dialog_command.cs | 2 +- .../commands/intent_command.cs | 2 +- .../commands/meeting_transcription_command.cs | 8 ++--- .../commands/parsers/batch_command_parser.cs | 2 +- ...ustom_speech_recognition_command_parser.cs | 2 +- .../commands/parsers/dialog_command_parser.cs | 2 +- .../parsers/profile_command_parser.cs | 2 +- .../commands/parsers/webjob_command_parser.cs | 2 +- .../commands/profile_command.cs | 14 ++++---- .../commands/recognize_command.cs | 2 +- .../commands/synthesize_command.cs | 33 ++++++++++--------- .../commands/translate_command.cs | 12 +++---- .../commands/webjob_command.cs | 20 +++++------ .../helpers/config_helpers.cs | 7 ++-- 51 files changed, 124 insertions(+), 113 deletions(-) diff --git a/src/ai/Program_AI.cs b/src/ai/Program_AI.cs index b83c2324..d18b74a6 100644 --- a/src/ai/Program_AI.cs +++ b/src/ai/Program_AI.cs @@ -154,7 +154,7 @@ public AiProgramData() public bool DispatchRunCommand(ICommandValues values) { - var command = values.GetCommand(); + var command = values.GetCommandOrEmpty(); var root = command.Split('.').FirstOrDefault(); return root switch { @@ -179,8 +179,8 @@ public bool DispatchRunCommand(ICommandValues values) public bool DispatchParseCommand(INamedValueTokens tokens, ICommandValues values) { - var command = values.GetCommand(null) ?? tokens.PeekNextToken(); - var root = command.Split('.').FirstOrDefault(); + var command = values.GetCommandOrDefault(null) ?? tokens.PeekNextToken(); + var root = command?.Split('.').FirstOrDefault(); return root switch { @@ -207,7 +207,7 @@ public bool DispatchParseCommand(INamedValueTokens tokens, ICommandValues values public bool DispatchParseCommandValues(INamedValueTokens tokens, ICommandValues values) { - var root = values.GetCommandRoot(); + var root = values.GetCommandRootOrEmpty(); return root switch { "init" => InitCommandParser.ParseCommandValues(tokens, values), diff --git a/src/ai/commands/chat_command.cs b/src/ai/commands/chat_command.cs index 9075c629..da7152bc 100644 --- a/src/ai/commands/chat_command.cs +++ b/src/ai/commands/chat_command.cs @@ -22,6 +22,7 @@ using System.Text; using System.Threading.Tasks; using System.Text.Json.Nodes; +using System.Threading; namespace Azure.AI.Details.Common.CLI { @@ -35,7 +36,7 @@ internal ChatCommand(ICommandValues values) : base(values) internal bool RunCommand() { - DoCommand(_values.GetCommand()); + DoCommand(_values.GetCommandOrEmpty()); return _values.GetOrDefault("passed", true); } @@ -571,6 +572,7 @@ private void DisplayAssistantPromptLabel() private void DisplayAssistantPromptTextStreaming(string text) { + Thread.Sleep(30); // do "tab" indentation when not quiet Console.Write(!_quiet ? text.Replace("\n", "\n ") diff --git a/src/ai/commands/dev_command.cs b/src/ai/commands/dev_command.cs index cba677fe..dfe53c38 100644 --- a/src/ai/commands/dev_command.cs +++ b/src/ai/commands/dev_command.cs @@ -38,7 +38,7 @@ internal bool RunCommand() private bool RunDevCommand() { - DoCommand(_values.GetCommand()); + DoCommand(_values.GetCommandOrEmpty()); return _values.GetOrDefault("passed", true); } diff --git a/src/ai/commands/eval_command.cs b/src/ai/commands/eval_command.cs index 60a44373..824deff2 100644 --- a/src/ai/commands/eval_command.cs +++ b/src/ai/commands/eval_command.cs @@ -43,7 +43,7 @@ internal bool RunCommand() private bool RunEvalCommand() { - DoCommand(_values.GetCommand()); + DoCommand(_values.GetCommandOrEmpty()); return _values.GetOrDefault("passed", true); } diff --git a/src/ai/commands/init_command.cs b/src/ai/commands/init_command.cs index d7e68618..d301523e 100644 --- a/src/ai/commands/init_command.cs +++ b/src/ai/commands/init_command.cs @@ -38,7 +38,7 @@ private async Task RunInitCommand() { try { - await DoCommand(_values.GetCommand()); + await DoCommand(_values.GetCommandOrEmpty()); return _values.GetOrDefault("passed", true); } catch (ApplicationException ex) diff --git a/src/ai/commands/language_command.cs b/src/ai/commands/language_command.cs index 2d580a70..3fe34844 100644 --- a/src/ai/commands/language_command.cs +++ b/src/ai/commands/language_command.cs @@ -43,7 +43,7 @@ internal bool RunCommand() private bool RunLanguageCommand() { - DoCommand(_values.GetCommand()); + DoCommand(_values.GetCommandOrEmpty()); return _values.GetOrDefault("passed", true); } diff --git a/src/ai/commands/parsers/chat_command_parser.cs b/src/ai/commands/parsers/chat_command_parser.cs index 6a135744..1231df4f 100644 --- a/src/ai/commands/parsers/chat_command_parser.cs +++ b/src/ai/commands/parsers/chat_command_parser.cs @@ -33,7 +33,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = { private static IEnumerable GetCommandParsers(ICommandValues values) { - var commandName = values.GetCommand(); + var commandName = values.GetCommandOrEmpty(); switch (commandName) { diff --git a/src/ai/commands/parsers/dev_command_parser.cs b/src/ai/commands/parsers/dev_command_parser.cs index c4152b4e..de97ecac 100644 --- a/src/ai/commands/parsers/dev_command_parser.cs +++ b/src/ai/commands/parsers/dev_command_parser.cs @@ -32,7 +32,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = { private static IEnumerable GetCommandParsers(ICommandValues values) { - var commandName = values.GetCommand(); + var commandName = values.GetCommandOrEmpty(); switch (commandName) { diff --git a/src/ai/commands/parsers/init_command_parser.cs b/src/ai/commands/parsers/init_command_parser.cs index 860da8a4..8a47bb2d 100644 --- a/src/ai/commands/parsers/init_command_parser.cs +++ b/src/ai/commands/parsers/init_command_parser.cs @@ -45,7 +45,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = { private static INamedValueTokenParser[] GetCommandParsers(ICommandValues values) { - var commandName = values.GetCommand(); + var commandName = values.GetCommandOrEmpty(); switch (commandName) { case "init.aiservices": diff --git a/src/ai/commands/parsers/language_command_parser.cs b/src/ai/commands/parsers/language_command_parser.cs index f9ec8d6e..fc690319 100644 --- a/src/ai/commands/parsers/language_command_parser.cs +++ b/src/ai/commands/parsers/language_command_parser.cs @@ -35,7 +35,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = { private static IEnumerable GetCommandParsers(ICommandValues values) { - var commandName = values.GetCommand(); + var commandName = values.GetCommandOrEmpty(); foreach (var command in _commands) { if (commandName == command.name) diff --git a/src/ai/commands/parsers/scenario_wizard_command_parser.cs b/src/ai/commands/parsers/scenario_wizard_command_parser.cs index f689561c..28a9081f 100644 --- a/src/ai/commands/parsers/scenario_wizard_command_parser.cs +++ b/src/ai/commands/parsers/scenario_wizard_command_parser.cs @@ -29,7 +29,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = { private static INamedValueTokenParser[] GetCommandParsers(ICommandValues values) { - var commandName = values.GetCommand(); + var commandName = values.GetCommandOrEmpty(); switch (commandName) { case "wizard": diff --git a/src/ai/commands/parsers/search_command_parser.cs b/src/ai/commands/parsers/search_command_parser.cs index 6d46c62b..0812b903 100644 --- a/src/ai/commands/parsers/search_command_parser.cs +++ b/src/ai/commands/parsers/search_command_parser.cs @@ -45,7 +45,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = { private static IEnumerable GetCommandParsers(ICommandValues values) { - var commandName = values.GetCommand(); + var commandName = values.GetCommandOrEmpty(); switch (commandName) { diff --git a/src/ai/commands/parsers/service_command_parser.cs b/src/ai/commands/parsers/service_command_parser.cs index 5451627e..7a1a0cff 100644 --- a/src/ai/commands/parsers/service_command_parser.cs +++ b/src/ai/commands/parsers/service_command_parser.cs @@ -73,7 +73,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = { private static IEnumerable GetCommandParsers(ICommandValues values) { - var commandName = values.GetCommand(); + var commandName = values.GetCommandOrEmpty(); switch (commandName) { diff --git a/src/ai/commands/parsers/speech_command_parser.cs b/src/ai/commands/parsers/speech_command_parser.cs index 9f1e0186..ca476a0a 100644 --- a/src/ai/commands/parsers/speech_command_parser.cs +++ b/src/ai/commands/parsers/speech_command_parser.cs @@ -106,7 +106,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = { private static IEnumerable GetCommandParsers(ICommandValues values) { - var check = string.Join(".", values.GetCommand() + var check = string.Join(".", values.GetCommandOrEmpty() .Split('.') .Take(2) .ToArray()); diff --git a/src/ai/commands/parsers/test_command_parser.cs b/src/ai/commands/parsers/test_command_parser.cs index 925073ca..4ae3cea4 100644 --- a/src/ai/commands/parsers/test_command_parser.cs +++ b/src/ai/commands/parsers/test_command_parser.cs @@ -30,7 +30,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = { private static IEnumerable GetCommandParsers(ICommandValues values) { - var commandName = values.GetCommand(); + var commandName = values.GetCommandOrEmpty(); switch (commandName) { diff --git a/src/ai/commands/parsers/tool_command_parser.cs b/src/ai/commands/parsers/tool_command_parser.cs index 1c44bf63..0ebbb7a6 100644 --- a/src/ai/commands/parsers/tool_command_parser.cs +++ b/src/ai/commands/parsers/tool_command_parser.cs @@ -31,7 +31,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = { private static IEnumerable GetCommandParsers(ICommandValues values) { - var commandName = values.GetCommand(); + var commandName = values.GetCommandOrEmpty(); foreach (var command in _commands) { if (commandName == command.name) diff --git a/src/ai/commands/parsers/update_command_parser.cs b/src/ai/commands/parsers/update_command_parser.cs index 1802bdd1..55c011df 100644 --- a/src/ai/commands/parsers/update_command_parser.cs +++ b/src/ai/commands/parsers/update_command_parser.cs @@ -30,7 +30,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = { private static IEnumerable GetCommandParsers(ICommandValues values) { - var commandName = values.GetCommand(); + var commandName = values.GetCommandOrEmpty(); switch (commandName) { diff --git a/src/ai/commands/parsers/version_command_parser.cs b/src/ai/commands/parsers/version_command_parser.cs index 78ccb2cd..9956e6a0 100644 --- a/src/ai/commands/parsers/version_command_parser.cs +++ b/src/ai/commands/parsers/version_command_parser.cs @@ -30,7 +30,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = { private static IEnumerable GetCommandParsers(ICommandValues values) { - var commandName = values.GetCommand(); + var commandName = values.GetCommandOrEmpty(); switch (commandName) { diff --git a/src/ai/commands/parsers/vision_command_parser.cs b/src/ai/commands/parsers/vision_command_parser.cs index d1b07aa6..af015511 100644 --- a/src/ai/commands/parsers/vision_command_parser.cs +++ b/src/ai/commands/parsers/vision_command_parser.cs @@ -61,7 +61,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = { private static IEnumerable GetCommandParsers(ICommandValues values) { - var commandName = values.GetCommand(); + var commandName = values.GetCommandOrEmpty(); switch (commandName) { case "vision.image": diff --git a/src/ai/commands/scenario_wizard_command.cs b/src/ai/commands/scenario_wizard_command.cs index 1b5c059b..9b633229 100644 --- a/src/ai/commands/scenario_wizard_command.cs +++ b/src/ai/commands/scenario_wizard_command.cs @@ -38,7 +38,7 @@ private async Task RunScenarioWizardCommand() { try { - await DoCommand(_values.GetCommand()); + await DoCommand(_values.GetCommandOrEmpty()); return _values.GetOrDefault("passed", true); } catch (ApplicationException) diff --git a/src/ai/commands/search_command.cs b/src/ai/commands/search_command.cs index 489211ca..43a113bd 100644 --- a/src/ai/commands/search_command.cs +++ b/src/ai/commands/search_command.cs @@ -58,7 +58,7 @@ internal bool RunCommand() private bool RunSearchCommand() { - DoCommand(_values.GetCommand()); + DoCommand(_values.GetCommandOrEmpty()); return _values.GetOrDefault("passed", true); } diff --git a/src/ai/commands/service_command.cs b/src/ai/commands/service_command.cs index c34d9374..cb23c9f0 100644 --- a/src/ai/commands/service_command.cs +++ b/src/ai/commands/service_command.cs @@ -43,7 +43,7 @@ internal bool RunCommand() private bool RunServiceCommand() { - DoCommand(_values.GetCommand()); + DoCommand(_values.GetCommandOrEmpty()); return _values.GetOrDefault("passed", true); } diff --git a/src/ai/commands/speech_command.cs b/src/ai/commands/speech_command.cs index f4393604..be9b3de1 100644 --- a/src/ai/commands/speech_command.cs +++ b/src/ai/commands/speech_command.cs @@ -43,7 +43,7 @@ internal bool RunCommand() private bool RunSpeechCommand() { - DoCommand(_values.GetCommand()); + DoCommand(_values.GetCommandOrEmpty()); return _values.GetOrDefault("passed", true); } diff --git a/src/ai/commands/test_command.cs b/src/ai/commands/test_command.cs index 393ec861..cb745cb8 100644 --- a/src/ai/commands/test_command.cs +++ b/src/ai/commands/test_command.cs @@ -40,7 +40,7 @@ internal bool RunCommand() private bool RunTestCommand() { - DoCommand(_values.GetCommand()); + DoCommand(_values.GetCommandOrEmpty()); return _values.GetOrDefault("passed", true); } diff --git a/src/ai/commands/tool_command.cs b/src/ai/commands/tool_command.cs index c9281b30..b0eb3c61 100644 --- a/src/ai/commands/tool_command.cs +++ b/src/ai/commands/tool_command.cs @@ -43,7 +43,7 @@ internal bool RunCommand() private bool RunToolCommand() { - DoCommand(_values.GetCommand()); + DoCommand(_values.GetCommandOrEmpty()); return _values.GetOrDefault("passed", true); } diff --git a/src/ai/commands/version_command.cs b/src/ai/commands/version_command.cs index bc2b6a94..1d4ad870 100644 --- a/src/ai/commands/version_command.cs +++ b/src/ai/commands/version_command.cs @@ -25,7 +25,7 @@ internal VersionCommand(ICommandValues values) : base(values) internal bool RunCommand() { - DoCommand(_values.GetCommand()); + DoCommand(_values.GetCommandOrEmpty()); return _values.GetOrDefault("passed", true); } diff --git a/src/ai/commands/vision_command.cs b/src/ai/commands/vision_command.cs index 1607f6c8..a7095314 100644 --- a/src/ai/commands/vision_command.cs +++ b/src/ai/commands/vision_command.cs @@ -37,7 +37,7 @@ internal bool RunCommand() private bool RunVisionCommand() { - DoCommand(_values.GetCommand()); + DoCommand(_values.GetCommandOrEmpty()); return _values.GetOrDefault("passed", true); } diff --git a/src/clis/vz/commands/image_command.cs b/src/clis/vz/commands/image_command.cs index f2353072..4231b923 100644 --- a/src/clis/vz/commands/image_command.cs +++ b/src/clis/vz/commands/image_command.cs @@ -364,9 +364,8 @@ private string GetVisionInputFromId(string id) return input; } - private string GetVisionInputFileFromId(string id) + private string? GetVisionInputFileFromId(string id) { - string file; var existing = FileHelpers.FindFileInDataPath(id, _values); if (existing == null) existing = FileHelpers.FindFileInDataPath(id + ".png", _values); if (existing == null) existing = FileHelpers.FindFileInDataPath(id + ".jpg", _values); @@ -381,7 +380,7 @@ private string GetVisionInputFileFromId(string id) } } - file = existing; + var file = existing; _values.Add("vision.input.file", file); return file; } diff --git a/src/common/Program.cs b/src/common/Program.cs index 582c2deb..225e00a6 100644 --- a/src/common/Program.cs +++ b/src/common/Program.cs @@ -407,7 +407,7 @@ private static bool RunCommand(ICommandValues values) else { outcome = Outcome.Failed; - errorInfo = $"Failed while running '{values.GetCommand()}' command"; + errorInfo = $"Failed while running '{values.GetCommandOrEmpty()}' command"; } } catch (OperationCanceledException ex) @@ -428,7 +428,7 @@ private static bool RunCommand(ICommandValues values) { _data?.Telemetry?.LogEvent(new CommandTelemetryEvent() { - Type = values.GetCommand("unknown")!, + Type = values.GetCommandOrDefault("unknown")!, Outcome = outcome, ErrorInfo = errorInfo }); diff --git a/src/common/details/commands/command.cs b/src/common/details/commands/command.cs index 0186488a..11bceed7 100644 --- a/src/common/details/commands/command.cs +++ b/src/common/details/commands/command.cs @@ -46,7 +46,7 @@ public static bool DispatchRunCommand(ICommandValues values) public static bool DispatchRunCommand(ICommandValues values, Queue? queue, bool expandOk, bool parallelOk) { - var command = values.GetCommand(); + var command = values.GetCommandOrEmpty(); if (command == "config") { @@ -101,7 +101,7 @@ private static void ZipCommand(ICommandValues values, string zipAsFile, string t var runScript = isWindows ? "run.cmd" : "run.sh"; if (verbose) Console.WriteLine($" Saving {runScript}... "); - var command = values.GetCommand(); + var command = values.GetCommandOrEmpty(); var commandJob = "./" + command + ".job"; var runScriptPath = PathHelpers.Combine(tempDirectory, runScript)!; @@ -613,7 +613,7 @@ private static bool RunCommandsOutOfProc(Queue queue, int maxPro var fileNames = values.SaveAs(values.Names, Path.GetTempFileName()); var fileName = fileNames.Split(';').First(); - var start = new ProcessStartInfo(Program.Exe, $"{values.GetCommand()} --nodefaults @{fileName}"); + var start = new ProcessStartInfo(Program.Exe, $"{values.GetCommandOrEmpty()} --nodefaults @{fileName}"); start.UseShellExecute = false; var process = Process.Start(start)!; diff --git a/src/common/details/commands/parsers/command_parser.cs b/src/common/details/commands/parsers/command_parser.cs index 8acb909b..0db6f00a 100644 --- a/src/common/details/commands/parsers/command_parser.cs +++ b/src/common/details/commands/parsers/command_parser.cs @@ -71,7 +71,7 @@ public class CommandParser { protected static bool ParseCommandValues(string commandName, IEnumerable parsers, INamedValueTokens tokens, ICommandValues values) { - return commandName != null && values.GetCommand()!.StartsWith(commandName) && ParseAllCommandValues(parsers, tokens, values); + return commandName != null && values.GetCommandOrEmpty()!.StartsWith(commandName) && ParseAllCommandValues(parsers, tokens, values); } protected static bool ParseCommand(string commandName, IEnumerable parsers, INamedValueTokens tokens, ICommandValues values) @@ -84,7 +84,7 @@ protected static bool ParseCommand(string commandName, IEnumerable commands, IEnumerable partials, INamedValueTokens tokens, ICommandValues values, Func> parsers) { return ParseCommandName(commands, partials, tokens, values) && - ParseCommandDefaults(values.GetCommand()!, parsers(values), tokens, values) && + ParseCommandDefaults(values.GetCommandOrEmpty()!, parsers(values), tokens, values) && ParseAllCommandValues(parsers(values), tokens, values); } @@ -124,7 +124,7 @@ protected static bool ParseCommandName(IEnumerable<(string name, bool requireCom protected static bool ParseCommandName(string commandName, INamedValueTokens tokens, ICommandValues values, bool requireCommandValues = true) { - if (commandName == values.GetCommand()) return true; + if (commandName == values.GetCommandOrEmpty()) return true; var parsedDotName = commandName.Contains(".") && ParseCommandDotName(commandName, tokens, values, requireCommandValues); var parsed = parsedDotName || ParseCommandName1(commandName, tokens, values, requireCommandValues); @@ -152,7 +152,7 @@ protected static bool ParseCommandName1(string commandName, INamedValueTokens to values.Add("x.command", commandName); } - return values.Contains("x.command") && values.GetCommand() == commandName; + return values.Contains("x.command") && values.GetCommandOrEmpty() == commandName; } protected static bool ParseCommandDotName(string commandName, INamedValueTokens tokens, ICommandValues values, bool requireCommandValues = true) diff --git a/src/common/details/commands/parsers/help_command_parser.cs b/src/common/details/commands/parsers/help_command_parser.cs index 89ae393d..6ab8e62a 100644 --- a/src/common/details/commands/parsers/help_command_parser.cs +++ b/src/common/details/commands/parsers/help_command_parser.cs @@ -237,7 +237,7 @@ private static bool DoDisplayHelpTopic(INamedValues values) private static bool DisplayHelp(string path, INamedValues values) { var interactive = values.GetOrDefault("x.help.interactive", true) && - values.GetCommand() == "help" && + values.GetCommandOrEmpty() == "help" && !Console.IsInputRedirected && !Console.IsOutputRedirected; diff --git a/src/common/details/helpers/file_helpers.cs b/src/common/details/helpers/file_helpers.cs index 977664f2..c65f380c 100644 --- a/src/common/details/helpers/file_helpers.cs +++ b/src/common/details/helpers/file_helpers.cs @@ -252,7 +252,7 @@ public static IEnumerable FindFilesInTemplatePath(string fileNames, INam private static IEnumerable FindFilesInPath(string fileNames, INamedValues? values, string searchPath) { - var commandActual = values?.GetCommand(); + var commandActual = values?.GetCommandOrEmpty(); var commandScope = values?.GetOrDefault("x.config.scope.command", commandActual == "config" ? "" : commandActual); if (commandScope != null && commandScope.Contains(".")) commandScope = commandScope.Substring(0, commandScope.IndexOf('.')); @@ -480,7 +480,7 @@ public static IEnumerable FindFilesInOsPath(string fileName) if (IsStandardInputReference(fileName)) return fileName; searchPaths += ";.x"; - var commandActual = values?.GetCommand(); + var commandActual = values?.GetCommandOrEmpty(); var commandScope = values?.GetOrDefault("x.config.scope.command", commandActual == "config" ? "" : commandActual); if (commandScope != null && commandScope.Contains(".")) commandScope = commandScope.Substring(0, commandScope.IndexOf('.')); diff --git a/src/common/details/helpers/http_helpers.cs b/src/common/details/helpers/http_helpers.cs index f7534f6e..09a4e529 100644 --- a/src/common/details/helpers/http_helpers.cs +++ b/src/common/details/helpers/http_helpers.cs @@ -237,7 +237,7 @@ public static bool WaitForComplete(Func createWebRequest, INamed return isJson ? text : null; } - public static string? GetOutputDataFileName(string? defaultFileName, HttpWebResponse response, ICommandValues values, string domain, out bool isText, out bool isJson) + public static string GetOutputDataFileName(string? defaultFileName, HttpWebResponse response, ICommandValues values, string domain, out bool isText, out bool isJson) { isText = response.ContentType.Contains("text/plain"); isJson = response.ContentType.Contains("application/json"); @@ -265,7 +265,7 @@ public static string GetFileNameFromResponse(WebResponse response, INamedValues return lastPartValid ? lastPart : defaultFileName; } - public static string? ReadWriteResponse(WebResponse response, string fileName, string message, bool returnAsText) + public static string? ReadWriteResponse(WebResponse response, string fileName, string? message, bool returnAsText) { Stream stream; using (stream = response.GetResponseStream()) diff --git a/src/common/details/named_values/named_values.cs b/src/common/details/named_values/named_values.cs index 008687e6..26c07a84 100644 --- a/src/common/details/named_values/named_values.cs +++ b/src/common/details/named_values/named_values.cs @@ -52,7 +52,7 @@ public static bool GetOrDefault(this INamedValues values, string name, bool defa return !string.IsNullOrEmpty(value) && bool.TryParse(value, out returnValue) ? returnValue : defaultValue; } - public static string DemandGetOrDefault(this INamedValues values, string name, string defaultValue, string error) + public static string DemandGetOrDefault(this INamedValues values, string name, string? defaultValue, string error) { var value = values.GetOrDefault(name, defaultValue); if (string.IsNullOrEmpty(value)) @@ -214,19 +214,29 @@ public static bool DumpHelpRequested(this INamedValues values) return values.GetOrDefault("display.help.dump", false); } - public static string? GetCommand(this INamedValues values, string defaultValue = "") + public static string GetCommandOrEmpty(this INamedValues values) + { + return values.GetOrDefault("x.command", string.Empty)!; + } + + public static string? GetCommandOrDefault(this INamedValues values, string? defaultValue = null) { return values.GetOrDefault("x.command", defaultValue); } - public static string? GetCommandRoot(this INamedValues values, string defaultValue = "") + public static string GetCommandRootOrEmpty(this INamedValues values) + { + return values.GetCommandOrEmpty().Split('.').First(); + } + + public static string? GetCommandRootOrDefault(this INamedValues values, string? defaultValue = null) { - return values.GetCommand(defaultValue)?.Split('.').FirstOrDefault() ?? string.Empty; + return values.GetCommandOrDefault(defaultValue)?.Split('.').FirstOrDefault(); } public static string? GetCommandForDisplay(this INamedValues values) { - return values.GetCommand()?.Replace('.', ' '); + return values.GetCommandOrEmpty()?.Replace('.', ' '); } } diff --git a/src/extensions/speech_extension/commands/batch_command.cs b/src/extensions/speech_extension/commands/batch_command.cs index 0f4a56f5..1f39b095 100644 --- a/src/extensions/speech_extension/commands/batch_command.cs +++ b/src/extensions/speech_extension/commands/batch_command.cs @@ -45,7 +45,7 @@ public bool RunCommand() private bool RunBatchCommand() { - DoCommand(_values.GetCommand()); + DoCommand(_values.GetCommandOrEmpty()); return _values.GetOrDefault("passed", true); } @@ -688,7 +688,7 @@ private bool CheckWaitForComplete(HttpWebResponse created, string statusJson, st return HttpHelpers.CheckWaitForComplete(created, statusJson, createWebRequest, _values, domain, message, _quiet, _verbose); } - private string? DownloadUrl(string url, string defaultFileName = null) + private string? DownloadUrl(string url, string? defaultFileName = null) { var message = url.Substring(0, Math.Min(100, url.Length)); message = url.Length > 100 @@ -705,7 +705,7 @@ private bool CheckWaitForComplete(HttpWebResponse created, string statusJson, st return ReadWritePrintResponse(response, defaultFileName); } - private string? ReadWritePrintResponse(HttpWebResponse response, string defaultFileName = null) + private string? ReadWritePrintResponse(HttpWebResponse response, string? defaultFileName = null) { var saveAs = HttpHelpers.GetOutputDataFileName(defaultFileName, response, _values, "batch", out _, out bool isJson); diff --git a/src/extensions/speech_extension/commands/custom_speech_recognition_command.cs b/src/extensions/speech_extension/commands/custom_speech_recognition_command.cs index 8a77c260..b9c77761 100644 --- a/src/extensions/speech_extension/commands/custom_speech_recognition_command.cs +++ b/src/extensions/speech_extension/commands/custom_speech_recognition_command.cs @@ -43,7 +43,7 @@ public bool RunCommand() private bool RunCustomSpeechCommand() { - DoCommand(_values.GetCommand()); + DoCommand(_values.GetCommandOrEmpty()); return _values.GetOrDefault("passed", true); } @@ -1183,7 +1183,7 @@ private bool CheckWaitForComplete(HttpWebResponse created, string statusJson, st return HttpHelpers.CheckWaitForComplete(created, statusJson, createWebRequest, _values, domain, message, _quiet, _verbose); } - private string? DownloadUrl(string url, string defaultFileName = null) + private string? DownloadUrl(string url, string? defaultFileName = null) { var message = url.Substring(0, Math.Min(100, url.Length)); message = url.Length > 100 @@ -1200,7 +1200,7 @@ private bool CheckWaitForComplete(HttpWebResponse created, string statusJson, st return ReadWritePrintResponse(response, defaultFileName); } - private string? ReadWritePrintResponse(HttpWebResponse response, string defaultFileName = null) + private string? ReadWritePrintResponse(HttpWebResponse response, string? defaultFileName = null) { var saveAs = HttpHelpers.GetOutputDataFileName(defaultFileName, response, _values, "csr", out _, out bool isJson); diff --git a/src/extensions/speech_extension/commands/dialog_command.cs b/src/extensions/speech_extension/commands/dialog_command.cs index ec824b94..0b3c0a0a 100644 --- a/src/extensions/speech_extension/commands/dialog_command.cs +++ b/src/extensions/speech_extension/commands/dialog_command.cs @@ -138,7 +138,7 @@ private DialogServiceConfig CreateDialogServiceConfig(string? key = null, string _values.AddThrowError("ERROR:", $"Creating DialogServiceConfig; requires one of: key or token."); } - var dialogType = _values.GetCommand() == "dialog.customcommands" + var dialogType = _values.GetCommandOrEmpty() == "dialog.customcommands" ? DialogType.CustomCommands : DialogType.Bot; DialogServiceConfig config; diff --git a/src/extensions/speech_extension/commands/intent_command.cs b/src/extensions/speech_extension/commands/intent_command.cs index ccc5fd20..1ccfe4db 100644 --- a/src/extensions/speech_extension/commands/intent_command.cs +++ b/src/extensions/speech_extension/commands/intent_command.cs @@ -150,7 +150,7 @@ private IntentRecognizer CreateIntentRecognizer() var config = CreateSpeechConfig(); var audioConfig = ConfigHelpers.CreateAudioConfig(_values); - // CreateSourceLanguageConfig(config, out SourceLanguageConfig language, out AutoDetectSourceLanguageConfig autoDetect); + // CreateSourceLanguageConfig(config, out SourceLanguageConfig? language, out AutoDetectSourceLanguageConfig? autoDetect); // var recognizer = autoDetect != null // ? new IntentRecognizer(config, autoDetect, audioConfig) // : language != null diff --git a/src/extensions/speech_extension/commands/meeting_transcription_command.cs b/src/extensions/speech_extension/commands/meeting_transcription_command.cs index 72cacb32..ce6c50e8 100644 --- a/src/extensions/speech_extension/commands/meeting_transcription_command.cs +++ b/src/extensions/speech_extension/commands/meeting_transcription_command.cs @@ -71,10 +71,10 @@ private void RecognizeContinuous() private MeetingTranscriber CreateMeetingTranscriber() { - SpeechConfig config = CreateSpeechConfig(); - Meeting meeting = CreateMeeting(config); + var config = CreateSpeechConfig(); + var meeting = CreateMeeting(config); - AudioConfig audioConfig = ConfigHelpers.CreateAudioConfig(_values); + var audioConfig = ConfigHelpers.CreateAudioConfig(_values); var transcriber = new MeetingTranscriber(audioConfig); transcriber.JoinMeetingAsync(meeting).Wait(); @@ -212,7 +212,7 @@ private void CheckNotYetImplementedConfigProperties() } } - private Meeting CreateMeeting(SpeechConfig config) + private Meeting? CreateMeeting(SpeechConfig config) { var meetingId = _values.GetOrDefault("meeting.id", Guid.NewGuid().ToString()); var task = Meeting.CreateMeetingAsync(config, meetingId); diff --git a/src/extensions/speech_extension/commands/parsers/batch_command_parser.cs b/src/extensions/speech_extension/commands/parsers/batch_command_parser.cs index b378c110..f277d7d8 100644 --- a/src/extensions/speech_extension/commands/parsers/batch_command_parser.cs +++ b/src/extensions/speech_extension/commands/parsers/batch_command_parser.cs @@ -44,7 +44,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = { public static IEnumerable GetCommandParsers(ICommandValues values) { - var commandName = values.GetCommand(); + var commandName = values.GetCommandOrEmpty(); switch (commandName.Replace("speech.", "")) { case "batch.list": diff --git a/src/extensions/speech_extension/commands/parsers/custom_speech_recognition_command_parser.cs b/src/extensions/speech_extension/commands/parsers/custom_speech_recognition_command_parser.cs index 2f342789..6f2a3745 100644 --- a/src/extensions/speech_extension/commands/parsers/custom_speech_recognition_command_parser.cs +++ b/src/extensions/speech_extension/commands/parsers/custom_speech_recognition_command_parser.cs @@ -66,7 +66,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = { public static INamedValueTokenParser[] GetCommandParsers(ICommandValues values) { - var commandName = string.Join('.', values.GetCommand() + var commandName = string.Join('.', values.GetCommandOrEmpty() .Split('.') .SkipWhile(x => x == "speech") .ToArray()); diff --git a/src/extensions/speech_extension/commands/parsers/dialog_command_parser.cs b/src/extensions/speech_extension/commands/parsers/dialog_command_parser.cs index d6f6b767..51198c42 100644 --- a/src/extensions/speech_extension/commands/parsers/dialog_command_parser.cs +++ b/src/extensions/speech_extension/commands/parsers/dialog_command_parser.cs @@ -34,7 +34,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = { private static INamedValueTokenParser[] GetCommandParsers(ICommandValues values) { - var commandName = values.GetCommand(); + var commandName = values.GetCommandOrEmpty(); switch (commandName) { case "dialog.bot": diff --git a/src/extensions/speech_extension/commands/parsers/profile_command_parser.cs b/src/extensions/speech_extension/commands/parsers/profile_command_parser.cs index 5d53c5b5..cd6df71f 100644 --- a/src/extensions/speech_extension/commands/parsers/profile_command_parser.cs +++ b/src/extensions/speech_extension/commands/parsers/profile_command_parser.cs @@ -38,7 +38,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = { public static IEnumerable GetCommandParsers(ICommandValues values) { - var commandName = values.GetCommand(); + var commandName = values.GetCommandOrEmpty(); switch (commandName.Replace("speech.", "")) { case "profile.list": diff --git a/src/extensions/speech_extension/commands/parsers/webjob_command_parser.cs b/src/extensions/speech_extension/commands/parsers/webjob_command_parser.cs index 220cdf0b..a9cf7432 100644 --- a/src/extensions/speech_extension/commands/parsers/webjob_command_parser.cs +++ b/src/extensions/speech_extension/commands/parsers/webjob_command_parser.cs @@ -35,7 +35,7 @@ private static readonly (string name, bool valuesRequired)[] _commands = { private static INamedValueTokenParser[] GetCommandParsers(ICommandValues values) { - var commandName = values.GetCommand(); + var commandName = values.GetCommandOrEmpty(); switch (commandName) { case "webjob.list": diff --git a/src/extensions/speech_extension/commands/profile_command.cs b/src/extensions/speech_extension/commands/profile_command.cs index 1ec5485a..42defe5e 100644 --- a/src/extensions/speech_extension/commands/profile_command.cs +++ b/src/extensions/speech_extension/commands/profile_command.cs @@ -43,7 +43,7 @@ public bool RunCommand() private bool RunSpeakerCommand() { - DoCommand(_values.GetCommand()); + DoCommand(_values.GetCommandOrEmpty()); return _values.GetOrDefault("passed", true); } @@ -181,7 +181,7 @@ private List ParseArray(JsonElement[] array, string key) foreach (var token in array) { var id = token.GetPropertyStringOrNull(key); - ids.Add(id); + if (id != null) ids.Add(id); } return ids; @@ -230,7 +230,7 @@ private VoiceProfileClient GetVoiceProfileClient() private VoiceProfileType GetVoiceProfileType() { - var kind = _values.GetOrDefault("profile.kind", "TextIndependentIdentification"); + var kind = _values.GetOrDefault("profile.kind", "TextIndependentIdentification")!; return kind.Equals("TextDependentVerification", StringComparison.OrdinalIgnoreCase) ? VoiceProfileType.TextDependentVerification : kind.Equals("TextIndependentVerification", StringComparison.OrdinalIgnoreCase) ? VoiceProfileType.TextIndependentVerification : VoiceProfileType.TextIndependentIdentification; @@ -384,7 +384,7 @@ private string ReadWritePrintObjectJson(object o) return json; } - private void CheckWriteOutputId(string id) + private void CheckWriteOutputId(string? id) { var idOk = !string.IsNullOrEmpty(id); @@ -405,7 +405,7 @@ private void CheckWriteOutputId(string id) } } - private string CheckWriteOutputSelf(string json, string key) + private string? CheckWriteOutputSelf(string json, string key) { var parsed = JsonDocument.Parse(json); var id = parsed.GetPropertyStringOrNull(key); @@ -457,7 +457,7 @@ private AudioConfig GetAudioConfig() if (string.IsNullOrEmpty(_file)) { var command = _values.GetCommandForDisplay(); - var action = _values.GetCommand().Split('.').LastOrDefault(); + var action = _values.GetCommandOrEmpty().Split('.').LastOrDefault(); _values.AddThrowError( "WARNING:", $"Cannot {action}; file not found!", "", @@ -465,7 +465,7 @@ private AudioConfig GetAudioConfig() "", "SEE:", $"{Program.Name} help {command}"); } - audioConfig = AudioHelpers.CreateAudioConfigFromFile(_file, null); + audioConfig = AudioHelpers.CreateAudioConfigFromFile(_file!, null); } return audioConfig; } diff --git a/src/extensions/speech_extension/commands/recognize_command.cs b/src/extensions/speech_extension/commands/recognize_command.cs index 7940305f..8ba66fc6 100644 --- a/src/extensions/speech_extension/commands/recognize_command.cs +++ b/src/extensions/speech_extension/commands/recognize_command.cs @@ -199,7 +199,7 @@ private void CreateSourceLanguageConfig(SpeechConfig config, out SourceLanguageC private SpeechConfig CreateSpeechConfig(string? key = null, string? region = null) { - SpeechConfig config = ConfigHelpers.CreateSpeechConfig(_values, key, region); + var config = ConfigHelpers.CreateSpeechConfig(_values, key, region); SetSpeechConfigProperties(config); return config; } diff --git a/src/extensions/speech_extension/commands/synthesize_command.cs b/src/extensions/speech_extension/commands/synthesize_command.cs index 6f85bdc7..fe6e5567 100644 --- a/src/extensions/speech_extension/commands/synthesize_command.cs +++ b/src/extensions/speech_extension/commands/synthesize_command.cs @@ -50,13 +50,17 @@ private string GetVoiceNameListUrl() var region = _values["service.config.region"]; var endpoint = _values["service.config.endpoint.uri"]; + if (string.IsNullOrEmpty(endpoint) && string.IsNullOrEmpty(region) && string.IsNullOrEmpty(host)) + { + _values.AddThrowError("ERROR:", $"Creating voice name list URL; requires one of: region, endpoint, or host."); + } + var url = !string.IsNullOrEmpty(endpoint) ? endpoint : !string.IsNullOrEmpty(host) ? $"{host}/cognitiveservices/voices/list" - : !string.IsNullOrEmpty(region) - ? $"https://{region}.tts.speech.microsoft.com/cognitiveservices/voices/list" - : null; + : $"https://{region}.tts.speech.microsoft.com/cognitiveservices/voices/list"; + return url; } @@ -116,7 +120,7 @@ private void SynthesizeInteractive(bool repeatedly = false) while (true) { Console.Write("Enter text: "); - var text = ConsoleHelpers.ReadLineOrDefault("", "exit"); + var text = ConsoleHelpers.ReadLineOrDefault("", "exit")!; if (text.ToLower() == "") break; if (text.ToLower() == "stop") break; @@ -171,7 +175,7 @@ private void SynthesizeSsml() private void SynthesizeSsmlFile() { - var fileName = _values.GetOrDefault("synthesizer.input.ssml.file", _values.GetOrEmpty("synthesizer.input.text.file")); + var fileName = _values.GetOrDefault("synthesizer.input.ssml.file", _values.GetOrEmpty("synthesizer.input.text.file"))!; var existing = FileHelpers.DemandFindFileInDataPath(fileName, _values, "ssml input"); var content = FileHelpers.ReadAllText(existing, Encoding.Default); @@ -206,8 +210,8 @@ private void SynthesizeSsml(string ssml) private SpeechSynthesizer CreateSpeechSynthesizer() { - SpeechConfig config = CreateSpeechConfig(); - AudioConfig audioConfig = CreateAudioConfig(); + var config = CreateSpeechConfig(); + var audioConfig = CreateAudioConfig(); var synthesizer = audioConfig != null ? new SpeechSynthesizer(config, audioConfig) @@ -457,9 +461,8 @@ private string GetInputFromId(string id) return input; } - private string GetInputFileFromId(string id) + private string? GetInputFileFromId(string id) { - string file; var existing = FileHelpers.FindFileInDataPath(id, _values); if (existing == null) existing = FileHelpers.FindFileInDataPath(id + ".txt", _values); if (existing == null) existing = FileHelpers.FindFileInDataPath(id + ".ssml", _values); @@ -474,17 +477,17 @@ private string GetInputFileFromId(string id) } } - file = existing; - _values.Add(existing.EndsWith(".txt") ? "synthesizer.input.text.file" : "synthesizer.input.ssml.file", file); + var file = existing; + _values.Add(existing?.EndsWith(".txt") ?? true ? "synthesizer.input.text.file" : "synthesizer.input.ssml.file", file); return file; } - private AudioConfig? CreateAudioConfig() + private AudioConfig CreateAudioConfig() { var output = _values["audio.output.type"]; var file = _values["audio.output.file"]; - AudioConfig audioConfig = null; + AudioConfig? audioConfig = null; if (output == "speaker" || string.IsNullOrEmpty(output)) { audioConfig = AudioOutputHelpers.CreateAudioConfigForSpeaker(); @@ -499,7 +502,7 @@ private string GetInputFileFromId(string id) _values.AddThrowError("WARNING:", $"'audio.output.type={output}' NOT YET IMPLEMENTED!!"); } - return audioConfig; + return audioConfig!; } private void SynthesisStarted(object? sender, SpeechSynthesisEventArgs e) @@ -560,7 +563,7 @@ private void StartCommand() _output = new OutputHelper(_values); _output!.StartOutput(); - var id = _values["synthesizer.input.id"]; + var id = _values["synthesizer.input.id"]!; _output!.EnsureOutputAll("synthesizer.input.id", id); _output!.EnsureOutputEach("synthesizer.input.id", id); diff --git a/src/extensions/speech_extension/commands/translate_command.cs b/src/extensions/speech_extension/commands/translate_command.cs index 9cba3eee..ab11aa30 100644 --- a/src/extensions/speech_extension/commands/translate_command.cs +++ b/src/extensions/speech_extension/commands/translate_command.cs @@ -147,12 +147,10 @@ private void RecognizeKeyword() private TranslationRecognizer CreateTranslationRecognizer() { - SpeechTranslationConfig config = CreateSpeechTranslationConfig(); - AudioConfig audioConfig = ConfigHelpers.CreateAudioConfig(_values); + var config = CreateSpeechTranslationConfig(); + var audioConfig = ConfigHelpers.CreateAudioConfig(_values); - SourceLanguageConfig language = null; - AutoDetectSourceLanguageConfig autoDetect = null; - CreateSourceLanguageConfig(config, out language, out autoDetect); + CreateSourceLanguageConfig(config, out var language, out var autoDetect); // var recognizer = autoDetect != null // ? new TranslationRecognizer(config, autoDetect, audioConfig) @@ -174,7 +172,7 @@ private TranslationRecognizer CreateTranslationRecognizer() return recognizer; } - private void CreateSourceLanguageConfig(SpeechConfig config, out SourceLanguageConfig language, out AutoDetectSourceLanguageConfig autoDetect) + private void CreateSourceLanguageConfig(SpeechConfig config, out SourceLanguageConfig? language, out AutoDetectSourceLanguageConfig? autoDetect) { language = null; autoDetect = null; @@ -224,7 +222,7 @@ private SpeechTranslationConfig CreateSpeechTranslationConfig() _values.AddThrowError("ERROR:", $"Creating SpeechConfig; use of region requires one of: key or token."); } - SpeechTranslationConfig config = null; + SpeechTranslationConfig config; if (!string.IsNullOrEmpty(endpoint)) { config = string.IsNullOrEmpty(key) diff --git a/src/extensions/speech_extension/commands/webjob_command.cs b/src/extensions/speech_extension/commands/webjob_command.cs index 006fb5b7..0a2ecacc 100644 --- a/src/extensions/speech_extension/commands/webjob_command.cs +++ b/src/extensions/speech_extension/commands/webjob_command.cs @@ -42,7 +42,7 @@ internal bool RunCommand() private bool RunWebJobCommand() { - DoCommand(_values.GetCommand()); + DoCommand(_values.GetCommandOrEmpty()); return _values.GetOrDefault("passed", true); } @@ -147,7 +147,7 @@ private void DoRun(string name = "") ReadWritePrintJson(response); - var location = response.Headers["Location"]; + var location = response.Headers["Location"]!; var id = location[(location.LastIndexOf('/') + 1)..]; DoStatus(name, id); } @@ -250,7 +250,7 @@ private void DoStatus(string? name = null, string? id = null) /// private void DoDelete() { - GetDeleteParameters(out string path, out string name, out string nameAction, out string message); + GetDeleteParameters(out var path, out var name, out var nameAction, out string message); if (!_quiet) Console.WriteLine(message); @@ -327,7 +327,7 @@ private void GetRunParameters(out string path, ref string name, out string nameA path = $"api/triggeredwebjobs"; } - private void GetStatusParameters(out string path, ref string name, out string nameAction, ref string id, out string message) + private void GetStatusParameters(out string path, ref string? name, out string nameAction, ref string? id, out string message) { nameAction = "history"; name = DemandWebJobName(name); @@ -359,7 +359,7 @@ private void GetDownloadParameters(out string url, out string message) file = "."; } - url = _values.GetOrDefault("webjob.download.url", file); + url = _values.GetOrDefault("webjob.download.url", file)!; if (!url.StartsWith("http")) { url = $"vfs/"; @@ -374,7 +374,7 @@ private void GetDownloadParameters(out string url, out string message) : $"Downloading {message} ... "; } - private void GetDeleteParameters(out string path, out string name, out string nameAction, out string message) + private void GetDeleteParameters(out string path, out string name, out string? nameAction, out string message) { nameAction = null; name = DemandWebJobName(); @@ -399,7 +399,7 @@ private string DemandWebJobId(string? id = null) "USE:", $"{Program.Name} webjob [...] --id ID")); } - private HttpWebRequest CreateWebRequest(string method, string path, string? name = null, string nameAction = null, string? id = null, string? contentType = null) + private HttpWebRequest CreateWebRequest(string method, string path, string? name = null, string? nameAction = null, string? id = null, string? contentType = null) { var endpoint = _values.GetOrEmpty("webjob.config.endpoint").Trim('\r', '\n'); var userName = _values.GetOrEmpty("webjob.config.username").Trim('\r', '\n'); @@ -428,7 +428,7 @@ private HttpWebRequest CreateWebRequest(string method, string path, string? name return request; } - private string GetWebJobUrl(string endpoint, string path, string? name = null, string nameAction = null, string? id = null) + private string GetWebJobUrl(string endpoint, string path, string? name = null, string? nameAction = null, string? id = null) { if (path.StartsWith("http")) return path; @@ -450,7 +450,7 @@ private string GetWebJobUrl(string endpoint, string path, string? name = null, s return $"{endpoint}/{pathPart}{namePart}{nameActionPart}{idPart}"; } - private string CheckWriteOutputRequest(HttpWebRequest request, string payload = null, bool append = false) + private string? CheckWriteOutputRequest(HttpWebRequest request, string? payload = null, bool append = false) { var output = _values.GetOrEmpty("webjob.output.request.file"); if (!string.IsNullOrEmpty(output)) @@ -479,7 +479,7 @@ private string ReadWritePrintJson(HttpWebResponse response) return json; } - private string? ReadWritePrintResponse(HttpWebResponse response, string defaultFileName = null) + private string? ReadWritePrintResponse(HttpWebResponse response, string? defaultFileName = null) { var saveAs = HttpHelpers.GetOutputDataFileName(defaultFileName, response, _values, "webjob", out bool isText, out bool isJson); diff --git a/src/extensions/speech_extension/helpers/config_helpers.cs b/src/extensions/speech_extension/helpers/config_helpers.cs index 47251ec0..bfe74a80 100644 --- a/src/extensions/speech_extension/helpers/config_helpers.cs +++ b/src/extensions/speech_extension/helpers/config_helpers.cs @@ -73,14 +73,14 @@ public static SpeechConfig CreateSpeechConfig(ICommandValues values, string? key return config; } - public static AudioConfig? CreateAudioConfig(ICommandValues values) + public static AudioConfig CreateAudioConfig(ICommandValues values) { var input = values["audio.input.type"]; var file = values["audio.input.file"]; var format = values["audio.input.format"]; var device = values["audio.input.microphone.device"]; - AudioConfig audioConfig; + AudioConfig? audioConfig = null; if (input == "microphone" || string.IsNullOrEmpty(input)) { audioConfig = AudioHelpers.CreateMicrophoneAudioConfig(device); @@ -93,10 +93,9 @@ public static SpeechConfig CreateSpeechConfig(ICommandValues values, string? key else { values.AddThrowError("WARNING:", $"'audio.input.type={input}' NOT YET IMPLEMENTED!!"); - return null; } - return audioConfig; + return audioConfig!; } public static void SetEndpointParams(SpeechConfig config, string endpointParams)