public bool IsUserBanned(SectionId sectionId, long userId, string userIp, string browserName) { KeyValueRepository commonRepository = _repositoryCache.GetCommonRepository(); UserBanInfo existingBanInfo; if (IdValidator.IsValid(userId)) { string userKey = GetUserKey(userId); existingBanInfo = GetUserBanInfo(commonRepository, userKey); if (existingBanInfo != null && existingBanInfo.IsBannedSection(sectionId)) { return(true); } } string anonymousKey = GetAnonymousUserKey(userIp, browserName); existingBanInfo = GetUserBanInfo(commonRepository, anonymousKey); if (existingBanInfo != null && existingBanInfo.IsBannedSection(sectionId)) { return(true); } return(false); }
public VotingManagerTests() { string dir = TestBase.CreateTestDir(this); var keyValueRepo = new KeyValueRepository(dir, new DBreezeSerializer(this.network)); this.votingManager = new VotingManager(this.federationManager, this.loggerFactory, keyValueRepo, this.slotsManager); }
private static bool SetUserBanInfo(KeyValueRepository commonRepository, string key, Action <UserBanInfo> editor, UserBanInfo userBanInfo) { return(commonRepository.SyncSet(USER_BAN_INFO_TABLE, key, editor, () => userBanInfo)); }
public KeyValue UpdateKeyValue(KeyValue keyValue) { var result = KeyValueRepository.Update(keyValue); Context.SaveChanges(); return(result); }
public KeyValue DeleteKeyValue(KeyValue keyValue) { var result = KeyValueRepository.Remove(keyValue); Context.SaveChanges(); return(result); }
public KeyValue AddKeyValue(KeyValue keyValue) { var result = KeyValueRepository.Add(keyValue); Context.SaveChanges(); return(result); }
public List <UserTask> GetTasks() { //var userRepository = _repositoryCache.GetUserRepository(_userId); KeyValueRepository commonRepository = _repositoryCache.GetCommonRepository(); List <List <CommonTaskInfo> > tasks = commonRepository.SelectAll <long, List <CommonTaskInfo> >(SORT_TASK_TABLE, SortOrder.Desc) ?? new List <List <CommonTaskInfo> >(); var result = new List <UserTask>(); //TODO: возвращать не все, а определенное кол-во //TODO: брать данные для текущего пользователя //NOTE: Distinct обеспечивается за счет перегрузки св-в в CommonTaskInfo foreach (CommonTaskInfo commonTaskInfo in tasks.SelectMany(e => e).Distinct()) { KeyValueRepository userRepository = _repositoryCache.GetUserRepository(commonTaskInfo.UserId); //var aaa = userRepository.SelectAll<string, UserTask>(TASK_TABLE); UserTask userTask = GetUserTask(userRepository, commonTaskInfo.Id); if (userTask != null && userTask.IsNotDeleted()) { result.Add(userTask); } } return(result); }
public SpeedyKvStore(string StoreName) { if (!Directory.Exists(Paths.DataDirectory)) { Directory.CreateDirectory(Paths.DataDirectory); } _coreRepository = new KeyValueRepository <object>(Paths.DataDirectory, StoreName); }
public TipsManagerTests() : base(KnownNetworks.StratisMain) { this.loggerFactory = new LoggerFactory(); string dir = CreateTestDir(this); this.keyValueRepo = new KeyValueRepository(dir, new DataStoreSerializer(this.Network.Consensus.ConsensusFactory)); this.tipsManager = new TipsManager(this.keyValueRepo, this.loggerFactory); this.mainChainHeaders = ChainedHeadersHelper.CreateConsecutiveHeaders(20, ChainedHeadersHelper.CreateGenesisChainedHeader(this.Network), true); }
public bool AddComment(string key, TaskComment comment) { KeyValueRepository userRepository = _repositoryCache.GetUserRepository(_userId); //TODO: проверить что такого коммента от этого же пользователя нет return(userRepository.SyncSet(COMMENT_TABLE, key, comments => comments.Insert(0, comment), () => new List <TaskComment> { comment })); }
private static bool SetEventInfo(KeyValueRepository commonRepository, string key, string @event) { return(commonRepository.SyncSet(USER_EVENT_INFO_TABLE, key, events => Register(@event, events), () => { var events = new Dictionary <string, Dictionary <string, long> >(); Register(@event, events); return events; })); }
public KeyValueRepository GetUserRepository(long userId) { //TODO: добавить кэширование репозитория для пользователя string fullPathName = GetFullPathName(_path, userId); KeyValueRepository repository = _usersRepository.GetOrAdd(userId, key => { var engine = new DBEngine(fullPathName); return(new KeyValueRepository(engine)); }); return(repository); }
private void LoadFuels() { List <KeyValue> listoffuels = KeyValueRepository.GetFuelTypes().ToList(); if (listoffuels.Count > 0) { cmb_fueltypes.DataSource = listoffuels; cmb_fueltypes.DisplayMember = "Name"; cmb_fueltypes.ValueMember = "Id"; cmb_fueltypes.SelectedIndex = 0; } }
private void LoadSessions(int dayid) { List <KeyValue> listoffuels = KeyValueRepository.GetSessions(dayid).ToList(); if (listoffuels.Count > 0) { cmb_sessions.DataSource = listoffuels; cmb_sessions.DisplayMember = "Name"; cmb_sessions.ValueMember = "Id"; cmb_sessions.SelectedIndex = 0; } }
private void LoadBanks() { List <KeyValue> listoffuels = KeyValueRepository.GetBanks().ToList(); if (listoffuels.Count > 0) { cmb_bank.DataSource = listoffuels; cmb_bank.DisplayMember = "Name"; cmb_bank.ValueMember = "Id"; cmb_bank.SelectedIndex = 0; } }
public static FederationManager CreateFederationManager(object caller, Network network, LoggerFactory loggerFactory) { string dir = TestBase.CreateTestDir(caller); var keyValueRepo = new KeyValueRepository(dir, new DBreezeSerializer(network)); var settings = new NodeSettings(network, args: new string[] { $"-datadir={dir}" }); var federationManager = new FederationManager(settings, network, loggerFactory, keyValueRepo); federationManager.Initialize(); return(federationManager); }
public KeyValueRepository GetCommonRepository() { if (_commonRepository == null) { lock (_syncRoot) { if (_commonRepository == null) { _commonRepository = new KeyValueRepository(new DBEngine(Path.Combine(_path, COMMON_FOLDER))); } } } return(_commonRepository); }
private void LoadDays() { List <KeyValue> listoffuels = KeyValueRepository.GetDays().ToList(); if (listoffuels.Count > 0) { cmb_days.DataSource = listoffuels; cmb_days.DisplayMember = "Name"; cmb_days.ValueMember = "Id"; cmb_days.SelectedIndex = 0; LoadSessions(commonFunctions.ToInt(cmb_days.SelectedValue.ToString())); } }
private void LoadPumper1() { List <KeyValue> listoffuels = KeyValueRepository.GetPumpers().ToList(); if (listoffuels.Count > 0) { cmb_pumperForcashcol.DataSource = listoffuels; cmb_pumperForcashcol.DisplayMember = "Name"; cmb_pumperForcashcol.ValueMember = "Id"; cmb_pumperForcashcol.SelectedIndex = 0; GetPumperSalesRecords(); } }
public List <TaskComment> GetComments(string key, int lastShowedComment) { KeyValueRepository userRepository = _repositoryCache.GetUserRepository(_userId); List <TaskComment> comments = userRepository.Select(COMMENT_TABLE, key, new List <TaskComment>()); var result = new List <TaskComment>(); int countComments = comments.Count; if (countComments > lastShowedComment) { result = comments.Take(countComments - lastShowedComment).ToList(); } return(result); }
public UserTask AddTask(UserTask userTask) { userTask.Id = _md5Helper.GetHash(userTask.Text); userTask.DeletedDate = 0; bool isAddedToCommon = AddToCommonTasks(userTask); KeyValueRepository userRepository = _repositoryCache.GetUserRepository(_userId); UserTask result = null; if (isAddedToCommon && userRepository.Set(TASK_TABLE, userTask.Id, userTask)) { result = userRepository.Select <string, UserTask>(TASK_TABLE, userTask.Id, null); } return(result); }
public UserTask GetTask(string key, bool fillComments) { KeyValueRepository userRepository = _repositoryCache.GetUserRepository(_userId); UserTask userTask = userRepository.Select <string, UserTask>(TASK_TABLE, key, null); if (userTask != null && !userTask.IsNotDeleted()) { //таск удален userTask = null; } if (userTask != null && fillComments) { List <TaskComment> comments = GetComments(key, 0); userTask.SetComments(comments); } return(userTask); }
public bool RemoveOrRestoreTask(string key, bool needRemove) { KeyValueRepository userRepository = _repositoryCache.GetUserRepository(_userId); //найти таск у текущего пользователя bool result = userRepository.SyncSet <string, UserTask>(TASK_TABLE, key, userTask => { if (needRemove && userTask.IsNotDeleted()) { userTask.DeletedDate = DateTime.Now.Ticks; } else if (!needRemove) { userTask.DeletedDate = 0; } }); return(result); }
private bool AddToCommonTasks(UserTask userTask) { KeyValueRepository commonRepository = _repositoryCache.GetCommonRepository(); var value = new CommonTaskInfo { Id = userTask.Id, UserId = _userId }; bool result = commonRepository.SyncSet(SORT_TASK_TABLE, userTask.CreationDate, dataByDate => dataByDate.Add(value), () => new List <CommonTaskInfo> { value }); return(result); }
public async Task FinalizedHeightSavedOnDiskAsync() { string dir = CreateTestDir(this); var kvRepo = new KeyValueRepository(dir, new DBreezeSerializer(this.Network)); using (var repo = new FinalizedBlockInfoRepository(kvRepo, this.loggerFactory)) { repo.SaveFinalizedBlockHashAndHeight(uint256.One, 777); } using (var repo = new FinalizedBlockInfoRepository(kvRepo, this.loggerFactory)) { await repo.LoadFinalizedBlockInfoAsync(this.Network); Assert.Equal(777, repo.GetFinalizedBlockInfo().Height); } }
public VotingManagerTests() { string dir = TestBase.CreateTestDir(this); var keyValueRepo = new KeyValueRepository(dir, new DBreezeSerializer(this.network)); this.resultExecutorMock = new Mock <IPollResultExecutor>(); this.encoder = new VotingDataEncoder(this.loggerFactory); this.changesApplied = new List <VotingData>(); this.changesReverted = new List <VotingData>(); this.resultExecutorMock.Setup(x => x.ApplyChange(It.IsAny <VotingData>())).Callback((VotingData data) => this.changesApplied.Add(data)); this.resultExecutorMock.Setup(x => x.RevertChange(It.IsAny <VotingData>())).Callback((VotingData data) => this.changesReverted.Add(data)); this.federationManager.SetPrivatePropertyValue(nameof(FederationManager.IsFederationMember), true); this.votingManager = new VotingManager(this.federationManager, this.loggerFactory, keyValueRepo, this.slotsManager, this.resultExecutorMock.Object); this.votingManager.Initialize(); }
private void LoadFuels() { try { List <KeyValue> listoffuels = KeyValueRepository.GetFuelTypes().ToList(); if (listoffuels.Count > 0) { cmb_fueltypes.DataSource = listoffuels; cmb_fueltypes.DisplayMember = "Name"; cmb_fueltypes.ValueMember = "Id"; cmb_fueltypes.SelectedIndex = 0; } } catch (Exception ex) { MessageBox.Show("Error Has found when loading data. Please forword following details to technical" + Environment.NewLine + "[" + ex.Message + Environment.NewLine + ex.Source + "]", Messaging.MessageCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public async Task CanQueryWithLimit() { var mappings = new KeyValueRepositoryMappings() .Map <Doc>("brokerage.docs"); var repo = new KeyValueRepository(ConnectionString, mappings); foreach (var i in Enumerable.Range(1, 10)) { await repo.DeleteAsync <Doc>(i.ToString("D5")); await repo.InsertAsync(i.ToString("D5"), new Doc { A = i.ToString("D5"), B = 123 }); } var all = (await repo.QueryAsync <Doc>(default, default, 5, true)).ToArray();
public void Reload() { if (_commonRepository != null) { lock (_syncRoot) { if (_commonRepository != null) { _commonRepository.Dispose(); _commonRepository = null; } } } foreach (var pair in _usersRepository) { pair.Value.Dispose(); } _usersRepository.Clear(); }
public async Task FinalizedHeightSavedOnDiskAsync() { string dir = CreateTestDir(this); var kvRepo = new KeyValueRepository(dir, new DBreezeSerializer(this.Network.Consensus.ConsensusFactory)); var asyncMock = new Mock <IAsyncProvider>(); asyncMock.Setup(a => a.RegisterTask(It.IsAny <string>(), It.IsAny <Task>())); using (var repo = new FinalizedBlockInfoRepository(kvRepo, this.loggerFactory, asyncMock.Object)) { repo.SaveFinalizedBlockHashAndHeight(uint256.One, 777); } using (var repo = new FinalizedBlockInfoRepository(kvRepo, this.loggerFactory, asyncMock.Object)) { await repo.LoadFinalizedBlockInfoAsync(this.Network); Assert.Equal(777, repo.GetFinalizedBlockInfo().Height); } }