SystemConfigManager.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Media;
  10. using System.Xml;
  11. using System.Xml.Linq;
  12. using Aitex.Common.Util;
  13. using Aitex.Core.Common;
  14. using Aitex.Core.RT.ConfigCenter;
  15. using Aitex.Core.RT.DataCenter;
  16. using Aitex.Core.RT.DBCore;
  17. using Aitex.Core.RT.Event;
  18. using Aitex.Core.RT.Log;
  19. using Aitex.Core.RT.OperationCenter;
  20. using Aitex.Core.RT.SCCore;
  21. using Aitex.Core.Util;
  22. using MECF.Framework.Common.Equipment;
  23. using MECF.Framework.Common.FAServices;
  24. namespace MECF.Framework.Common.SCCore
  25. {
  26. public class SystemConfigManager : Singleton<SystemConfigManager>, ISCManager
  27. {
  28. private Dictionary<string, SCConfigItem> _items = new Dictionary<string, SCConfigItem>(StringComparer.OrdinalIgnoreCase);
  29. private object _itemLocker = new object();
  30. private string _scConfigFile;
  31. private string _scDataFile = PathManager.GetCfgDir() + "_sc.data";
  32. private string _scDataBackupFile = PathManager.GetCfgDir() + "_sc.data.bak";
  33. private string _scDataErrorFile = PathManager.GetCfgDir() + "_sc.data.err.";
  34. public List<VIDItem> VidConfigList
  35. {
  36. get
  37. {
  38. List<VIDItem> result = new List<VIDItem>();
  39. foreach (var dataItem in _items)
  40. {
  41. result.Add(new VIDItem()
  42. {
  43. DataType = "",
  44. Description = dataItem.Value.Description,
  45. Index = 0,
  46. Name = dataItem.Key,
  47. Unit = "",
  48. });
  49. }
  50. return result;
  51. }
  52. }
  53. private Dictionary<string, WaferTypeInfo> _waferTypes;
  54. public Dictionary<string, WaferTypeInfo> WaferTypes
  55. {
  56. get
  57. {
  58. if (_waferTypes == null)
  59. {
  60. _waferTypes = new Dictionary<string, WaferTypeInfo>();
  61. string key = "System.WaferType.";
  62. var typedatas = _items.Keys.Where(r => r.StartsWith(key));
  63. BrushConverter converter = new BrushConverter();
  64. foreach (var data in typedatas)
  65. {
  66. string[] dataStr = data.Split('.');
  67. if (dataStr.Length != 4) continue;
  68. var item = dataStr[2].Trim();
  69. ///排除异常类型
  70. if (string.IsNullOrWhiteSpace(item) || item == "None" || item == SC.VaribleType) continue;
  71. if (!_waferTypes.ContainsKey(item))
  72. _waferTypes[item] = new WaferTypeInfo() { Name = item };
  73. string para = dataStr[3].Trim();
  74. if (para == "FullName")
  75. _waferTypes[item].FullName = string.IsNullOrWhiteSpace(_items[data].Default) ? string.Empty : _items[data].Default.Trim();
  76. else if (para == "AccFilmThick")
  77. _waferTypes[item].AccFilmThick = bool.Parse(_items[data].Default);
  78. else if (para == "AlternativeWaferType")
  79. _waferTypes[item].AlternativeWaferType = string.IsNullOrWhiteSpace(_items[data].Default) ? string.Empty : _items[data].Default.Trim();
  80. else if (para == "IsReturnWafer")
  81. _waferTypes[item].IsReturnWafer = bool.Parse(_items[data].Default);
  82. else if (para == "ReturnWaferType")
  83. _waferTypes[item].ReturnWaferType = string.IsNullOrWhiteSpace(_items[data].Default) ? string.Empty : _items[data].Default.Trim();
  84. else if (para == "READY")
  85. {
  86. if (string.IsNullOrWhiteSpace(_items[data].Default) || converter.IsValid(_items[data].Default)) _waferTypes[item].ShowColor = _items[data].Default ?? "".Trim();//null或者空白没有颜色
  87. else _waferTypes[item].ShowColor = "LightGray";//保证颜色有效
  88. }
  89. else if (para == "CanProcessContinuously")
  90. _waferTypes[item].CanProcessContinuously = bool.Parse(_items[data].Default);
  91. else if (para == "IsDummy")
  92. _waferTypes[item].IsDummy = bool.Parse(_items[data].Default);
  93. }
  94. foreach (var type in _waferTypes.Values)
  95. {
  96. if (type.AlternativeWaferType != string.Empty)
  97. {
  98. if (!_waferTypes.ContainsKey(type.AlternativeWaferType))
  99. {
  100. LOG.Warning($"SystemconfigManager.WaferTypes find Undefined Type: [{type.Name}.AlternativeWaferType]=[{type.AlternativeWaferType}].use empty replace");
  101. type.AlternativeWaferType = string.Empty;
  102. }
  103. }
  104. }
  105. }
  106. return _waferTypes;
  107. }
  108. }
  109. public void Initialize(string scConfigPathName)
  110. {
  111. _scConfigFile = scConfigPathName;
  112. BuildItems(_scConfigFile);
  113. BackupAndRecoverDataFile();
  114. CustomData();
  115. GenerateDataFile();
  116. foreach (var item in _items)
  117. {
  118. CONFIG.Subscribe("", item.Key, () => item.Value.Value);
  119. }
  120. OP.Subscribe("System.SetConfig", InvokeSetConfig);
  121. SC.Manager = this;
  122. }
  123. private bool InvokeSetConfig(string cmd, object[] parameters)
  124. {
  125. string key = (string)parameters[0];
  126. if (!ContainsItem(key))
  127. {
  128. EV.PostWarningLog("System", string.Format("Not find SC with name {0}", key));
  129. return false;
  130. }
  131. object old = GetConfigValueAsObject(key);
  132. if (InitializeItemValue(_items[(string)parameters[0]], parameters[1].ToString()))
  133. {
  134. GenerateDataFile();
  135. EV.PostInfoLog("System", string.Format("SC {0} value changed from {1} to {2}", key, old, parameters[1]));
  136. }
  137. return true;
  138. }
  139. public void Terminate()
  140. {
  141. }
  142. public string GetFileContent()
  143. {
  144. if (!File.Exists(_scConfigFile))
  145. return "";
  146. StringBuilder s = new StringBuilder();
  147. try
  148. {
  149. using (StreamReader sr = new StreamReader(_scConfigFile))
  150. {
  151. while (!sr.EndOfStream)
  152. {
  153. s.Append(sr.ReadLine());
  154. }
  155. }
  156. }
  157. catch (Exception ex)
  158. {
  159. LOG.Write(ex);
  160. return "";
  161. }
  162. return s.ToString();
  163. }
  164. private void BuildItems(string xmlFile)
  165. {
  166. XmlDocument xml = new XmlDocument();
  167. try
  168. {
  169. xml.Load(xmlFile);
  170. XmlNodeList nodeConfigs = xml.SelectNodes("root/configs");
  171. foreach (XmlElement nodeConfig in nodeConfigs)
  172. {
  173. BuildPathConfigs(nodeConfig.GetAttribute("name"), nodeConfig as XmlElement);
  174. }
  175. }
  176. catch (Exception ex)
  177. {
  178. LOG.Write(ex);
  179. }
  180. }
  181. private void BuildPathConfigs(string parentPath, XmlElement configElement)
  182. {
  183. XmlNodeList nodeConfigsList = configElement.SelectNodes("configs");
  184. foreach (XmlElement nodeConfig in nodeConfigsList)
  185. {
  186. if (string.IsNullOrEmpty(parentPath))
  187. {
  188. BuildPathConfigs(nodeConfig.GetAttribute("name"), nodeConfig as XmlElement);
  189. }
  190. else
  191. {
  192. BuildPathConfigs(parentPath + "." + nodeConfig.GetAttribute("name"), nodeConfig as XmlElement);
  193. }
  194. }
  195. XmlNodeList nodeConfigs = configElement.SelectNodes("config");
  196. foreach (XmlElement nodeConfig in nodeConfigs)
  197. {
  198. SCConfigItem item = new SCConfigItem()
  199. {
  200. Default = nodeConfig.GetAttribute("default"),
  201. Name = nodeConfig.GetAttribute("name"),
  202. Description = nodeConfig.GetAttribute("description"),
  203. Max = nodeConfig.GetAttribute("max"),
  204. Min = nodeConfig.GetAttribute("min"),
  205. Parameter = nodeConfig.GetAttribute("paramter"),
  206. Path = parentPath,
  207. Tag = nodeConfig.GetAttribute("tag"),
  208. Type = nodeConfig.GetAttribute("type"),
  209. Unit = nodeConfig.GetAttribute("unit"),
  210. };
  211. InitializeItemValue(item, item.Default);
  212. if (_items.ContainsKey(item.PathName))
  213. {
  214. LOG.Error("Duplicated SC item, " + item.PathName);
  215. }
  216. _items[item.PathName] = item;
  217. }
  218. }
  219. private void BackupAndRecoverDataFile()
  220. {
  221. try
  222. {
  223. if (File.Exists(_scDataFile) && IsXmlFileLoadable(_scDataFile))
  224. {
  225. File.Copy(_scDataFile, _scDataBackupFile, true);
  226. }
  227. else if (File.Exists(_scDataBackupFile) && IsXmlFileLoadable(_scDataBackupFile))
  228. {
  229. if (File.Exists(_scDataFile))
  230. {
  231. File.Copy(_scDataFile, _scDataErrorFile + DateTime.Now.ToString("yyyyMMdd_HHmmss"), true);
  232. }
  233. File.Copy(_scDataBackupFile, _scDataFile, true);
  234. }
  235. }
  236. catch (Exception ex)
  237. {
  238. LOG.Write(ex);
  239. }
  240. }
  241. private void CustomData()
  242. {
  243. Dictionary<string, string> values = new Dictionary<string, string>();
  244. try
  245. {
  246. if (File.Exists(_scDataFile))
  247. {
  248. XmlDocument xmlData = new XmlDocument();
  249. xmlData.Load(_scDataFile);
  250. XmlNodeList scdatas = xmlData.SelectNodes("root/scdata");
  251. foreach (XmlElement nodedata in scdatas)
  252. {
  253. string name = nodedata.GetAttribute("name");
  254. if (_items.ContainsKey(name))
  255. {
  256. InitializeItemValue(_items[name], nodedata.GetAttribute("value"));
  257. }
  258. }
  259. }
  260. }
  261. catch (Exception ex)
  262. {
  263. LOG.Write(ex);
  264. }
  265. }
  266. private void GenerateDataFile()
  267. {
  268. try
  269. {
  270. XmlDocument xml = new XmlDocument();
  271. xml.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?><root></root>");
  272. XmlElement nodeRoot = xml.SelectSingleNode("root") as XmlElement;
  273. foreach (var scConfigItem in _items)
  274. {
  275. XmlElement node = xml.CreateElement("scdata");
  276. node.SetAttribute("name", scConfigItem.Key);
  277. node.SetAttribute("value", scConfigItem.Value.Value.ToString());
  278. nodeRoot.AppendChild(node);
  279. }
  280. if (File.Exists(_scDataFile) && IsXmlFileLoadable(_scDataFile))
  281. {
  282. File.Copy(_scDataFile, _scDataBackupFile, true);
  283. //File.Delete(_scDataFile);
  284. }
  285. using (FileStream fsFileStream = new FileStream(_scDataFile,
  286. FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, 1024, FileOptions.WriteThrough))
  287. {
  288. fsFileStream.SetLength(0);
  289. XmlWriterSettings settings = new XmlWriterSettings();
  290. settings.Indent = true;
  291. settings.OmitXmlDeclaration = false;
  292. using (XmlWriter xmlWrite = XmlWriter.Create(fsFileStream, settings))
  293. {
  294. xml.Save(xmlWrite);
  295. }
  296. }
  297. }
  298. catch (Exception ex)
  299. {
  300. LOG.Write(ex);
  301. }
  302. }
  303. private bool IsXmlFileLoadable(string file)
  304. {
  305. try
  306. {
  307. XmlDocument xml = new XmlDocument();
  308. xml.Load(file);
  309. }
  310. catch (Exception ex)
  311. {
  312. LOG.Write(ex);
  313. return false;
  314. }
  315. return true;
  316. }
  317. public SCConfigItem GetConfigItem(string name)
  318. {
  319. //Debug.Assert(_items.ContainsKey(name), "can not find sc name, "+name);
  320. if (!_items.ContainsKey(name))
  321. {
  322. return null;
  323. }
  324. return _items[name];
  325. }
  326. public bool ContainsItem(string name)
  327. {
  328. return _items.ContainsKey(name);
  329. }
  330. public object GetConfigValueAsObject(string name)
  331. {
  332. SCConfigItem item = GetConfigItem(name);
  333. switch (item.Type)
  334. {
  335. case "Bool": return item.BoolValue;
  336. case "Integer": return item.IntValue;
  337. case "Double": return item.DoubleValue;
  338. case "String": return item.StringValue;
  339. }
  340. return null;
  341. }
  342. public T GetValue<T>(string name) where T : struct
  343. {
  344. try
  345. {
  346. if (typeof(T) == typeof(bool))
  347. return (T)(object)_items[name].BoolValue;
  348. if (typeof(T) == typeof(int))
  349. return (T)(object)_items[name].IntValue;
  350. if (typeof(T) == typeof(double))
  351. return (T)(object)_items[name].DoubleValue;
  352. }
  353. catch (KeyNotFoundException)
  354. {
  355. EV.PostAlarmLog("System", $"Can not find system config item {name}");
  356. return default(T);
  357. }
  358. catch (Exception)
  359. {
  360. EV.PostAlarmLog("System", $"Can not get valid system config item value {name}");
  361. return default(T);
  362. }
  363. Debug.Assert(false, "unsupported type");
  364. return default(T);
  365. }
  366. public string GetStringValue(string name)
  367. {
  368. if (!_items.ContainsKey(name))
  369. return null;
  370. return _items[name].StringValue;
  371. }
  372. public T SafeGetValue<T>(string name, T defaultValue) where T : struct
  373. {
  374. try
  375. {
  376. if (typeof(T) == typeof(bool))
  377. return (T)(object)_items[name].BoolValue;
  378. if (typeof(T) == typeof(int))
  379. return (T)(object)_items[name].IntValue;
  380. if (typeof(T) == typeof(double))
  381. return (T)(object)_items[name].DoubleValue;
  382. }
  383. catch (KeyNotFoundException)
  384. {
  385. return defaultValue;
  386. }
  387. catch (Exception)
  388. {
  389. return defaultValue;
  390. }
  391. Debug.Assert(false, "unsupported type");
  392. return defaultValue;
  393. }
  394. public string SafeGetStringValue(string name, string defaultValue)
  395. {
  396. if (!_items.ContainsKey(name))
  397. return defaultValue;
  398. return _items[name].StringValue;
  399. }
  400. public List<SCConfigItem> GetItemList()
  401. {
  402. return _items.Values.ToList();
  403. }
  404. public Dictionary<string, Dictionary<string, string>> GetAllWaferTypeColor()
  405. {
  406. Dictionary<string, Dictionary<string, string>> resultDict = new Dictionary<string, Dictionary<string, string>>();
  407. var xmlContent = GetFileContent();
  408. XDocument doc = XDocument.Parse(xmlContent);
  409. foreach (var waferType in doc.Descendants("configs").Where(e => e.Attribute("name")?.Value == "WaferType"))
  410. {
  411. foreach (var pElement in waferType.Elements("configs"))
  412. {
  413. string dataKey = pElement.Attribute("name")?.Value ?? "";
  414. if (!string.IsNullOrEmpty(dataKey))
  415. {
  416. resultDict[dataKey] = new Dictionary<string, string>();
  417. foreach (var config in pElement.Elements("config"))
  418. {
  419. string attrName = config.Attribute("name")?.Value ?? "";
  420. string attrDefault = config.Attribute("default")?.Value ?? "";
  421. if (!string.IsNullOrEmpty(attrName) && !string.IsNullOrEmpty(attrDefault))
  422. {
  423. resultDict[dataKey][attrName] = attrDefault;
  424. }
  425. }
  426. }
  427. }
  428. }
  429. return resultDict;
  430. }
  431. public List<WaferTypeInfo> GetWaferTypes()
  432. {
  433. return WaferTypes.Values.ToList();
  434. }
  435. public void SetItemValueFromString(string name, string value)
  436. {
  437. if (InitializeItemValue(_items[name], value))
  438. {
  439. GenerateDataFile();
  440. }
  441. }
  442. private bool InitializeItemValue(SCConfigItem item, string value)
  443. {
  444. bool changed = false;
  445. switch (item.Type)
  446. {
  447. case "Bool":
  448. bool boolValue;
  449. if (bool.TryParse(value, out boolValue) && boolValue != item.BoolValue)
  450. {
  451. item.BoolValue = boolValue;
  452. changed = true;
  453. }
  454. break;
  455. case "Integer":
  456. int intValue;
  457. if (int.TryParse(value, out intValue) && intValue != item.IntValue)
  458. {
  459. int.TryParse(item.Min, out int min);
  460. int.TryParse(item.Max, out int max);
  461. if (intValue < min || intValue > max)
  462. {
  463. EV.PostWarningLog(ModuleNameString.System, $"SC {item.PathName} value {intValue} out of setting range ({item.Min}, {item.Max})");
  464. break;
  465. }
  466. item.IntValue = intValue;
  467. changed = true;
  468. }
  469. break;
  470. case "Double":
  471. double doubleValue;
  472. if (double.TryParse(value, out doubleValue) && Math.Abs(doubleValue - item.DoubleValue) > 0.0001)
  473. {
  474. double.TryParse(item.Min, out double min);
  475. double.TryParse(item.Max, out double max);
  476. if (doubleValue < min || doubleValue > max)
  477. {
  478. EV.PostWarningLog(ModuleNameString.System, $"SC {item.PathName} value {doubleValue} out of setting range ({item.Min}, {item.Max})");
  479. break;
  480. }
  481. item.DoubleValue = doubleValue;
  482. changed = true;
  483. }
  484. break;
  485. case "String":
  486. if (value != item.StringValue)
  487. {
  488. item.StringValue = value;
  489. changed = true;
  490. }
  491. break;
  492. }
  493. return changed;
  494. }
  495. public void SetItemValue(string name, object value)
  496. {
  497. Debug.Assert(_items.ContainsKey(name), "can not find sc name, " + name);
  498. if (!_items.ContainsKey(name))
  499. {
  500. return;
  501. }
  502. bool changed = false;
  503. switch (_items[name].Type)
  504. {
  505. case "Bool":
  506. bool boolValue = (bool)value;
  507. if (boolValue != _items[name].BoolValue)
  508. {
  509. _items[name].BoolValue = boolValue;
  510. changed = true;
  511. }
  512. break;
  513. case "Integer":
  514. int intValue = (int)value;
  515. if (intValue != _items[name].IntValue)
  516. {
  517. _items[name].IntValue = intValue;
  518. changed = true;
  519. }
  520. break;
  521. case "Double":
  522. double doubleValue = (double)value;
  523. if (Math.Abs(doubleValue - _items[name].DoubleValue) > 0.0001)
  524. {
  525. _items[name].DoubleValue = doubleValue;
  526. changed = true;
  527. }
  528. break;
  529. case "String":
  530. string stringValue = (string)value;
  531. if (stringValue != _items[name].StringValue)
  532. {
  533. _items[name].StringValue = stringValue;
  534. changed = true;
  535. }
  536. break;
  537. }
  538. if (changed)
  539. {
  540. GenerateDataFile();
  541. }
  542. }
  543. public void SetItemValues(Dictionary<string,object> itemValues)
  544. {
  545. if (itemValues == null || itemValues.Count == 0) return;
  546. bool changed = false;
  547. foreach (var name in itemValues.Keys)
  548. {
  549. Debug.Assert(_items.ContainsKey(name), "can not find sc name, " + name);
  550. if (!_items.ContainsKey(name))
  551. {
  552. continue;
  553. }
  554. switch (_items[name].Type)
  555. {
  556. case "Bool":
  557. bool boolValue = (bool)itemValues[name];
  558. if (boolValue != _items[name].BoolValue)
  559. {
  560. _items[name].BoolValue = boolValue;
  561. changed = true;
  562. }
  563. break;
  564. case "Integer":
  565. int intValue = (int)itemValues[name];
  566. if (intValue != _items[name].IntValue)
  567. {
  568. _items[name].IntValue = intValue;
  569. changed = true;
  570. }
  571. break;
  572. case "Double":
  573. double doubleValue = (double)itemValues[name];
  574. if (Math.Abs(doubleValue - _items[name].DoubleValue) > 0.0001)
  575. {
  576. _items[name].DoubleValue = doubleValue;
  577. changed = true;
  578. }
  579. break;
  580. case "String":
  581. string stringValue = (string)itemValues[name];
  582. if (stringValue != _items[name].StringValue)
  583. {
  584. _items[name].StringValue = stringValue;
  585. changed = true;
  586. }
  587. break;
  588. }
  589. }
  590. if (changed)
  591. {
  592. GenerateDataFile();
  593. }
  594. }
  595. public void SetItemValueStringFormat(string name, string value)
  596. {
  597. Debug.Assert(_items.ContainsKey(name), "can not find sc name, " + name);
  598. if (!_items.ContainsKey(name))
  599. {
  600. return;
  601. }
  602. bool changed = false;
  603. switch (_items[name].Type)
  604. {
  605. case "Bool":
  606. bool boolValue = Convert.ToBoolean(value);
  607. if (boolValue != _items[name].BoolValue)
  608. {
  609. _items[name].BoolValue = boolValue;
  610. changed = true;
  611. }
  612. break;
  613. case "Integer":
  614. int intValue = Convert.ToInt32(value);
  615. if (intValue != _items[name].IntValue)
  616. {
  617. _items[name].IntValue = intValue;
  618. changed = true;
  619. }
  620. break;
  621. case "Double":
  622. double doubleValue = Convert.ToDouble(value);
  623. if (Math.Abs(doubleValue - _items[name].DoubleValue) > 0.0001)
  624. {
  625. _items[name].DoubleValue = doubleValue;
  626. changed = true;
  627. }
  628. break;
  629. case "String":
  630. string stringValue = (string)value;
  631. if (stringValue != _items[name].StringValue)
  632. {
  633. _items[name].StringValue = stringValue;
  634. changed = true;
  635. }
  636. break;
  637. }
  638. if (changed)
  639. {
  640. GenerateDataFile();
  641. }
  642. }
  643. public void SetItemValue(string name, bool value)
  644. {
  645. Debug.Assert(_items.ContainsKey(name), "can not find sc name, " + name);
  646. Debug.Assert(_items[name].Type == "Bool", "sc type not bool, defined as" + _items[name].Type);
  647. if (value != _items[name].BoolValue)
  648. {
  649. _items[name].BoolValue = value;
  650. GenerateDataFile();
  651. }
  652. }
  653. public void SetItemValue(string name, int value)
  654. {
  655. Debug.Assert(_items.ContainsKey(name), "can not find sc name, " + name);
  656. Debug.Assert(_items[name].Type == "Integer", "sc type not bool, defined as" + _items[name].Type);
  657. if (value != _items[name].IntValue)
  658. {
  659. _items[name].IntValue = value;
  660. GenerateDataFile();
  661. }
  662. }
  663. public void SetItemValue(string name, double value)
  664. {
  665. Debug.Assert(_items.ContainsKey(name), "can not find sc name, " + name);
  666. Debug.Assert(_items[name].Type == "Double", "sc type not bool, defined as" + _items[name].Type);
  667. if (Math.Abs(value - _items[name].DoubleValue) > 0.0001)
  668. {
  669. _items[name].DoubleValue = value;
  670. GenerateDataFile();
  671. }
  672. }
  673. public void SetItemValue(string name, string value)
  674. {
  675. Debug.Assert(_items.ContainsKey(name), "can not find sc name, " + name);
  676. if (value != _items[name].StringValue)
  677. {
  678. _items[name].StringValue = value;
  679. GenerateDataFile();
  680. }
  681. }
  682. }
  683. }