protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); //添加程序集解析事件 AppDomain.CurrentDomain.AssemblyResolve += OnResolveAssembly; InstallConfigurationEntity InstallConfigEntity = Common.GetSysInstallConfig("Install.InstallApp.config"); var FindList = InstallConfigEntity.ListPrograms.Where(o => o.ProgramName == InstallConfigEntity.UsingProgramName).ToList(); if (FindList.Count == 1) { Common.InstallEntity = FindList[0]; } else { MessageBox.Show("系统配置异常!"); Application.Current.Shutdown(); } Application currApp = Application.Current; currApp.StartupUri = new Uri(Common.InstallEntity.StartupUri, UriKind.RelativeOrAbsolute); }
public static InstallConfigurationEntity GetSysInstallConfig(string FileName) { try { InstallConfigurationEntity Result = new InstallConfigurationEntity(); string StrXml = ""; //如果不存在 则从嵌入资源内读取 BlockSet.xml Assembly asm = Assembly.GetExecutingAssembly();//读取嵌入式资源 using (Stream sm = asm.GetManifestResourceStream(FileName)) { StreamReader reader = new StreamReader(sm); StrXml = reader.ReadToEnd(); reader.Close(); reader.Dispose(); } XmlDocument xd = new XmlDocument(); xd.LoadXml(StrXml); foreach (XmlNode item in xd.ChildNodes) { foreach (XmlNode item1 in item.ChildNodes) { switch (item1.Name) { case "Programs": List <ProgramsEntity> ListPrograms = new List <ProgramsEntity>(); foreach (XmlNode item2 in item1.ChildNodes) { if (item2.Name == "#comment") { continue; } ProgramsEntity programs = new ProgramsEntity(); foreach (XmlNode item3 in item2.ChildNodes) { if (item3.Name == "#comment") { continue; } programs = (ProgramsEntity)SetDataValue(programs, item3.Name, item3.InnerText); } ListPrograms.Add(programs); } Result.ListPrograms = ListPrograms; break; case "UsingProgramName": Result.UsingProgramName = item1.InnerText; break; default: break; } } } return(Result); } catch (Exception) { throw; } }