Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce warnings #376

Merged
merged 33 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e028182
Update nuget packages
CartBlanche Oct 12, 2023
559c509
Refactor Connection State into base class.
CartBlanche Oct 12, 2023
07e3132
Refactor DefaultHost to remove duplications.
CartBlanche Oct 12, 2023
95bde03
Some belt and braces clean-up.
CartBlanche Oct 12, 2023
e3dbd7a
Remove all Logger. null warnings.
CartBlanche Oct 12, 2023
042c484
Remove warnings from Meadow.SoftwareManager
CartBlanche Oct 13, 2023
f9b5d60
Refactor Trace commands to have a common base.
CartBlanche Oct 13, 2023
8e2548c
Rename to BaseTraceCommand.
CartBlanche Oct 13, 2023
31e42dc
Refactor to use BaseTraceCommand to avoid duplicate code.
CartBlanche Oct 14, 2023
640b63d
Moved FileManager.Refresh() and FileManager.Firmware into base class …
CartBlanche Oct 14, 2023
8bd2ac3
Make deploy finish a bit nicer.
CartBlanche Oct 14, 2023
85c2ee2
Some belt and braces defensive codeing for the File commands.
CartBlanche Oct 14, 2023
7f16bef
Remove warnings from App Commands.
CartBlanche Oct 14, 2023
fa5e0d2
Remove warnings from Cloud Commands.
CartBlanche Oct 14, 2023
4f0d5a5
Remove warnings from Config Command.
CartBlanche Oct 14, 2023
3e14f2c
Remove warnings from Device Commands.
CartBlanche Oct 14, 2023
7b8de78
Remove warnings from Developer Command.
CartBlanche Oct 14, 2023
f83619f
Remove warnings from Firmware Commands.
CartBlanche Oct 14, 2023
610fd90
Remove warnings from Runtime Commands.
CartBlanche Oct 14, 2023
acc5707
Remove warnings from DfuSharp structs.
CartBlanche Oct 14, 2023
91012aa
Remove warnings from Current and Legacy Commands
CartBlanche Oct 14, 2023
36e3fd8
Remove warnings from Cloud Client Commands
CartBlanche Oct 14, 2023
6e618de
Remove warnings from Hcom Debugging server.
CartBlanche Oct 14, 2023
7c13cac
Remove warnings from Hcom Firmware classes.
CartBlanche Oct 14, 2023
376b02a
Remove warnings from Hcom Connection classes.
CartBlanche Oct 14, 2023
330d8a6
Remove warnings from Hcom Serial Request classes.
CartBlanche Oct 14, 2023
b79639f
Add scaffolding for the VS debugging calls.
CartBlanche Oct 14, 2023
bdfdf55
Remove MeadowConnectionManager warnings.
CartBlanche Oct 14, 2023
c358e89
Remove Program warnings.
CartBlanche Oct 14, 2023
d0b7f01
Remove PackageManager warnings.
CartBlanche Oct 14, 2023
b597d44
Slight refactor.
CartBlanche Oct 15, 2023
4fb2ce1
Refactor to have common Connection initialisation to reduce duplice c…
CartBlanche Oct 15, 2023
2534b8d
Remove spaces in directory name for easier reference on command line.
CartBlanche Oct 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/v2/Meadow.Cli.Core/Meadow.Cli.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions Source/v2/Meadow.Cli/AppManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static async Task DeployApplication(
{
var existing = deviceFiles.FirstOrDefault(f => Path.GetFileName(f.Name) == Path.GetFileName(localFile.Key));

if (existing != null)
if (existing != null && existing.Crc != null)
{
if (uint.Parse(existing.Crc.Substring(2), System.Globalization.NumberStyles.HexNumber) == localFile.Value)
{
Expand All @@ -104,7 +104,7 @@ public static async Task DeployApplication(

send_file:

if (!await connection?.WriteFile(localFile.Key, null, cancellationToken))
if (connection != null && !await connection.WriteFile(localFile.Key, null, cancellationToken))
{
logger.LogWarning($"Error sending'{Path.GetFileName(localFile.Key)}'. Retrying.");
await Task.Delay(100);
Expand Down
45 changes: 24 additions & 21 deletions Source/v2/Meadow.Cli/Commands/Current/App/AppBuildCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,38 @@ public AppBuildCommand(IPackageManager packageManager, ILoggerFactory loggerFact

protected override async ValueTask ExecuteCommand()
{
string path = Path == null
await Task.Run(() =>
{
string path = Path == null
? AppDomain.CurrentDomain.BaseDirectory
: Path;

// is the path a file?
if (!File.Exists(path))
{
// is it a valid directory?
if (!Directory.Exists(path))
// is the path a file?
if (!File.Exists(path))
{
Logger?.LogError($"Invalid application path '{path}'");
return;
// is it a valid directory?
if (!Directory.Exists(path))
{
Logger?.LogError($"Invalid application path '{path}'");
return;
}
}
}

if (Configuration == null) Configuration = "Release";
if (Configuration == null) Configuration = "Release";

Logger?.LogInformation($"Building {Configuration} configuration of {path}...");
Logger?.LogInformation($"Building {Configuration} configuration of {path}...");

// TODO: enable cancellation of this call
var success = _packageManager.BuildApplication(path, Configuration);
// TODO: enable cancellation of this call
var success = _packageManager.BuildApplication(path, Configuration);

if (!success)
{
Logger?.LogError($"Build failed!");
}
else
{
Logger?.LogError($"Build success.");
}
if (!success)
{
Logger?.LogError($"Build failed!");
}
else
{
Logger?.LogError($"Build success.");
}
});
}
}
17 changes: 3 additions & 14 deletions Source/v2/Meadow.Cli/Commands/Current/App/AppDebugCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,11 @@ public AppDebugCommand(MeadowConnectionManager connectionManager, ILoggerFactory

protected override async ValueTask ExecuteCommand()
{
var connection = await GetCurrentConnection();
await base.ExecuteCommand();

if (connection == null)
if (Connection != null)
{
Logger?.LogError($"No connection path is defined");
return;
}

if (connection != null)
{
connection.DeviceMessageReceived += (s, e) =>
{
Logger?.LogInformation(e.message);
};

using (var server = await connection.StartDebuggingSession(Port, Logger, CancellationToken))
using (var server = await Connection.StartDebuggingSession(Port, Logger, CancellationToken))
{
if (Console != null)
{
Expand Down
25 changes: 12 additions & 13 deletions Source/v2/Meadow.Cli/Commands/Current/App/AppDeployCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,9 @@ public AppDeployCommand(IPackageManager packageManager, MeadowConnectionManager

protected override async ValueTask ExecuteCommand()
{
var connection = await GetCurrentConnection();
await base.ExecuteCommand();

if (connection == null)
{
return;
}

if (connection != null)
if (Connection != null)
{
string path = Path == null
? Environment.CurrentDirectory
Expand All @@ -39,15 +34,15 @@ protected override async ValueTask ExecuteCommand()
var lastFile = string.Empty;

// in order to deploy, the runtime must be disabled
var wasRuntimeEnabled = await connection.IsRuntimeEnabled();
var wasRuntimeEnabled = await Connection.IsRuntimeEnabled();
if (wasRuntimeEnabled)
{
Logger?.LogInformation("Disabling runtime...");

await connection.RuntimeDisable(CancellationToken);
await Connection.RuntimeDisable(CancellationToken);
}

connection.FileWriteProgress += (s, e) =>
Connection.FileWriteProgress += (s, e) =>
{
var p = (e.completed / (double)e.total) * 100d;

Expand Down Expand Up @@ -94,14 +89,18 @@ protected override async ValueTask ExecuteCommand()

var targetDirectory = file.DirectoryName;

await AppManager.DeployApplication(_packageManager, connection, targetDirectory, true, false, Logger, CancellationToken);
if (Logger != null && !string.IsNullOrEmpty(targetDirectory))
{
await AppManager.DeployApplication(_packageManager, Connection, targetDirectory, true, false, Logger, CancellationToken);
Console?.Output.WriteAsync("\n");
}

if (wasRuntimeEnabled)
{
// restore runtime state
Logger.LogInformation("Enabling runtime...");
Logger?.LogInformation("Enabling runtime...");

await connection.RuntimeEnable(CancellationToken);
await Connection.RuntimeEnable(CancellationToken);
}
}
}
Expand Down
34 changes: 18 additions & 16 deletions Source/v2/Meadow.Cli/Commands/Current/App/AppRunCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Meadow.CLI.Commands.DeviceManagement;
public class AppRunCommand : BaseDeviceCommand<AppRunCommand>
{
private IPackageManager _packageManager;
private string _lastFile;
private string _lastFile = string.Empty;

[CommandOption("no-prefix", 'n', IsRequired = false, Description = "When set, the message source prefix (e.g. 'stdout>') is suppressed during 'listen'")]
public bool NoPrefix { get; set; }
Expand All @@ -28,15 +28,9 @@ public AppRunCommand(IPackageManager packageManager, MeadowConnectionManager con

protected override async ValueTask ExecuteCommand()
{
var connection = await GetCurrentConnection();
await base.ExecuteCommand();

if (connection == null)
{
Logger?.LogError($"No connection path is defined");
return;
}

if (connection != null)
if (Connection != null)
{
string path = Path == null
? AppDomain.CurrentDomain.BaseDirectory
Expand All @@ -51,12 +45,12 @@ protected override async ValueTask ExecuteCommand()
var lastFile = string.Empty;

// in order to deploy, the runtime must be disabled
var wasRuntimeEnabled = await connection.IsRuntimeEnabled();
var wasRuntimeEnabled = await Connection.IsRuntimeEnabled();
if (wasRuntimeEnabled)
{
Logger?.LogInformation("Disabling runtime...");

await connection.RuntimeDisable(CancellationToken);
await Connection.RuntimeDisable(CancellationToken);
}

if (!await BuildApplication(path, CancellationToken))
Expand All @@ -72,16 +66,16 @@ protected override async ValueTask ExecuteCommand()
// illink returns before all files are actually written. That's not fun, but we must just wait a little while.
await Task.Delay(1000);

if (!await DeployApplication(connection, path, CancellationToken))
if (!await DeployApplication(Connection, path, CancellationToken))
{
return;
}

Logger?.LogInformation("Enabling the runtime...");
await connection.RuntimeEnable(CancellationToken);
await Connection.RuntimeEnable(CancellationToken);

Logger?.LogInformation("Listening for messages from Meadow...\n");
connection.DeviceMessageReceived += OnDeviceMessageReceived;
Connection.DeviceMessageReceived += OnDeviceMessageReceived;

while (!CancellationToken.IsCancellationRequested)
{
Expand Down Expand Up @@ -136,10 +130,18 @@ private async Task<bool> DeployApplication(IMeadowConnection connection, string
}

var file = candidates.OrderByDescending(c => c.LastWriteTime).First();
var directoryName = file.DirectoryName;

Logger?.LogInformation($"Deploying app from {file.DirectoryName}...");
Logger?.LogInformation($"Deploying app from {directoryName}...");

await AppManager.DeployApplication(_packageManager, connection, file.DirectoryName, true, false, Logger, CancellationToken);
if (!string.IsNullOrEmpty(directoryName) && Logger != null)
{
await AppManager.DeployApplication(_packageManager, connection, directoryName, true, false, Logger, CancellationToken);
}
else
{
Logger?.LogError($"Invalid DirectoryName");
}

connection.FileWriteProgress -= OnFileWriteProgress;

Expand Down
18 changes: 17 additions & 1 deletion Source/v2/Meadow.Cli/Commands/Current/BaseDeviceCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ namespace Meadow.CLI.Commands.DeviceManagement;
public abstract class BaseDeviceCommand<T> : BaseCommand<T>
{
protected MeadowConnectionManager ConnectionManager { get; }
public IMeadowConnection? Connection { get; private set; }

public BaseDeviceCommand(MeadowConnectionManager connectionManager, ILoggerFactory loggerFactory) : base(loggerFactory)
{
ConnectionManager = connectionManager;
}

protected override async ValueTask ExecuteCommand()
{
Connection = await GetCurrentConnection();
}

protected async Task<IMeadowConnection?> GetCurrentConnection()
{
var connection = ConnectionManager.GetCurrentConnection();
Expand All @@ -23,6 +29,16 @@ public BaseDeviceCommand(MeadowConnectionManager connectionManager, ILoggerFacto
Logger?.LogError(e.Message);
};

connection.ConnectionMessage += (s, message) =>
{
Logger?.LogInformation(message);
};

connection.DeviceMessageReceived += (s, e) =>
{
Logger?.LogInformation(e.message);
};

try
{
await connection.Attach(CancellationToken);
Expand Down Expand Up @@ -51,7 +67,7 @@ public BaseDeviceCommand(MeadowConnectionManager connectionManager, ILoggerFacto
}
else
{
Logger?.LogError("Current Connnection Unavailable");
Logger?.LogError("Current Connnection Unavailable"); // No connection path is defined ??
}

return null;
Expand Down
12 changes: 11 additions & 1 deletion Source/v2/Meadow.Cli/Commands/Current/BaseFileCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,20 @@ namespace Meadow.CLI.Commands.DeviceManagement;
public abstract class BaseFileCommand<T> : BaseSettingsCommand<T>
{
protected FileManager FileManager { get; }
protected IFirmwarePackageCollection? Collection { get; private set; }

public BaseFileCommand(FileManager fileManager, ISettingsManager settingsManager, ILoggerFactory loggerFactory)
: base(settingsManager, loggerFactory)
{
FileManager = fileManager;
}
}

protected override async ValueTask ExecuteCommand()
{
await FileManager.Refresh();

// for now we only support F7
// TODO: add switch and support for other platforms
Collection = FileManager.Firmware["Meadow F7"];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ namespace Meadow.CLI.Commands.DeviceManagement;
[Command("cloud login", Description = "Log into the Meadow Service")]
public class CloudLoginCommand : BaseCloudCommand<CloudLoginCommand>
{
public const string DefaultHost = "https://www.meadowcloud.co";

[CommandOption("host", Description = $"Optionally set a host (default is {DefaultHost})", IsRequired = false)]
public string? Host { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ public CloudLogoutCommand(

protected override async ValueTask ExecuteCommand()
{
Logger?.LogInformation($"Logging out of Meadow.Cloud...");
await Task.Run(() =>
{
Logger?.LogInformation($"Logging out of Meadow.Cloud...");

IdentityManager.Logout();
IdentityManager.Logout();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,27 @@ public CloudCollectionListCommand(

protected override async ValueTask ExecuteCommand()
{
if (Host == null) Host = DefaultHost;
if (Host == null)
Host = DefaultHost;
var org = await ValidateOrg(Host, OrgId, CancellationToken);

if (org == null) return;
if (org == null)
return;

var collections = await CollectionService.GetOrgCollections(org.Id, Host, CancellationToken);
if (!string.IsNullOrEmpty(org.Id)) {
var collections = await CollectionService.GetOrgCollections(org.Id, Host, CancellationToken);

if (collections == null || collections.Count == 0)
{
Logger?.LogInformation("No collections found.");
}
else
{
Logger?.LogInformation("Collections:");
foreach (var collection in collections)
if (collections == null || collections.Count == 0)
{
Logger?.LogInformation("No collections found.");
}
else
{
Logger?.LogInformation($" {collection.Id} | {collection.Name}");
Logger?.LogInformation("Collections:");
foreach (var collection in collections)
{
Logger?.LogInformation($" {collection.Id} | {collection.Name}");
}
}
}
}
Expand Down
Loading
Loading