예제 #1
0
        internal static void DoWork()
        {
            int pulseStartTime = 0;

            while (true)
            {
                try
                {
                    pulseStartTime = Environment.TickCount;
                    if (Utility.HasInternetConnection)
                    {
                        foreach (var character in Settings.CharacterProfiles)
                        {
                            if (character.IsRunning)
                            {
                                character.Pulse();
                            }
                        }

                        if (_crashCheckTimer.ElapsedMilliseconds >= 5000)
                        {
                            KillWoWCrashDialogs();
                            KillHonorbuddyCrashDialogs();
                            _crashCheckTimer.Restart();
                        }

                        if (Settings.CheckRealmStatus)
                        {
                            if (_updateRealmStatusTimer == null)
                            {
                                _updateRealmStatusTimer = Stopwatch.StartNew();
                            }

                            if (_updateRealmStatusTimer.ElapsedMilliseconds >= 60000)
                            {
                                // update Wow Realm status
                                if (Settings.CheckRealmStatus)
                                {
                                    WowRealmStatus.Update();
                                }
                                _updateRealmStatusTimer.Restart();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Err(ex.ToString());
                }
                finally
                {
                    // sleep for 1000 millisec minus time it took to execute
                    int sleepTime = 1000 - (Environment.TickCount - pulseStartTime);
                    if (sleepTime > 0)
                    {
                        Thread.Sleep(sleepTime);
                    }
                }
            }
        }
예제 #2
0
        static HbRelogManager()
        {
            try
            {
                // if in designer mode then return
                if (MainWindow.Instance == null || DesignerProperties.GetIsInDesignMode(MainWindow.Instance))
                    return;
                WorkerThread = new Thread(DoWork) { IsBackground = true };
                WorkerThread.Start();
                try
                {
                    _host = new ServiceHost(typeof(RemotingApi), new Uri("net.pipe://localhost/HBRelog"));
                    _host.AddServiceEndpoint(typeof(IRemotingApi),
                        new NetNamedPipeBinding() { ReceiveTimeout = TimeSpan.MaxValue },
                        "Server");
                    _host.Open();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    Log.Err(ex.ToString());
                }

                WowRealmStatus = new WowRealmStatus();
                // update Wow Realm status
                if (Settings.CheckRealmStatus)
                    WowRealmStatus.Update();
                IsInitialized = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                Log.Err(ex.ToString());
            }
        }
예제 #3
0
        static HbRelogManager()
        {
            try
            {
                // if in designer mode then return
                if (MainWindow.Instance == null || DesignerProperties.GetIsInDesignMode(MainWindow.Instance))
                {
                    return;
                }
                Settings     = GlobalSettings.Load();
                WorkerThread = new Thread(DoWork)
                {
                    IsBackground = true
                };
                WorkerThread.Start();
                try
                {
                    _host = new ServiceHost(typeof(RemotingApi), new Uri("net.pipe://localhost/HBRelog"));
                    _host.AddServiceEndpoint(typeof(IRemotingApi),
                                             new NetNamedPipeBinding()
                    {
                        ReceiveTimeout = TimeSpan.MaxValue
                    },
                                             "Server");
                    _host.Open();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    Log.Err(ex.ToString());
                }

                WowRealmStatus = new WowRealmStatus();
                // update Wow Realm status
                if (Settings.CheckRealmStatus)
                {
                    WowRealmStatus.Update();
                }
                IsInitialized = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                Log.Err(ex.ToString());
            }
        }
예제 #4
0
        static HbRelogManager()
        {
            try
            {
                // if in designer mode then return
                if (MainWindow.Instance == null || DesignerProperties.GetIsInDesignMode(MainWindow.Instance))
                    return;
                Settings = GlobalSettings.Load();

                Settings.FreeHBKeyPool.Clear();
                if (!string.IsNullOrEmpty(Settings.HBKeyPool))
                {
                    foreach (var key in Settings.HBKeyPool.Split(','))
                    {
                        Settings.FreeHBKeyPool.Add(key);
                    }
                }

                WorkerThread = new Thread(DoWork) { IsBackground = true };
                WorkerThread.Start();
                try
                {
                    remoting = new RemotingApi();
                    _host = new ServiceHost(remoting, new Uri(string.Format("net.pipe://localhost/HBRelog{0}", Program.IsAssemblyDebugBuild() ? "_debug" : "")));
                    _host.AddServiceEndpoint(typeof(IRemotingApi), new NetNamedPipeBinding { ReceiveTimeout = TimeSpan.MaxValue }, "Server");
                    _host.Open();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    Log.Err(ex.ToString());
                }

                WowRealmStatus = new WowRealmStatus();
                // update Wow Realm status
                if (Settings.CheckRealmStatus)
                    WowRealmStatus.Update();

                Settings.CharacterProfiles.ToList().ForEach(cp => cp.PropertyChanged += (sender, args) =>
                {
                    var profile = (CharacterProfile)sender;
                    if (profile.TaskManager.HonorbuddyManager.BotProcess == null)
                        return;
                    var pid = profile.TaskManager.HonorbuddyManager.BotProcess.Id;
                    if (Clients.ContainsKey(pid))
                    {
                        try
                        {
                            if (args.PropertyName != "Status" || profile.Status != "Honorbuddy Startup Complete")
                                return;
                            if (profile.TaskManager.HonorbuddyManager.Settings.AutoStartBot)
                            {
                                Log.Write(string.Format("Starting bot {0} {1}",
                                    profile.TaskManager.HonorbuddyManager.Settings.BotBase,
                                    profile.TaskManager.HonorbuddyManager.Settings.HonorbuddyProfile));
                                Clients[pid].StartBot(
                                    profile.TaskManager.HonorbuddyManager.Settings.BotBase,
                                    profile.TaskManager.HonorbuddyManager.Settings.HonorbuddyProfile);
                            }
                        }
                        catch (Exception)
                        {
                            Clients.Remove(pid);
                        }
                    }
                });
                IsInitialized = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                Log.Err(ex.ToString());
            }
        }