Пример #1
0
        //Files stories

        public static async Task <bool> TryCreateFileAsync()
        {
            // Grab a list of folder items
            var items = await FilesSnippets.GetFolderChildrenAsync("root");

            if (items == null)
            {
                return(false);
            }

            var origCount = items.Count;

            var createdFileId = await FilesSnippets.CreateFileAsync(STORY_DATA_IDENTIFIER + "_" + Guid.NewGuid().ToString(), new MemoryStream(Encoding.UTF8.GetBytes("TryAddFileAsync")));

            if (createdFileId == null)
            {
                return(false);
            }


            // Grab the files again
            items = await FilesSnippets.GetFolderChildrenAsync("root");

            if (items == null)
            {
                return(false);
            }

            // Number of files should have increased by 1
            if (items.Count != origCount + 1)
            {
                return(false);
            }

            //Cleanup
            await FilesSnippets.DeleteFileAsync(createdFileId);


            return(true);
        }
Пример #2
0
        public static async Task <bool> TryUpdateFileContentAsync()
        {
            // Add a file & verify
            // Grab a list of files
            var items = await FilesSnippets.GetFolderChildrenAsync("root");

            if (items == null)
            {
                return(false);
            }

            var origCount = items.Count;

            // Create a file
            var createdFileId = await FilesSnippets.CreateFileAsync(STORY_DATA_IDENTIFIER + "_" + Guid.NewGuid().ToString(), new MemoryStream(Encoding.UTF8.GetBytes("TryUpdateFileAsync")));

            if (createdFileId == null)
            {
                return(false);
            }

            // Grab the files again
            items = await FilesSnippets.GetFolderChildrenAsync("root");

            if (items == null)
            {
                return(false);
            }

            // Number of files should have increased by 1
            if (items.Count != origCount + 1)
            {
                return(false);
            }

            // Update the content

            string updatedContent = "Updated content";
            var    updated        = await FilesSnippets.UpdateFileContentAsync(createdFileId, new MemoryStream(Encoding.UTF8.GetBytes(updatedContent)));

            // Download the file and compare with the updated content.

            using (var stream = await FilesSnippets.DownloadFileAsync(createdFileId))
            {
                if (stream == null)
                {
                    return(false);
                }

                StreamReader reader           = new StreamReader(stream);
                var          downloadedString = await reader.ReadToEndAsync();

                if (downloadedString != updatedContent)
                {
                    return(false);
                }
            }

            //Cleanup
            await FilesSnippets.DeleteFileAsync(createdFileId);

            return(updated);
        }