You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
121 lines
3.9 KiB
C#
121 lines
3.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.IO;
|
|
using System.Xml;
|
|
|
|
namespace Mesnac.Action.Base
|
|
{
|
|
public class DeviceDataName
|
|
{
|
|
private Dictionary<string, string> _deviceDataNameDic { get; set; }
|
|
#region 单例模式
|
|
private static DeviceDataName _this;
|
|
public static DeviceDataName Instance
|
|
{
|
|
get
|
|
{
|
|
if (null == _this)
|
|
_this = new DeviceDataName();
|
|
return _this;
|
|
}
|
|
}
|
|
private DeviceDataName()
|
|
{
|
|
this._deviceDataNameDic = new Dictionary<string, string>();
|
|
}
|
|
#endregion
|
|
#region 基本信息
|
|
private string _projectWizardName = string.Empty;
|
|
public string ProjectWizardName
|
|
{
|
|
get
|
|
{
|
|
return _projectWizardName;
|
|
}
|
|
set
|
|
{
|
|
if (_projectWizardName != value)
|
|
{
|
|
this._deviceDataNameDic.Clear();
|
|
_projectWizardName = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private readonly string ActionConfigPath = "Data\\EventConfig\\";
|
|
private string GetConfigFilePath(string path)
|
|
{
|
|
FileInfo fi = new FileInfo(AppDomain.CurrentDomain.FriendlyName);
|
|
return Path.Combine(fi.Directory.ToString(), ActionConfigPath, path);
|
|
}
|
|
#endregion
|
|
#region IniDeviceDataNameDic
|
|
private void IniDeviceDataNameDic(FileInfo fi)
|
|
{
|
|
XmlDocument xmlDocument = new XmlDocument();
|
|
xmlDocument.Load(fi.FullName);
|
|
foreach (XmlNode serviceNode in xmlDocument)
|
|
{
|
|
if (!serviceNode.Name.Equals("EquipDataNameExchange", StringComparison.CurrentCultureIgnoreCase))
|
|
{
|
|
continue;
|
|
}
|
|
foreach (XmlNode runtimeNode in serviceNode.ChildNodes)
|
|
{
|
|
if (runtimeNode.Attributes != null
|
|
&& runtimeNode.Attributes.Count > 1
|
|
&& runtimeNode.Attributes["runtime"] != null
|
|
&& runtimeNode.Attributes["runtime"].Value != null
|
|
&& runtimeNode.Attributes["design"] != null
|
|
&& runtimeNode.Attributes["design"].Value != null)
|
|
{
|
|
if (!this._deviceDataNameDic.ContainsKey(runtimeNode.Attributes["runtime"].Value.ToString()))
|
|
{
|
|
this._deviceDataNameDic.Add(runtimeNode.Attributes["runtime"].Value.ToString(),
|
|
runtimeNode.Attributes["design"].Value.ToString());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
private void IniDeviceDataNameDic()
|
|
{
|
|
if (this._deviceDataNameDic.Count > 0)
|
|
{
|
|
return;
|
|
}
|
|
this._deviceDataNameDic.Clear();
|
|
DirectoryInfo dir = new DirectoryInfo(GetConfigFilePath(this._projectWizardName));
|
|
if (dir.Exists)
|
|
{
|
|
foreach (FileInfo fi in dir.GetFiles())
|
|
{
|
|
IniDeviceDataNameDic(fi);
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
public string GetDeviceDesignDataName(string runtime)
|
|
{
|
|
if (this._deviceDataNameDic.Count == 0)
|
|
{
|
|
IniDeviceDataNameDic();
|
|
}
|
|
string Result = runtime;
|
|
if (this._deviceDataNameDic.TryGetValue(runtime, out Result))
|
|
{
|
|
return Result;
|
|
}
|
|
return runtime;
|
|
}
|
|
public string GetDeviceDesignDataName(string projectWizardName, string runtime)
|
|
{
|
|
this.ProjectWizardName = projectWizardName;
|
|
return GetDeviceDesignDataName(runtime);
|
|
}
|
|
}
|
|
}
|