@@ -131,15 +131,19 @@ Namespace CloudFiles
131
131
End Get
132
132
End Property
133
133
134
- ' The CDN Management URL can be useful...
134
+ ' The CDN Management URL for each datacenter can be useful...
135
135
Private pManagementUrl As String = Nothing
136
- Public Property ManagementUrl As String
136
+
137
+ Public ReadOnly Property DallasManagementUrl As String
137
138
Get
138
139
Return pManagementUrl
139
140
End Get
140
- Set (value As String )
141
- pManagementUrl = value
142
- End Set
141
+ End Property
142
+
143
+ Public ReadOnly Property ChicagoManagementUrl As String
144
+ Get
145
+ Return pManagementUrl.Replace( "//cdn1." , "//cdn2." )
146
+ End Get
143
147
End Property
144
148
145
149
# End Region
@@ -184,7 +188,7 @@ Namespace CloudFiles
184
188
Dim AuthenticationResponse As HttpWebResponse = AuthenticationRequest.GetResponse
185
189
186
190
Me .XAuthToken = AuthenticationResponse.Headers( "X-Auth-Token" )
187
- Me .ManagementUrl = AuthenticationResponse.Headers( "X-CDN-Management-Url" )
191
+ Me .pManagementUrl = AuthenticationResponse.Headers( "X-CDN-Management-Url" )
188
192
Me .pStorageUrl = AuthenticationResponse.Headers( "X-Storage-Url" ).Replace( ".dfw1." , ".<location>." )
189
193
Me .XAuthTokenReceivedOn = Now
190
194
@@ -200,6 +204,20 @@ Namespace CloudFiles
200
204
' Make sure we've got a valid token. Reauthenticate if need be.
201
205
If Me .XAuthTokenIsExpired Then Me .Authenticate()
202
206
207
+ Try
208
+
209
+ Catch ex As WebException
210
+
211
+ Dim Response As HttpWebResponse = ex.Response
212
+
213
+ If Response.StatusCode = HttpStatusCode.Unauthorized Then
214
+
215
+
216
+
217
+ End If
218
+
219
+ End Try
220
+
203
221
' A request to get account metadata.
204
222
Dim MetadataRequest As HttpWebRequest
205
223
@@ -305,6 +323,74 @@ Namespace CloudFiles
305
323
306
324
End Function
307
325
326
+ Public Function CdnEnableContainer( ByVal ContainerName As String , ByVal ServerLocation As ServerLocation, Optional ByVal TimeToLive As Long = 259200 ) As CdnEnableContainerResult
327
+
328
+ ' Make sure we've got a valid token. Reauthenticate if need be.
329
+ If Me .XAuthTokenIsExpired Then Me .Authenticate()
330
+
331
+ ' A request to CDN-enable the container.
332
+ Dim CdnEnableRequest As HttpWebRequest
333
+
334
+ ' Change the target URL based on what server farm we're counting on.
335
+ If ServerLocation = CloudFiles.ServerLocation.Chicago Then
336
+ CdnEnableRequest = HttpWebRequest.Create( Me .ChicagoManagementUrl & "/" & ContainerName)
337
+ Else
338
+ CdnEnableRequest = HttpWebRequest.Create( Me .DallasManagementUrl & "/" & ContainerName)
339
+ End If
340
+
341
+ With CdnEnableRequest
342
+ .Method = "PUT"
343
+ .Headers.Add( "X-Auth-Token" , Me .XAuthToken)
344
+ .Headers.Add( "X-CDN-Enabled" , "True" )
345
+ .Headers.Add( "X-TTL" , CStr (TimeToLive))
346
+ End With
347
+
348
+ Dim CdnEnableContainerResponse As HttpWebResponse = CdnEnableRequest.GetResponse
349
+
350
+ If CdnEnableContainerResponse.StatusCode = HttpStatusCode.Created Then
351
+ Return CdnEnableContainerResult.CdnEnabledContainerSuccessfully
352
+ ElseIf CdnEnableContainerResponse.StatusCode = HttpStatusCode.Accepted Then
353
+ Return CdnEnableContainerResult.ContainerAlreadyCdnEnabled
354
+ Else
355
+ Return CdnEnableContainerResult.UnknownResultProbableFailure
356
+ End If
357
+
358
+ End Function
359
+
360
+ Public Function CdnDisableContainer( ByVal ContainerName As String , ByVal ServerLocation As ServerLocation, Optional ByVal TimeToLive As Long = 259200 ) As CdnEnableContainerResult
361
+
362
+ ' Make sure we've got a valid token. Reauthenticate if need be.
363
+ If Me .XAuthTokenIsExpired Then Me .Authenticate()
364
+
365
+ ' A request to CDN-disable the container.
366
+ Dim CdnEnableRequest As HttpWebRequest
367
+
368
+ ' Change the target URL based on what server farm we're counting on.
369
+ If ServerLocation = CloudFiles.ServerLocation.Chicago Then
370
+ CdnEnableRequest = HttpWebRequest.Create( Me .ChicagoManagementUrl & "/" & ContainerName)
371
+ Else
372
+ CdnEnableRequest = HttpWebRequest.Create( Me .DallasManagementUrl & "/" & ContainerName)
373
+ End If
374
+
375
+ With CdnEnableRequest
376
+ .Method = "PUT"
377
+ .Headers.Add( "X-Auth-Token" , Me .XAuthToken)
378
+ .Headers.Add( "X-CDN-Enabled" , "False" )
379
+ .Headers.Add( "X-TTL" , CStr (TimeToLive))
380
+ End With
381
+
382
+ Dim CdnEnableContainerResponse As HttpWebResponse = CdnEnableRequest.GetResponse
383
+
384
+ If CdnEnableContainerResponse.StatusCode = HttpStatusCode.Created Then
385
+ Return CdnEnableContainerResult.CdnEnabledContainerSuccessfully
386
+ ElseIf CdnEnableContainerResponse.StatusCode = HttpStatusCode.Accepted Then
387
+ Return CdnEnableContainerResult.ContainerAlreadyCdnEnabled
388
+ Else
389
+ Return CdnEnableContainerResult.UnknownResultProbableFailure
390
+ End If
391
+
392
+ End Function
393
+
308
394
Public Function DeleteContainer( ByVal ContainerToDelete As String , ByVal ServerLocation As ServerLocation) As DeleteContainerResult
309
395
310
396
' Make sure we've got a valid token. Reauthenticate if need be.
0 commit comments