Пример #1
0
        public async Task <IHttpActionResult> Post(OneDriveWebhook webhook)
        {
            if (null == webhook)
            {
                return(BadRequest("Missing correctly formatted notification value"));
            }

            ActionController.LastWebhookReceived = webhook;

            foreach (var notification in webhook.Value)
            {
                try
                {
                    // Record the activity of receiving the webhook
                    await AzureStorage.InsertActivityAsync(
                        new Activity
                    {
                        UserId  = notification.UserId,
                        Type    = ActivityEventCode.WebhookReceived,
                        Message = Newtonsoft.Json.JsonConvert.SerializeObject(notification)
                    });

                    // Enqueue an action to process this account again
                    await AzureStorage.AddToPendingSubscriptionQueueAsync(notification);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Trace.WriteLine("Exception adding the webhook to storage queue: " + ex.Message);
                }
            }
            return(Ok());
        }
        public async Task <IHttpActionResult> CreateTestWebhook()
        {
            var cookies = Request.Headers.GetCookies("session").FirstOrDefault();

            if (cookies == null)
            {
                return(JsonResponseEx.Create(HttpStatusCode.Unauthorized, new { message = "Session cookie is missing." }));
            }
            var sessionCookieValue = cookies["session"].Values;
            var account            = await AuthorizationController.AccountFromCookie(sessionCookieValue, false);

            if (null == account)
            {
                return(JsonResponseEx.Create(HttpStatusCode.Unauthorized, new { message = "Failed to locate an account for the auth cookie." }));
            }

            OneDriveNotification notification = new OneDriveNotification {
                UserId = account.Id
            };
            await AzureStorage.AddToPendingSubscriptionQueueAsync(notification);

            return(Ok());
        }
Пример #3
0
        protected async void buttonSaveChanges_Click(object sender, EventArgs e)
        {
            var updateAccount = await Controllers.AuthorizationController.AccountFromCookie(Request.Cookies);

            if (null != updateAccount)
            {
                bool validFormatString;
                try
                {
                    string.Format(textBoxFolderFormatString.Value, DateTimeOffset.Now);
                    labelErrors.Text  = "";
                    validFormatString = true;
                }
                catch (Exception ex)
                {
                    labelErrors.Text  = ex.Message;
                    validFormatString = false;
                }

                if (validFormatString)
                {
                    updateAccount.SubfolderFormat = textBoxFolderFormatString.Value;
                }

                updateAccount.Enabled = checkBoxEnableAccount.Checked;
                await AzureStorage.UpdateAccountAsync(updateAccount);

                if (updateAccount.Enabled == true || updateAccount.SyncToken == null)
                {
                    // Fake a webhook to kick off the organization process
                    PhotoOrganizerShared.Models.OneDriveNotification notification = new PhotoOrganizerShared.Models.OneDriveNotification {
                        UserId = account.Id
                    };
                    await AzureStorage.AddToPendingSubscriptionQueueAsync(notification);
                }
            }
        }