Add materials converting from DTOs

This commit is contained in:
Evgeny Redikultsev
2024-10-27 21:29:50 +05:00
parent b0c24126da
commit 223e69263f
71 changed files with 1398 additions and 253 deletions

View File

@@ -3,10 +3,10 @@
{
public enum MaterialTypes
{
Concrete,
Reinforcement,
//Steel,
CarbonFiber,
GlassFiber,
Concrete = 0,
Reinforcement = 1,
Steel = 3,
CarbonFiber = 4,
GlassFiber = 5,
}
}

View File

@@ -0,0 +1,40 @@
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Loggers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Infrastructures.Interfaces
{
public abstract class ConvertStrategy<T, V> : IConvertStrategy<T, V>
where T : ISaveable
where V : ISaveable
{
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
public virtual T Convert(V source)
{
try
{
Check();
return GetNewItem(source);
}
catch (Exception ex)
{
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Error);
TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
throw;
}
}
public abstract T GetNewItem(V source);
private void Check()
{
var checkLogic = new CheckConvertLogic<T,V>(this);
checkLogic.Check();
}
}
}

View File

@@ -10,6 +10,11 @@ using System.Windows.Media;
namespace StructureHelperCommon.Infrastructures.Interfaces
{
/// <summary>
/// Find object in refernce dictionary, if it exists return existing object, else return new one by child logic
/// </summary>
/// <typeparam name="T">Type of target object</typeparam>
/// <typeparam name="V">Type of source object</typeparam>
public class DictionaryConvertStrategy<T, V> : IConvertStrategy<T, V>
where T : ISaveable
where V : ISaveable

View File

@@ -7,10 +7,20 @@ using System.Threading.Tasks;
namespace StructureHelperCommon.Infrastructures.Interfaces
{
/// <summary>
/// Converts object of type of ISaveable to another one
/// </summary>
/// <typeparam name="T">Target object type</typeparam>
/// <typeparam name="V">Source object type</typeparam>
public interface IConvertStrategy<T,V> : IBaseConvertStrategy
where T :ISaveable
where V :ISaveable
{
/// <summary>
/// Converts object to another one
/// </summary>
/// <param name="source">Source object</param>
/// <returns>Converted object</returns>
T Convert(V source);
}
}

View File

@@ -0,0 +1,30 @@
using StructureHelper.Models.Materials;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Forces;
using StructureHelperCommon.Models.Repositories;
namespace StructureHelperCommon.Infrastructures.Settings
{
internal static class GlobalRepository
{
private static IDataRepository<IHeadMaterial> materials;
private static IDataRepository<IAction> actions;
//public static IDataRepository<IHeadMaterial> Materials
//{
// get
// {
// materials ??= new ListRepository<IHeadMaterial>(new HeadMaterialUpdateStrategy());
// return materials;
// }
//}
//public static IDataRepository<IAction> Actions
//{
// get
// {
// actions ??= new ListRepository<IAction>(new ActionUpdateStrategy());
// return actions;
// }
//}
}
}