first commit -push

This commit is contained in:
dungtt
2025-10-15 15:15:53 +07:00
parent 674ae395be
commit a9577c5756
885 changed files with 74595 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
namespace RobotNet.Script.Shares;
public record CreateModel(string Path, string Name);

View File

@@ -0,0 +1,23 @@
using System.ComponentModel.DataAnnotations;
namespace RobotNet.Script.Shares.Dashboard;
public class DailyMissionDto
{
[Range(0, int.MaxValue)]
public int Completed { get; set; }
[Range(0, int.MaxValue)]
public int Error { get; set; }
[Range(0, int.MaxValue)]
public int Total { get; set; }
[Range(0, int.MaxValue)]
public int CompletedRate { get; set; }
[Range(0, double.MaxValue)]
public double TaktTimeMin { get; set; }
[Range(0, double.MaxValue)]
public double TaktTimeAverage { get; set; }
[Range(0, double.MaxValue)]
public double TaktTimeMax { get; set; }
[Range(0, int.MaxValue)]
public int RobotOnline { get; set; }
}

View File

@@ -0,0 +1,14 @@
using System.ComponentModel.DataAnnotations;
namespace RobotNet.Script.Shares.Dashboard;
public class DailyPerformanceDto
{
public string Label { get; set; } = string.Empty;
[Range(0, int.MaxValue)]
public int Completed { get; set; }
[Range(0, int.MaxValue)]
public int Error { get; set; }
[Range(0, int.MaxValue)]
public int Other { get; set; }
}

View File

@@ -0,0 +1,11 @@
namespace RobotNet.Script.Shares.Dashboard;
public class DashboardDto
{
public string TimeUpdate { get; set; } = DateTime.Now.ToString("dd/MM/yyy HH:mm:ss");
public DailyMissionDto DailyMission { get; set; } = new ();
public DailyPerformanceDto TodayPerformance { get; set; } = new();
public DailyPerformanceDto ThisWeekPerformance { get; set; } = new();
public TaktTimeMissionDto[] TaktTimeMissions { get; set; } = [];
public DailyPerformanceDto[] TotalMissionPerformance { get; set; } = [];
}

View File

@@ -0,0 +1,14 @@
using System.ComponentModel.DataAnnotations;
namespace RobotNet.Script.Shares.Dashboard;
public class TaktTimeMissionDto
{
public string Label { get; set; } = string.Empty;
[Range(0, double.MaxValue)]
public double Min { get; set; }
[Range(0, double.MaxValue)]
public double Max { get; set; }
[Range(0, double.MaxValue)]
public double Average { get; set; }
}

View File

@@ -0,0 +1,16 @@
namespace RobotNet.Script.Shares;
public interface IRobotNetGlobals
{
Guid CurrentMissionId { get; }
RobotNet.Script.ILogger Logger { get; }
RobotNet.Script.IRobotManager RobotManager { get; }
RobotNet.Script.IMapManager MapManager { get; }
RobotNet.Script.IUnixDevice UnixDevice { get; }
RobotNet.Script.IConnectionManager ConnectionManager { get; }
Task<Guid> CreateMission(string name);
Task<Guid> CreateMission(string name, params object[] parameters);
bool CancelMission(Guid missionId, string reason);
bool EnableTask(string name);
bool DisableTask(string name);
}

View File

@@ -0,0 +1,3 @@
namespace RobotNet.Script.Shares;
public record InstanceMissionCreateModel(string Name, IDictionary<string, string> Parameters);

View File

@@ -0,0 +1,11 @@
namespace RobotNet.Script.Shares;
public class InstanceMissionDto
{
public Guid Id { get; set; }
public string MissionName { get; set; } = "";
public string Parameters { get; set; } = "{}";
public DateTime CreatedAt { get; set; }
public MissionStatus Status { get; set; }
public string? Log { get; set; }
}

View File

@@ -0,0 +1,14 @@
namespace RobotNet.Script.Shares;
public enum MissionStatus
{
Idle = 0,
Running,
Canceling,
Pausing,
Paused,
Resuming,
Canceled,
Completed,
Error,
}

View File

@@ -0,0 +1,29 @@
namespace RobotNet.Script.Shares;
public enum ProcessorRequest
{
/// <summary>
///
/// </summary>
None,
/// <summary>
///
/// </summary>
Build,
/// <summary>
///
/// </summary>
Run,
/// <summary>
///
/// </summary>
Stop,
/// <summary>
///
/// </summary>
Reset,
}

View File

@@ -0,0 +1,44 @@
namespace RobotNet.Script.Shares;
public enum ProcessorState
{
/// <summary>
/// The processor is idle and not currently processing any scripts.
/// </summary>
Idle,
/// <summary>
///
/// </summary>
Building,
/// <summary>
///
/// </summary>
Ready,
/// <summary>
///
/// </summary>
Starting,
/// <summary>
/// The processor is currently running a script.
/// </summary>
Running,
/// <summary>
///
/// </summary>
Stopping,
/// <summary>
/// The processor encountered an error while running a script.
/// </summary>
Error,
/// <summary>
///
/// </summary>
BuildError,
}

View File

@@ -0,0 +1,3 @@
namespace RobotNet.Script.Shares;
public record RenameModel(string Path, string NewName);

View File

@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\RobotNet.Script\RobotNet.Script.csproj" />
<ProjectReference Include="..\RobotNet.Shares\RobotNet.Shares.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,93 @@
using System.Reflection;
namespace RobotNet.Script.Shares;
public static class ScriptExtensions
{
private static readonly string PreCode;
static ScriptExtensions()
{
var preCode = "";
var glovalType = typeof(IRobotNetGlobals);
var properties = glovalType.GetProperties();
foreach (var property in properties)
{
preCode = string.Join(Environment.NewLine, preCode, ToDeclarationString(property));
}
var fields = glovalType.GetFields();
foreach (var field in fields)
{
preCode = string.Join(Environment.NewLine, preCode, ToDeclarationString(field));
}
var methods = glovalType.GetMethods();
foreach (var method in methods)
{
if (method.Name.StartsWith("get_") || method.Name.StartsWith("set_")) continue;
preCode = string.Join(Environment.NewLine, preCode, ToMethodString(method));
}
PreCode = preCode;
}
private static string ToDeclarationString(PropertyInfo property)
{
if (property.CanRead)
{
return $"{property.PropertyType.FullName} {property.Name} {{ get; {(property.CanWrite ? "set; " : "")}}}";
}
else if (property.CanWrite)
{
return $"{property.PropertyType.FullName} {property.Name} {{ set => throw new System.NotImplementedException(); }}";
}
else
{
return "";
}
}
private static string ToDeclarationString(FieldInfo field)
{
return $"{field.FieldType.FullName} {field.Name};";
}
private static string ToMethodString(MethodInfo method)
{
return $"{ToTypeString(method.ReturnType)} {method.Name}({string.Join(',', method.GetParameters().Select(ToParameterString))}) => throw new System.NotImplementedException();";
}
private static string ToParameterString(ParameterInfo parameter)
{
var defaultValue = "";
if (parameter.HasDefaultValue)
{
if (parameter.DefaultValue != null)
{
if (parameter.ParameterType.IsEnum)
{
defaultValue = $" = {parameter.ParameterType.FullName}.{parameter.DefaultValue}";
}
else
{
defaultValue = $" = {parameter.DefaultValue}";
}
}
else
{
defaultValue = " = null";
}
}
return $"{parameter.ParameterType.FullName} {parameter.Name}{defaultValue}";
}
private static string ToTypeString(Type type)
{
return type == typeof(void) ? "void" : type.FullName ?? type.Name;
}
}

View File

@@ -0,0 +1,3 @@
namespace RobotNet.Script.Shares;
public record ScriptFile(string Name, string Code);

View File

@@ -0,0 +1,3 @@
namespace RobotNet.Script.Shares;
public record ScriptFolder(string Name, IEnumerable<ScriptFolder> Folders, IEnumerable<ScriptFile> Files);

View File

@@ -0,0 +1,4 @@
namespace RobotNet.Script.Shares;
public record ScriptMissionParameterDto(string Name, string Type, string? Default);
public record ScriptMissionDto (string Name, IEnumerable<ScriptMissionParameterDto> Parameters, string Code);

View File

@@ -0,0 +1,3 @@
namespace RobotNet.Script.Shares;
public record ScriptTaskDto(string Name, int Interval, string Code);

View File

@@ -0,0 +1,3 @@
namespace RobotNet.Script.Shares;
public record ScriptVariableDto(string Name, string TypeName, string Value);

View File

@@ -0,0 +1,3 @@
namespace RobotNet.Script.Shares;
public record UpdateModel(string Path, string Code);

View File

@@ -0,0 +1,3 @@
namespace RobotNet.Script.Shares;
public record UpdateVariableModel(string Name, string Value);