public override void ExecuteCmdlet()
        {
            // We will let this throw itself if the path they give us is invalid
            // TODO: perhaps in the future catch this and throw a cmdlet specific exception
            var powerShellReadyPath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(Destination);

            FileType type;

            ConfirmAction(
                VerbsData.Export,
                Path.TransformedPath,
                () =>
            {
                if (!DataLakeStoreFileSystemClient.TestFileOrFolderExistence(Path.TransformedPath, Account, out type))
                {
                    throw new CloudException(string.Format(Resources.InvalidExportPathType, Path.TransformedPath));
                }

                DataLakeStoreTraceLogger logger = null;
                var originalLevel       = AdalTrace.TraceSource.Switch.Level;
                var originalLegacyLevel = AdalTrace.LegacyTraceSwitch.Level;
                try
                {
                    if (ParameterSetName.Equals(DiagnosticParameterSetName) && DiagnosticLogLevel != LogLevel.None)
                    {
                        var diagnosticPath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(DiagnosticLogPath);
                        logger             = new DataLakeStoreTraceLogger(this, diagnosticPath, DiagnosticLogLevel);
                    }

                    if (type == FileType.FILE)
                    {
                        DataLakeStoreFileSystemClient.CopyFile(powerShellReadyPath, Account, Path.TransformedPath, CmdletCancellationToken,
                                                               isDownload: true, overwrite: Force, cmdletRunningRequest: this, threadCount: PerFileThreadCount, resume: Resume);
                    }
                    else
                    {
                        DataLakeStoreFileSystemClient.CopyDirectory(powerShellReadyPath, Account, Path.TransformedPath,
                                                                    CmdletCancellationToken,
                                                                    isDownload: true, overwrite: Force, cmdletRunningRequest: this,
                                                                    perFileThreadCount: PerFileThreadCount, concurrentFileCount: ConcurrentFileCount, recursive: Recurse, resume: Resume);
                    }

                    WriteObject(powerShellReadyPath);
                }
                finally
                {
                    if (logger != null)
                    {
                        // dispose and free the logger.
                        logger.Dispose();
                        logger = null;
                    }
                }
            });
        }
Esempio n. 2
0
        public override void ExecuteCmdlet()
        {
            var powerShellSourcePath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(Path);

            ConfirmAction(
                Resources.UploadFileMessage,
                Destination.TransformedPath,
                () =>
            {
                DataLakeStoreTraceLogger logger = null;
                var previousTracing             = ServiceClientTracing.IsEnabled;
                try
                {
                    if (ParameterSetName.Equals(DiagnosticParameterSetName) && DiagnosticLogLevel != LogLevel.None)
                    {
                        var diagnosticPath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(DiagnosticLogPath);
                        logger             = new DataLakeStoreTraceLogger(this, diagnosticPath, DiagnosticLogLevel);
                    }

                    if (logger == null)
                    {
                        // if the caller does not explicitly want logging, we will explicitly turn it off
                        // for performance reasons
                        ServiceClientTracing.IsEnabled = false;
                    }

                    if (Directory.Exists(powerShellSourcePath))
                    {
                        DataLakeStoreFileSystemClient.CopyDirectory(
                            Destination.TransformedPath,
                            Account,
                            powerShellSourcePath,
                            CmdletCancellationToken,
                            ConcurrentFileCount,
                            PerFileThreadCount,
                            Recurse,
                            Force,
                            Resume, ForceBinary, ForceBinary, cmdletRunningRequest: this);
                    }
                    else if (File.Exists(powerShellSourcePath))
                    {
                        DataLakeStoreFileSystemClient.CopyFile(
                            Destination.TransformedPath,
                            Account,
                            powerShellSourcePath,
                            CmdletCancellationToken,
                            PerFileThreadCount,
                            Force,
                            Resume,
                            ForceBinary,
                            cmdletRunningRequest: this);
                    }
                    else
                    {
                        throw new FileNotFoundException(string.Format(Resources.FileOrFolderDoesNotExist, powerShellSourcePath));
                    }

                    // only attempt to write output if this cmdlet hasn't been cancelled.
                    if (!CmdletCancellationToken.IsCancellationRequested && !Stopping)
                    {
                        WriteObject(Destination.OriginalPath);
                    }
                }
                finally
                {
                    // set service client tracing back always
                    ServiceClientTracing.IsEnabled = previousTracing;
                    if (logger != null)
                    {
                        // dispose and free the logger.
                        logger.Dispose();
                        logger = null;
                    }
                }
            });
        }
Esempio n. 3
0
        public override void ExecuteCmdlet()
        {
            var powerShellSourcePath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(Path);

            ConfirmAction(
                Resources.UploadFileMessage,
                Destination.TransformedPath,
                () =>
            {
                DataLakeStoreTraceLogger logger = null;
                var originalLevel       = AdalTrace.TraceSource.Switch.Level;
                var originalLegacyLevel = AdalTrace.LegacyTraceSwitch.Level;
                try
                {
                    if (ParameterSetName.Equals(DiagnosticParameterSetName) && DiagnosticLogLevel != LogLevel.None)
                    {
                        var diagnosticPath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(DiagnosticLogPath);
                        logger             = new DataLakeStoreTraceLogger(this, diagnosticPath, DiagnosticLogLevel);
                    }

                    if (Directory.Exists(powerShellSourcePath))
                    {
                        DataLakeStoreFileSystemClient.CopyDirectory(
                            Destination.TransformedPath,
                            Account,
                            powerShellSourcePath,
                            CmdletCancellationToken,
                            ConcurrentFileCount,
                            PerFileThreadCount,
                            Recurse,
                            Force,
                            Resume, ForceBinary, ForceBinary, cmdletRunningRequest: this);
                    }
                    else if (File.Exists(powerShellSourcePath))
                    {
                        DataLakeStoreFileSystemClient.CopyFile(
                            Destination.TransformedPath,
                            Account,
                            powerShellSourcePath,
                            CmdletCancellationToken,
                            PerFileThreadCount,
                            Force,
                            Resume,
                            ForceBinary,
                            cmdletRunningRequest: this);
                    }
                    else
                    {
                        throw new FileNotFoundException(string.Format(Resources.FileOrFolderDoesNotExist, powerShellSourcePath));
                    }

                    // only attempt to write output if this cmdlet hasn't been cancelled.
                    if (!CmdletCancellationToken.IsCancellationRequested && !Stopping)
                    {
                        WriteObject(Destination.OriginalPath);
                    }
                }
                finally
                {
                    if (logger != null)
                    {
                        // dispose and free the logger.
                        logger.Dispose();
                        logger = null;
                    }
                }
            });
        }