// </Snippet_DownloadBinaryFromDirectory>

        #endregion

        #region User menu

        //-------------------------------------------------
        // CRUD menu (Can call asynchronous and synchronous methods)
        //-------------------------------------------------

        public async Task <bool> MenuAsync()
        {
            Console.Clear();
            Console.WriteLine("Choose a Create, Read, Update, or Delete (CRUD) scenario:");
            Console.WriteLine("1) Create a file system");
            Console.WriteLine("2) Create a directory");
            Console.WriteLine("3) Rename a directory");
            Console.WriteLine("4) Delete a directory");
            Console.WriteLine("5) List directory contents");
            Console.WriteLine("6) Upload files to a directory");
            Console.WriteLine("7) Upload files to a directory in bulk");
            Console.WriteLine("8) Download a file from a directory");
            Console.WriteLine("X) Exit to main menu");
            Console.Write("\r\nSelect an option: ");

            Authorize_DataLake.GetDataLakeServiceClient(ref dataLakeServiceClient, Constants.storageAccountName, Constants.accountKey);

            // Uncomment if you want to test AD Authorization.
            //   Authorize_DataLake.GetDataLakeServiceClient(ref dataLakeServiceClient, Constants.storageAccountName,
            //       Constants.clientID, Constants.clientSecret, Constants.tenantID);

            // Get file system client

            DataLakeFileSystemClient fileSystemClient =
                GetFileSystem(dataLakeServiceClient, Constants.containerName);

            switch (Console.ReadLine())
            {
            case "1":

                await CreateFileSystem(dataLakeServiceClient);

                Console.WriteLine("Press enter to continue");
                Console.ReadLine();
                return(true);

            case "2":

                await CreateDirectory(dataLakeServiceClient, Constants.containerName);

                Console.WriteLine("Press enter to continue");
                Console.ReadLine();
                return(true);

            case "3":

                await MoveDirectory(fileSystemClient);

                Console.WriteLine("Press enter to continue");
                Console.ReadLine();
                return(true);

            case "4":

                DeleteDirectory(fileSystemClient);

                Console.WriteLine("Press enter to continue");
                Console.ReadLine();
                return(true);

            case "5":

                await ListFilesInDirectory(fileSystemClient);

                Console.WriteLine("Press enter to continue");
                Console.ReadLine();
                return(true);

            case "6":

                await UploadFile(fileSystemClient);

                Console.WriteLine("Press enter to continue");
                Console.ReadLine();
                return(true);

            case "7":

                await UploadFileBulk(fileSystemClient);

                Console.WriteLine("Press enter to continue");
                Console.ReadLine();
                return(true);

            case "8":

                await DownloadFile2(fileSystemClient);

                Console.WriteLine("Press enter to continue");
                Console.ReadLine();
                return(true);


            case "x":
            case "X":

                return(false);

            default:

                return(true);
            }
        }
Exemplo n.º 2
0
        // </Snippet_ContinueOnFailure>

        #endregion

        //-------------------------------------------------
        // Security menu (Can call asynchronous and synchronous methods)
        //-------------------------------------------------

        public async Task <bool> MenuAsync()
        {
            Console.Clear();
            Console.WriteLine("Choose a security scenario:");
            Console.WriteLine("1) Set a directory ACL");
            Console.WriteLine("2) Set a file ACL");
            Console.WriteLine("3) Update an ACL");
            Console.WriteLine("4) Set ACLs recursively");
            Console.WriteLine("5) Update ACLs recursively");
            Console.WriteLine("6) Remove an ACL entry");
            Console.WriteLine("7) Remove ACLs recursively");
            Console.WriteLine("8) Resume after failure with token");
            Console.WriteLine("9) Continue past failure");

            Console.WriteLine("X) Exit to main menu");
            Console.Write("\r\nSelect an option: ");

            Authorize_DataLake.GetDataLakeServiceClient(ref dataLakeServiceClient, Constants.storageAccountName, Constants.accountKey);

            // Uncomment if you want to test AD Authorization.
            //   Authorize_DataLake.GetDataLakeServiceClient(ref dataLakeServiceClient, Constants.storageAccountName,
            //       Constants.clientID, Constants.clientSecret, Constants.tenantID);

            // Get file system client

            DataLakeFileSystemClient fileSystemClient =
                GetFileSystem(dataLakeServiceClient, Constants.containerName);

            switch (Console.ReadLine())
            {
            case "1":

                await ManageDirectoryACLs(fileSystemClient);

                Console.WriteLine("Press enter to continue");
                Console.ReadLine();
                return(true);

            case "2":

                await ManageFileACLs(fileSystemClient);

                Console.WriteLine("Press enter to continue");
                Console.ReadLine();
                return(true);

            case "3":

                await UpdateDirectoryACLs(fileSystemClient);

                Console.WriteLine("Press enter to continue");
                Console.ReadLine();
                return(true);

            case "4":

                await SetACLRecursively(dataLakeServiceClient, false);

                Console.WriteLine("Press enter to continue");
                Console.ReadLine();
                return(true);

            case "5":

                await UpdateACLsRecursively(dataLakeServiceClient, false);

                Console.WriteLine("Press enter to continue");
                Console.ReadLine();
                return(true);

            case "6":

                await RemoveDirectoryACLEntry(fileSystemClient);

                Console.WriteLine("Press enter to continue");
                Console.ReadLine();
                return(true);

            case "7":

                await RemoveACLsRecursively(dataLakeServiceClient, false);

                Console.WriteLine("Press enter to continue");
                Console.ReadLine();
                return(true);

            case "8":

                DataLakeDirectoryClient directoryClient =
                    dataLakeServiceClient.GetFileSystemClient("my-container").
                    GetDirectoryClient("my-parent-directory");

                directoryClient =
                    dataLakeServiceClient.GetFileSystemClient("my-container").
                    GetDirectoryClient("my-parent-directory");

                List <PathAccessControlItem> accessControlList = new List <PathAccessControlItem>()
                {
                    new PathAccessControlItem(AccessControlType.User,
                                              RolePermissions.Read |
                                              RolePermissions.Write |
                                              RolePermissions.Execute),

                    new PathAccessControlItem(AccessControlType.Group,
                                              RolePermissions.Read |
                                              RolePermissions.Execute),

                    new PathAccessControlItem(AccessControlType.Other,
                                              RolePermissions.None),

                    new PathAccessControlItem(AccessControlType.User, RolePermissions.Read |
                                              RolePermissions.Write | RolePermissions.Execute,
                                              entityId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx"),
                };

                await ResumeAsync(dataLakeServiceClient, directoryClient, accessControlList, null);


                Console.WriteLine("Press enter to continue");
                Console.ReadLine();
                return(true);

            case "9":

                DataLakeDirectoryClient directoryClient2 =
                    dataLakeServiceClient.GetFileSystemClient("my-container").
                    GetDirectoryClient("my-parent-directory");

                List <PathAccessControlItem> accessControlList2 = new List <PathAccessControlItem>()
                {
                    new PathAccessControlItem(AccessControlType.User,
                                              RolePermissions.Read |
                                              RolePermissions.Write |
                                              RolePermissions.Execute),

                    new PathAccessControlItem(AccessControlType.Group,
                                              RolePermissions.Read |
                                              RolePermissions.Execute),

                    new PathAccessControlItem(AccessControlType.Other,
                                              RolePermissions.None),

                    new PathAccessControlItem(AccessControlType.User, RolePermissions.Read |
                                              RolePermissions.Write | RolePermissions.Execute,
                                              entityId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx"),
                };

                await ContinueOnFailureAsync(dataLakeServiceClient, directoryClient2, accessControlList2);

                Console.WriteLine("Press enter to continue");
                Console.ReadLine();
                return(true);

            case "x":
            case "X":

                return(false);

            default:

                return(true);
            }
        }