Exemple #1
0
        public async ValueTask InsertAsync(string contextId, string workerName, string[] arguments, int requests, int errors, TimeSpan duration, CancellationToken token = default)
        {
            // run only if profiler is enabled.
            if (_option.EnableProfiler)
            {
                var entity = new ProfileHistory
                {
                    ContextId  = contextId,
                    WorkerName = workerName,
                    Argument   = string.Join(" ", arguments),
                    Requests   = requests,
                    Errors     = errors,
                    Duration   = duration.TotalSeconds,
                };

                if (_option?.OnPreInsertAsync != null)
                {
                    await _option?.OnPreInsertAsync.Invoke(entity, token);
                }

                await _context.AddAsync <ProfileHistory>(entity, token);

                await _context.SaveChangesAsync(token);

                if (_option?.OnPostInsertAsync != null)
                {
                    await _option?.OnPostInsertAsync.Invoke(entity, token);
                }
            }
        }
Exemple #2
0
        public async ValueTask InsertAsync(ProfileHistory entity, CancellationToken token = default)
        {
            if (_option.EnableProfiler)
            {
                if (_option?.OnPreInsertAsync != null)
                {
                    await _option?.OnPreInsertAsync.Invoke(entity, token);
                }

                await _context.AddAsync <ProfileHistory>(entity, token);

                await _context.SaveChangesAsync(token);

                if (_option?.OnPostInsertAsync != null)
                {
                    await _option?.OnPostInsertAsync.Invoke(entity, token);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// This is wired up by Plugin.OnEnabled, and called when the bot is started
        /// </summary>
        /// <param name="bot"></param>
        private static void TrinityBotStart(IBot bot)
        {
            Logger.Log("Bot Starting");
            DateTime timeBotStart = DateTime.UtcNow;

            V.ValidateLoad();

            // Recording of all the XML's in use this run
            try
            {
                string sThisProfile = GlobalSettings.Instance.LastProfile;
                if (sThisProfile != CurrentProfile)
                {
                    ProfileHistory.Add(sThisProfile);
                    CurrentProfile = sThisProfile;
                    if (FirstProfile == "")
                    {
                        FirstProfile = sThisProfile;
                    }
                }

                DebugUtil.LogSystemInformation();
            }
            catch
            {
            }

            if (!ItemDropStats.MaintainStatTracking)
            {
                ItemDropStats.ItemStatsWhenStartedBot   = DateTime.UtcNow;
                ItemDropStats.ItemStatsLastPostedReport = DateTime.UtcNow;
                ItemDropStats.MaintainStatTracking      = true;
            }
            else
            {
                Logger.Log(TrinityLogLevel.Info, LogCategory.UserInformation,
                           "Note: Maintaining item stats from previous run. To reset stats fully, please restart DB.");
            }

            TrinityItemManager.ResetBackPackCheck();

            BeginInvoke(UsedProfileManager.RefreshProfileBlacklists);
            UsedProfileManager.SetProfileInWindowTitle();

            BotManager.ReplaceTreeHooks();
            TreeHooks.Instance.OnHooksCleared += BotManager.InstanceOnOnHooksCleared;


            PlayerMover.TimeLastRecordedPosition = DateTime.UtcNow;
            PlayerMover.LastRestartedGame        = DateTime.UtcNow;
            Logger.Log("Bot Starting, Resetting Gold Inactivity Timer");
            GoldInactivity.Instance.ResetCheckGold();
            XpInactivity.Instance.ResetCheckXp();

            if (CharacterSettings.Instance.KillRadius < 20)
            {
                Logger.Log("WARNING: Low Kill Radius detected, currently set to: {0} (you can change this through Demonbuddy bot settings)",
                           CharacterSettings.Instance.KillRadius);
            }

            if (CharacterSettings.Instance.LootRadius < 50)
            {
                Logger.Log("WARNING: Low Gold Loot Radius detected, currently set to: {0} (you can change this through Demonbuddy bot settings)",
                           CharacterSettings.Instance.LootRadius);
            }

            if (Settings.Loot.ItemFilterMode == ItemFilterMode.TrinityWithItemRules)
            {
                try
                {
                    if (StashRule == null)
                    {
                        StashRule = new Interpreter();
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogError("Error configuring ItemRules Interpreter: " + ex);
                }
            }

            Logger.LogDebug("Trinity BotStart took {0:0}ms", DateTime.UtcNow.Subtract(timeBotStart).TotalMilliseconds);
        }