using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Text; namespace EShang { public class Update { /// /// 自动更新程序中间类入口 /// 入口方法名称LoadAssembly请勿更改 /// 如有其他功能需要实现请在LoadAssembly方法下进行实现 /// /// 加载类型 /// dll文件所在文件夹 /// public static bool LoadAssembly(string LoadType, string DLLDir) { string _DLLFilePath = ""; switch (LoadType) { //收银机端 case "AutoUpdateEx": if (String.IsNullOrWhiteSpace(DLLDir)) { _DLLFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AutoUpdater.dll"); } else { _DLLFilePath = Path.Combine(DLLDir, "AutoUpdater.dll"); } if (File.Exists(_DLLFilePath)) { try { byte[] _File = File.ReadAllBytes(_DLLFilePath); Assembly _Assembly = Assembly.Load(_File);////我们要调用的dll文件路径 Type _Type = _Assembly.GetType("AutoUpdater.MainWindow");//获取类名,必须 命名空间+类名 (Activator.CreateInstance(_Type) as System.Windows.Window).Show(); } catch { return false; } } else { return false; } break; //服务器端 case "RunUpdateExe": if (String.IsNullOrWhiteSpace(DLLDir)) { _DLLFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin", "RunUpdater.dll"); } else { _DLLFilePath = Path.Combine(DLLDir, "RunUpdater.dll"); } if (File.Exists(_DLLFilePath)) { try { byte[] _File = File.ReadAllBytes(_DLLFilePath); Assembly _Assembly = Assembly.Load(_File);////我们要调用的dll文件路径 Type _Type = _Assembly.GetType("RunUpdater.MainWindow");//获取类名,必须 命名空间+类名 (Activator.CreateInstance(_Type) as System.Windows.Window).Show(); } catch { return false; } } else { return false; } break; } return true; } } }