Exemplo n.º 1
0
        private async Task ProcessChangesToUserFolder(OneDriveUser user, SignalR.NotificationService notificationService)
        {
            var client = await SubscriptionController.GetOneDriveClientAsync(user);

            List <string> filesChanged = new List <string>();

            var knownFiles = user.FileNameAndETag;
            var request    = client.Drive.Special["approot"].Children.Request();

            while (request != null)
            {
                var items = await request.GetAsync();

                // Pull out the changes we're interested in

                foreach (var item in items)
                {
                    string etag;
                    if (knownFiles.TryGetValue(item.Name, out etag))
                    {
                        if (etag == item.ETag)
                        {
                            continue;
                        }
                    }
                    knownFiles[item.Name] = item.ETag;
                    filesChanged.Add(item.Name);
                }
                request = items.NextPageRequest;
            }

            notificationService.SendFileChangeNotification(filesChanged);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Enumerate the changes detected by this notification
        /// </summary>
        /// <param name="notifications"></param>
        /// <returns></returns>
        private async Task ProcessNotificationsAsync(Models.OneDriveWebhookNotification[] notifications)
        {
            SignalR.NotificationService service = new SignalR.NotificationService();
            service.SendNotificationToClient(notifications.ToList());

            // In a production service, you should store notifications into a queue and process them on a WebJob or
            // other background service runner
            foreach (var notification in notifications)
            {
                var user = OneDriveUserManager.LookupUserForSubscriptionId(notification.SubscriptionId);
                if (null != user)
                {
                    await ProcessChangesToUserFolder(user, service);
                }
            }
        }