public async Task <IHttpActionResult> FetchStatisticsAsync()
        {
            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." }));
            }

            var client = await SharedConfig.GetOneDriveClientForAccountAsync(account);

            var cameraRollFolder = await client.Drive.Special["cameraroll"].Request().GetAsync();


            var responseObj = new
            {
                itemCount    = cameraRollFolder.Folder.ChildCount,
                totalSize    = cameraRollFolder.Size,
                lastModified = cameraRollFolder.LastModifiedDateTime
            };

            return(JsonResponseEx.Create(HttpStatusCode.OK, responseObj));
        }
        public async Task <IHttpActionResult> CreateFile()
        {
            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." }));
            }

            var client = await SharedConfig.GetOneDriveClientForAccountAsync(account);

            var item = await client.Drive.Special[account.SourceFolder].ItemWithPath("test_file.txt").Content.Request().PutAsync <Item>(this.TestFileStream());

            await AzureStorage.InsertActivityAsync(
                new Activity
            {
                UserId  = account.Id,
                Type    = ActivityEventCode.FileChanged,
                Message = string.Format("Creating test file test_file.txt with resource id: {0}", item.Id)
            });

            return(JsonResponseEx.Create(HttpStatusCode.OK, item));
        }
        public async Task <IHttpActionResult> RecentActivity(string cid = null)
        {
            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." }));
            }

            var activity = await AzureStorage.RecentActivityAsync(cid ?? account.Id);

            return(JsonResponseEx.Create(HttpStatusCode.OK, new { value = activity }));
        }
        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());
        }