Skip to content

Commit

Permalink
Merge pull request #15 from enmerk4r/dev-0-1-8
Browse files Browse the repository at this point in the history
Dev 0.1.8
  • Loading branch information
enmerk4r authored Mar 29, 2023
2 parents e50abe4 + bfce407 commit 43942e6
Show file tree
Hide file tree
Showing 38 changed files with 5,386 additions and 3,399 deletions.
7,940 changes: 4,565 additions & 3,375 deletions Assets/ComponentIcons/Icons.ai

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/ComponentIcons/Icons_construct_url_24x24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/ComponentIcons/Icons_read_csv_line_24x24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Logo/Logo_16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 105 additions & 0 deletions Swiftlet/Components/2_Request/CreateUrl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using Grasshopper.Kernel;
using Rhino.Geometry;
using Swiftlet.DataModels.Implementations;
using Swiftlet.Goo;
using Swiftlet.Params;
using Swiftlet.Util;

namespace Swiftlet.Components
{
public class CreateUrl : GH_Component
{
/// <summary>
/// Initializes a new instance of the DeconstructHttpResponse class.
/// </summary>
public CreateUrl()
: base("Create URL", "CURL",
"Construct a URL from its constituent parts",
NamingUtility.CATEGORY, NamingUtility.REQUEST)
{
}

public override GH_Exposure Exposure => GH_Exposure.primary;
/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddTextParameter("Scheme", "S", "URL scheme (http or https)", GH_ParamAccess.item);
pManager.AddTextParameter("Host", "H", "Host component of the URL", GH_ParamAccess.item);
pManager.AddIntegerParameter("Port", "P", "TCP port number", GH_ParamAccess.item);
pManager.AddTextParameter("Route", "R", "A route (path) to an online resource", GH_ParamAccess.item);

pManager[2].Optional = true;
pManager[3].Optional = true;
}

/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddTextParameter("URL", "U", "Constructed URL string", 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)
{
string scheme = string.Empty;
string host = string.Empty;
int port = -1;
string route = string.Empty;


DA.GetData(0, ref scheme);
DA.GetData(1, ref host);
DA.GetData(2, ref port);
DA.GetData(3, ref route);

UriBuilder builder = new UriBuilder();
builder.Scheme = scheme;
builder.Host = host;

if (port > 0) builder.Port = port;


if (!string.IsNullOrEmpty(route))
{
builder.Path = route;
}

DA.SetData(0, builder.ToString());
}


/// <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 Properties.Resources.Icons_construct_url_24x24;
}
}

/// <summary>
/// Gets the unique ID for this component. Do not change this ID after release.
/// </summary>
public override Guid ComponentGuid
{
get { return new Guid("104e0b1e-9954-475c-8046-a7259a8967f5"); }
}
}
}
31 changes: 20 additions & 11 deletions Swiftlet/Components/3_Send/BaseRequestComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,37 @@ protected bool ValidateUrl(string url, bool throwOnInvalid = true)
{
if (String.IsNullOrEmpty(url))
{
return InvalidUrlReturnValue("Invalid URL.", throwOnInvalid);
return InvalidUrlReturnValue(" Invalid URL.", throwOnInvalid);
}

if (!Uri.IsWellFormedUriString(url, UriKind.Absolute))


if (!url.StartsWith("http://") && !url.StartsWith("https://"))
{
return InvalidUrlReturnValue("URL is not well formed.", throwOnInvalid);
return InvalidUrlReturnValue(" URL must include a scheme (http:// or https://)", throwOnInvalid);
}

Uri uri = new Uri(url);

if (!Uri.IsWellFormedUriString(url, UriKind.Absolute))
{
return InvalidUrlReturnValue(" URL is not well formed.", throwOnInvalid);
}


if (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps)
{
return InvalidUrlReturnValue("Please make sure your URL starts with 'http' or 'https'.", throwOnInvalid);
return InvalidUrlReturnValue(" Please make sure your URL starts with 'http' or 'https'.", throwOnInvalid);
}

if (!String.IsNullOrEmpty(uri.Query))
{
return InvalidUrlReturnValue("Please do not include query parameters in your URL. Use the Params (P) input instead.", throwOnInvalid);
return InvalidUrlReturnValue(" Please do not include query parameters in your URL. Use the Params (P) input instead.", throwOnInvalid);
}

if (!String.IsNullOrEmpty(uri.Fragment))
{
return InvalidUrlReturnValue("Please do not include a fragment in your URL.", throwOnInvalid);
return InvalidUrlReturnValue(" Please do not include a fragment in your URL.", throwOnInvalid);
}

if (uri.HostNameType == UriHostNameType.Dns)
Expand All @@ -82,27 +91,27 @@ protected bool ValidateUrl(string url, bool throwOnInvalid = true)
}
catch (System.Net.Sockets.SocketException)
{
return InvalidUrlReturnValue("Please use a valid hostname or IP address.", throwOnInvalid);
return InvalidUrlReturnValue(" Please use a valid hostname or IP address.", throwOnInvalid);
}
if (IpBlacklistUtil.IsIpHostBlacklisted(hostEntry))
{
return InvalidUrlReturnValue("The given hostname or IP address is blacklisted.", throwOnInvalid);
return InvalidUrlReturnValue(" The given hostname or IP address is blacklisted.", throwOnInvalid);
}
}
else if (uri.HostNameType == UriHostNameType.IPv6 || uri.HostNameType == UriHostNameType.IPv4)
{
if ( !IPAddress.TryParse(uri.Host, out IPAddress ipAddress) )
{
return InvalidUrlReturnValue("Please use a valid hostname or IP address.", throwOnInvalid);
return InvalidUrlReturnValue(" Please use a valid hostname or IP address.", throwOnInvalid);
}
if (IpBlacklistUtil.IsIpAddressBlacklisted(ipAddress))
{
return InvalidUrlReturnValue("The given hostname or IP address is blacklisted.", throwOnInvalid);
return InvalidUrlReturnValue(" The given hostname or IP address is blacklisted.", throwOnInvalid);
}
}
else
{
return InvalidUrlReturnValue("The given hostname or IP address is invalid.", throwOnInvalid);
return InvalidUrlReturnValue(" The given hostname or IP address is invalid.", throwOnInvalid);
}

return true;
Expand Down
104 changes: 104 additions & 0 deletions Swiftlet/Components/3_Send/DeconstructUrl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using Grasshopper.Kernel;
using Rhino.Geometry;
using Swiftlet.DataModels.Implementations;
using Swiftlet.Goo;
using Swiftlet.Params;
using Swiftlet.Util;

namespace Swiftlet.Components
{
public class DeconstructUrl : GH_Component
{
/// <summary>
/// Initializes a new instance of the DeconstructHttpResponse class.
/// </summary>
public DeconstructUrl()
: base("Deconstruct URL", "DURL",
"Deconstruct a URL into its constituent parts",
NamingUtility.CATEGORY, NamingUtility.SEND)
{
}

public override GH_Exposure Exposure => GH_Exposure.tertiary;
/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddTextParameter("URL", "U", "A URL string to be deconstructed", GH_ParamAccess.item);
}

/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddTextParameter("Base", "B", "Base URL", GH_ParamAccess.item);
pManager.AddTextParameter("Scheme", "S", "URL scheme (http or https)", GH_ParamAccess.item);
pManager.AddTextParameter("Host", "H", "Host component of the URL", GH_ParamAccess.item);
pManager.AddTextParameter("Route", "R", "A route (path) to the online resource", GH_ParamAccess.item);
pManager.AddParameter(new QueryParamParam(), "Params", "P", "Http Query Parameters", GH_ParamAccess.list);


}

/// <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)
{
string url = string.Empty;
DA.GetData(0, ref url);

if (!url.StartsWith("http")) throw new Exception(" A valid URL must include a scheme (http or https)");

Uri myUri = new Uri(url);
NameValueCollection parameters = HttpUtility.ParseQueryString(myUri.Query);

List<QueryParamGoo> paramGoo = new List<QueryParamGoo>();

string baseUri = url.Split('?').First();

foreach (string key in parameters.AllKeys)
{
string value = parameters.Get(key);
paramGoo.Add(new QueryParamGoo(key, value));
}

DA.SetData(0, baseUri);
DA.SetData(1, myUri.Scheme);
DA.SetData(2, myUri.Host);
DA.SetData(3, myUri.AbsolutePath);
DA.SetDataList(4, paramGoo);

}


/// <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 Properties.Resources.Icons_deconstruct_url_24x24;
}
}

/// <summary>
/// Gets the unique ID for this component. Do not change this ID after release.
/// </summary>
public override Guid ComponentGuid
{
get { return new Guid("6240a6fa-f6fa-47af-a796-0a2fc3dd6cc1"); }
}
}
}
2 changes: 1 addition & 1 deletion Swiftlet/Components/6_Utilities/Base64ToText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public Base64ToText()
{
}

public override GH_Exposure Exposure => GH_Exposure.quarternary;
public override GH_Exposure Exposure => GH_Exposure.quinary;

/// <summary>
/// Registers all the input parameters for this component.
Expand Down
2 changes: 1 addition & 1 deletion Swiftlet/Components/6_Utilities/ByteArrayToFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ByteArrayToFile()
{
}

public override GH_Exposure Exposure => GH_Exposure.tertiary;
public override GH_Exposure Exposure => GH_Exposure.quarternary;

/// <summary>
/// Registers all the input parameters for this component.
Expand Down
76 changes: 76 additions & 0 deletions Swiftlet/Components/6_Utilities/ByteArrayToList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Grasshopper.Kernel;
using Rhino.Geometry;
using Swiftlet.Goo;
using Swiftlet.Params;
using Swiftlet.Util;

namespace Swiftlet.Components
{
public class ByteArrayToList : GH_Component
{
/// <summary>
/// Initializes a new instance of the TextToByteArray class.
/// </summary>
public ByteArrayToList()
: base("Byte Array To List", "BAL",
"Converts a byte array into a list of integers",
NamingUtility.CATEGORY, NamingUtility.UTILITIES)
{
}

public override GH_Exposure Exposure => GH_Exposure.quarternary;

/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddParameter(new ByteArrayParam(), "Byte Array", "A", "Byte Array to convert", GH_ParamAccess.item);
}

/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddIntegerParameter("Bytes", "B", "Byte Array as a list of integers", GH_ParamAccess.list);
}

/// <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)
{
ByteArrayGoo goo = null;
DA.GetData(0, ref goo);

DA.SetDataList(0, goo.Value.Select(b => ((int)b)).ToList());
}

/// <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 Properties.Resources.Icons_byte_array_to_list_24x24;
}
}

/// <summary>
/// Gets the unique ID for this component. Do not change this ID after release.
/// </summary>
public override Guid ComponentGuid
{
get { return new Guid("60e16712-a6aa-4e02-860a-d587b512320c"); }
}
}
}
2 changes: 1 addition & 1 deletion Swiftlet/Components/6_Utilities/ByteArrayToText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public ByteArrayToText()
{
}

public override GH_Exposure Exposure => GH_Exposure.tertiary;
public override GH_Exposure Exposure => GH_Exposure.quarternary;

/// <summary>
/// Registers all the input parameters for this component.
Expand Down
Loading

0 comments on commit 43942e6

Please sign in to comment.