static void Main() { try { BaseVariable.InitXmlVar();//初始化基础变量 if (!File.Exists(BaseVariable.XmlFilePath)) { throw new Exception("Config.xml配置文件不存在,请检查"); } XmlHelper xml = new XmlHelper(); BaseVariable.RequestURL = xml.SelectValue("/Root/Server/APIURL"); string modelVaild = xml.SelectValue("/Root/Sys/ModelVaild"); if (modelVaild.Trim().Equals("1")) { string c = BaseVariable.APPRootPath + "config.dat"; if (!File.Exists(BaseVariable.XmlFilePath)) { throw new Exception("config.dat系统文件不存在,请检查"); } SystemIdentity info = SystemIdentity.GetFromFile(c); if (info.GetDeviceModel() != "CK3X") { throw new Exception("设备版本不兼容!!!"); } } string appName = Assembly.GetExecutingAssembly().GetName().Name; if (!MutexHelper.IsApplicationOnRun(appName)) { #region 创建快捷方式 Shortcut sc = new Shortcut(Assembly.GetExecutingAssembly(), "鸿泰集成防错系统"); if (!sc.IsExist()) { sc.Create(); } #endregion TaskBarHelper.ShowTaskBar(false); Application.Run(new FrmLogin()); Application.Exit(); } else { MessageBox.Show("系统正在运行!");//如果该程序已经运行则返回,避免程序重复运行 Application.Exit(); return; } } catch (Exception e) { MessageBox.Show(e.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); } finally { TaskBarHelper.ShowTaskBar(true); } }
/// <summary> /// 获取设备型号 /// </summary> /// <param name="info">设备对象</param> /// <param name="isUpper">是否大写</param> /// <returns>型号</returns> public static string GetDeviceModel(SystemIdentity info, bool isUpper) { string m = null; if (info != null && info.Group != null && info.Group.Fields != null) { List <Field> list = info.Group.Fields; foreach (Field item in list) { m += item.Value.Trim(); } } return(isUpper ? m.ToUpper() : m); }
public static SystemIdentity GetFromText(string xmlConfText) { SystemIdentity info = null; string systeminfo = xmlConfText; if (string.IsNullOrEmpty(systeminfo)) { return(null); } ITCSSApi ss = new ITCSSApi(); int size = 4096; StringBuilder builder = new StringBuilder(size); uint ret = ss.Get(systeminfo, builder, ref size, 10); if (ret == ITCSSErrors.E_SS_SUCCESS) { using (MemoryStream stream = new MemoryStream()) { StreamWriter writer = new StreamWriter(stream); writer.Write(builder.ToString().Trim()); writer.Flush(); stream.Seek(0, SeekOrigin.Begin); StreamReader reader = new StreamReader(stream); XmlSerializer xmlSerializer = new XmlSerializer(typeof(SystemIdentity)); info = (SystemIdentity)xmlSerializer.Deserialize(reader); reader.Close(); reader.Close(); writer.Close(); writer.Dispose(); } } return(info); }
/// <summary> /// 获取设备型号 /// </summary> /// <param name="info">设备对象</param> /// <returns>大写的型号</returns> public static string GetDeviceModel(SystemIdentity info) { return(GetDeviceModel(info, true)); }