Skip to content
Open

Arze #33

Show file tree
Hide file tree
Changes from all commits
Commits
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
143 changes: 143 additions & 0 deletions Components/API/GH_HTTPGetRequestAsync.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
using System;
using System.Collections.Generic;

using Grasshopper.Kernel;
using Rhino.Geometry;
using System.IO;
using System.Net;
using System.Threading.Tasks;
using Formicae.Helpers.API;
using Formicae.Templates;

namespace Formicae.Components.API
{
public class MyComponent1 : GH_Component_HTTPAsync
{
/// <summary>
/// Initializes a new instance of the MyComponent1 class.
/// </summary>
public MyComponent1()
: base("HTTP GET (Async)", "GET Async",
"A generic HTTP GET request (asynchronous)",
Config.FormicaeTab, Config.Tabs.API)
{
}

/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_InputParamManager pManager)
{// active
pManager.AddBooleanParameter("Send", "S", "Perform the request?", GH_ParamAccess.item, false);
// url (endpoint)
pManager.AddTextParameter("Url", "U", "Url for the request", GH_ParamAccess.item);

// custom headers (future)
// custom headers would be nice here: how to handle key-value pairs in GH? takes in a tree?

// auth
int authId = pManager.AddTextParameter("Authorization", "A", "If this request requires authorization, input your formatted token as an Auth string, e.g. \"Bearer h1g23g1fdg3d1\"", GH_ParamAccess.item);
// timeout
pManager.AddIntegerParameter("Timeout", "T", "Timeout for the request in ms. If the request takes longer that this, it will fail.", GH_ParamAccess.item, 10000);

pManager[authId].Optional = true;
}

/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
pManager.AddTextParameter("Response", "R", "Request response", GH_ParamAccess.item);
}

/// <summary>
/// This is the method that actually does the work.
/// </summary>
/// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
protected override void SolveInstance(IGH_DataAccess DA)
{
if (_shouldExpire)
{
switch (_currentState)
{
case RequestState.Off:
Message = "Inactive";
_currentState = RequestState.Idle;
break;

case RequestState.Error:
Message = "ERROR";
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, _response);
_currentState = RequestState.Idle;
break;

case RequestState.Done:
Message = "Complete!";
_currentState = RequestState.Idle;
break;
}
// Output...
DA.SetData(0, _response);
_shouldExpire = false;
return;
}

bool active = false;
string url = "";
string authToken = "";
int timeout = 0;

DA.GetData("Send", ref active);
if (!active)
{
_currentState = RequestState.Off;
_shouldExpire = true;
_response = "";
ExpireSolution(true);
return;
}

if (!DA.GetData("Url", ref url)) return;
DA.GetData("Authorization", ref authToken);
if (!DA.GetData("Timeout", ref timeout)) return;

// Validity checks
if (url == null || url.Length == 0)
{
_response = "Empty URL";
_currentState = RequestState.Error;
_shouldExpire = true;
ExpireSolution(true);
return;
}

_currentState = RequestState.Requesting;
Message = "Requesting...";

GETAsync(url, authToken, timeout);
}


/// <summary>
/// Provides an Icon for the component.
/// </summary>
protected override System.Drawing.Bitmap Icon
{
get
{
//You can add image files to your project resources and access them like this:
// return Resources.IconForThisComponent;
return null;
}
}

/// <summary>
/// Gets the unique ID for this component. Do not change this ID after release.
/// </summary>
public override Guid ComponentGuid
{
get { return new Guid("5FAB55FB-06C1-4F8D-AC13-4A95BC79727F"); }
}
}
}
15 changes: 8 additions & 7 deletions api/auth.cs → Components/API/GH_auth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,30 @@
using Newtonsoft.Json.Linq;
using Grasshopper.Kernel;
using System.Threading.Tasks;
namespace Formicae.api
using Formicae.Helpers.API;
namespace Formicae.Components.API
{
public class auth : GH_Component
public class GH_auth : GH_Component
{
/// <summary>
/// Initializes a new instance of the MyComponent1 class.
/// </summary>
public auth()
public GH_auth()
: base("auth", "auth",
"auth",
"Formicae", "api")
Config.FormicaeTab, Config.Tabs.API)
{
}

/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
protected override void RegisterInputParams(GH_InputParamManager pManager)
{
pManager.AddBooleanParameter("Trigger", "T", "Set to true to start the authentication process.", GH_ParamAccess.item);
}

protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
pManager.AddTextParameter("AccessToken", "Token", "The OAuth access token.", GH_ParamAccess.item);
}
Expand Down Expand Up @@ -58,7 +59,7 @@ protected override void SolveInstance(IGH_DataAccess DA)
{
Rhino.RhinoApp.InvokeOnUiThread((Action)(() =>
{
this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error during authentication: " + ex.Message);
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error during authentication: " + ex.Message);
}));
}
});
Expand Down
45 changes: 45 additions & 0 deletions Components/DataVisualization/showWindRose.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;

using Grasshopper.Kernel;
using Rhino.Geometry;

using System.Drawing;
using Newtonsoft.Json;
namespace Formicae.Components.DataVisualization
{
public class showWindRose : GH_Component
{
public override Guid ComponentGuid => new Guid("A45FC4A2-0E1C-415C-86D7-D29D21AD74E1");
protected override Bitmap Icon => null;
public showWindRose()
: base("showWindRose", "showWindRose",
"showWindRose",
Config.FormicaeTab, Config.Tabs.Show)
{
}

/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
}

/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
}

/// <summary>
/// This is the method that actually does the work.
/// </summary>
/// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
protected override void SolveInstance(IGH_DataAccess DA)
{
}

}
}
86 changes: 0 additions & 86 deletions Components/GH_CreateHeightMaps.cs

This file was deleted.

Loading