2026-09-14 14:05:50 +09:00

133 lines
2.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
namespace Demo.Weld
{
public enum WeldMode
{
Spot,
Seam
}
public sealed class WeldRecipe
{
private readonly List<WeldStep> _steps = new List<WeldStep>();
public string Name
{
get;
set;
}
public int RetryCount { get; set; } = 3;
public IReadOnlyList<WeldStep> Steps
{
get
{
return _steps;
}
}
public WeldRecipe(string name)
{
Name = name;
}
public void Add(WeldStep step)
{
if (step == null)
{
throw new ArgumentNullException(nameof(step));
}
else if (step.Power <= 0)
{
throw new ArgumentOutOfRangeException(nameof(step));
}
else
{
_steps.Add(step);
}
}
public bool Run(Func<WeldStep, bool> fire)
{
for (var attempt = 0; attempt < RetryCount; attempt++)
{
try
{
if (_steps.All(fire))
{
return true;
}
}
catch (InvalidOperationException ex)
{
Log($"재시도 {attempt + 1}: {ex.Message}");
}
finally
{
Cool();
}
}
return false;
}
public static WeldRecipe Sample()
{
var recipe = new WeldRecipe("기본")
{
RetryCount = 2
};
var steps = new[]
{
new WeldStep { Power = 150, Millis = 40 },
new WeldStep { Power = 180, Millis = 55 }
};
foreach (var step in steps)
{
recipe.Add(step);
}
var summary = new
{
recipe.Name,
Count = steps.Length
};
Log(summary.ToString());
Action done = () =>
{
Log("준비 끝");
};
done();
return recipe;
}
private static void Cool()
{
switch (DateTime.Now.Second % 2)
{
case 0:
Log("공랭");
break;
default:
Log("수랭");
break;
}
}
private static void Log(string text)
{
}
}
public sealed class WeldStep
{
public int Power { get; set; }
public int Millis { get; set; }
}
}