public IDisposable AddObserver <T>(string key, T observer) where T : class { var container = Containers.OfType <KeySubscriptionContainer <T> >().FirstOrDefault(); if (container == null) { container = new KeySubscriptionContainer <T>(); Containers.Add(container); container.SubscriptionRemoved += SubscriptionRemovedInternal; } var subscription = container.AddItem(key, observer); var count = container.Count(key); var arg = new SubscriptionArg(key, count, observer); SubscriptionCreated?.Invoke(arg); return(subscription); }
public async Task <Subscription> Create(UserAccount userAccount, Uri uri, int?parentFolderId) { // Verify parent folder ID exists SubscriptionFolder parent = null; if (parentFolderId.HasValue) { parent = dataContext.SubscriptionFolders.Find(parentFolderId.Value); if (parent == null) { throw new Exception("Parent folder not found!"); } } // Find subscription provider and create subscription var provider = await providerManager.FindFromSubscriptionUrl(uri).FirstOrDefaultAsync(); if (provider == null) { throw new Exception("Could not find a subscription provider that can handle this URL!"); } Subscription sub = await provider.CreateSubscription(uri); sub.User = userAccount; sub.ParentFolder = parent; dataContext.Subscriptions.Add(sub); dataContext.SaveChanges(); SubscriptionCreated?.Invoke(this, new SubscriptionCreatedEventArgs() { User = userAccount, Subscription = sub }); // Start a sync job await SynchronizeSubscription(sub); return(sub); }
public Subscription CreateEmpty(UserAccount userAccount, string name, int?parentFolderId) { // Verify parent folder ID exists SubscriptionFolder parent = null; if (parentFolderId.HasValue) { parent = dataContext.SubscriptionFolders.Find(parentFolderId.Value); if (parent == null) { throw new Exception("Parent folder not found!"); } } // Verify name is unique ValidateName(name, parentFolderId); // Create subscription Subscription sub = new() { Name = name, ParentFolder = parent, User = userAccount, }; dataContext.Subscriptions.Add(sub); dataContext.SaveChanges(); SubscriptionCreated?.Invoke(this, new SubscriptionCreatedEventArgs() { User = userAccount, Subscription = sub }); return(sub); }
private void NotifySubscriptionCreated(ApiSubscription subscription) { SubscriptionCreated?.Invoke(this, subscription); }