public void Save(MetaAccount entity) { if (!WebResourceAccountIdValidator.IsValidAccountId(entity.WebResourceId, entity.AccountId)) { throw this.ValidationException(e => e.AccountId, "Invalid."); } MetaAccountRepository.Save(entity); }
public void Set(long webResourceId, string accountId) { if (!WebResourceRepository.Any(r => r.Id == webResourceId)) { throw new ArgumentException("Not exist.", nameof(webResourceId)); } var validAccountId = WebResourceAccountIdValidator.GetValidAccountId(webResourceId, accountId); if (validAccountId == null) { throw new ArgumentException("Invalid.", nameof(accountId)); } var personId = MetaAccountRepository.FirstOrDefault( a => a.AccountId == validAccountId && a.WebResourceId == webResourceId, a => a.PersonId); if (personId == 0) { var person = new Person(); PersonService.Save(person); UnitOfWork.Commit(); personId = person.Id; var account = new MetaAccount { PersonId = personId, Type = MetaType.Created, AccountId = validAccountId, WebResourceId = webResourceId }; MetaAccountService.Save(account); UnitOfWork.Commit(); } if (WatchRepository.Any(w => w.PersonId == personId && w.WebResourceId == webResourceId)) { return; } Save(new Watch { PersonId = personId, WebResourceId = webResourceId }); }
public void FetchOnline(IEnumerable <long> personIds) { if (personIds == null) { throw new ArgumentNullException(nameof(personIds)); } if (personIds.Count() > MaxStackSize) { throw new ArgumentException($"Maximum count is \"{MaxStackSize}\".", nameof(personIds)); } var webResourceId = WebResourceRepository.Single(r => r.Uuid == WebResourceUuids.Vk, r => r.Id); var providerId = PersonMetaProviderRepository.Single(p => p.Uuid == PersonMetaProviderUuid, p => p.Id); var personAccountDict = MetaAccountRepository.Select(a => a.WebResourceId == webResourceId && personIds.Contains(a.PersonId)) .GroupBy(a => a.PersonId) .ToDictionary(g => g.Key, g => g.Select(a => a.AccountId)); var allAccountIds = personAccountDict.SelectMany(pa => pa.Value).ToArray(); var accountOnlineSnapshotDict = VkApiConnector.FetchOnlineSnapshots(allAccountIds).Result; foreach (var accountSnapshot in accountOnlineSnapshotDict) { var personId = personAccountDict.First(p => p.Value.Any(a => a == accountSnapshot.Key)).Key; var onlineSnapshots = accountOnlineSnapshotDict[accountSnapshot.Key]; foreach (var onlineSnapshot in onlineSnapshots) { var todayOnlineDataSnapshot = MetaDataSnapshotRepository.GetOrFetchDataSnapshot(providerId, personId, accountSnapshot.Key, onlineSnapshot.Time, (int)VkSnapshotType.Online); var snapshots = todayOnlineDataSnapshot.GetSnapshots <VkOnlineSnapshot>().Append(onlineSnapshot).ToArray(); todayOnlineDataSnapshot.SetSnapshots(snapshots); MetaDataSnapshotRepository.Save(todayOnlineDataSnapshot); } } UnitOfWork.Commit(); }
public void Delete(long id) { MetaAccountRepository.Delete(id); }