ConfigHelper.cs
4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System;
using System.IO;
using System.Windows.Forms;
using System.Xml;
namespace OS.Spin.Common.Files
{
public class ConfigHelper
{
private static XmlDocument doc = null;
private static ConfigHelper _helper = null;
public static ConfigHelper GetInstance()
{
return _helper ?? (_helper = new ConfigHelper());
}
/// <summary>
/// 修改配置文件信息
/// </summary>
public bool SetConfig(ParamEntity entity)
{
try
{
doc = new XmlDocument();
doc.Load(Path.Combine(Application.StartupPath, @"config\ParaSettings.xml"));
doc.SelectSingleNode("root/prob_cls").InnerText = entity.Prob_cls.ToString();
doc.SelectSingleNode("root/prob_sma").InnerText = entity.Prob_sma.ToString();
doc.SelectSingleNode("root/prob_color").InnerText = entity.Prob_color.ToString();
doc.SelectSingleNode("root/prob_thin").InnerText = entity.Prob_thin.ToString();
doc.SelectSingleNode("root/len_sma").InnerText = entity.Len_sma.ToString();
doc.SelectSingleNode("root/m_base").InnerText = entity.M_base.ToString();
doc.SelectSingleNode("root/thre_area").InnerText = entity.Thre_Area.ToString();
doc.SelectSingleNode("root/thre_location").InnerText = entity.Thre_Location.ToString();
doc.SelectSingleNode("root/index_shift").InnerText = entity.Index_shift.ToString();
doc.SelectSingleNode("root/thresh_ratio").InnerText = entity.Thresh_ratio.ToString();
doc.SelectSingleNode("root/num_ratio").InnerText = entity.Num_ratio.ToString();
doc.Save(Path.Combine(Application.StartupPath, @"config\ParaSettings.xml"));
}
catch (Exception ex)
{
LogisTrac.WriteLog(string.Format("SetConfig:{0}", ex.Message));
return false;
}
return true;
}
/// <summary>
/// 获取配置文件信息
/// </summary>
/// <param name="nodeName"></param>
/// <returns></returns>
public ParamEntity GetConfig()
{
try
{
doc = new XmlDocument();
doc.Load(Path.Combine(Application.StartupPath, @"config\ParaSettings.xml"));
ParamEntity entity = new ParamEntity();
entity.Prob_cls = Convert.ToSingle(doc.SelectSingleNode("root/prob_cls").InnerText);
entity.Prob_sma = Convert.ToSingle(doc.SelectSingleNode("root/prob_sma").InnerText);
entity.Prob_color = Convert.ToSingle(doc.SelectSingleNode("root/prob_color").InnerText);
entity.Prob_thin = Convert.ToSingle(doc.SelectSingleNode("root/prob_thin").InnerText);
entity.Len_sma = Convert.ToInt32(doc.SelectSingleNode("root/len_sma").InnerText);
entity.M_base = Convert.ToInt32(doc.SelectSingleNode("root/m_base").InnerText);
entity.Thre_Area = Convert.ToInt32(doc.SelectSingleNode("root/thre_area").InnerText);
entity.Thre_Location = Convert.ToInt32(doc.SelectSingleNode("root/thre_location").InnerText);
entity.Index_shift = Convert.ToInt32(doc.SelectSingleNode("root/index_shift").InnerText);
entity.Thresh_ratio = Convert.ToSingle(doc.SelectSingleNode("root/thresh_ratio").InnerText);
entity.Num_ratio = Convert.ToSingle(doc.SelectSingleNode("root/num_ratio").InnerText);
return entity;
}
catch (Exception ex)
{
LogisTrac.WriteLog(string.Format("GetConfig:{0}", ex.Message));
return null;
}
}
}
public class ParamEntity
{
//CLAS_PARAM
public float Prob_cls { get; set; }//通用瑕疵
public float Prob_sma { get; set; }//小瑕疵
public float Prob_color { get; set; }//色纤
public float Prob_thin { get; set; }//淡痕
public int Len_sma { get; set; }//小瑕疵长度限制阈值
public int M_base { get; set; }//增益基准值
public int Thre_Area { get; set; }//点状瑕疵面积
public int Thre_Location { get; set; }//布尾米数位置阈值
//DETC_PARAM
public int Index_shift { get; set; }//切边偏移
public float Thresh_ratio { get; set; }//二值化系数
public float Num_ratio { get; set; }//二值化系数2
}
}