Skip to content

Commit

Permalink
created variable registration system so that they are no longer restr…
Browse files Browse the repository at this point in the history
…icted to the 4 types
  • Loading branch information
EarliestFall988 committed Dec 8, 2023
1 parent 7b7b7f4 commit 8257e88
Show file tree
Hide file tree
Showing 38 changed files with 676 additions and 252 deletions.
2 changes: 1 addition & 1 deletion DiscoverFunctionsHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Avalon;
using ValkyrieFSMCore;

using System.Text.Json;

Expand Down
37 changes: 33 additions & 4 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using Avalon;
using ValkyrieFSMCore;

using Microsoft.AspNetCore.Mvc;

using System.Diagnostics;
using System.Text.Json;

using Valkyrie_Server;
using ValkyrieFSMCore.WM;

var builder = WebApplication.CreateBuilder(args);

Expand All @@ -16,8 +17,10 @@

string linkURI = env["VALK_DASHBOARD_LINK"];

string version = env["VERSION"];

var splash = "<!DOCTYPE html>\r\n<html>\r\n<head>\r\n <meta charset=\"utf-8\" />\r\n <title>It Works!!</title>\r\n <link rel=\"preconnect\" href=\"https://fonts.googleapis.com\">\r\n <link rel=\"preconnect\" href=\"https://fonts.gstatic.com\" crossorigin>\r\n <link href=\"https://fonts.googleapis.com/css2?family=Roboto&display=swap\" rel=\"stylesheet\">\r\n</head>\r\n<script>\r\n\r\n getURI = () => {\r\n document.getElementById(\"link-to-paste\").innerHTML = window.location.href + \"api/v1/sync\";\r\n }\r\n\r\n</script>\r\n<style>\r\n .body {\r\n background-color: #171717;\r\n width: 90vw;\r\n height: 90vh;\r\n color: #ffffff;\r\n padding: 3rem;\r\n font-family: 'Roboto', sans-serif;\r\n display: block;\r\n box-sizing: border-box;\r\n }\r\n\r\n h1 {\r\n font-size: 3rem;\r\n }\r\n\r\n h1, h2 {\r\n user-select: none;\r\n }\r\n\r\n h2 {\r\n font-size: 1.5rem;\r\n font-weight: 200;\r\n }\r\n\r\n p {\r\n font-size: 1.25rem;\r\n }\r\n\r\n a {\r\n font-size: 1.25rem;\r\n color: #ffff;\r\n text-decoration: none;\r\n background-color: #1d4ed8;\r\n padding: 0.25rem;\r\n border-radius: 0.25rem;\r\n }\r\n\r\n .sync-link {\r\n color: lightblue;\r\n text-decoration: underline;\r\n text-underline-offset: 0.25rem;\r\n font-size: 1.5rem;\r\n }\r\n\r\n .no-select {\r\n user-select: none;\r\n }\r\n</style>\r\n<body onload=\"getURI()\" class=\"body\">\r\n " +
$"<h1>It Works!🎉🎉</h1>\r\n <h2>Copy the link below and paste it back in the Valkyrie Connection Page</h2>\r\n <p> <span class=\"no-select\">👉 </span><span id=\"link-to-paste\" class=\"sync-link\"></span></p>\r\n <p class=\"no-select\"><a href=\"{linkURI ?? "https://google.com"}\"> Go To Dashboard </a></p>\r\n</body>\r\n</html>\r\n";
$"<h1>It Works!🎉🎉</h1>\r\n <h2>Copy the link below and paste it back in the Valkyrie Connection Page</h2>\r\n <p> <span class=\"no-select\">👉 </span><span id=\"link-to-paste\" class=\"sync-link\"></span></p>\r\n <p class=\"no-select\"><a href=\"{linkURI ?? "https://google.com"}\"> Go To Dashboard </a></p> <p class=\"no-select\">v{version}</p>\r\n</body>\r\n</html>\r\n";
// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
Expand All @@ -28,6 +31,32 @@
var apiKey = env["API_KEY"];
var valkApiKey = "some key";

var projectTest = new GetProjects();
projectTest.Parameters.Add("out", VariableDefinition<List<Project>>.CreateCustom("out", "projects", new()));
var result = projectTest.Function();

Debug.WriteLine("projects ");
foreach (var x in projectTest.Get<List<Project>>("out"))
{
Debug.WriteLine(x.Name);
}

Debug.WriteLine("\n\n\n\n");

var project = projectTest.Get<List<Project>>("out")[0];

var split = new SplitProject();
split.Parameters.Add("project", new VariableDefinition<Project>("project", project, "project"));
split.Parameters.Add("name", VariableDefinition<string>.CreateString("name", ""));
split.Parameters.Add("id", VariableDefinition<string>.CreateString("id", ""));


var splitResult = split.Function();

Debug.WriteLine("split result: " + splitResult);

Debug.WriteLine("name: " + split.Get<string>("name"));


long minuteCountWaitTime = 5;
StateMachinesController? stateMachinesController = new StateMachinesController(minuteCountWaitTime);
Expand Down Expand Up @@ -82,7 +111,7 @@
}

Debug.WriteLine("test 1");

ValkyrieServerController valkyrieServerController = new ValkyrieServerController()
{
ValkyrieAPIKey = valkApiKey
Expand All @@ -91,8 +120,8 @@

Debug.WriteLine("test 2");

var res = await valkyrieServerController.UpdateInstructionFunctionDefinitions(instructionId);

var res = await valkyrieServerController.UpdateInstructionFunctionDefinitions(instructionId);
if (res.statusCode.ToLower() == "ok")
{
ctx.Response.StatusCode = 200;
Expand Down
33 changes: 33 additions & 0 deletions State Machine/Custom Types/Project.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@


using System.Text.Json.Serialization;

namespace ValkyrieFSMCore
{
/// <summary>
/// The variable type
/// </summary>
public class Project
{
[JsonPropertyName("id")]
public string Id { get; set; } = "";

/// <summary>
/// The name of the project
/// </summary>
[JsonPropertyName ("name")]
public string Name { get; set; } = "";

/// <summary>
/// the description of the project
/// </summary>
[JsonPropertyName("startDate")]
public string StartDate { get; set; } = "";

/// <summary>
/// the id of the sector that the project is associated with
/// </summary>
[JsonPropertyName("endDate")]
public string EndDate { get; set; } = "";
}
}
8 changes: 8 additions & 0 deletions State Machine/Custom Types/Sector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace ValkyrieFSMCore
{
public class Sector
{
public string Id { get; set; } = "";
public string Name { get; set; } = "";
}
}
20 changes: 20 additions & 0 deletions State Machine/CustomVariableLibrary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


namespace ValkyrieFSMCore
{
/// <summary>
/// The custom variable library
/// </summary>
public class CustomVariableLibrary
{
/// <summary>
/// The dictionary of custom variables created
/// </summary>
public Dictionary<string, IVariableSignature> CustomVariables { get; set; } = new Dictionary<string, IVariableSignature>();

public CustomVariableLibrary()
{
// Add your custom variables here
}
}
}
2 changes: 1 addition & 1 deletion State Machine/Function Definitions/ContinueFunction.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics;

namespace Avalon
namespace ValkyrieFSMCore
{
public sealed class ContinueFunction : FunctionDefinition
{
Expand Down
2 changes: 1 addition & 1 deletion State Machine/Function Definitions/ExitQuestionFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Threading.Tasks;


namespace Avalon
namespace ValkyrieFSMCore
{
public sealed class ExitQuestionFunction : FunctionDefinition
{
Expand Down
4 changes: 2 additions & 2 deletions State Machine/Function Definitions/GreetFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Threading.Tasks;


namespace Avalon
namespace ValkyrieFSMCore
{
public sealed class GreetUserFunction : FunctionDefinition
{
Expand All @@ -23,7 +23,7 @@ protected override void DefineFunction()

ExpectedParameters = new Dictionary<string, Parameter>()
{
{ "name", new Parameter(StateMachineVariableType.Text) }
{ "name", new Parameter(StateMachineVariableType.Text.ToString()) }
};

Func<int> GreetUser = () =>
Expand Down
6 changes: 3 additions & 3 deletions State Machine/Function Definitions/GuessFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Threading.Tasks;


namespace Avalon
namespace ValkyrieFSMCore
{
public sealed class GuessFunction : FunctionDefinition
{
Expand All @@ -27,8 +27,8 @@ protected override void DefineFunction()

ExpectedParameters = new Dictionary<string, Parameter>()
{
{ "name", new Parameter(StateMachineVariableType.Text) },
{ "guess", new Parameter(StateMachineVariableType.Integer) }
{ "name", new Parameter(StateMachineVariableType.Text.ToString()) },
{ "guess", new Parameter(StateMachineVariableType.Integer.ToString()) }
};

Name = "Guess";
Expand Down
8 changes: 4 additions & 4 deletions State Machine/Function Definitions/Math/AddNumber.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics;

namespace Avalon
namespace ValkyrieFSMCore
{
public class AddNumber : FunctionDefinition
{
Expand All @@ -15,9 +15,9 @@ void Setup()
{
ExpectedParameters = new Dictionary<string, Parameter>()
{
{ "a", new Parameter(StateMachineVariableType.Decimal) },
{ "b", new Parameter(StateMachineVariableType.Decimal) },
{ "out", new Parameter(StateMachineVariableType.Decimal, VariableIO.Out) }
{ "a", new Parameter(StateMachineVariableType.Decimal.ToString()) },
{ "b", new Parameter(StateMachineVariableType.Decimal.ToString()) },
{ "out", new Parameter(StateMachineVariableType.Decimal.ToString(), VariableIO.Out) }
};
}

Expand Down
8 changes: 4 additions & 4 deletions State Machine/Function Definitions/Math/DivideNumber.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics;

namespace Avalon
namespace ValkyrieFSMCore
{
/// <summary>
/// Divide Number Function Definition
Expand All @@ -19,9 +19,9 @@ void Setup()
{
ExpectedParameters = new Dictionary<string, Parameter>()
{
{ "a", new Parameter(StateMachineVariableType.Decimal) },
{ "b", new Parameter(StateMachineVariableType.Decimal) },
{ "out", new Parameter(StateMachineVariableType.Decimal, VariableIO.Out) }
{ "a", new Parameter(StateMachineVariableType.Decimal.ToString()) },
{ "b", new Parameter(StateMachineVariableType.Decimal.ToString()) },
{ "out", new Parameter(StateMachineVariableType.Decimal.ToString(), VariableIO.Out) }
};
}

Expand Down
8 changes: 4 additions & 4 deletions State Machine/Function Definitions/Math/MultiplyNumber.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics;

namespace Avalon
namespace ValkyrieFSMCore
{
/// <summary>
/// Multiply Number Function Definition
Expand All @@ -18,9 +18,9 @@ void Setup()
{
ExpectedParameters = new Dictionary<string, Parameter>()
{
{ "a", new Parameter(StateMachineVariableType.Decimal) },
{ "b", new Parameter(StateMachineVariableType.Decimal) },
{ "out", new Parameter(StateMachineVariableType.Decimal, VariableIO.Out) }
{ "a", new Parameter(StateMachineVariableType.Decimal.ToString()) },
{ "b", new Parameter(StateMachineVariableType.Decimal.ToString()) },
{ "out", new Parameter(StateMachineVariableType.Decimal.ToString(), VariableIO.Out) }
};
}

Expand Down
8 changes: 4 additions & 4 deletions State Machine/Function Definitions/Math/Pow.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics;

namespace Avalon
namespace ValkyrieFSMCore
{
/// <summary>
/// Power Number Function Definition
Expand All @@ -18,9 +18,9 @@ void Setup()
{
ExpectedParameters = new Dictionary<string, Parameter>()
{
{ "a", new Parameter(StateMachineVariableType.Decimal) },
{ "b", new Parameter(StateMachineVariableType.Decimal) },
{ "out", new Parameter(StateMachineVariableType.Decimal, VariableIO.Out) }
{ "a", new Parameter(StateMachineVariableType.Decimal.ToString()) },
{ "b", new Parameter(StateMachineVariableType.Decimal.ToString()) },
{ "out", new Parameter(StateMachineVariableType.Decimal.ToString(), VariableIO.Out) }
};
}

Expand Down
8 changes: 4 additions & 4 deletions State Machine/Function Definitions/Math/SubtractNumber.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics;

namespace Avalon
namespace ValkyrieFSMCore
{
/// <summary>
/// Subtact Number Function Definition
Expand All @@ -18,9 +18,9 @@ void Setup()
{
ExpectedParameters = new Dictionary<string, Parameter>()
{
{ "a", new Parameter(StateMachineVariableType.Decimal) },
{ "b", new Parameter(StateMachineVariableType.Decimal) },
{ "out", new Parameter(StateMachineVariableType.Decimal, VariableIO.Out) }
{ "a", new Parameter(StateMachineVariableType.Decimal.ToString()) },
{ "b", new Parameter(StateMachineVariableType.Decimal.ToString()) },
{ "out", new Parameter(StateMachineVariableType.Decimal.ToString(), VariableIO.Out) }
};
}

Expand Down
8 changes: 4 additions & 4 deletions State Machine/Function Definitions/SetRandomNumberFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Threading.Tasks;


namespace Avalon
namespace ValkyrieFSMCore
{
/// <summary>
/// Set a random number
Expand All @@ -25,9 +25,9 @@ void Setup()

ExpectedParameters = new Dictionary<string, Parameter>()
{
{ "valueToChange", new Parameter(StateMachineVariableType.Integer) },
{ "min", new Parameter(StateMachineVariableType.Integer) },
{ "max", new Parameter(StateMachineVariableType.Integer) }
{ "valueToChange", new Parameter(StateMachineVariableType.Integer.ToString()) },
{ "min", new Parameter(StateMachineVariableType.Integer.ToString()) },
{ "max", new Parameter(StateMachineVariableType.Integer.ToString()) }
};
}

Expand Down
49 changes: 49 additions & 0 deletions State Machine/Function Definitions/WM/EachProject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
namespace ValkyrieFSMCore
{
public class EachProject : FunctionDefinition
{

int iterator = 0;

public EachProject()
{
Setup();
DefineFunction();
}

void Setup()
{
Name = "EachProject";
ExpectedParameters = new Dictionary<string, Parameter>()
{
{ "projects", new Parameter("projects") },
{ "project", new Parameter("project", VariableIO.Out) }
};
}

protected override void DefineFunction()
{
Function = () =>
{
var proj = Get<List<Project>>("project");

if (proj is List<Project> projects)
{
if (iterator < projects.Count)
{
Set("project", projects[iterator]);
iterator++;
return 0;
}
else
{
iterator = 0;
return 1;
}
}

return -1;
};
}
}
}
Loading

0 comments on commit 8257e88

Please sign in to comment.