Ancora update in import Tags
This commit is contained in:
@@ -244,7 +244,9 @@ namespace MP.FileData.Controllers
|
||||
FileContent = File.ReadAllBytes(o.FullName)
|
||||
}).ToList();
|
||||
|
||||
// gestione Tags (da migliorare...)
|
||||
List<string> excludeTags = new List<string>() { "M4", "M5", "M4+A", "M4+B", "M5+A", "M5+B" };
|
||||
var currTags = TagGetAll();
|
||||
|
||||
// calcolo MD5 e tags
|
||||
foreach (var item in newRec)
|
||||
@@ -253,11 +255,13 @@ namespace MP.FileData.Controllers
|
||||
item.MD5 = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
|
||||
|
||||
List<string> Tags = new List<string>();
|
||||
// cerco codice tag come nome file(TAG) nei primi 500 char
|
||||
List<TagModel> Tag2ins = new List<TagModel>();
|
||||
// cerco codice tag come nome file(TAG) nei primi 100 char
|
||||
int maxChar = 100;
|
||||
string code2search = "";
|
||||
if (item.FileStringContent.Length > 200)
|
||||
if (item.FileStringContent.Length > maxChar)
|
||||
{
|
||||
code2search = item.FileStringContent.Substring(0, 200);
|
||||
code2search = item.FileStringContent.Substring(0, maxChar);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -265,8 +269,21 @@ namespace MP.FileData.Controllers
|
||||
}
|
||||
Tags = TagsUtils.searchProgComment(item.Name, code2search, excludeTags);
|
||||
|
||||
//// aggiungo i tags SE non ci fossero
|
||||
//item.Tags = Tags;
|
||||
foreach (var tag in Tags)
|
||||
{
|
||||
var foundTag = currTags.Where(x => x.TagId == tag).ToList();
|
||||
// aggiungo i tags SE non ci fossero
|
||||
if (foundTag.Count == 0)
|
||||
{
|
||||
Tag2ins.Add(new TagModel() { TagId = tag });
|
||||
}
|
||||
}
|
||||
|
||||
// salvo i tags
|
||||
TagInsert(Tag2ins);
|
||||
|
||||
// salvo i tags relativi ai files
|
||||
item.Tags = Tag2ins;
|
||||
}
|
||||
|
||||
// aggiungo in blocco
|
||||
@@ -468,6 +485,25 @@ namespace MP.FileData.Controllers
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco TAGS (tutti)
|
||||
/// </summary>
|
||||
/// <param name="searchVal"></param>
|
||||
/// <param name="maxNum"></param>
|
||||
/// <returns></returns>
|
||||
public List<DatabaseModels.TagModel> TagGetAll()
|
||||
{
|
||||
List<DatabaseModels.TagModel> dbResult = new List<DatabaseModels.TagModel>();
|
||||
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
||||
{
|
||||
dbResult = localDbCtx
|
||||
.DbSetTags
|
||||
.OrderBy(x => x.TagId)
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco TAGS (FILTRATO!!!)
|
||||
/// </summary>
|
||||
@@ -506,6 +542,47 @@ namespace MP.FileData.Controllers
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ricerca singolo record
|
||||
/// </summary>
|
||||
/// <param name="TagId"></param>
|
||||
/// <returns></returns>
|
||||
public TagModel TagGetSingle(string TagId)
|
||||
{
|
||||
TagModel dbResult = new TagModel();
|
||||
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
||||
{
|
||||
dbResult = localDbCtx
|
||||
.DbSetTags
|
||||
.Where(x => x.TagId == TagId)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// inserisce i tag
|
||||
/// </summary>
|
||||
/// <param name="newTags"></param>
|
||||
/// <returns></returns>
|
||||
public bool TagInsert(List<TagModel> newTags)
|
||||
{
|
||||
bool done = false;
|
||||
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
||||
{
|
||||
try
|
||||
{
|
||||
localDbCtx.DbSetTags.AddRange(newTags);
|
||||
localDbCtx.SaveChanges();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in TagInsert{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return done;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#if false
|
||||
|
||||
Reference in New Issue
Block a user