コード例 #1
0
        /// <summary>
        /// Upload File with Datalake API
        /// </summary>
        internal virtual async Task UploadDataLakeFile(long taskId, DataLakeFileClient fileClient, string filePath)
        {
            if (this.Force.IsPresent || !fileClient.Exists() || ShouldContinue(string.Format(Resources.OverwriteConfirmation, GetDataLakeItemUriWithoutSas(fileClient)), null))
            {
                // Set Item Properties and MetaData
                PathHttpHeaders pathHttpHeaders       = SetDatalakegen2ItemProperties(fileClient, BlobProperties, setToServer: false);
                IDictionary <string, string> metadata = SetDatalakegen2ItemMetaData(fileClient, BlobMetadata, setToServer: false);

                fileClient.Create(pathHttpHeaders,
                                  metadata,
                                  this.Permission,
                                  this.Umask != null ? DataLakeModels.PathPermissions.ParseSymbolicPermissions(this.Umask).ToOctalPermissions() : null);

                long             fileSize        = new FileInfo(ResolvedFileName).Length;
                string           activity        = String.Format(Resources.SendAzureBlobActivity, this.Source, this.Path, this.FileSystem);
                string           status          = Resources.PrepareUploadingBlob;
                ProgressRecord   pr              = new ProgressRecord(OutputStream.GetProgressId(taskId), activity, status);
                IProgress <long> progressHandler = new Progress <long>((finishedBytes) =>
                {
                    if (pr != null)
                    {
                        // Size of the source file might be 0, when it is, directly treat the progress as 100 percent.
                        pr.PercentComplete   = 0 == fileSize ? 100 : (int)(finishedBytes * 100 / fileSize);
                        pr.StatusDescription = string.Format(CultureInfo.CurrentCulture, Resources.FileTransmitStatus, pr.PercentComplete);
                        this.OutputStream.WriteProgress(pr);
                    }
                });

                using (FileStream stream = File.OpenRead(ResolvedFileName))
                {
                    await fileClient.AppendAsync(stream, 0, progressHandler : progressHandler, cancellationToken : CmdletCancellationToken).ConfigureAwait(false);
                }
                WriteDataLakeGen2Item(Channel, fileClient, taskId: taskId);
            }
        }
コード例 #2
0
        /// <summary>
        /// execute command
        /// </summary>
        public override void ExecuteCmdlet()
        {
            IStorageBlobManagement localChannel = Channel;

            bool foundAFolder = false;
            DataLakeFileClient      srcBlob    = null;
            DataLakeDirectoryClient srcBlobDir = null;

            if (ParameterSetName == ManualParameterSet)
            {
                DataLakeFileSystemClient fileSystem = GetFileSystemClientByName(localChannel, this.FileSystem);
                foundAFolder = GetExistDataLakeGen2Item(fileSystem, this.Path, out srcBlob, out srcBlobDir);
            }
            else //BlobParameterSet
            {
                if (!InputObject.IsDirectory)
                {
                    srcBlob = InputObject.File;
                }
                else
                {
                    srcBlobDir   = InputObject.Directory;
                    foundAFolder = true;
                }
            }

            if (foundAFolder)
            {
                if (ShouldProcess(GetDataLakeItemUriWithoutSas(srcBlobDir), "Move Directory: "))
                {
                    DataLakeFileSystemClient destFileSystem = GetFileSystemClientByName(localChannel, this.DestFileSystem != null ? this.DestFileSystem : this.FileSystem);
                    DataLakeDirectoryClient  destBlobDir    = destFileSystem.GetDirectoryClient(this.DestPath);

                    if (this.Force || !destBlobDir.Exists() || ShouldContinue(string.Format("Overwrite destination {0}", GetDataLakeItemUriWithoutSas(destBlobDir)), ""))
                    {
                        destBlobDir = srcBlobDir.Rename(this.DestPath, this.DestFileSystem).Value;
                        WriteDataLakeGen2Item(localChannel, destBlobDir);
                    }
                }
            }
            else
            {
                if (ShouldProcess(GetDataLakeItemUriWithoutSas(srcBlob), "Move File: "))
                {
                    DataLakeFileSystemClient destFileSystem = GetFileSystemClientByName(localChannel, this.DestFileSystem != null ? this.DestFileSystem : this.FileSystem);
                    DataLakeFileClient       destFile       = destFileSystem.GetFileClient(this.DestPath);

                    if (this.Force || !destFile.Exists() || ShouldContinue(string.Format("Overwrite destination {0}", GetDataLakeItemUriWithoutSas(destFile)), ""))
                    {
                        destFile = srcBlob.Rename(this.DestPath, this.DestFileSystem).Value;
                        WriteDataLakeGen2Item(localChannel, destFile);
                    }
                }
            }
        }