Ejemplo n.º 1
0
        /// <summary>
        /// Displays the tracker counts one after another.
        /// </summary>
        /// <returns>A Task that sets the activity</returns>
        public static async Task UpdateStatusAsync()
        {
            if (!init)
            {
                try{
                    await Program.Client.SetActivityAsync(new Game("Currently Restarting!", ActivityType.Playing));

                    await Program.MopsLog(new LogMessage(LogSeverity.Verbose, "", "Heartbeat. I was born :)"));

                    await Task.Delay(30000);

                    await Program.MopsLog(new LogMessage(LogSeverity.Verbose, "", "Heartbeat. I am still alive :)"));

                    await Task.Delay(30000);
                } catch {}

                int status = Enum.GetNames(typeof(BaseTracker.TrackerType)).Length;
                while (true)
                {
                    try
                    {
                        BaseTracker.TrackerType type = (BaseTracker.TrackerType)status++;

                        //Skip everything after GW2, as this is hidden
                        if (type.ToString().Equals("GW2"))
                        {
                            status = Enum.GetNames(typeof(BaseTracker.TrackerType)).Length;
                            continue;
                        }

                        var trackerCount = Trackers[type].GetTrackers().Count;
                        await Program.Client.SetActivityAsync(new Game($"{trackerCount} {type.ToString()} Trackers", ActivityType.Watching));
                    }
                    catch
                    {
                        //Trackers were not initialised yet, or status exceeded trackertypes
                        //Show servers instead
                        status = 0;
                        try{
                            await UpdateServerCount();
                        } catch {}
                    }
                    finally{
                        await Program.MopsLog(new LogMessage(LogSeverity.Verbose, "", $"Heartbeat. I am still alive :)\nRatio: {MopsBot.Module.Information.FailedRequests} failed vs {MopsBot.Module.Information.SucceededRequests} succeeded requests"));

                        MopsBot.Module.Information.FailedRequests    = 0;
                        MopsBot.Module.Information.SucceededRequests = 0;
                    }
                    await Task.Delay(30000);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Displays the tracker counts one after another.
        /// </summary>
        /// <returns>A Task that sets the activity</returns>
        public static async Task UpdateStatusAsync()
        {
            if (!init)
            {
                try
                {
                    if (Program.Client.LoginState == LoginState.LoggedIn)
                    {
                        await Program.Client.SetActivityAsync(new Game("Currently Restarting!", ActivityType.Playing));
                    }

                    await SendHeartbeat();

                    await Task.Delay(30000);
                }
                catch { }

                int      status = Enum.GetNames(typeof(BaseTracker.TrackerType)).Length;
                DateTime LastGC = default(DateTime);
                while (true)
                {
                    try
                    {
                        //Collect garbage when over 2GB of RAM is used
                        if (((System.Diagnostics.Process.GetCurrentProcess().WorkingSet64 / 1024) / 1024) > 2200 && (DateTime.UtcNow - LastGC).TotalMinutes > 1)
                        {
                            await Program.MopsLog(new LogMessage(LogSeverity.Verbose, "", $"GC triggered."));

                            System.Runtime.GCSettings.LargeObjectHeapCompactionMode = System.Runtime.GCLargeObjectHeapCompactionMode.CompactOnce;
                            System.GC.Collect();
                            LastGC = DateTime.UtcNow;
                        }

                        BaseTracker.TrackerType type = (BaseTracker.TrackerType)status++;

                        //Skip everything after GW2, as this is hidden
                        if (type.ToString().Equals("GW2"))
                        {
                            status = Enum.GetNames(typeof(BaseTracker.TrackerType)).Length;
                            continue;
                        }

                        var trackerCount = Trackers[type].GetTrackers().Count;

                        if (Program.Client.LoginState == LoginState.LoggedIn)
                        {
                            await Program.Client.SetActivityAsync(new Game($"{trackerCount} {type.ToString()} Trackers", ActivityType.Watching));
                        }
                    }
                    catch
                    {
                        //Trackers were not initialised yet, or status exceeded trackertypes
                        //Show servers instead
                        status = 0;
                        try
                        {
                            await UpdateServerCount();
                        }
                        catch { }
                    }
                    finally
                    {
                        await SendHeartbeat();
                    }
                    await Task.Delay(30000);
                }
            }
        }