public void TestInitialize() { _cache = new MemCache("MyCache"); _cache.Set("k1", "Test simple value 1"); _cache.Set("k2", "Test simple value 2"); _cache.Set("k3", "Test simple value 3", TimeSpan.FromSeconds(3), true); }
public Recorder(IDataCache cache, ISettings settings) { _logger = settings.LoggerProvider.CreateLogger(typeof(Recorder)); _configSeed = settings.ConfigSeed; _cache = cache; _settings = settings; }
public SetupSystemTables(IDataCache cache, IStorageCommandsSetup storageFactory, ISettings settings) { _logger = settings.LoggerProvider.CreateLogger(typeof(SetupSystemTables)); _cache = cache; _storageCommands = storageFactory; _settings = settings; }
public SetupSystemData(IDataCache cache, IStorageCommandsSetup storageCommands, ISettings settings) { _logger = settings.LoggerProvider.CreateLogger(typeof(SetupSystemData)); _cache = cache; _storageCommands = storageCommands; _settings = settings; }
public RecordFlush(ISetupMonitorConfig setupMonitorConfig, IDataCache cache, IStorageCommands storageCommands, IRecordFlushUpdate logic, IStorageFactory dbFactory, ISettings settings) { _logger = settings.LoggerProvider.CreateLogger(typeof(RecordFlush)); _setupMonitorConfig = setupMonitorConfig; _cache = cache; _storageCommands = storageCommands; _logic = logic; _dbFactory = dbFactory; _settings = settings; }
public RecordReduce(IRecordReduceStatus reduceStatus, IRecordReduceAggregate reduceAggregater, IDataCache cache, IRecordCompare recordCompare, IStorageCommands storageCommands, IStorageFactory dbFactory, ISettings settings) { _logger = settings.LoggerProvider.CreateLogger(typeof(RecordReduce)); _configSeed = settings.ConfigSeed; _reduceStatus = reduceStatus; _reduceAggregater = reduceAggregater; _cache = cache; _recordCompare = recordCompare; _storageCommands = storageCommands; _dbFactory = dbFactory; _settings = settings; }
/// <summary> /// Initializes a new instance of the <see cref="YafDbBroker" /> class. /// </summary> /// <param name="serviceLocator">The service locator.</param> /// <param name="boardSettings">The board settings.</param> /// <param name="httpSessionState">The http session state.</param> /// <param name="dataCache">The data cache.</param> /// <param name="dbFunction">The database function.</param> public YafDbBroker( IServiceLocator serviceLocator, YafBoardSettings boardSettings, HttpSessionStateBase httpSessionState, IDataCache dataCache, IDbFunction dbFunction) { this.ServiceLocator = serviceLocator; this.BoardSettings = boardSettings; this.HttpSessionState = httpSessionState; this.DataCache = dataCache; this.DbFunction = dbFunction; }
public AppFabricChangeMonitor(ReadOnlyCollection<string> keys, string regionName, IDataCache dataCache) : base(keys, regionName) { this.dataCache = dataCache; this.notificationDescriptorList = new List<DataCacheNotificationDescriptor>(); foreach (var key in keys) { var notificationDescriptor = this.dataCache.AddItemLevelCallback( key, DataCacheOperations.RemoveItem | DataCacheOperations.ReplaceItem | DataCacheOperations.AddItem, ItemChangedCallbackDelegate); notificationDescriptorList.Add(notificationDescriptor); } }
/// <summary> /// Initializes a new instance of the <see cref="CategoryEventHandleCacheInvalidate"/> class. /// </summary> /// <param name="dataCache"> /// The data cache. /// </param> public CategoryEventHandleCacheInvalidate(IDataCache dataCache) { this._dataCache = dataCache; }
public StatsService(DiscordSocketClient client, CommandHandler cmdHandler, IBotCredentials creds, NadekoBot nadeko, IDataCache cache, IHttpClientFactory factory) { _log = LogManager.GetCurrentClassLogger(); _client = client; _creds = creds; _redis = cache.Redis; _httpFactory = factory; _started = DateTime.UtcNow; _client.MessageReceived += _ => Task.FromResult(Interlocked.Increment(ref _messageCounter)); cmdHandler.CommandExecuted += (_, e) => Task.FromResult(Interlocked.Increment(ref _commandsRan)); _client.ChannelCreated += (c) => { var _ = Task.Run(() => { if (c is ITextChannel) { Interlocked.Increment(ref _textChannels); } else if (c is IVoiceChannel) { Interlocked.Increment(ref _voiceChannels); } }); return(Task.CompletedTask); }; _client.ChannelDestroyed += (c) => { var _ = Task.Run(() => { if (c is ITextChannel) { Interlocked.Decrement(ref _textChannels); } else if (c is IVoiceChannel) { Interlocked.Decrement(ref _voiceChannels); } }); return(Task.CompletedTask); }; _client.GuildAvailable += (g) => { var _ = Task.Run(() => { var tc = g.Channels.Count(cx => cx is ITextChannel); var vc = g.Channels.Count - tc; Interlocked.Add(ref _textChannels, tc); Interlocked.Add(ref _voiceChannels, vc); }); return(Task.CompletedTask); }; _client.JoinedGuild += (g) => { var _ = Task.Run(() => { var tc = g.Channels.Count(cx => cx is ITextChannel); var vc = g.Channels.Count - tc; Interlocked.Add(ref _textChannels, tc); Interlocked.Add(ref _voiceChannels, vc); }); return(Task.CompletedTask); }; _client.GuildUnavailable += (g) => { var _ = Task.Run(() => { var tc = g.Channels.Count(cx => cx is ITextChannel); var vc = g.Channels.Count - tc; Interlocked.Add(ref _textChannels, -tc); Interlocked.Add(ref _voiceChannels, -vc); }); return(Task.CompletedTask); }; _client.LeftGuild += (g) => { var _ = Task.Run(() => { var tc = g.Channels.Count(cx => cx is ITextChannel); var vc = g.Channels.Count - tc; Interlocked.Add(ref _textChannels, -tc); Interlocked.Add(ref _voiceChannels, -vc); }); return(Task.CompletedTask); }; if (_client.ShardId == 0) { _carbonitexTimer = new Timer(async(state) => { if (string.IsNullOrWhiteSpace(_creds.CarbonKey)) { return; } try { using (var http = _httpFactory.CreateClient()) { using (var content = new FormUrlEncodedContent( new Dictionary <string, string> { { "servercount", nadeko.GuildCount.ToString() }, { "key", _creds.CarbonKey } })) { content.Headers.Clear(); content.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); using (await http.PostAsync(new Uri("https://www.carbonitex.net/discord/data/botdata.php"), content).ConfigureAwait(false)) { } } } } catch { // ignored } }, null, TimeSpan.FromHours(1), TimeSpan.FromHours(1)); } _botlistTimer = new Timer(async(state) => { if (string.IsNullOrWhiteSpace(_creds.BotListToken)) { return; } try { using (var http = _httpFactory.CreateClient()) { using (var content = new FormUrlEncodedContent( new Dictionary <string, string> { { "shard_count", _creds.TotalShards.ToString() }, { "shard_id", client.ShardId.ToString() }, { "server_count", client.Guilds.Count().ToString() } })) { content.Headers.Clear(); content.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); http.DefaultRequestHeaders.Add("Authorization", _creds.BotListToken); using (await http.PostAsync(new Uri($"https://discordbots.org/api/bots/{client.CurrentUser.Id}/stats"), content).ConfigureAwait(false)) { } } } } catch (Exception ex) { _log.Error(ex); // ignored } }, null, TimeSpan.FromMinutes(5), TimeSpan.FromHours(1)); var platform = "other"; if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { platform = "linux"; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { platform = "osx"; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { platform = "windows"; } _dataTimer = new Timer(async(state) => { try { using (var http = _httpFactory.CreateClient()) { using (var content = new FormUrlEncodedContent( new Dictionary <string, string> { { "id", string.Concat(MD5.Create().ComputeHash(Encoding.ASCII.GetBytes(_creds.ClientId.ToString())).Select(x => x.ToString("X2"))) }, { "guildCount", nadeko.GuildCount.ToString() }, { "version", BotVersion }, { "platform", platform } })) { content.Headers.Clear(); content.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); using (await http.PostAsync(new Uri("https://selfstats.nadekobot.me/"), content).ConfigureAwait(false)) { } } } } catch { // ignored } }, null, TimeSpan.FromSeconds(1), TimeSpan.FromHours(1)); }
public AnimeSearchService(IDataCache cache) { _log = LogManager.GetCurrentClassLogger(); _cache = cache; _http = new HttpClient(); }
public XpService(CommandHandler cmd, IBotConfigProvider bc, NadekoBot bot, DbService db, NadekoStrings strings, IDataCache cache, FontProvider fonts, IBotCredentials creds, ICurrencyService cs) { _db = db; _cmd = cmd; _bc = bc; _images = cache.LocalImages; _log = LogManager.GetCurrentClassLogger(); _strings = strings; _cache = cache; _fonts = fonts; _creds = creds; _cs = cs; //load settings var allGuildConfigs = bot.AllGuildConfigs.Where(x => x.XpSettings != null); _excludedChannels = allGuildConfigs .ToDictionary( x => x.GuildId, x => new ConcurrentHashSet <ulong>(x.XpSettings .ExclusionList .Where(ex => ex.ItemType == ExcludedItemType.Channel) .Select(ex => ex.ItemId) .Distinct())) .ToConcurrent(); _excludedRoles = allGuildConfigs .ToDictionary( x => x.GuildId, x => new ConcurrentHashSet <ulong>(x.XpSettings .ExclusionList .Where(ex => ex.ItemType == ExcludedItemType.Role) .Select(ex => ex.ItemId) .Distinct())) .ToConcurrent(); _excludedServers = new ConcurrentHashSet <ulong>( allGuildConfigs.Where(x => x.XpSettings.ServerExcluded) .Select(x => x.GuildId)); _cmd.OnMessageNoTrigger += _cmd_OnMessageNoTrigger; _updateXpTimer = new Timer(async _ => { try { var toNotify = new List <(IMessageChannel MessageChannel, IUser User, int Level, XpNotificationType NotifyType, NotifOf NotifOf)>(); var roleRewards = new Dictionary <ulong, List <XpRoleReward> >(); var curRewards = new Dictionary <ulong, List <XpCurrencyReward> >(); var toAddTo = new List <UserCacheItem>(); while (_addMessageXp.TryDequeue(out var usr)) { toAddTo.Add(usr); } var group = toAddTo.GroupBy(x => (GuildId: x.Guild.Id, User: x.User)); if (toAddTo.Count == 0) { return; } using (var uow = _db.UnitOfWork) { foreach (var item in group) { var xp = item.Select(x => bc.BotConfig.XpPerMessage).Sum(); //1. Mass query discord users and userxpstats and get them from local dict //2. (better but much harder) Move everything to the database, and get old and new xp // amounts for every user (in order to give rewards) var usr = uow.Xp.GetOrCreateUser(item.Key.GuildId, item.Key.User.Id); var du = uow.DiscordUsers.GetOrCreate(item.Key.User); var globalXp = du.TotalXp; var oldGlobalLevelData = new LevelStats(globalXp); var newGlobalLevelData = new LevelStats(globalXp + xp); var oldGuildLevelData = new LevelStats(usr.Xp + usr.AwardedXp); usr.Xp += xp; du.TotalXp += xp; if (du.Club != null) { du.Club.Xp += xp; } var newGuildLevelData = new LevelStats(usr.Xp + usr.AwardedXp); if (oldGlobalLevelData.Level < newGlobalLevelData.Level) { du.LastLevelUp = DateTime.UtcNow; var first = item.First(); if (du.NotifyOnLevelUp != XpNotificationType.None) { toNotify.Add((first.Channel, first.User, newGlobalLevelData.Level, du.NotifyOnLevelUp, NotifOf.Global)); } } if (oldGuildLevelData.Level < newGuildLevelData.Level) { usr.LastLevelUp = DateTime.UtcNow; //send level up notification var first = item.First(); if (usr.NotifyOnLevelUp != XpNotificationType.None) { toNotify.Add((first.Channel, first.User, newGuildLevelData.Level, usr.NotifyOnLevelUp, NotifOf.Server)); } //give role if (!roleRewards.TryGetValue(usr.GuildId, out var rrews)) { rrews = uow.GuildConfigs.XpSettingsFor(usr.GuildId).RoleRewards.ToList(); roleRewards.Add(usr.GuildId, rrews); } if (!curRewards.TryGetValue(usr.GuildId, out var crews)) { crews = uow.GuildConfigs.XpSettingsFor(usr.GuildId).CurrencyRewards.ToList(); curRewards.Add(usr.GuildId, crews); } var rrew = rrews.FirstOrDefault(x => x.Level == newGuildLevelData.Level); if (rrew != null) { var role = first.User.Guild.GetRole(rrew.RoleId); if (role != null) { var __ = first.User.AddRoleAsync(role); } } //get currency reward for this level var crew = crews.FirstOrDefault(x => x.Level == newGuildLevelData.Level); if (crew != null) { //give the user the reward if it exists await _cs.AddAsync(item.Key.User.Id, "Level-up Reward", crew.Amount).ConfigureAwait(false); } } } uow.Complete(); } await Task.WhenAll(toNotify.Select(async x => { if (x.NotifOf == NotifOf.Server) { if (x.NotifyType == XpNotificationType.Dm) { var chan = await x.User.GetOrCreateDMChannelAsync().ConfigureAwait(false); if (chan != null) { await chan.SendConfirmAsync(_strings.GetText("level_up_dm", (x.MessageChannel as ITextChannel)?.GuildId, "xp", x.User.Mention, Format.Bold(x.Level.ToString()), Format.Bold((x.MessageChannel as ITextChannel)?.Guild.ToString() ?? "-"))) .ConfigureAwait(false); } } else // channel { await x.MessageChannel.SendConfirmAsync(_strings.GetText("level_up_channel", (x.MessageChannel as ITextChannel)?.GuildId, "xp", x.User.Mention, Format.Bold(x.Level.ToString()))) .ConfigureAwait(false); } } else { IMessageChannel chan; if (x.NotifyType == XpNotificationType.Dm) { chan = await x.User.GetOrCreateDMChannelAsync().ConfigureAwait(false); } else // channel { chan = x.MessageChannel; } await chan.SendConfirmAsync(_strings.GetText("level_up_global", (x.MessageChannel as ITextChannel)?.GuildId, "xp", x.User.Mention, Format.Bold(x.Level.ToString()))) .ConfigureAwait(false); } })).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } }, null, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5)); _clearRewardTimerTokenSource = new CancellationTokenSource(); var token = _clearRewardTimerTokenSource.Token; //just a first line, in order to prevent queries. But since other shards can try to do this too, //i'll check in the db too. _clearRewardTimer = Task.Run(async() => { while (!token.IsCancellationRequested) { _rewardedUsers.Clear(); await Task.Delay(TimeSpan.FromMinutes(_bc.BotConfig.XpMinutesTimeout)).ConfigureAwait(false); } }, token); }
public TriviaQuestionPool(IDataCache cache) { _cache = cache; maxPokemonId = 721; //xd }
public HandyDataStorage(IApplicationDataService applicationDataService, IDataCache dataCache) { _dataCache = dataCache; }
public RoutePalController(ILogger <RoutePalController> logger, IDataCache dataCache) { this.logger = logger; this.dataCache = dataCache; }
public ModerationAuthentication(IObjectFactory factory) { Contract.Requires(factory != null); this.Repository = factory.Resolve<IDataCache<Korisnik>>(); }
public Birb(IBotCredentials creds, IDataCache data) { _creds = creds; _images = data.LocalImages; }
public Quantify_Quote(string tagName, IDataCache <Data_Quote> dataCache) { _QuantifyIndexs = new Dictionary <typeIndex, QuantifyIndex>(); _DataCache = dataCache; }
public DiceRollCommands(IDataCache data) { _images = data.LocalImages; }
public GenericBLL(IUnitOfWork unitOfWork, IDataCache DataCache) { this.unitOfWork = unitOfWork; this.dataCache = DataCache;; }
public SearchesService(DiscordSocketClient client, IGoogleApiService google, DbService db, NadekoBot bot, IImagesService imgs, IDataCache cache, FontProvider fonts) { Http = new HttpClient(); Http.AddFakeHeaders(); _client = client; _google = google; _db = db; _log = LogManager.GetCurrentClassLogger(); _imgs = imgs; _cache = cache; _fonts = fonts; http = new HttpClient(); _blacklistedTags = new ConcurrentDictionary <ulong, HashSet <string> >( bot.AllGuildConfigs.ToDictionary( x => x.GuildId, x => new HashSet <string>(x.NsfwBlacklistedTags.Select(y => y.Tag)))); //translate commands _client.MessageReceived += (msg) => { var _ = Task.Run(async() => { try { var umsg = msg as SocketUserMessage; if (umsg == null) { return; } if (!TranslatedChannels.TryGetValue(umsg.Channel.Id, out var autoDelete)) { return; } var key = new UserChannelPair() { UserId = umsg.Author.Id, ChannelId = umsg.Channel.Id, }; if (!UserLanguages.TryGetValue(key, out string langs)) { return; } var text = await Translate(langs, umsg.Resolve(TagHandling.Ignore)) .ConfigureAwait(false); if (autoDelete) { try { await umsg.DeleteAsync().ConfigureAwait(false); } catch { } } await umsg.Channel.SendConfirmAsync($"{umsg.Author.Mention} `:` " + text.Replace("<@ ", "<@").Replace("<@! ", "<@!")).ConfigureAwait(false); } catch { } }); return(Task.CompletedTask); }; //pokemon commands if (File.Exists(PokemonListFile)) { Pokemons = JsonConvert.DeserializeObject <Dictionary <string, SearchPokemon> >(File.ReadAllText(PokemonListFile)); } else { _log.Warn(PokemonListFile + " is missing. Pokemon abilities not loaded."); } if (File.Exists(PokemonAbilitiesFile)) { PokemonAbilities = JsonConvert.DeserializeObject <Dictionary <string, SearchPokemonAbility> >(File.ReadAllText(PokemonAbilitiesFile)); } else { _log.Warn(PokemonAbilitiesFile + " is missing. Pokemon abilities not loaded."); } //joke commands if (File.Exists("data/wowjokes.json")) { WowJokes = JsonConvert.DeserializeObject <List <WoWJoke> >(File.ReadAllText("data/wowjokes.json")); } else { _log.Warn("data/wowjokes.json is missing. WOW Jokes are not loaded."); } if (File.Exists("data/magicitems.json")) { MagicItems = JsonConvert.DeserializeObject <List <MagicItem> >(File.ReadAllText("data/magicitems.json")); } else { _log.Warn("data/magicitems.json is missing. Magic items are not loaded."); } }
/// <summary> /// Initializes a new instance of the <see cref="AppFabricCache"/> class. /// </summary> /// <param name="dataCache">The data cache.</param> public AppFabricCache(IDataCache dataCache) { cache = dataCache; }
public ConfigSeed(IDataCache cache, ISettings settings) { _cache = cache; _settings = settings; }
public WaifuService(DbService db, ICurrencyService cs, IBotConfigProvider bc, IDataCache cache) { _db = db; _cs = cs; _bc = bc; _cache = cache; _log = LogManager.GetCurrentClassLogger(); }
public StatsService(DiscordClient client, CommandHandler cmdHandler, Core creds, Core nadeko, IDataCache cache) { _client = client; _creds = creds; _redis = cache.Redis; _started = DateTime.UtcNow; _client.MessageReceived += _ => Task.FromResult(Interlocked.Increment(ref _messageCounter)); cmdHandler.CommandExecuted += (_, e) => Task.FromResult(Interlocked.Increment(ref _commandsRan)); _client.ChannelCreated += (c) => { var _ = Task.Run(() => { if (c is ITextChannel) { Interlocked.Increment(ref _textChannels); } else if (c is IVoiceChannel) { Interlocked.Increment(ref _voiceChannels); } }); return(Task.CompletedTask); }; _client.ChannelDestroyed += (c) => { var _ = Task.Run(() => { if (c is ITextChannel) { Interlocked.Decrement(ref _textChannels); } else if (c is IVoiceChannel) { Interlocked.Decrement(ref _voiceChannels); } }); return(Task.CompletedTask); }; _client.GuildAvailable += (g) => { var _ = Task.Run(() => { var tc = g.Channels.Count(cx => cx is ITextChannel); var vc = g.Channels.Count - tc; Interlocked.Add(ref _textChannels, tc); Interlocked.Add(ref _voiceChannels, vc); }); return(Task.CompletedTask); }; _client.JoinedGuild += (g) => { var _ = Task.Run(() => { var tc = g.Channels.Count(cx => cx is ITextChannel); var vc = g.Channels.Count - tc; Interlocked.Add(ref _textChannels, tc); Interlocked.Add(ref _voiceChannels, vc); }); return(Task.CompletedTask); }; _client.GuildUnavailable += (g) => { var _ = Task.Run(() => { var tc = g.Channels.Count(cx => cx is ITextChannel); var vc = g.Channels.Count - tc; Interlocked.Add(ref _textChannels, -tc); Interlocked.Add(ref _voiceChannels, -vc); }); return(Task.CompletedTask); }; _client.GuildDeleted += (g) => { var _ = Task.Run(() => { var tc = g.Channels.Count(cx => cx is ITextChannel); var vc = g.Channels.Count - tc; Interlocked.Add(ref _textChannels, -tc); Interlocked.Add(ref _voiceChannels, -vc); }); return(Task.CompletedTask); }; if (_client.ShardId == 0) { _carbonitexTimer = new Timer(async(state) => { if (string.IsNullOrWhiteSpace(_creds.CarbonKey)) { return; } try { using (var http = new HttpClient()) { using (var content = new FormUrlEncodedContent( new Dictionary <string, string> { { "servercount", nadeko.GuildCount.ToString() }, { "key", _creds.CarbonKey } })) { content.Headers.Clear(); content.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); await http.PostAsync("https://www.carbonitex.net/discord/data/botdata.php", content).ConfigureAwait(false); } } } catch { // ignored } }, null, TimeSpan.FromHours(1), TimeSpan.FromHours(1)); var platform = "other"; if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { platform = "linux"; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { platform = "osx"; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { platform = "windows"; } _dataTimer = new Timer(async(state) => { try { using (var http = new HttpClient()) { using (var content = new FormUrlEncodedContent( new Dictionary <string, string> { { "id", string.Concat(MD5.Create().ComputeHash(Encoding.ASCII.GetBytes(_creds.ClientId.ToString())).Select(x => x.ToString("X2"))) }, { "guildCount", nadeko.GuildCount.ToString() }, { "version", BotVersion }, { "platform", platform } })) { content.Headers.Clear(); content.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); await http.PostAsync("https://selfstats.nadekobot.me/", content).ConfigureAwait(false); } } } catch { // ignored } }, null, TimeSpan.FromSeconds(1), TimeSpan.FromHours(1)); } }
public DeletePatientDataAccess() { conn = KernelInjection.GetService<IConnectionInformation>(); dataCache = KernelInjection.GetService<IDataCache>(); }
public CustomerRepository(IServiceProvider locator, IDatabaseQuery query, IEagerNotification Notifications, IDataCache <global::UseCase1.Customer> DataCache) { this.Locator = locator; this.DatabaseQuery = query; this.Notifications = Notifications; this.DataCache = DataCache; }
public CoinFlipCommands(IDataCache data, ICurrencyService cs, DbService db) { _images = data.LocalImages; _cs = cs; _db = db; }
public MockCwsDesignClient(IWebRequest gracefulClient, IConfigurationStore configuration, ILoggerFactory logger, IDataCache dataCache, IServiceResolution serviceResolution) : base(gracefulClient, configuration, logger, dataCache, serviceResolution) { }
static void Main(string[] args) { Console.WriteLine("Hello World!"); //测试因子及设置 Console.WriteLine("测试因子及设置:"); DateTime dtBase = DateTime.Now; IData_Factor poFactor = new Data_Factor("Factor_001", "Sdssf", "测试因子", "测试标准"); IDataCache_Set poDataCache_Set = new DataCache_Set("", dtBase, typeTimeFrequency.None, 0, poFactor); //测试 DataCache Console.WriteLine("测试 DataCache:"); DataCache <int> dataCache0 = new DataCache <int>("int002", typeTimeFrequency.Hour, 12, poDataCache_Set); dataCache0.Init(dtBase); dataCache0.SetData(dtBase, 10); dataCache0.SetData(dtBase.AddHours(1), 10); DataCache <Data_Iot <string> > dataCache2 = new DataCache <Data_Iot <string> >("Data_Iot001", typeTimeFrequency.Minute_1, 60, poDataCache_Set); dataCache2.Init(dtBase); dataCache2.SetData(dtBase, new Data_Iot <string>(dtBase, "10")); dataCache2.SetData(dtBase.AddMinutes(1), new Data_Iot <string>(dtBase.AddMinutes(1), "11")); dataCache2.SetData(dtBase.AddMinutes(5), new Data_Iot <string>(dtBase.AddMinutes(5), "15")); //测试 IDataCaches Console.WriteLine("测试 DataCaches:"); IDataCaches dataCaches = new DataCaches(poFactor, poDataCache_Set); dataCaches.InitDataCache <int>("int002", typeTimeFrequency.Day, 6); dataCaches.InitDataCache <Data_Iot <string> >("Data_Iot002", typeTimeFrequency.Hour, 24); IDataCache <Data_Iot <string> > poDataCache2 = dataCaches.GetDataCache <Data_Iot <string> >("Data_Iot001", typeTimeFrequency.Minute_1); //测试 IDataCaches_Manage Console.WriteLine("测试 IDataCaches_Manage:"); IData_Factors poFactors = new Data_Factors("Factors_001", "Sdssf", "测试因子", "测试标准"); IDataCaches_Manage dataCaches_Manage = new DataCaches_Manage(poFactors, poDataCache_Set); dataCaches_Manage.InitDataCache <int>(poFactor, "manage001", typeTimeFrequency.Day, 7); dataCaches_Manage.SetData <int>(poFactor, "manage001", dtBase, 11, typeTimeFrequency.Day); int data = dataCaches_Manage.GetData <int>(poFactor, "manage001", dtBase, typeTimeFrequency.Day); //测试 DataCaches_Manager Console.WriteLine("测试 DataCaches_Manager:"); DataCaches_Manager dataCaches_Manager = new DataCaches_Manager(); dataCaches_Manager.Init(dtBase); dataCaches_Manager.InitDataCache <int>(poFactors, poFactor, "manage001", typeTimeFrequency.Day, 3); IData_Factors poFactors2 = new Data_Factors("Factors_002", "Nosdfsf", "测试因子2", "测试标准2"); IData_Factor poFactor2 = new Data_Factor("Factor_002", "Sdssf02", "测试因子", "测试标准"); IData_Factor poFactor3 = new Data_Factor("Factor_003", "Sdssf03", "测试因子", "测试标准"); dataCaches_Manager.InitDataCache <Data_Iot <int> >(poFactors2, poFactor2, "manage002", typeTimeFrequency.Hour, 12); dataCaches_Manager.InitDataCache <Data_Iot <int> >(poFactors2, poFactor2, "manage002", typeTimeFrequency.Minute_1, 5); //测试 DataCheck_Test --缓存数据对象 IDataCheck_Msger poMsger = new DataCheck_Msger_Test(false, 0); IDataCaches poDataCaches = dataCaches_Manager.GetDataCaches(poFactors2, poFactor2); IDataCache <Data_Iot <int> > poDataCache = poDataCaches.GetDataCache <Data_Iot <int> >("manage002", typeTimeFrequency.Hour); IDataChecks poDataChecks = new DataChecks_Test(poDataCache.ID, poDataCache, null, poMsger); poDataCache.InitDataChecks(poDataChecks); IDataCheck <Data_Iot <int> > poDataCheck = new DataCheck_Test <Data_Iot <int> >(poDataCache.ID, poDataCache); poDataChecks.InitDataCheck <Data_Iot <int> >(poDataCheck.Tag, poDataCheck, true); dataCaches_Manager.SetData <Data_Iot <int> >(poFactors2, poFactor2, "manage002", dtBase.AddHours(1), new Data_Iot <int>(dtBase, 11), typeTimeFrequency.Hour); //测试 DataCheck_Test --缓存数据集对象 IDataChecks poDataChecks2 = new DataChecks_Test(poDataCaches.ID + "_2", poDataCaches); IDataCheck <Data_Iot <int> > poDataCheck2 = new DataCheck_Tests <Data_Iot <int> >(poDataCache.ID + "_2", poDataCache); poDataCaches.InitDataChecks(poDataChecks2); poDataCaches.InitDataCheck <Data_Iot <int> >(poDataCheck2.Tag, poDataCheck2); poDataChecks.InitDataChecks(poDataChecks2); //设置因子的上级联动IDataChecks dataCaches_Manager.SetData <Data_Iot <int> >(poFactors2, poFactor2, "manage002", dtBase.AddHours(1), new Data_Iot <int>(dtBase, 9), typeTimeFrequency.Hour); //测试 DataCheck_Test --缓存数据集管理对象 IDataChecks poDataChecks3 = new DataChecks_Test(poDataCaches.ID + "_3", poDataCaches); IDataCheck <Data_Iot <int> > poDataCheck3 = new DataCheck_TestM <Data_Iot <int> >(poDataCache.ID + "_3", poDataCache); IDataCaches_Manage poDataCaches_Manage = dataCaches_Manager.GetDataCaches_Manage(poFactors2); poDataCaches_Manage.InitDataChecks(poDataChecks3); poDataChecks3.InitDataCheck(poDataCheck3.Tag, poDataCheck3); poDataChecks2.InitDataChecks(poDataChecks3); //设置因子集的上级联动IDataChecks dataCaches_Manager.SetData <Data_Iot <int> >(poFactors2, poFactor2, "manage002", dtBase.AddHours(1), new Data_Iot <int>(dtBase, 5), typeTimeFrequency.Hour); Data_Iot <int> pp = dataCaches_Manager.GetData <Data_Iot <int> >(poFactors2, poFactor2, "manage002", dtBase.AddHours(1), typeTimeFrequency.Hour); //压力测试 数据初始建议用 InitDatas 避免历史数据判断 Console.WriteLine("测试 Stress testing!\n"); Console.WriteLine("测试 初始:"); DataCaches_Manager manager = new DataCaches_Manager(); manager.Init(dtBase); DateTime dtStart0 = DateTime.Now; int factorsNums = 2000; int factorNums = 10; int factorTagNums = 5; int cachesNums = 10; int nsum0 = 0; for (int i = 0; i < factorsNums; i++) { IData_Factors pFactors = new Data_Factors("TestFactors_" + i.ToString(), "Factors_" + i.ToString(), i.ToString(), i.ToString()); for (int j = 0; j < factorNums; j++) { IData_Factor pFactor = new Data_Factor("TestFactor_" + j.ToString(), "Factor_" + j.ToString(), j.ToString(), j.ToString()); for (int k = 0; k < factorTagNums; k++) { manager.InitDataCache <Data_Iot <int> >(pFactors, pFactor, k.ToString(), typeTimeFrequency.Minute_1, cachesNums); for (int kk = 0; kk < cachesNums; kk++) { Data_Iot <int> pData = new Data_Iot <int>(dtBase.AddMinutes(-kk), -kk); manager.SetData <Data_Iot <int> >(pFactors, pFactor, k.ToString(), pData.Time, pData, typeTimeFrequency.Minute_1); nsum0++; } } } } DateTime dtEnd0 = DateTime.Now; Console.WriteLine(string.Format("测试 初始耗时: {0} s. {1}个, 频率 {2} 万/s", (dtEnd0 - dtStart0).TotalSeconds, nsum0, nsum0 / 10000 / (dtEnd0 - dtStart0).TotalSeconds)); Console.WriteLine("测试 赋值:"); DateTime dtStart1 = DateTime.Now; int nsum = 0, nStep = 1, nStpes = 10; for (int step = 0; step < nStpes; step++) { for (int i = 0; i < factorsNums; i++) { for (int j = 0; j < factorNums; j++) { for (int k = 0; k < factorTagNums; k++) { for (int kk = 0; kk < cachesNums; kk++) { Data_Iot <int> pData = new Data_Iot <int>(dtBase.AddMinutes(nStep), nStep); manager.SetData <Data_Iot <int> >("TestFactors_" + i.ToString(), "TestFactor_" + j.ToString(), k.ToString(), pData.Time, pData, typeTimeFrequency.Minute_1); nsum++; } } } } } nStep++; DateTime dtEnd1 = DateTime.Now; Console.WriteLine(string.Format("测试 赋值耗时: {0} s. {1}个, 频率 {2} 万/s", (dtEnd1 - dtStart1).TotalSeconds, nsum, nsum / 10000 / (dtEnd1 - dtStart1).TotalSeconds)); Console.WriteLine("测试 ended!"); //DatasCache_Manage_Iot<float> manager = new DatasCache_Manage_Iot<float>(DateTime.Now, (float)-1001.0001); //for (int i = 0; i < 10000; i++) //{ // manager.Init(i.ToString(), (float)-1001.0001); //} //// 模拟值(载入旧的) //IDataCache_Manage<float> datas = manager.GetData("1"); //IDatas_Iot<float> data = datas.GetDatas(typeTimeFrequency.Hour); //DateTime dt = data.DataSet_TypeTime.Time_Start; //for (int i = 0; i < data.DataSet_TypeTime.Sum_Step + 2; i++) //{ // data.SetData(dt.AddHours(i), i); //} //Dictionary<int, IotDatas_Manage> datas = new Dictionary<int, IotDatas_Manage>(); //for (int i = 0; i < 1; i++) //{ // IotDatas_Manage manage = new IotDatas_Manage(); // manage.Init(); // datas.Add(i, manage); //} }
public FileImportV6Proxy(IWebRequest webRequest, IConfigurationStore configurationStore, ILoggerFactory logger, IDataCache dataCache, IServiceResolution serviceResolution) : base(webRequest, configurationStore, logger, dataCache, serviceResolution) { }
/// <summary> /// Creates a new MainViewModel. /// </summary> public MainViewModel(IDataCache cache, INewsService feedsService, INavigationService navigationService) : base(cache) { _feedsService = feedsService; _navigationService = navigationService; }
public SlotCommands(IDataCache data, ICurrencyService cs) { _images = data.LocalImages; _cs = cs; }
public HomeController(IDataCache dataCache) { this.cache = dataCache; }
public StreamNotificationService(DbService db, DiscordSocketClient client, IBotStrings strings, IDataCache cache, IBotCredentials creds, IHttpClientFactory httpFactory, NadekoBot bot) { _db = db; _client = client; _strings = strings; _multi = cache.Redis; _creds = creds; _streamTracker = new NotifChecker(httpFactory, cache.Redis, creds.RedisKey(), client.ShardId == 0); using (var uow = db.GetDbContext()) { var ids = client.GetGuildIds(); var guildConfigs = uow._context.Set <GuildConfig>() .AsQueryable() .Include(x => x.FollowedStreams) .Where(x => ids.Contains(x.GuildId)) .ToList(); _offlineNotificationServers = new ConcurrentHashSet <ulong>(guildConfigs .Where(gc => gc.NotifyStreamOffline) .Select(x => x.GuildId) .ToList()); var followedStreams = guildConfigs .SelectMany(x => x.FollowedStreams) .ToList(); _shardTrackedStreams = followedStreams .GroupBy(x => new { Type = x.Type, Name = x.Username.ToLower() }) .ToList() .ToDictionary( x => new StreamDataKey(x.Key.Type, x.Key.Name.ToLower()), x => x.GroupBy(y => y.GuildId) .ToDictionary(y => y.Key, y => y.AsEnumerable().ToHashSet())); // shard 0 will keep track of when there are no more guilds which track a stream if (client.ShardId == 0) { var allFollowedStreams = uow._context.Set <FollowedStream>() .AsQueryable() .ToList(); foreach (var fs in allFollowedStreams) { _streamTracker.CacheAddData(fs.CreateKey(), null, replace: false); } _trackCounter = allFollowedStreams .GroupBy(x => new { Type = x.Type, Name = x.Username.ToLower() }) .ToDictionary( x => new StreamDataKey(x.Key.Type, x.Key.Name), x => x.Select(fs => fs.GuildId).ToHashSet()); } } var sub = _multi.GetSubscriber(); sub.Subscribe($"{_creds.RedisKey()}_streams_offline", HandleStreamsOffline); sub.Subscribe($"{_creds.RedisKey()}_streams_online", HandleStreamsOnline); if (client.ShardId == 0) { // only shard 0 will run the tracker, // and then publish updates with redis to other shards _streamTracker.OnStreamsOffline += OnStreamsOffline; _streamTracker.OnStreamsOnline += OnStreamsOnline; _ = _streamTracker.RunAsync(); _notifCleanupTimer = new Timer(_ => { try { var errorLimit = TimeSpan.FromHours(12); var failingStreams = _streamTracker.GetFailingStreams(errorLimit, true) .ToList(); if (!failingStreams.Any()) { return; } var deleteGroups = failingStreams.GroupBy(x => x.Type) .ToDictionary(x => x.Key, x => x.Select(x => x.Name).ToList()); using (var uow = _db.GetDbContext()) { foreach (var kvp in deleteGroups) { Log.Information($"Deleting {kvp.Value.Count} {kvp.Key} streams because " + $"they've been erroring for more than {errorLimit}: {string.Join(", ", kvp.Value)}"); var toDelete = uow._context.Set <FollowedStream>() .AsQueryable() .Where(x => x.Type == kvp.Key && kvp.Value.Contains(x.Username)) .ToList(); uow._context.RemoveRange(toDelete); uow.SaveChanges(); foreach (var loginToDelete in kvp.Value) { _streamTracker.UntrackStreamByKey(new StreamDataKey(kvp.Key, loginToDelete)); } } } } catch (Exception ex) { Log.Error("Error cleaning up FollowedStreams"); Log.Error(ex.ToString()); } }, null, TimeSpan.FromMinutes(30), TimeSpan.FromMinutes(30)); sub.Subscribe($"{_creds.RedisKey()}_follow_stream", HandleFollowStream); sub.Subscribe($"{_creds.RedisKey()}_unfollow_stream", HandleUnfollowStream); } bot.JoinedGuild += ClientOnJoinedGuild; client.LeftGuild += ClientOnLeftGuild; }
public AppVariables(ISettingsProvider settingsProvider, IDataCache dataCache = null) : base(settingsProvider, dataCache) { }
public AiringInfoProvider(IDataCache dataCache, IApplicationDataService applicationDataService) { _dataCache = dataCache; _applicationDataService = applicationDataService; }
/// <summary> /// Initializes a new instance of the <see cref="AppFabricCache"/> class. /// </summary> /// <param name="name">The name.</param> /// <param name="dataCacheFactory">The data cache factory.</param> public AppFabricCache(string name, IDataCacheFactory dataCacheFactory) : base() { cache = dataCacheFactory.GetCache(name); }
public PokemonSearchCommands(IDataCache cache) { _cache = cache; }
public static void RegisterDataCacheAdapter(IDataCache dataCache) { SimpleIoc.Default.Register<IDataCache>(() => dataCache); }
public async Task <ReadOnlyCollection <PeriodisedRequiredPaymentEvent> > HandleEarningEvent(TEarningEvent earningEvent, IDataCache <PaymentHistoryEntity[]> paymentHistoryCache, CancellationToken cancellationToken) { if (earningEvent == null) { throw new ArgumentNullException(nameof(earningEvent)); } try { var result = new List <PeriodisedRequiredPaymentEvent>(); var cachedPayments = await paymentHistoryCache.TryGet(CacheKeys.PaymentHistoryKey, cancellationToken); var academicYearPayments = cachedPayments.HasValue ? cachedPayments.Value .Where(p => p.LearnAimReference == earningEvent.LearningAim.Reference) .Select(p => mapper.Map <PaymentHistoryEntity, Payment>(p)) .ToList() : new List <Payment>(); foreach (var(period, type) in GetPeriods(earningEvent)) { if (period.Period > earningEvent.CollectionPeriod.Period) // cut off future periods { continue; } if (period.Amount != 0 && !period.SfaContributionPercentage.HasValue) { throw new InvalidOperationException("Non-zero amount with no Sfa Contribution"); } var payments = academicYearPayments.Where(payment => payment.DeliveryPeriod == period.Period && payment.TransactionType == type) .ToList(); List <RequiredPayment> requiredPayments; var holdBackCompletionPayments = false; if (NegativeEarningWillResultInARefund(period, payments)) { requiredPayments = negativeEarningService .ProcessNegativeEarning(period.Amount, academicYearPayments, period.Period, period.PriceEpisodeIdentifier); } else { var earning = new Earning { Amount = period.Amount, SfaContributionPercentage = period.SfaContributionPercentage, EarningType = GetEarningType(type), PriceEpisodeIdentifier = period.PriceEpisodeIdentifier, AccountId = period.AccountId, TransferSenderAccountId = period.TransferSenderAccountId }; requiredPayments = requiredPaymentProcessor.GetRequiredPayments(earning, payments); if (requiredPayments.Count > 0) { holdBackCompletionPayments = await HoldBackCompletionPayments(earningEvent, earning, type, cancellationToken).ConfigureAwait(false); } } if (requiredPayments.Sum(x => x.Amount) == 0) { continue; } foreach (var requiredPayment in requiredPayments) { var requiredPaymentEvent = CreateRequiredPaymentEvent(requiredPayment.EarningType, type, holdBackCompletionPayments); mapper.Map(period, requiredPaymentEvent); mapper.Map(earningEvent, requiredPaymentEvent); mapper.Map(requiredPayment, requiredPaymentEvent); AddRefundCommitmentDetails(requiredPayment, requiredPaymentEvent); var priceEpisodeIdentifier = requiredPaymentEvent.PriceEpisodeIdentifier; if (earningEvent.PriceEpisodes != null && earningEvent.PriceEpisodes.Any()) { var priceEpisode = earningEvent.PriceEpisodes.Count == 1 ? earningEvent.PriceEpisodes.FirstOrDefault() : earningEvent.PriceEpisodes?.SingleOrDefault(x => x.Identifier == priceEpisodeIdentifier); mapper.Map(priceEpisode, requiredPaymentEvent); if (requiredPaymentEvent.LearningAim != null) { mapper.Map(priceEpisode, requiredPaymentEvent.LearningAim); } } result.Add(requiredPaymentEvent); } } return(result.AsReadOnly()); } catch (Exception e) { paymentLogger.LogError($"Error while Handling EarningEvent for {earningEvent.Ukprn} ", e); throw; } }
public RecordFlushUpdate(IDataCache cache, IStorageCommands storageCommands) { _cache = cache; _storageCommands = storageCommands; }
public DrawCommands(IDataCache data) { _images = data.LocalImages; }
/// <summary> /// Initializes a new instance of the <see cref="YafDBBroker"/> class. /// </summary> /// <param name="serviceLocator"> /// The service locator. /// </param> /// <param name="httpSessionState"> /// The http session state. /// </param> /// <param name="dataCache"> /// The data cache. /// </param> public YafDBBroker(IServiceLocator serviceLocator, HttpSessionStateBase httpSessionState, IDataCache dataCache) { this.ServiceLocator = serviceLocator; this.HttpSessionState = httpSessionState; this.DataCache = dataCache; }
public BotConfigProvider(DbService db, BotConfig bc, IDataCache cache) { _db = db; _cache = cache; BotConfig = bc; }
/// <summary> /// Prepare notification class with advanced features /// </summary> /// <param name="fieldsName">List of field name that you want in the data cache (use to recreate data)</param> /// <param name="dataCache">Class call one time to load a previous data save in your database</param> /// <param name="autoFilter">Activate auto filter function. Remove bad data like data with date in the future or not order</param> /// <param name="fixMoving">Activate function to detect when a unit move or not.This information is send by the unit but can be not correct in some case</param> public void Initialize(string[] fieldsName, IDataCache dataCache, bool autoFilter = true, bool fixMoving = false) { if (fieldsName != null && fieldsName.Length > 0) { _fieldsCache.Clear(); _fieldsUse = fieldsName; _dataCache = dataCache; } _autoFilter = autoFilter; _fixMoving = fixMoving; }
/// <summary> /// Initializes a new instance of the <see cref="DataConfiguration"/> class. /// </summary> /// <param name="providerFactory">The database provider factory.</param> /// <param name="connectionString">The database connection string.</param> /// <param name="logger">The logger.</param> /// <param name="cache">The data cache manager.</param> public DataConfiguration(DbProviderFactory providerFactory, string connectionString, IDataCache cache = null, Action <string> logger = null) { ProviderFactory = providerFactory; ConnectionString = connectionString; Logger = logger; DataCache = cache; }