12
12
// limitations under the License.
13
13
// ----------------------------------------------------------------------------------
14
14
15
- using System . IO ;
16
15
using Microsoft . Azure . Commands . DataLakeStore . Models ;
17
16
using Microsoft . Azure . Commands . DataLakeStore . Properties ;
18
17
using Microsoft . Azure . Management . DataLake . Store . Models ;
19
18
using Microsoft . Rest . Azure ;
20
- using System ;
21
19
using System . Management . Automation ;
22
- using System . Net ;
23
- using Microsoft . Rest ;
24
20
using Microsoft . IdentityModel . Clients . ActiveDirectory ;
25
21
26
22
namespace Microsoft . Azure . Commands . DataLakeStore
27
23
{
28
- [ Cmdlet ( VerbsData . Export , "AzureRmDataLakeStoreItem" , SupportsShouldProcess = true ) , OutputType ( typeof ( string ) ) ]
24
+ [ Cmdlet ( VerbsData . Export , "AzureRmDataLakeStoreItem" , SupportsShouldProcess = true , DefaultParameterSetName = BaseParameterSetName ) , OutputType ( typeof ( string ) ) ]
29
25
[ Alias ( "Export-AdlStoreItem" ) ]
30
26
public class ExportAzureDataLakeStoreItem : DataLakeStoreFileSystemCmdletBase
31
27
{
28
+ // define parameter sets.
29
+ internal const string BaseParameterSetName = "No diagnostic logging" ;
30
+ internal const string DiagnosticParameterSetName = "Include diagnostic logging" ;
31
+
32
32
// default number of threads
33
33
private int numThreadsPerFile = 10 ;
34
34
private int fileCount = 5 ;
35
- private LogLevel logLevel = LogLevel . None ;
35
+ private LogLevel logLevel = LogLevel . Error ;
36
36
37
37
[ Parameter ( ValueFromPipelineByPropertyName = true , Position = 0 , Mandatory = true ,
38
- HelpMessage = "The DataLakeStore account to execute the filesystem operation in" ) ]
38
+ HelpMessage = "The DataLakeStore account to execute the filesystem operation in" ,
39
+ ParameterSetName = BaseParameterSetName ) ]
40
+ [ Parameter ( ValueFromPipelineByPropertyName = true , Position = 0 , Mandatory = true ,
41
+ HelpMessage = "The DataLakeStore account to execute the filesystem operation in" ,
42
+ ParameterSetName = DiagnosticParameterSetName ) ]
39
43
[ ValidateNotNullOrEmpty ]
40
44
[ Alias ( "AccountName" ) ]
41
45
public string Account { get ; set ; }
42
46
43
47
[ Parameter ( ValueFromPipelineByPropertyName = true , Position = 1 , Mandatory = true ,
44
- HelpMessage = "The path to the file or folder to download" ) ]
48
+ HelpMessage = "The path to the file or folder to download" ,
49
+ ParameterSetName = BaseParameterSetName ) ]
50
+ [ Parameter ( ValueFromPipelineByPropertyName = true , Position = 1 , Mandatory = true ,
51
+ HelpMessage = "The path to the file or folder to download" ,
52
+ ParameterSetName = DiagnosticParameterSetName ) ]
45
53
[ ValidateNotNull ]
46
54
public DataLakeStorePathInstance Path { get ; set ; }
47
55
48
56
[ Parameter ( ValueFromPipelineByPropertyName = true , Position = 2 , Mandatory = true ,
49
- HelpMessage = "The local path to download the file or folder to" ) ]
57
+ HelpMessage = "The local path to download the file or folder to" ,
58
+ ParameterSetName = BaseParameterSetName ) ]
59
+ [ Parameter ( ValueFromPipelineByPropertyName = true , Position = 2 , Mandatory = true ,
60
+ HelpMessage = "The local path to download the file or folder to" ,
61
+ ParameterSetName = DiagnosticParameterSetName ) ]
50
62
[ ValidateNotNullOrEmpty ]
51
63
public string Destination { get ; set ; }
52
64
53
65
[ Parameter ( ValueFromPipelineByPropertyName = true , Position = 3 , Mandatory = false ,
54
- HelpMessage = "Indicates if the download should be recursive for folder downloads. The default is false." ) ]
66
+ HelpMessage = "Indicates if the download should be recursive for folder downloads. The default is false." ,
67
+ ParameterSetName = BaseParameterSetName ) ]
68
+ [ Parameter ( ValueFromPipelineByPropertyName = true , Position = 3 , Mandatory = false ,
69
+ HelpMessage = "Indicates if the download should be recursive for folder downloads. The default is false." ,
70
+ ParameterSetName = DiagnosticParameterSetName ) ]
55
71
[ ValidateNotNullOrEmpty ]
56
72
public SwitchParameter Recurse { get ; set ; }
57
73
58
74
[ Parameter ( ValueFromPipelineByPropertyName = true , Position = 4 , Mandatory = false ,
59
75
HelpMessage =
60
- "Indicates that the file(s) being copied are a continuation of a previous download. This will cause the system to attempt to resume from the last file that was not fully downloaded."
61
- ) ]
76
+ "Indicates that the file(s) being copied are a continuation of a previous download. This will cause the system to attempt to resume from the last file that was not fully downloaded." ,
77
+ ParameterSetName = BaseParameterSetName ) ]
78
+ [ Parameter ( ValueFromPipelineByPropertyName = true , Position = 4 , Mandatory = false ,
79
+ HelpMessage =
80
+ "Indicates that the file(s) being copied are a continuation of a previous download. This will cause the system to attempt to resume from the last file that was not fully downloaded." ,
81
+ ParameterSetName = DiagnosticParameterSetName ) ]
62
82
public SwitchParameter Resume { get ; set ; }
63
83
64
84
[ Parameter ( ValueFromPipelineByPropertyName = true , Position = 5 , Mandatory = false ,
65
- HelpMessage = "Indicates the maximum number of threads to use per file. Default is 10" ) ]
85
+ HelpMessage = "Indicates the maximum number of threads to use per file. Default is 10" ,
86
+ ParameterSetName = BaseParameterSetName ) ]
87
+ [ Parameter ( ValueFromPipelineByPropertyName = true , Position = 5 , Mandatory = false ,
88
+ HelpMessage = "Indicates the maximum number of threads to use per file. Default is 10" ,
89
+ ParameterSetName = DiagnosticParameterSetName ) ]
66
90
public int PerFileThreadCount
67
91
{
68
92
get { return numThreadsPerFile ; }
69
93
set { numThreadsPerFile = value ; }
70
94
}
71
95
72
96
[ Parameter ( ValueFromPipelineByPropertyName = true , Position = 6 , Mandatory = false ,
73
- HelpMessage = "Indicates the maximum number of files to download in parallel for a folder download. Default is 5" ) ]
97
+ HelpMessage = "Indicates the maximum number of files to download in parallel for a folder download. Default is 5" ,
98
+ ParameterSetName = BaseParameterSetName ) ]
99
+ [ Parameter ( ValueFromPipelineByPropertyName = true , Position = 6 , Mandatory = false ,
100
+ HelpMessage = "Indicates the maximum number of files to download in parallel for a folder download. Default is 5" ,
101
+ ParameterSetName = DiagnosticParameterSetName ) ]
74
102
public int ConcurrentFileCount
75
103
{
76
104
get { return fileCount ; }
77
105
set { fileCount = value ; }
78
106
}
79
107
80
108
[ Parameter ( ValueFromPipelineByPropertyName = true , Position = 7 , Mandatory = false ,
81
- HelpMessage = "Indicates that, if the file or folder exists, it should be overwritten" ) ]
109
+ HelpMessage = "Indicates that, if the file or folder exists, it should be overwritten" ,
110
+ ParameterSetName = BaseParameterSetName ) ]
111
+ [ Parameter ( ValueFromPipelineByPropertyName = true , Position = 7 , Mandatory = false ,
112
+ HelpMessage = "Indicates that, if the file or folder exists, it should be overwritten" ,
113
+ ParameterSetName = DiagnosticParameterSetName ) ]
82
114
public SwitchParameter Force { get ; set ; }
83
115
84
116
[ Parameter ( ValueFromPipelineByPropertyName = true , Mandatory = false ,
85
- HelpMessage = "Optionally indicates the diagnostic log level to use to record events during the file or folder import. Default is none, and specifying -Debug overwrites this value and sets it to Debug." ) ]
117
+ HelpMessage = "Optionally indicates the diagnostic log level to use to record events during the file or folder import. Default is Error." ,
118
+ ParameterSetName = DiagnosticParameterSetName ) ]
86
119
public LogLevel DiagnosticLogLevel
87
120
{
88
121
get { return logLevel ; }
89
122
set { logLevel = value ; }
90
123
}
91
124
92
- [ Parameter ( ValueFromPipelineByPropertyName = true , Mandatory = false ,
93
- HelpMessage = "Optionally specifies the path for the diagnostic log to record events to during the file or folder import. If logging is enabled, the default is in %LOCALAPPDATA%\\ ADLDataTransfer." ) ]
125
+ [ Parameter ( ValueFromPipelineByPropertyName = true , Mandatory = true ,
126
+ HelpMessage = "Specifies the path for the diagnostic log to record events to during the file or folder import." ,
127
+ ParameterSetName = DiagnosticParameterSetName ) ]
94
128
[ ValidateNotNullOrEmpty ]
95
129
public string DiagnosticLogPath { get ; set ; }
96
130
@@ -99,11 +133,6 @@ public override void ExecuteCmdlet()
99
133
// We will let this throw itself if the path they give us is invalid
100
134
// TODO: perhaps in the future catch this and throw a cmdlet specific exception
101
135
var powerShellReadyPath = SessionState . Path . GetUnresolvedProviderPathFromPSPath ( Destination ) ;
102
- string diagnosticPath = string . Empty ;
103
- if ( ! string . IsNullOrEmpty ( DiagnosticLogPath ) )
104
- {
105
- diagnosticPath = SessionState . Path . GetUnresolvedProviderPathFromPSPath ( DiagnosticLogPath ) ;
106
- }
107
136
108
137
FileType type ;
109
138
ConfirmAction (
@@ -121,22 +150,12 @@ public override void ExecuteCmdlet()
121
150
var originalLegacyLevel = AdalTrace . LegacyTraceSwitch . Level ;
122
151
try
123
152
{
124
- if ( DiagnosticLogLevel != LogLevel . None )
153
+ if ( ParameterSetName . Equals ( DiagnosticParameterSetName ) && DiagnosticLogLevel != LogLevel . None )
125
154
{
155
+ var diagnosticPath = SessionState . Path . GetUnresolvedProviderPathFromPSPath ( DiagnosticLogPath ) ;
126
156
logger = new DataLakeStoreTraceLogger ( this , diagnosticPath , DiagnosticLogLevel ) ;
127
- if ( logger . SdkTracingInterceptor != null )
128
- {
129
- ServiceClientTracing . AddTracingInterceptor ( logger . SdkTracingInterceptor ) ;
130
- }
131
-
132
- // only log all ADAL messages when the level is debug.
133
- // In all other cases only log Warning and above.
134
- if ( DiagnosticLogLevel != LogLevel . Debug )
135
- {
136
- AdalTrace . TraceSource . Switch . Level = System . Diagnostics . SourceLevels . Warning ;
137
- AdalTrace . LegacyTraceSwitch . Level = System . Diagnostics . TraceLevel . Warning ;
138
- }
139
157
}
158
+
140
159
if ( type == FileType . FILE )
141
160
{
142
161
DataLakeStoreFileSystemClient . CopyFile ( powerShellReadyPath , Account , Path . TransformedPath , CmdletCancellationToken ,
@@ -156,18 +175,10 @@ public override void ExecuteCmdlet()
156
175
{
157
176
if ( logger != null )
158
177
{
159
- if ( logger . SdkTracingInterceptor != null )
160
- {
161
- ServiceClientTracing . RemoveTracingInterceptor ( logger . SdkTracingInterceptor ) ;
162
- }
163
-
164
178
// dispose and free the logger.
165
179
logger . Dispose ( ) ;
166
180
logger = null ;
167
181
}
168
-
169
- AdalTrace . TraceSource . Switch . Level = originalLevel ;
170
- AdalTrace . LegacyTraceSwitch . Level = originalLegacyLevel ;
171
182
}
172
183
} ) ;
173
184
}
0 commit comments