diff --git a/DiscoverFunctionsHandler.cs b/DiscoverFunctionsHandler.cs
deleted file mode 100644
index df9252e..0000000
--- a/DiscoverFunctionsHandler.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using ValkyrieFSMCore;
-
-using System.Text.Json;
-
-
-namespace Valkyrie_Server
-{
- public class DiscoverFunctionsHandler
- {
-
- ///
- /// Get the functions from the libary as a JSON string
- ///
- /// returns the json string of the functions
- public static string GetFunctionDefinitionsJSON() => JsonSerializer.Serialize(
- new FunctionLibrary().ImportedFunctions
- .Select(x =>
- new FunctionListItem(x.Key, x.Value.Description, x.Value.ExpectedParametersList))
- .ToArray());
- }
-}
diff --git a/GetSyncDataHandler.cs b/GetSyncDataHandler.cs
new file mode 100644
index 0000000..a0a406a
--- /dev/null
+++ b/GetSyncDataHandler.cs
@@ -0,0 +1,64 @@
+using ValkyrieFSMCore;
+
+using System.Text.Json;
+using System.Collections;
+using System.Diagnostics;
+
+namespace Valkyrie_Server
+{
+ public class GetSyncDataHandler
+ {
+
+ ///
+ /// Get the functions from the libary as a JSON string
+ ///
+ /// returns the json string of the functions
+ public static IEnumerable GetFunctionDefinitions() =>
+ new FunctionLibrary().ImportedFunctions.Values.Select(x => new FunctionListItem()
+ {
+ Name = x.Name,
+ Description = x.Description,
+ Parameters = x.ExpectedParametersList
+ });
+
+ public static IEnumerable GetVariableTypes() => new VariableFactory().GetAllPossibleVarableTypes.Select(x => new VariableTypeDef()
+ {
+ Description = x.description,
+ Name = x.key
+ });
+
+ public static string GetSyncData()
+ {
+ var functions = GetFunctionDefinitions();
+ var variableTypes = GetVariableTypes();
+
+ foreach (var x in functions)
+ {
+ foreach (var y in x.Parameters)
+ {
+ Debug.WriteLine(y.Name + " " + y.Type + " " + y.IO + " " + y.Description);
+ }
+ }
+
+ var syncData = new SyncRequestBody(functions.ToArray(), variableTypes.ToArray());
+
+ return JsonSerializer.Serialize(syncData);
+ }
+ }
+
+ public class VariableTypeDef
+ {
+ public string Name { get; set; } = "";
+ public string Description { get; set; } = "";
+ }
+
+ public class FunctionListItem
+ {
+ public string Name { get; set; } = "";
+ public string Description { get; set; } = "";
+
+ public ExpectedParameter[] Parameters { get; set; } = new ExpectedParameter[0];
+ }
+
+ internal record SyncRequestBody(FunctionListItem[] Functions, VariableTypeDef[] CustomTypes);
+}
diff --git a/Program.cs b/Program.cs
index 796c608..e7abcfd 100644
--- a/Program.cs
+++ b/Program.cs
@@ -16,7 +16,6 @@
.Build();
string linkURI = env["VALK_DASHBOARD_LINK"];
-
string version = env["VERSION"];
var splash = "\r\n\r\n\r\n \r\n It Works!!\r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n " +
@@ -31,33 +30,6 @@
var apiKey = env["API_KEY"];
var valkApiKey = "some key";
-var projectTest = new GetProjects();
-projectTest.Parameters.Add("out", VariableDefinition>.CreateCustom("out", "projects", new()));
-var result = projectTest.Function();
-
-Debug.WriteLine("projects ");
-foreach (var x in projectTest.Get>("out"))
-{
- Debug.WriteLine(x.Name);
-}
-
-Debug.WriteLine("\n\n\n\n");
-
-var project = projectTest.Get>("out")[0];
-
-var split = new SplitProject();
-split.Parameters.Add("project", new VariableDefinition("project", project, "project"));
-split.Parameters.Add("name", VariableDefinition.CreateString("name", ""));
-split.Parameters.Add("id", VariableDefinition.CreateString("id", ""));
-
-
-var splitResult = split.Function();
-
-Debug.WriteLine("split result: " + splitResult);
-
-Debug.WriteLine("name: " + split.Get("name"));
-
-
long minuteCountWaitTime = 5;
StateMachinesController? stateMachinesController = new StateMachinesController(minuteCountWaitTime);
@@ -230,36 +202,36 @@
});
-app.MapGet("/api/v1/functions", (HttpContext context) =>
-{
-
- string key = context.Request.Headers["apikey"];
-
- if (key == null)
- {
- context.Response.StatusCode = 401;
- return "No API key provided";
- }
-
- if (apiKey != key)
- {
- context.Response.StatusCode = 401;
- return "incorrect api key";
- }
-
+//app.MapGet("/api/v1/functions", (HttpContext context) =>
+//{
- try
- {
- context.Response.Headers.Add("Content-Type", "application/json");
- context.Response.StatusCode = 200;
- return DiscoverFunctionsHandler.GetFunctionDefinitionsJSON();
- }
- catch (Exception e)
- {
- context.Response.StatusCode = 500;
- return e.Message;
- }
-});
+// string key = context.Request.Headers["apikey"];
+
+// if (key == null)
+// {
+// context.Response.StatusCode = 401;
+// return "No API key provided";
+// }
+
+// if (apiKey != key)
+// {
+// context.Response.StatusCode = 401;
+// return "incorrect api key";
+// }
+
+
+// try
+// {
+// context.Response.Headers.Add("Content-Type", "application/json");
+// context.Response.StatusCode = 200;
+// return GetSyncDataHandler.GetFunctionDefinitions();
+// }
+// catch (Exception e)
+// {
+// context.Response.StatusCode = 500;
+// return e.Message;
+// }
+//});
app.Run();
@@ -270,7 +242,7 @@
/// The name of the function
/// The description of the function
/// the parameters of the function
-internal record FunctionListItem(string Name, string Description, ExpectedParameter[] Parameters);
+
internal record message(string content);
internal record errResult(string error, string reasonPhrase);
diff --git a/State Machine/Function Definitions/WM/GetProjects.cs b/State Machine/Function Definitions/WM/GetProjects.cs
index d34f972..d10cf1f 100644
--- a/State Machine/Function Definitions/WM/GetProjects.cs
+++ b/State Machine/Function Definitions/WM/GetProjects.cs
@@ -7,6 +7,9 @@
namespace ValkyrieFSMCore.WM
{
+ ///
+ /// Get the list of projects function
+ ///
public class GetProjects : FunctionDefinition
{
private static readonly string BASE_URL = "https://valkyrie-git-get-functions-from-server-earliestfall988.vercel.app/";
@@ -25,7 +28,7 @@ void Setup()
Name = "GetProjects";
ExpectedParameters = new Dictionary()
{
- { "out", new Parameter("Projects", VariableIO.Out) }
+ { "result", new Parameter("projects", VariableIO.Out) }
};
}
@@ -71,8 +74,6 @@ protected override void DefineFunction()
Debug.WriteLine(json);
-
-
var projects = JsonSerializer.Deserialize(json);
if (projects == null)
diff --git a/State Machine/FunctionDefinition.cs b/State Machine/FunctionDefinition.cs
index 705d038..35a4473 100644
--- a/State Machine/FunctionDefinition.cs
+++ b/State Machine/FunctionDefinition.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Drawing;
using System.Linq;
using System.Threading.Tasks;
@@ -50,7 +51,7 @@ public ExpectedParameter[] ExpectedParametersList
foreach (var x in ExpectedParameters)
{
- parameters.Add(new ExpectedParameter(x.Key, x.Value.IO.ToString(), x.Value.Type.ToString()));
+ parameters.Add(new ExpectedParameter(x.Key, x.Value.Type.ToString(), x.Value.IO.ToString(), x.Value.Description));
}
return parameters.ToArray();
diff --git a/State Machine/FunctionLibrary.cs b/State Machine/FunctionLibrary.cs
index b1d5d5d..f414874 100644
--- a/State Machine/FunctionLibrary.cs
+++ b/State Machine/FunctionLibrary.cs
@@ -73,7 +73,7 @@ public void BuildFunctionLibrary()
ImportedFunctions.Add(eachProject.Name, eachProject);
ImportedFunctions.Add(getProjects.Name, getProjects);
- ImportedFunctions.Add(splitProject.Name, getProjects);
+ ImportedFunctions.Add(splitProject.Name, splitProject);
#endregion
}
diff --git a/State Machine/VariableTypes/VariableFactory.cs b/State Machine/VariableTypes/VariableFactory.cs
index 70adcac..3c408c6 100644
--- a/State Machine/VariableTypes/VariableFactory.cs
+++ b/State Machine/VariableTypes/VariableFactory.cs
@@ -8,7 +8,14 @@ public class VariableFactory
///
/// The variable constructors
///
- private Dictionary> VariableConstructors { get; set; } = new();
+ private Dictionary function)> VariableConstructors { get; set; } = new();
+
+ ///
+ /// Get the possible variable types
+ ///
+ public IEnumerable<(string key, string description)> GetAllPossibleVarableTypes =>
+ VariableConstructors.Select(x => (x.Key, x.Value.description));
+
///
/// Default constructor
@@ -20,11 +27,12 @@ public class VariableFactory
///
void Register()
{
- VariableConstructors.Add("projects", (key, io) =>
+ VariableConstructors.Add("projects", ("this variable maps to a list of projects", (key, io) =>
{
var x = VariableDefinition>.CreateCustom(key, "projects", new List(), io);
return x;
- });
+ }
+ ));
}
///
@@ -44,7 +52,7 @@ public bool TryConstructVariable(string key, string type, out T? result, Vari
return false;
}
- var func = VariableConstructors[type];
+ var func = VariableConstructors[type].function;
result = func(key, io) as T;
return true;
diff --git a/ValkyrieServerController.cs b/ValkyrieServerController.cs
index 9772ce8..d3b4542 100644
--- a/ValkyrieServerController.cs
+++ b/ValkyrieServerController.cs
@@ -96,7 +96,7 @@ public ValkyrieServerController()
}
- var functionJSON = DiscoverFunctionsHandler.GetFunctionDefinitionsJSON();
+ var functionJSON = GetSyncDataHandler.GetSyncData();
Debug.WriteLine(functionJSON);
using HttpClient client = new();
@@ -105,7 +105,7 @@ public ValkyrieServerController()
client.DefaultRequestHeaders.Add("x-api-key", ValkyrieAPIKey);
client.DefaultRequestHeaders.Add("x-instruction-id", instructionId);
- var response = await client.PostAsync(prodSyncFunctionsURITestBranch, content);
+ var response = await client.PostAsync(testSyncFunctionsURI, content);
using StreamReader reader = new StreamReader(response.Content.ReadAsStream());
@@ -113,7 +113,7 @@ public ValkyrieServerController()
if (!response.IsSuccessStatusCode)
{
- return ("Error: " + response.StatusCode + "\n" + responseString, false, response.StatusCode.ToString());
+ return ("Server Response Error: " + response.StatusCode + "\n" + responseString, false, response.StatusCode.ToString());
}
if (string.IsNullOrEmpty(responseString))
@@ -125,6 +125,9 @@ public ValkyrieServerController()
}
}
+
+
+
///
/// Typical content requested by the valkyrie server
///
@@ -136,4 +139,7 @@ public struct Content
[JsonPropertyName("Id")]
public string InstructionId { get; set; }
}
+
+
+
}