@@ -22,21 +22,23 @@ namespace Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel
22
22
using global ::Azure . Storage . Files . Shares ;
23
23
using global ::Azure . Storage ;
24
24
using Microsoft . WindowsAzure . Commands . Storage . Common ;
25
+ using global ::Azure . Storage . Files . Shares . Models ;
26
+ using Microsoft . Azure . Storage . Auth ;
25
27
26
28
/// <summary>
27
29
/// Azure storage file object
28
30
/// </summary>
29
31
public class AzureStorageFile : AzureStorageBase
30
32
{
31
33
/// <summary>
32
- /// CloudBlob object
34
+ /// File object
33
35
/// </summary>
34
36
[ Ps1Xml ( Label = "Share Uri" , Target = ViewControl . Table , GroupByThis = true , ScriptBlock = "$_.CloudFile.Share.Uri" ) ]
35
37
[ Ps1Xml ( Label = "Name" , Target = ViewControl . Table , ScriptBlock = "$_.Name" , Position = 0 , TableColumnWidth = 20 ) ]
36
38
public CloudFile CloudFile { get ; private set ; }
37
39
38
40
/// <summary>
39
- /// Blob length
41
+ /// File length
40
42
/// </summary>
41
43
[ Ps1Xml ( Label = "Length" , Target = ViewControl . Table , Position = 1 , TableColumnWidth = 15 ) ]
42
44
public long Length { get ; private set ; }
@@ -56,7 +58,7 @@ public ShareFileClient ShareFileClient
56
58
{
57
59
if ( privateFileClient == null )
58
60
{
59
- privateFileClient = GetTrack2FileClient ( this . CloudFile , ( AzureStorageContext ) this . Context ) ;
61
+ privateFileClient = GetTrack2FileClient ( this . CloudFile , this . shareClientOptions ) ;
60
62
}
61
63
return privateFileClient ;
62
64
}
@@ -80,20 +82,85 @@ public ShareFileClient ShareFileClient
80
82
private global ::Azure . Storage . Files . Shares . Models . ShareFileProperties privateFileProperties = null ;
81
83
82
84
/// <summary>
83
- /// Azure storage file constructor
85
+ /// XSCL Track2 File List properties
86
+ /// </summary>
87
+ public global ::Azure . Storage . Files . Shares . Models . ShareFileItem ListFileProperties { get ; private set ; }
88
+
89
+
90
+ private ShareClientOptions shareClientOptions { get ; set ; }
91
+
92
+ /// <summary>
93
+ /// Azure storage file constructor from track1 file object
84
94
/// </summary>
85
95
/// <param name="file">Cloud file object</param>
86
- public AzureStorageFile ( CloudFile file , AzureStorageContext storageContext )
96
+ public AzureStorageFile ( CloudFile file , AzureStorageContext storageContext , ShareClientOptions clientOptions = null )
87
97
{
88
98
Name = file . Name ;
89
99
CloudFile = file ;
90
100
Length = file . Properties . Length ;
91
101
LastModified = file . Properties . LastModified ;
92
102
Context = storageContext ;
103
+ shareClientOptions = clientOptions ;
104
+ }
105
+
106
+ /// <summary>
107
+ /// Azure storage file constructor from Track2 list file item
108
+ /// </summary>
109
+ /// <param name="file">Cloud file object</param>
110
+ public AzureStorageFile ( ShareFileClient shareFileClient , AzureStorageContext storageContext , ShareFileItem shareFileItem , ShareClientOptions clientOptions = null )
111
+ {
112
+ Name = shareFileClient . Name ;
113
+ this . privateFileClient = shareFileClient ;
114
+ CloudFile = GetTrack1FileClient ( shareFileClient , storageContext . StorageAccount . Credentials ) ;
115
+ if ( shareFileItem != null )
116
+ {
117
+ ListFileProperties = shareFileItem ;
118
+ if ( shareFileItem . FileSize != null )
119
+ {
120
+ Length = shareFileItem . FileSize . Value ;
121
+ }
122
+ if ( shareFileItem . Properties != null )
123
+ {
124
+ LastModified = shareFileItem . Properties . LastModified ;
125
+ }
126
+ }
127
+ Context = storageContext ;
128
+ shareClientOptions = clientOptions ;
129
+ }
130
+
131
+ /// <summary>
132
+ /// Azure storage file constructor from Track2 get file properties output
133
+ /// </summary>
134
+ /// <param name="file">Cloud file object</param>
135
+ public AzureStorageFile ( ShareFileClient shareFileClient , AzureStorageContext storageContext , ShareFileProperties shareFileProperties = null , ShareClientOptions clientOptions = null )
136
+ {
137
+ Name = shareFileClient . Name ;
138
+ this . privateFileClient = shareFileClient ;
139
+ CloudFile = GetTrack1FileClient ( shareFileClient , storageContext . StorageAccount . Credentials ) ;
140
+ if ( shareFileProperties != null )
141
+ {
142
+ privateFileProperties = shareFileProperties ;
143
+ Length = shareFileProperties . ContentLength ;
144
+ LastModified = shareFileProperties . LastModified ;
145
+ }
146
+ Context = storageContext ;
147
+ shareClientOptions = clientOptions ;
148
+ }
149
+
150
+ // Convert Track2 File object to Track 1 file object
151
+ public static CloudFile GetTrack1FileClient ( ShareFileClient shareFileClient , StorageCredentials credentials )
152
+ {
153
+ if ( credentials . IsSAS ) // the Uri already contains credentail.
154
+ {
155
+ credentials = null ;
156
+ }
157
+ CloudFile track1CloudFile ;
158
+ track1CloudFile = new CloudFile ( shareFileClient . Uri , credentials ) ;
159
+ return track1CloudFile ;
93
160
}
94
161
95
162
// Convert Track1 File object to Track 2 file Client
96
- public static ShareFileClient GetTrack2FileClient ( CloudFile cloudFile , AzureStorageContext context )
163
+ public static ShareFileClient GetTrack2FileClient ( CloudFile cloudFile , ShareClientOptions clientOptions = null )
97
164
{
98
165
ShareFileClient fileClient ;
99
166
if ( cloudFile . ServiceClient . Credentials . IsSAS ) //SAS
@@ -109,16 +176,16 @@ public static ShareFileClient GetTrack2FileClient(CloudFile cloudFile, AzureStor
109
176
{
110
177
fullUri = fullUri + "?" + sas ;
111
178
}
112
- fileClient = new ShareFileClient ( new Uri ( fullUri ) ) ;
179
+ fileClient = new ShareFileClient ( new Uri ( fullUri ) , clientOptions ) ;
113
180
}
114
181
else if ( cloudFile . ServiceClient . Credentials . IsSharedKey ) //Shared Key
115
182
{
116
183
fileClient = new ShareFileClient ( cloudFile . SnapshotQualifiedUri ,
117
- new StorageSharedKeyCredential ( context . StorageAccountName , cloudFile . ServiceClient . Credentials . ExportBase64EncodedKey ( ) ) ) ;
184
+ new StorageSharedKeyCredential ( cloudFile . ServiceClient . Credentials . AccountName , cloudFile . ServiceClient . Credentials . ExportBase64EncodedKey ( ) ) , clientOptions ) ;
118
185
}
119
186
else //Anonymous
120
187
{
121
- fileClient = new ShareFileClient ( cloudFile . SnapshotQualifiedUri ) ;
188
+ fileClient = new ShareFileClient ( cloudFile . SnapshotQualifiedUri , clientOptions ) ;
122
189
}
123
190
124
191
return fileClient ;
0 commit comments