public PWClient(Process process, DTO.Configuration.Cuenta config, DAL.CuentaConfig dbConfig) { this.Process = process; this.Config = config; this.dbConfig = dbConfig; this.dbConfig.OnHideWinChatChanged += (sender, e) => { this.Action.Global.ShowWin(!e, BLL.Mem.Basic.GUIObj.GUIs.WinChat); }; this.Manager = new YerbaSoft.Windows.API.ProcessManager(this.Process); this.Mem = new Mem.PWMem(this); this.Auto = new Auto.AutoManager(this); this.Action = new Actions.PWActions(this); this.Mem.OnConnect += (sender, e) => { if (!e) { this.Dispose(); } }; // solo se dispara cuando se logró conectar alguna vez y se desconecta this.Mem.Link.OnPlayerConnect += (sender, e) => { if (e) { new Thread(() => { Thread.Sleep(3000); this.Action.Global.ShowWin(!this.dbConfig.HideWinChat, BLL.Mem.Basic.GUIObj.GUIs.WinChat); }).Start(); } }; }
public static PWClient OpenPW(DTO.Configuration.Cuenta config) { Process proc = null; var reintentos = 0; do { var pi = new ProcessStartInfo(Config.AppPath) { WorkingDirectory = System.IO.Path.GetDirectoryName(Config.AppPath), UseShellExecute = true }; proc = Process.Start(pi); proc.WaitForInputIdle(10000); if (!proc.Responding) { proc.Kill(); proc.Dispose(); proc = null; } reintentos++; } while (proc == null && reintentos < 5); if (proc == null) { return(null); } return(GetClient(proc, config)); }
private static PWClient GetClient(Process proc, DTO.Configuration.Cuenta config) { var dbConfig = DAL.CuentaConfig.Get(config.Name ?? config.Login) ?? new DAL.CuentaConfig() { Id = Guid.NewGuid(), Login = config.Name ?? config.Login }; var cuenta = new PWClient(proc, config, dbConfig); cuenta.Manager.SetWindowTitle(config.Name ?? config.Login); lock (Cuentas) Cuentas.Add(cuenta); cuenta.OnDisposing += (sender, c) => { lock (Cuentas) if (Cuentas.Contains(c)) { Cuentas.Remove(c); } }; return(cuenta); }