Esempio n. 1
0
        public AggregatorTemplate(SporeServerAggregator aggregator, int subscriberCount)
        {
            // <feed />
            //
            var document = AtomFeedBuilder.CreateDocument("feed");

            // <id />
            AtomFeedBuilder.AddCustomElement(document, "id", $"tag:spore.com,2006:aggregator/{aggregator.AggregatorId}");
            // <title />
            AtomFeedBuilder.AddCustomElement(document, "title", $"{aggregator.Name}");
            // <updated />
            AtomFeedBuilder.AddCustomElement(document, "updated", $"{XmlConvert.ToString(aggregator.Timestamp, XmlDateTimeSerializationMode.Utc)}");
            // <subtitle />
            AtomFeedBuilder.AddCustomElement(document, "subtitle", $"{aggregator.Description}");
            // <author />
            AtomFeedBuilder.AddAuthorElement(document, $"{aggregator.Author.UserName}", $"{aggregator.Author.Id}");
            // <subcount />
            AtomFeedBuilder.AddCustomElement(document, "subcount", $"{subscriberCount}");
            // <link />
            AtomFeedBuilder.AddLinkElement(document, "self", $"https://www.spore.com/pollinator/atom/aggregator/{aggregator.AggregatorId}", null, null);

            // add assets to feed
            SporeAtomFeedHelper.AddAssetsToFeed(document, aggregator.Assets.ToArray());

            // save xml
            _xml = document.OuterXml;
        }
        public async Task <SporeServerAggregator> AddAsync(SporeServerUser author, string name, string description, SporeServerAsset[] assets)
        {
            try
            {
                var aggregator = new SporeServerAggregator()
                {
                    Name        = name,
                    Description = description,
                    Timestamp   = DateTime.Now,
                    Author      = author,
                    Assets      = assets
                };

                // add aggregator to database
                await _context.Aggregators.AddAsync(aggregator);

                await _context.SaveChangesAsync();

                _logger.LogInformation($"AddAsync: Added Aggregator {aggregator.AggregatorId} For User {aggregator.Author.Id}");
                return(aggregator);
            }
            catch (Exception e)
            {
                _logger.LogError($"AddAsync: Failed To Add Aggregator: {e}");
                return(null);
            }
        }
 public async Task <Int32> GetSubscriberCountAsync(SporeServerAggregator aggregator)
 {
     try
     {
         return(await _context.AggregatorSubscriptions
                .Where(a => a.AggregatorId == aggregator.AggregatorId)
                .CountAsync());
     }
     catch (Exception e)
     {
         _logger.LogError($"GetSubscriberCount: Failed To Get Subscriber Count For {aggregator.AggregatorId}: {e}");
         return(0);
     }
 }
        public async Task <bool> UpdateAsync(SporeServerAggregator aggregator)
        {
            try
            {
                // update aggregator from database
                _context.Aggregators.Update(aggregator);
                await _context.SaveChangesAsync();

                _logger.LogInformation($"UpdateAsync: Updated Aggregator {aggregator.AggregatorId}");
                return(true);
            }
            catch (Exception e)
            {
                _logger.LogError($"UpdateAsync: Failed To Update Aggregator {aggregator.AggregatorId}: {e}");
                return(false);
            }
        }
        public async Task <bool> AddAsync(SporeServerUser author, SporeServerAggregator aggregator)
        {
            try
            {
                var subscription = new SporeServerAggregatorSubscription()
                {
                    Author     = author,
                    Aggregator = aggregator
                };

                // add subscription to database
                await _context.AggregatorSubscriptions.AddAsync(subscription);

                await _context.SaveChangesAsync();

                _logger.LogInformation($"AddAsync: Added Subscription {subscription.SubscriptionId} For User {author.Id}");
                return(true);
            }
            catch (Exception e)
            {
                _logger.LogError($"AddAsync: Failed To Add Subscription: {e}");
                return(false);
            }
        }
Esempio n. 6
0
 public async Task <Int32> GetSubscriberCountAsync(SporeServerAggregator aggregator)
 {
     return(await _aggregatorSubscriptionManager.GetSubscriberCountAsync(aggregator));
 }
 public async Task <SporeServerAggregatorSubscription> FindAsync(SporeServerUser author, SporeServerAggregator aggregator)
 {
     try
     {
         return(await _context.AggregatorSubscriptions
                .Where(s => s.AuthorId == author.Id &&
                       s.AggregatorId == aggregator.AggregatorId)
                .FirstOrDefaultAsync());
     }
     catch (Exception e)
     {
         _logger.LogError($"FindAsync: Failed To Find Subscription: {e}");
         return(null);
     }
 }