예제 #1
0
        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);
            }
        }
예제 #2
0
        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));
            }
        }
예제 #3
0
        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
                });
            }
        }
예제 #4
0
        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);
        }
예제 #5
0
 public ApiSubscriptionFolder ToApi(SubscriptionFolder folder)
 {
     return(new ApiSubscriptionFolder()
     {
         Id = folder.Id,
         Name = folder.Name,
         ParentId = folder.ParentId
     });
 }
예제 #6
0
 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
                ));
 }
예제 #7
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);
        }
예제 #8
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);
            await dataContext.SaveChangesAsync();

            await messaging.NotifySubscriptionCreated(userAccount, apiModelFactory.ToApi(sub));

            // Start a sync job
            await scheduler.ScheduleSynchronizeSubscription(sub.Id);

            return(sub);
        }
예제 #9
0
        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);
        }
예제 #10
0
 public Task SynchronizeFolder(SubscriptionFolder folder)
 {
     return(SynchronizeJob.Schedule(scheduler, folder));
 }
예제 #11
0
 public IQueryable <Subscription> GetSubscriptionsRecursive(SubscriptionFolder root)
 {
     return(dataContext.GetSubscriptionsRecursive(root));
 }