示例#1
0
        public ChannelContext(DbContextOptions <ChannelContext> options)
            : base(options)
        {
            Database.EnsureCreated();
            if (!Channels.Any())
            {
                Channels.Add(new Channel {
                    Name = "Great New Channel", UserId = 1, Date = DateTime.Now, Description = "Great and New"
                });
                Channels.Add(new Channel {
                    Name = "Not great Channel", UserId = 1, Date = DateTime.Now, Description = "not great at all"
                });

                SaveChanges();
            }

            if (!Subscriptions.Any())
            {
                Subscriptions.Add(new Subscription {
                    UserId = 2, ChannelId = 1
                });
                SaveChanges();
            }

            if (!ChannelImages.Any())
            {
                ChannelImages.Add(new ChannelImage {
                    ChannelId = 1, Description = "Hey guys, it's a great new channel", Date = DateTime.Now, ImageId = 1
                });
                SaveChanges();
            }
        }
        private async void AddChannelSubscriptionTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (YoutubeClient.TryParseChannelId(AddChannelSubscriptionTextBox.Text, out string channelId) && !Subscriptions.Any(x => x.ChannelId == channelId))
            {
                SubscriptionChannelId      = channelId;
                AddChannelButton.IsEnabled = true;
            }
            else if (YoutubeClient.TryParseUsername(AddChannelSubscriptionTextBox.Text, out string username))
            {
                try
                {
                    var client    = GlobalConsts.YoutubeClient;
                    var channelID = await client.GetChannelIdAsync(username);

                    if (!Subscriptions.Any(x => x.ChannelId == channelID))
                    {
                        SubscriptionChannelId      = channelID;
                        AddChannelButton.IsEnabled = true;
                    }
                    else
                    {
                        AddChannelButton.IsEnabled = false;
                    }
                }
                catch
                {
                    AddChannelButton.IsEnabled = false;
                }
            }

            else
            {
                AddChannelButton.IsEnabled = false;
            }
        }
        protected override async Task <bool> OnAuditedExecute(IReadWriteDataSource dataSource, IDbTransaction transaction, Jibberwock.DataModels.Security.Audit.EntryTypes.SynchroniseSubscription provisionalAuditTrailEntry)
        {
            if (Subscriptions.Any(s => s.Id == 0))
            {
                throw new ArgumentOutOfRangeException(nameof(Subscriptions), "Subscriptions.Id[] must always have values");
            }

            var subscriptionIdsParameter = (from subs in Subscriptions
                                            select new TableTypes.Products.Subscription(subs.Id))
                                           .AsTableValuedParameter("tenants.udt_Subscription");
            var databaseConnection = await dataSource.GetDbConnection();

            await databaseConnection.ExecuteAsync("tenants.usp_SyncSubscriptionsFromBillingProvider",
                                                  new
            {
                Subscription_External_Identifier = ExternalIdentifier,
                Status_ID = Status,
                Last_Invoice_External_Identifier = LatestInvoiceExternalIdentifier,
                Subscription_IDs = subscriptionIdsParameter
            }, transaction : transaction, commandType : CommandType.StoredProcedure, commandTimeout : 30);

            provisionalAuditTrailEntry.SubscriptionIds = Subscriptions.Select(s => s.Id);
            provisionalAuditTrailEntry.NewStatus       = Status;
            provisionalAuditTrailEntry.ExternalSubscriptionIdentifier  = ExternalIdentifier;
            provisionalAuditTrailEntry.LatestInvoiceExternalIdentifier = LatestInvoiceExternalIdentifier;

            return(true);
        }
示例#4
0
        /// <summary>
        /// Returns true if the security contains at least one subscription that represents custom data
        /// </summary>
        public bool IsCustomData()
        {
            if (Subscriptions == null || !Subscriptions.Any())
            {
                return(false);
            }

            return(Subscriptions.Any(x => x.IsCustomData));
        }
示例#5
0
        void IDataStore.Save(Subscription sub)
        {
            if (!Subscriptions.Any(s => s.Id == sub.Id))
            {
                Subscriptions.Add(sub);
            }

            SaveChanges();
        }
示例#6
0
        public int TotalSubscribedDays()
        {
            if (Subscriptions == null || !Subscriptions.Any())
            {
                return(0);
            }

            return(Subscriptions.Sum(s => s.Dates.ToDays(DateTime.Today)));
        }
        /// <summary>
        ///     Evaluate the metric.
        /// </summary>
        /// <param name="remoteFactory">Remote factory</param>
        /// <returns>True if the metric passed, false otherwise</returns>
        public override async Task EvaluateAsync()
        {
            IRemote remote = await RemoteFactory.GetRemoteAsync(Repository, Logger);

            Logger.LogInformation("Evaluating subscription health metrics for {repo}@{branch}", Repository, Branch);

            // Get subscriptions that target this repo/branch
            Subscriptions = (await remote.GetSubscriptionsAsync(targetRepo: Repository))
                            .Where(s => s.TargetBranch.Equals(Branch, StringComparison.OrdinalIgnoreCase)).ToList();

            // Get the dependencies of the repository/branch. Skip pinned and subscriptions tied to another
            // dependency (coherent parent), as well as those not selected by the dependency selector.
            try
            {
                Dependencies = (await remote.GetDependenciesAsync(Repository, Branch))
                               .Where(d => !d.Pinned && string.IsNullOrEmpty(d.CoherentParentDependencyName))
                               .Where(d => DependencySelector(d))
                               .ToList();
            }
            catch (DependencyFileNotFoundException)
            {
                // When the dependency file is not found, then we're good as long as this repo is not
                // targeted by any subscriptions
                if (Subscriptions.Any())
                {
                    MissingVersionDetailsFile = true;
                    Result = HealthResult.Failed;
                    return;
                }
                else
                {
                    Result = HealthResult.Passed;
                    return;
                }
            }

            Dictionary <string, Subscription> latestAssets = await GetLatestAssetsAndComputeConflicts(remote);

            ComputeSubscriptionUse(latestAssets);

            // Determine the result. A conflict or missing subscription is an error.
            // A non-flowing subscription or unused subscription is a warning
            if (DependenciesMissingSubscriptions.Any() ||
                ConflictingSubscriptions.Any())
            {
                Result = HealthResult.Failed;
            }
            else if (UnusedSubscriptions.Any() || DependenciesThatDoNotFlow.Any())
            {
                Result = HealthResult.Warning;
            }
            else
            {
                Result = HealthResult.Passed;
            }
        }
示例#8
0
 private void SecurityEditor_SecuritySelected()
 {
     if (Subscriptions.Any(s => s.Security == SecurityEditor.SelectedSecurity))
     {
         return;
     }
     Subscriptions.Add(new UserSubscription {
         Security = SecurityEditor.SelectedSecurity
     });
 }
示例#9
0
        public override void OnNavigatingTo(INavigationParameters parameters)
        {
            if (!Subscriptions.Any())
            {
                foreach (var subscInfo in _subscriptionManager.GetAllSubscriptionInfo().OrderBy(x => x.entity.SortIndex))
                {
                    var vm    = new SubscriptionViewModel(_logger, subscInfo.entity, this, _subscriptionManager, _pageManager, _dialogService, _VideoPlayWithQueueCommand);
                    var items = _nicoVideoProvider.GetCachedVideoInfoItems(subscInfo.feedResult.Videos.Select(x => (VideoId)x.VideoId));
                    vm.UpdateFeedResult(items, subscInfo.feedResult.LastUpdatedAt);
                    Subscriptions.Add(vm);
                }
            }

            base.OnNavigatingTo(parameters);
        }
示例#10
0
 public bool ShouldSendMessage(Type messageType)
 {
     return(Subscriptions.Any(x => x.Matches(messageType)));
 }
示例#11
0
 private bool ContainsSubscription(string instructorId) => Subscriptions.Any(x => x.InstructorId == instructorId);
示例#12
0
 private bool CanUnloading(object obj)
 {
     return(IsConnected && Subscriptions.Any(s => s.MarketDepth || s.Level1 || s.Trades));
 }