update x step gestione conf serializzata json
This commit is contained in:
@@ -8,6 +8,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MP.FileData.DatabaseModels;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MP.FileData.Controllers
|
||||
{
|
||||
@@ -112,6 +113,9 @@ namespace MP.FileData.Controllers
|
||||
Dictionary<string, string> confReplace = new Dictionary<string, string>();
|
||||
confReplace.Add("(", " ");
|
||||
confReplace.Add(")", " ");
|
||||
|
||||
Dictionary<string, string> fileExtReplace = new Dictionary<string, string>();
|
||||
fileExtReplace.Add(".P-2", "");
|
||||
// hard coded + salvataggio conf x creare json
|
||||
SearchRules currRule = new SearchRules()
|
||||
{
|
||||
@@ -119,13 +123,19 @@ namespace MP.FileData.Controllers
|
||||
Mode = SearchMode.StringOnFile,
|
||||
MaxChar2Search = 100,
|
||||
ReplaceCR = true,
|
||||
RegExPattern = "\\b{{fileName}}" + @".{0,2}\([\w\d\s.]+\)",
|
||||
RegExPattern = "\\b{{fileName}}" + @".{0,2}\([\w\d\s./]+\)",
|
||||
RegExRepFileName = true,
|
||||
ExcludedTags = ".xls .xlsx",
|
||||
FileNameExtReplace = fileExtReplace,
|
||||
ExcludedTags = new List<string>() { "M4", "M5", "M4+A", "M4+B", "M5+A", "M5+B" },
|
||||
OutReplace = confReplace,
|
||||
OutExcludeFileName = true
|
||||
};
|
||||
|
||||
// serializzo
|
||||
|
||||
string rawRule = JsonConvert.SerializeObject(currRule, Formatting.Indented);
|
||||
Log.Info($"Conf rule:{Environment.NewLine}{rawRule}");
|
||||
|
||||
// salvo i NUOVI file
|
||||
if (fileNew != null && fileNew.Count > 0)
|
||||
{
|
||||
@@ -284,7 +294,6 @@ namespace MP.FileData.Controllers
|
||||
}).ToList();
|
||||
|
||||
// gestione Tags (da migliorare...)
|
||||
List<string> excludeTags = new List<string>() { "M4", "M5", "M4+A", "M4+B", "M5+A", "M5+B" };
|
||||
List<TagModel> currTags = TagGetAll();
|
||||
|
||||
// calcolo MD5 e tags
|
||||
@@ -295,18 +304,17 @@ namespace MP.FileData.Controllers
|
||||
|
||||
List<string> Tags = new List<string>();
|
||||
List<TagModel> Tag4File = new List<TagModel>();
|
||||
// cerco codice tag come nome file(TAG) nei primi 100 char
|
||||
int maxChar = 100;
|
||||
string code2search = "";
|
||||
if (item.FileStringContent.Length > maxChar)
|
||||
// se necessario bonifico filename...
|
||||
string fileName = item.Name;
|
||||
if (currRule.FileNameExtReplace.Count > 0)
|
||||
{
|
||||
code2search = item.FileStringContent.Substring(0, maxChar);
|
||||
foreach (var fReplace in currRule.FileNameExtReplace)
|
||||
{
|
||||
fileName = fileName.Replace(fReplace.Key, fReplace.Value).Trim();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
code2search = item.FileStringContent;
|
||||
}
|
||||
Tags = TagsUtils.searchProgComment(item.Name, code2search, currRule);
|
||||
// cerco codice tag da configurazione
|
||||
Tags = TagsUtils.searchProgComment(fileName, item.FileStringContent, currRule);
|
||||
|
||||
foreach (var tag in Tags)
|
||||
{
|
||||
@@ -366,6 +374,10 @@ namespace MP.FileData.Controllers
|
||||
Dictionary<string, string> confReplace = new Dictionary<string, string>();
|
||||
confReplace.Add("(", " ");
|
||||
confReplace.Add(")", " ");
|
||||
|
||||
Dictionary<string, string> fileExtReplace = new Dictionary<string, string>();
|
||||
fileExtReplace.Add(".P-2", "");
|
||||
|
||||
// hard coded + salvataggio conf x creare json
|
||||
SearchRules currRule = new SearchRules()
|
||||
{
|
||||
@@ -375,7 +387,8 @@ namespace MP.FileData.Controllers
|
||||
ReplaceCR = true,
|
||||
RegExPattern = "\\b{{fileName}}" + @".{0,2}\([\w\d\s.]+\)",
|
||||
RegExRepFileName = true,
|
||||
ExcludedTags = ".xls .xlsx",
|
||||
ExcludedTags = new List<string>() { "M4", "M5", "M4+A", "M4+B", "M5+A", "M5+B" },
|
||||
FileNameExtReplace = fileExtReplace,
|
||||
OutReplace = confReplace,
|
||||
OutExcludeFileName = true
|
||||
};
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace MP.FileData
|
||||
{
|
||||
// inizializzazione dei valori di default x MACCHINA
|
||||
modelBuilder.Entity<MacchinaModel>().HasData(
|
||||
new MacchinaModel { IdxMacchina = "0", CodMacchina = "0", Descrizione = "--- Tutte ---", Nome = "--- Tutte ---", BasePath = "", ImgUrl = "", Note = "", ShowOrder = 0 }
|
||||
new MacchinaModel { IdxMacchina = "0", RuleName = "0", Descrizione = "--- Tutte ---", Nome = "--- Tutte ---", BasePath = "", ImgUrl = "", Note = "", ShowOrder = 0 }
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,12 @@ namespace MP.FileData
|
||||
/// <summary>
|
||||
/// Pattern esclusione Tags (stop-words)
|
||||
/// </summary>
|
||||
public string ExcludedTags { get; set; } = "";
|
||||
public List<string> ExcludedTags { get; set; } = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// Pattern in formato RegExp
|
||||
/// </summary>
|
||||
public Dictionary<string, string> FileNameExtReplace { get; set; } = new Dictionary<string, string>();
|
||||
|
||||
/// <summary>
|
||||
/// Quantità massima di caratteri da analizzare, 0 = tutti
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace MP.FileData
|
||||
// verifico se trimmare contenuto file
|
||||
if (fileContent.Length > currRule.MaxChar2Search && currRule.MaxChar2Search > 0)
|
||||
{
|
||||
fileContent.Substring(0, currRule.MaxChar2Search);
|
||||
fileContent = fileContent.Substring(0, currRule.MaxChar2Search);
|
||||
}
|
||||
// bonifico: a capo --> spazi
|
||||
fileContent = fileContent.Replace(Environment.NewLine, " ");
|
||||
@@ -65,7 +65,7 @@ namespace MP.FileData
|
||||
// bonifica preliminare (se richiesta)
|
||||
if (currRule.OutExcludeFileName)
|
||||
{
|
||||
currMatch.Replace(fileName, "");
|
||||
currMatch = currMatch.Replace(fileName, "");
|
||||
}
|
||||
if (currRule.OutReplace.Count > 0)
|
||||
{
|
||||
@@ -74,13 +74,6 @@ namespace MP.FileData
|
||||
currMatch = currMatch.Replace(item.Key, item.Value);
|
||||
}
|
||||
}
|
||||
#if false
|
||||
// pulizia: elimino nome programma e parentesi
|
||||
string currMatch = matchTags[count].Value
|
||||
.Replace(fileName, "")
|
||||
.Replace("(", " ")
|
||||
.Replace(")", " ").Trim();
|
||||
#endif
|
||||
// trim finale
|
||||
currMatch = currMatch.Trim();
|
||||
|
||||
@@ -88,23 +81,22 @@ namespace MP.FileData
|
||||
var splitTags = currMatch.Split(" ");
|
||||
foreach (var item in splitTags)
|
||||
{
|
||||
if (!currRule.ExcludedTags.Contains(item) && !string.IsNullOrEmpty(item))
|
||||
if (!string.IsNullOrEmpty(item))
|
||||
{
|
||||
// esclusione valori ignorati
|
||||
answ.Add(item);
|
||||
if (!currRule.ExcludedTags.Contains(item) && item != fileName)
|
||||
{
|
||||
// esclusione valori ignorati
|
||||
answ.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Warn($"searchProgComment Attenzione Match non trovato | {fileName} | pattern: {currRule.RegExPattern}");
|
||||
}
|
||||
}
|
||||
// se nullo --> segnalo!
|
||||
if (answ.Count == 0)
|
||||
{
|
||||
Log.Warn($"searchProgComment Attenzione Tag non trovati | {fileName} | pattern: {currRule.RegExPattern}{Environment.NewLine}{fileContent}");
|
||||
Log.Warn($"searchProgComment Attenzione Tag non trovati | {fileName} | pattern: {pattern}{Environment.NewLine}{fileContent}");
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
@@ -1 +1,24 @@
|
||||
|
||||
{
|
||||
"ExcludedTags": [
|
||||
"M4",
|
||||
"M5",
|
||||
"M4+A",
|
||||
"M4+B",
|
||||
"M5+A",
|
||||
"M5+B"
|
||||
],
|
||||
"FileNameExtReplace": {
|
||||
".P-2": ""
|
||||
},
|
||||
"MaxChar2Search": 100,
|
||||
"Mode": 0,
|
||||
"Name": "Commento Filename",
|
||||
"OutExcludeFileName": true,
|
||||
"OutReplace": {
|
||||
"(": " ",
|
||||
")": " "
|
||||
},
|
||||
"RegExPattern": "\\b{{fileName}}.{0,2}\\([\\w\\d\\s./]+\\)",
|
||||
"RegExRepFileName": true,
|
||||
"ReplaceCR": true
|
||||
}
|
||||
@@ -21,6 +21,7 @@
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="5.0.1" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="NLog.Web.AspNetCore" Version="4.13.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
{
|
||||
foreach (var item in MacList)
|
||||
{
|
||||
<option value="@item.IdxMacchina">@item.Descrizione (@item.CodMacchina)</option>
|
||||
<option value="@item.IdxMacchina">@item.Descrizione (@item.RuleName)</option>
|
||||
}
|
||||
}
|
||||
</select>
|
||||
@@ -132,7 +132,7 @@
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<div>@record.Macchina.CodMacchina</div>
|
||||
<div>@record.Macchina.RuleName</div>
|
||||
<div class="small">@record.Macchina.Descrizione</div>
|
||||
</td>
|
||||
<td>
|
||||
|
||||
Reference in New Issue
Block a user