Ejemplo n.º 1
0
        public void EnsureRegistered()
        {
            var webResourceId = WebResourceRepository.FirstOrDefault(r => r.Uuid == WebResourceUuids.Vk, r => r.Id);

            if (webResourceId == 0)
            {
                var resource = new WebResource
                {
                    Uuid     = WebResourceUuids.Vk,
                    Name     = WebResourceName,
                    Url      = WebResourceUrl,
                    ImageUrl = WebResourceImageUrl
                };

                WebResourceRepository.Save(resource);
                UnitOfWork.Commit();

                webResourceId = resource.Id;
            }

            var isProviderRegistered = PersonMetaProviderRepository.Any(r => r.Uuid == PersonMetaProviderUuid);

            if (!isProviderRegistered)
            {
                PersonMetaProviderRepository.Save(new PersonMetaProvider
                {
                    Uuid          = PersonMetaProviderUuid,
                    Name          = typeof(VkWatch).FullName,
                    WebResourceId = webResourceId
                });

                UnitOfWork.Commit();
            }
        }
Ejemplo n.º 2
0
        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();
        }