Skip to content

Commit

Permalink
Handling few invalid inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielAbalde committed Apr 16, 2021
1 parent c7e726a commit a8ef6be
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
6 changes: 6 additions & 0 deletions GHUI/BuildHtmlUiComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ protected override void SolveInstance(IGH_DataAccess da)
List<string> jsScripts = new List<string>();

if (!da.GetData(0, ref path)) return;
if(!System.IO.File.Exists(path))
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"File path: \"{path}\" not found on this computer");
da.SetData(0, false);
return;
}
if (!da.GetData(1, ref htmlString)) return;
da.GetData(2, ref title);
da.GetDataList(3, stylesheets);
Expand Down
2 changes: 2 additions & 0 deletions GHUI/Classes/WebView2Wrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ private void OnDocumentUpdated(object sender, DOM.DocumentUpdatedEventArgs args)
/// </summary>
public void SubscribeToHtmlChanged()
{
if (!System.IO.Directory.Exists(Directory))
throw new System.IO.DirectoryNotFoundException($"Can not find: \"{Directory}\" on this computer");
_watcher = new FileSystemWatcher(Directory)
{
NotifyFilter = NotifyFilters.LastAccess
Expand Down
5 changes: 5 additions & 0 deletions GHUI/HtmlUiComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ protected override void SolveInstance(IGH_DataAccess da)

// get input
if (!da.GetData(0, ref path)) return;
if (!System.IO.File.Exists(path))
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"File path: \"{path}\" not found on this computer");
return;
}
if (!da.GetData<bool>(1, ref show)) return;
da.GetData(2, ref title);
da.GetData(3, ref _height);
Expand Down
6 changes: 6 additions & 0 deletions GHUI/SettersDefineComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ protected override void SolveInstance(IGH_DataAccess da)
if (!da.GetDataList(0, ids)) return;
if (!da.GetDataList(1, vals)) return;

if(ids.Count != vals.Count)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Amount of IDs and Values must be equal");
return;
}

//List<DomSetValueModelGoo> setValueModels =
// ids.Select((t, i) => new DomSetValueModelGoo() {id = t, value = vals[i]}).ToList();

Expand Down
2 changes: 1 addition & 1 deletion GHUI/Web UI/createdInput.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div style=''><input type='range' id='mySlider' name='mySlider' value='50' min='0' max='100'></div><div style='width:100%; height:200px; background:lightgray;'><input type='range' id='mySlider2' name='mySlider2' value='50' min='0' max='100'></div>
<!DOCTYPE html><html lang=en><meta charset=utf-8><title>UI</title><!DOCTYPE html><html lang=en><meta charset=utf-8><title>UI</title><!DOCTYPE html><html lang=en xmlns=http://www.w3.org/1999/xhtml><div id=app><h1>HELLO THERE</h1></div>

1 comment on commit a8ef6be

@DanielAbalde
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few validators.

I changed createdInput.html I don't know how, the original is back in the next commit.

Please sign in to comment.