Skip to content

Commit

Permalink
Give better feedback to user about what's happening during OPC UA ser…
Browse files Browse the repository at this point in the history
…ver connect.
  • Loading branch information
barnstee committed Sep 19, 2024
1 parent 1d11632 commit 5c01c5e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
13 changes: 9 additions & 4 deletions Controllers/BrowserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ public ActionResult Index()
[HttpPost]
public ActionResult UserPassword(string endpointUrl)
{
if (string.IsNullOrEmpty(endpointUrl) || !endpointUrl.StartsWith("opc.tcp://"))
{
_session.StatusMessage = "Please provide a valid OPC UA endpoint URL in the format opc.tcp://ipaddress:port";
return View("Index", _session);
}

_session.EndpointUrl = endpointUrl;

HttpContext.Session.SetString("EndpointUrl", endpointUrl);
Expand All @@ -74,8 +80,7 @@ public ActionResult ConnectAsync(string username, string password)
_session.EndpointUrl = HttpContext.Session.GetString("EndpointUrl");
_session.UserName = username;
_session.Password = password;
_session.StatusMessage = "Connected to: " + _session.EndpointUrl;


return View("Browse", _session);
}

Expand Down Expand Up @@ -172,7 +177,7 @@ public async Task<ActionResult> GenerateCSV()
return View("Browse", _session);
}
}

[HttpPost]
public async Task<ActionResult> PushCert()
{
Expand All @@ -181,7 +186,7 @@ public async Task<ActionResult> PushCert()
try
{
await _client.GDSServerPush(_session.EndpointUrl, _session.UserName, _session.Password).ConfigureAwait(false);

_session.StatusMessage = "New certificate and trust list pushed successfully to server!";
}
catch (Exception ex)
Expand Down
24 changes: 20 additions & 4 deletions Pages/UABrowser.razor
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,28 @@
private string NodeValue { get; set; } = string.Empty;
private bool NodeNotPublishable { get; set; } = true;

protected override void OnInitialized()
protected async override void OnInitialized()
{
UANodes.Add(new UANode() {
StatusMessage = "Connecting to " + EndpointUrl + "...";
await InvokeAsync(StateHasChanged).ConfigureAwait(false);

UANode root = new()
{
Text = "Root",
NodeId = ObjectIds.ObjectsFolder.ToString()
});
};

root.Children = await GetChildrenAsync(root).ConfigureAwait(false);
if (root.Children == null)
{
StatusMessage = "Could not connect to server " + EndpointUrl + "!";
}
else
{
UANodes.Add(root);
StatusMessage = "Connected to " + EndpointUrl + ".";
await InvokeAsync(StateHasChanged).ConfigureAwait(false);
}
}

private async Task OnNodeExpand(UANode expendedNode)
Expand Down Expand Up @@ -143,7 +159,7 @@
{
StatusMessage = ex.Message;

return new List<UANode>();
return null;
}
}

Expand Down

0 comments on commit 5c01c5e

Please sign in to comment.