inizio scrittura script per manipolazione file rule
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
namespace SMGen.Data
|
||||
{
|
||||
public class RuleClass
|
||||
{
|
||||
public string state { get; set; } = "";
|
||||
public string expression { get; set; } = "";
|
||||
public string next_state { get; set; } = "";
|
||||
public string event_to_send { get; set; } = "";
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
namespace SMGen.Data
|
||||
{
|
||||
public class WeatherForecast
|
||||
{
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
public int TemperatureC { get; set; }
|
||||
|
||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||
|
||||
public string? Summary { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
namespace SMGen.Data
|
||||
{
|
||||
public class WeatherForecastService
|
||||
{
|
||||
private static readonly string[] Summaries = new[]
|
||||
{
|
||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||
};
|
||||
|
||||
public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate)
|
||||
{
|
||||
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
||||
{
|
||||
Date = startDate.AddDays(index),
|
||||
TemperatureC = Random.Shared.Next(-20, 55),
|
||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
||||
}).ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace SMGen
|
||||
{
|
||||
public class Enum
|
||||
{
|
||||
public enum LEVELS
|
||||
{
|
||||
LIVELLO_INGRESSI = 1,
|
||||
LIVELLO_TRANSIZIONI = 2
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,3 +13,14 @@
|
||||
<p>
|
||||
Vista in preview si può poi inserire in prod se confermato
|
||||
</p>
|
||||
|
||||
<input type="input" @bind="@sz_file2Read" />
|
||||
|
||||
<button @onclick="()=>Read_rule_file_transitions()"></button>
|
||||
|
||||
<span class="fs-1">@sz_file2Read</span>
|
||||
|
||||
@*@foreach (var item in bits)
|
||||
{
|
||||
<span>@item</span>
|
||||
}*@
|
||||
|
||||
@@ -13,10 +13,182 @@ using Microsoft.AspNetCore.Components.Web.Virtualization;
|
||||
using Microsoft.JSInterop;
|
||||
using SMGen;
|
||||
using SMGen.Shared;
|
||||
using System.Data;
|
||||
using SMGen.Data;
|
||||
|
||||
namespace SMGen.Pages
|
||||
{
|
||||
public partial class SMIn2Event
|
||||
{
|
||||
protected string sz_file2Write { get; set; } = "prova.csv";
|
||||
protected string sz_file2Read { get; set; } = "D:\\Repo\\Mapo-IOB\\StateMachine\\_DEFAULT\\60_STD_MACHINE.rul";
|
||||
protected string sz_state_machine_name { get; set; } = "";
|
||||
protected string n_state_machine_index { get; set; } = "";
|
||||
protected int n_states { get; set; } = 0;
|
||||
protected int n_bits { get; set; } = 0;
|
||||
protected bool b_rules_definition { get; set; } = false;
|
||||
|
||||
protected List<string> fileLines { get; set; } = new List<string>();
|
||||
protected List<string> Bits { get; set; } = new List<string>();
|
||||
protected List<string> States { get; set; } = new List<string>();
|
||||
protected List<string> Events_to_send { get; set; } = new List<string>();
|
||||
protected List<RuleClass> Rules { get; set; } = new List<RuleClass>();
|
||||
|
||||
//// va dopo
|
||||
//private StreamWriter objWriter { get; set; };
|
||||
|
||||
protected async Task Read_rule_file_transitions()
|
||||
{
|
||||
using (StreamReader sr = new StreamReader(sz_file2Read))
|
||||
{
|
||||
States.Clear();
|
||||
Bits.Clear();
|
||||
Events_to_send.Clear();
|
||||
Rules.Clear();
|
||||
string line = "";
|
||||
while ((line = await sr.ReadLineAsync().ConfigureAwait(false)) != null)
|
||||
{
|
||||
if (!line.StartsWith("#") && !string.IsNullOrEmpty(line))
|
||||
{
|
||||
var sz_tokens = line.Split(":");
|
||||
|
||||
var sz_temp = sz_tokens[0].Trim();
|
||||
switch (sz_temp)
|
||||
{
|
||||
case "$DEFINITIONS":
|
||||
b_rules_definition = false;
|
||||
break;
|
||||
case "$NAME":
|
||||
sz_state_machine_name = sz_tokens[1].Trim();
|
||||
break;
|
||||
|
||||
case "$IDX":
|
||||
n_state_machine_index = sz_tokens[1].Trim();
|
||||
break;
|
||||
|
||||
case "$N_STATES":
|
||||
n_states = int.Parse(sz_tokens[1].Trim());
|
||||
break;
|
||||
|
||||
case "$N_BITS":
|
||||
n_bits = int.Parse(sz_tokens[1].Trim());
|
||||
break;
|
||||
|
||||
case "$BIT":
|
||||
Bits.Add(sz_tokens[2].Trim().ToUpper());
|
||||
break;
|
||||
|
||||
case "$STATE":
|
||||
States.Add(sz_tokens[2].Trim().ToUpper());
|
||||
break;
|
||||
|
||||
case "$EVENT":
|
||||
Events_to_send.Add(sz_tokens[2].Trim().ToUpper());
|
||||
break;
|
||||
|
||||
case "$RULES":
|
||||
b_rules_definition = true;
|
||||
break;
|
||||
|
||||
case "$DO":
|
||||
b_rules_definition = false;
|
||||
evaluate_transitions();
|
||||
break;
|
||||
|
||||
default:
|
||||
if (b_rules_definition)
|
||||
{
|
||||
var temp_rule = new RuleClass()
|
||||
{
|
||||
state = sz_temp,
|
||||
expression = sz_tokens[1].Trim().ToUpper(),
|
||||
next_state = sz_tokens[2].Trim().ToUpper(),
|
||||
event_to_send = sz_tokens[3].Trim().ToUpper()
|
||||
};
|
||||
|
||||
Rules.Add(temp_rule);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
//fileLines.Add(lineSplit[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void evaluate_transitions()
|
||||
{
|
||||
using (StreamWriter sw = new StreamWriter(sz_file2Write))
|
||||
{
|
||||
string sz_actual_state = "";
|
||||
string sz_actual_bit = "";
|
||||
string sz_line = "";
|
||||
//int i = 0;
|
||||
int n_input = 0;
|
||||
//int n = 0;
|
||||
int n_mask = 0;
|
||||
int n_bit = 0;
|
||||
|
||||
bool[] b_bit = new bool[20];
|
||||
bool b_invert = false;
|
||||
//ciclo negli stati
|
||||
for (var i = 0; i < n_states - 1; i++)
|
||||
{
|
||||
sz_actual_state = States.ToArray()[i];
|
||||
|
||||
//ciclo negli ingressi
|
||||
for (n_input = 0; n_input < (Math.Pow(2, n_bits) - 1); n_input++)
|
||||
{
|
||||
n_mask = 1;
|
||||
for (var n = 0; n < n_bits - 1; n++)
|
||||
{
|
||||
b_bit[n] = Convert.ToBoolean(n_input & n_mask);
|
||||
n_mask = n_mask << 1;
|
||||
}
|
||||
|
||||
foreach (var act_rule in Rules)
|
||||
{
|
||||
n_bit = -1;
|
||||
if ((act_rule.state == "ALL_STATES") || (act_rule.state == sz_actual_state))
|
||||
{
|
||||
sz_actual_bit = act_rule.expression;
|
||||
|
||||
//controllo se la riga contiene l'istruzione per negare il bit
|
||||
if (sz_actual_bit.Trim().StartsWith("NOT"))
|
||||
{
|
||||
//inverto il bit
|
||||
b_invert = true;
|
||||
sz_actual_bit = sz_actual_bit.Replace("NOT ", "").Trim();
|
||||
}
|
||||
//cerca il nome del bit e ne trova l' indice da 0
|
||||
n_bit = Bits.FindIndex(x => x == sz_actual_bit);
|
||||
|
||||
//TODO: gestire errore in caso non trovi indice (quindi -1)
|
||||
|
||||
if (((!b_invert) && b_bit[n_bit]) || (b_invert && (!b_bit[n_bit])))
|
||||
{
|
||||
sz_line = "";
|
||||
|
||||
//eseguo solo se diverso dallo stato corrente
|
||||
if (States.IndexOf(act_rule.next_state) != i)
|
||||
{
|
||||
|
||||
sz_line = $"{n_state_machine_index};{i};{n_input};{Events_to_send.IndexOf(act_rule.event_to_send)};{States.IndexOf(act_rule.next_state)}";
|
||||
|
||||
sw.WriteLine(sz_line);
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// sz_line = $"----{n_state_machine_index};{i};{n_input};{Events_to_send.IndexOf(act_rule.event_to_send)};{States.IndexOf(act_rule.next_state)}";
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ var builder = WebApplication.CreateBuilder(args);
|
||||
// Add services to the container.
|
||||
builder.Services.AddRazorPages();
|
||||
builder.Services.AddServerSideBlazor();
|
||||
builder.Services.AddSingleton<WeatherForecastService>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
|
||||
+9081
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user