using Microsoft.Win32;
|
using System;
|
using System.Collections.Generic;
|
using System.IO;
|
|
namespace SHARP_CLAS_UI
|
{
|
public class Position_Info_Manager
|
{
|
#region Define
|
string str_extension = ".xml";
|
#endregion
|
|
#region Property
|
private static readonly Lazy<Position_Info_Manager> _instatnce = new Lazy<Position_Info_Manager>(() => new Position_Info_Manager());
|
|
public static Position_Info_Manager Instance
|
{
|
get
|
{
|
return _instatnce.Value;
|
}
|
}
|
#endregion
|
|
#region Field
|
private Dictionary<string, Position_Info> Recipes;
|
|
private Xml_Manager<Position_Info> xml_manager = new Xml_Manager<Position_Info>();
|
|
private string file_path;
|
#endregion
|
|
#region Construct
|
public Position_Info_Manager()
|
{
|
Recipes = new Dictionary<string, Position_Info>();
|
Get_Position_infos();
|
}
|
#endregion
|
|
#region Function
|
private void Get_File_Path()
|
{
|
RegistryKey rkk = Registry.CurrentUser.OpenSubKey(Equipment.Registry_Path, true);
|
|
try
|
{
|
if (rkk == null)
|
{
|
rkk = Registry.CurrentUser.CreateSubKey(Equipment.Registry_Path);
|
|
rkk.SetValue("POSITION_PARAMETER_PATH", @"C:\SHARP_CLAS\Config\POSITION_PARAMETER\");
|
file_path = @"C:\SHARP_CLAS\Config\POSITION_PARAMETER\";
|
}
|
else
|
{
|
object value = rkk.GetValue("POSITION_PARAMETER_PATH");
|
if (value == null)
|
{
|
rkk.SetValue("POSITION_PARAMETER_PATH", @"C:\SHARP_CLAS\Config\POSITION_PARAMETER\");
|
file_path = @"C:\SHARP_CLAS\Config\POSITION_PARAMETER\";
|
}
|
else
|
{
|
file_path = value.ToString();
|
}
|
}
|
}
|
finally
|
{
|
rkk.Close();
|
}
|
}
|
|
private void Get_Position_infos()
|
{
|
Get_File_Path();
|
|
Recipes.Clear();
|
|
if (Directory.Exists(file_path))
|
{
|
DirectoryInfo di = new DirectoryInfo(file_path);
|
FileInfo[] recipes = di.GetFiles($"*{str_extension}");
|
|
foreach (FileInfo recipe in recipes)
|
{
|
Position_Info position_info = new Position_Info();
|
|
if (xml_manager.Try_Read_File(file_path + recipe, out position_info))
|
{
|
//if (Recipes.ContainsKey(position_info.Name))
|
//{
|
// Recipes[position_info.Name] = position_info;
|
//}
|
//else
|
//{
|
// Recipes.Add(position_info.Name, position_info);
|
//}
|
}
|
}
|
}
|
}
|
#endregion
|
}
|
}
|