public IEnumerable <SubscriptionFolder> GetFoldersRecursive(SubscriptionFolder root) { var folderIds = new HashSet <int>(); var queue = new Queue <SubscriptionFolder>(); queue.Enqueue(root); // Build set of subfolders while (queue.TryDequeue(out SubscriptionFolder current)) { if (folderIds.Contains(current.Id)) { Debug.Fail($"Folder cycle detected for id {current.Id}!!!"); continue; } folderIds.Add(current.Id); yield return(current); SubscriptionFolders.AsQueryable() .Where(f => f.ParentId == current.Id) .ForEach(queue.Enqueue); } }
public async Task CreateFolder(UserAccount user, string name, ParentId parentId) { // Verify if any folder exists bool alreadyExists = dataContext.SubscriptionFolders.AsQueryable() .Where(x => x.UserId == user.Id) .Where(x => x.ParentId == parentId) .Where(x => x.Name.ToUpper() == name.ToUpper()) .Any(); if (!alreadyExists) { var newFolder = new SubscriptionFolder() { User = user, ParentId = parentId, Name = name }; dataContext.SubscriptionFolders.Add(newFolder); await dataContext.SaveChangesAsync(); await messaging.NotifySubscriptionFolderCreated(user, apiModelFactory.ToApi(newFolder)); } }
public void CreateFolder(UserAccount user, string name, ParentId parentId) { // Verify if any folder exists bool alreadyExists = dataContext.SubscriptionFolders.AsQueryable() .Where(x => x.UserId == user.Id) .Where(x => x.ParentId == parentId) .Where(x => x.Name.ToUpper() == name.ToUpper()) .Any(); if (!alreadyExists) { var newFolder = new SubscriptionFolder() { User = user, ParentId = parentId, Name = name }; dataContext.SubscriptionFolders.Add(newFolder); dataContext.SaveChanges(); FolderCreated?.Invoke(this, new SubscriptionFolderCreatedEventArgs() { User = user, Folder = newFolder }); } }
public async Task <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); await dataContext.SaveChangesAsync(); await messaging.NotifySubscriptionCreated(userAccount, apiModelFactory.ToApi(sub)); return(sub); }
public ApiSubscriptionFolder ToApi(SubscriptionFolder folder) { return(new ApiSubscriptionFolder() { Id = folder.Id, Name = folder.Name, ParentId = folder.ParentId }); }
public static Task <DateTimeOffset> Schedule(RegardScheduler scheduler, SubscriptionFolder folder) { return(scheduler.Schedule <SynchronizeJob>( name: $"Synchronize subscriptions in folder {folder.Name}", jobData: new Dictionary <string, object> { [Data_FolderId] = folder.Id }, retryCount: 0, retryIntervalSecs: 0 )); }
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 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); await dataContext.SaveChangesAsync(); await messaging.NotifySubscriptionCreated(userAccount, apiModelFactory.ToApi(sub)); // Start a sync job await scheduler.ScheduleSynchronizeSubscription(sub.Id); 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); }
public Task SynchronizeFolder(SubscriptionFolder folder) { return(SynchronizeJob.Schedule(scheduler, folder)); }
public IQueryable <Subscription> GetSubscriptionsRecursive(SubscriptionFolder root) { return(dataContext.GetSubscriptionsRecursive(root)); }