Files
Samuele Locatelli 0df7a2cd81 Fix gestione Log instance
Aggiunta api alive x cancellazione vecchi dati redis e mongoDB
2023-11-29 09:55:45 +01:00

49 lines
1.4 KiB
C#

using NKC_SDK;
using SteamWare;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
namespace AppData
{
public class utils
{
#region Public Methods
/// <summary>
///
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
public static string getPath(string filePath)
{
string answ = "";
try
{
answ = HttpContext.Current.Server.MapPath(filePath);
}
catch (Exception exc)
{
Log.Instance.Error($"{ComLib.traduci("UtilsErrorMapPath")}:{Environment.NewLine}{exc}");
}
return answ;
}
public static void SaveToCsv<T>(List<T> reportData, string path)
{
var lines = new List<string>();
IEnumerable<PropertyDescriptor> props = TypeDescriptor.GetProperties(typeof(T)).OfType<PropertyDescriptor>();
var header = string.Join(";", props.ToList().Select(x => x.Name));
lines.Add(header);
var valueLines = reportData.Select(row => string.Join(";", header.Split(';').Select(a => row.GetType().GetProperty(a).GetValue(row, null))));
lines.AddRange(valueLines);
File.WriteAllLines(path, lines.ToArray());
}
#endregion Public Methods
}
}