Files
LeafWeb/Core/Remote/PiscalUtility.cs
T

28 lines
875 B
C#

using System;
using System.Text.RegularExpressions;
using LeafWeb.Core.Entities;
using LeafWeb.Core.Utility;
namespace LeafWeb.Core.Remote
{
public static class PiscalUtility
{
public static string GetPiscalDirectoryName(int id, string name, string identifier)
{
return $"{id}_{name.FilterAlphaNumeric()}_{identifier.FilterAlphaNumeric()}";
}
public static string GetPiscalDirectoryName(LeafInputFile leafInputFile)
{
return GetPiscalDirectoryName(leafInputFile.Id, leafInputFile.LeafInput.Name, leafInputFile.LeafInput.Identifier);
}
public static int GetIdFromDirectoryName(string directoryName)
{
var match = Regex.Match(directoryName, @"\d_");
if (!match.Success)
throw new FormatException("DirectoryName expected to be formatted {number}_{name}_{identifier}: " + directoryName);
return int.Parse(match.Captures[0].Value);
}
}
}