Exemple #1
0
        public async Task UpdadeDbIdToUid(Ts3Client ts3Client)
        {
            var upgradedEntries = new List <AudioLogEntry>();
            var dbIdCache       = new Dictionary <uint, (bool valid, Uid uid)>();

            foreach (var audioLogEntry in audioLogEntries.FindAll())
            {
#pragma warning disable CS0612
                if (audioLogEntry.UserInvokeId is null)
                {
                    continue;
                }

                if (audioLogEntry.UserUid != null || audioLogEntry.UserInvokeId.Value == 0)
                {
                    audioLogEntry.UserInvokeId = null;
                    upgradedEntries.Add(audioLogEntry);
                    continue;
                }

                if (!dbIdCache.TryGetValue(audioLogEntry.UserInvokeId.Value, out var data))
                {
                    try
                    {
                        var dbData = await ts3Client.GetDbClientByDbId((ClientDbId)audioLogEntry.UserInvokeId.Value);

                        data = (true, dbData.Uid);
                    }
                    catch (AudioBotException)
                    {
                        Log.Warn("Client DbId {0} could not be found.", audioLogEntry.UserInvokeId.Value);
                        data = (false, Uid.Null);
                    }
                    dbIdCache.Add(audioLogEntry.UserInvokeId.Value, data);
                }

                if (!data.valid)
                {
                    continue;
                }

                audioLogEntry.UserInvokeId = null;
                audioLogEntry.UserUid      = data.uid.Value;
                upgradedEntries.Add(audioLogEntry);
#pragma warning restore CS0612
            }

            if (upgradedEntries.Count > 0)
            {
                audioLogEntries.Update(upgradedEntries);
            }
            Log.Info("Upgraded {0} entries.", upgradedEntries.Count);
        }
        public void UpdadeDbIdToUid(Ts3Client ts3Client)
        {
            var upgradedEntries = new List <AudioLogEntry>();
            var dbIdCache       = new Dictionary <uint, (bool valid, string uid)>();

            foreach (var audioLogEntry in audioLogEntries.FindAll())
            {
#pragma warning disable CS0612
                if (!audioLogEntry.UserInvokeId.HasValue)
                {
                    continue;
                }

                if (audioLogEntry.UserUid != null || audioLogEntry.UserInvokeId.Value == 0)
                {
                    audioLogEntry.UserInvokeId = null;
                    upgradedEntries.Add(audioLogEntry);
                    continue;
                }

                if (!dbIdCache.TryGetValue(audioLogEntry.UserInvokeId.Value, out var data))
                {
                    var result = ts3Client.GetDbClientByDbId(audioLogEntry.UserInvokeId.Value);
                    data.uid = (data.valid = result.Ok) ? result.Value.Uid : null;
                    if (!data.valid)
                    {
                        Log.Warn("Client DbId {0} could not be found.", audioLogEntry.UserInvokeId.Value);
                    }
                    dbIdCache.Add(audioLogEntry.UserInvokeId.Value, data);
                }

                if (!data.valid)
                {
                    continue;
                }

                audioLogEntry.UserInvokeId = null;
                audioLogEntry.UserUid      = data.uid;
                upgradedEntries.Add(audioLogEntry);
#pragma warning restore CS0612
            }

            if (upgradedEntries.Count > 0)
            {
                audioLogEntries.Update(upgradedEntries);
            }
            Log.Info("Upgraded {0} entries.", upgradedEntries.Count);
        }