/// <summary> /// This method sets a container as private on the CDN /// </summary> /// <example> /// <code> /// UserCredentials userCredentials = new UserCredentials("username", "api key"); /// IConnection connection = new Connection(userCredentials); /// connection.MarkContainerAsPrivate("container name"); /// </code> /// </example> /// <param name="containerName">The name of the container to mark public</param> /// <exception cref="ArgumentNullException">Thrown when any of the reference parameters are null</exception> public void MarkContainerAsPrivate(string containerName) { if (string.IsNullOrEmpty(containerName)) throw new ArgumentNullException(); Log.Info(this, "Marking container " + containerName + " as private for user " + _usercreds.Username); try { var request = new SetPublicContainerDetails(CdnManagementUrl, containerName, false, false, -1, "", ""); _requestfactory.Submit(request, AuthToken); } catch (WebException we) { Log.Error(this, "Error marking container " + containerName + " as private for user " + _usercreds.Username, we); var response = (HttpWebResponse)we.Response; if (response != null && response.StatusCode == HttpStatusCode.Unauthorized) throw new UnauthorizedAccessException("Your access credentials are invalid or have expired. "); if (response != null && response.StatusCode == HttpStatusCode.NotFound) throw new PublicContainerNotFoundException("The specified container does not exist."); throw; } }
public void SetDetailsOnPublicContainer(string publiccontainer, bool loggingenabled, int ttl, string referreracl, string useragentacl) { if (string.IsNullOrEmpty(publiccontainer)) throw new ArgumentNullException(); Log.Info(this, "Adding logging to container named " + publiccontainer + " for user " + _usercreds.Username); try { var request = new SetPublicContainerDetails(CdnManagementUrl, publiccontainer, true, loggingenabled, ttl, useragentacl, referreracl); _requestfactory.Submit(request, AuthToken); } catch (WebException we) { Log.Error(this, "Error setting logging on container named " + publiccontainer + " for user " + _usercreds.Username, we); var response = (HttpWebResponse)we.Response; if (response != null && response.StatusCode == HttpStatusCode.Unauthorized) throw new UnauthorizedAccessException("Your access credentials are invalid or have expired. "); if (response != null && response.StatusCode == HttpStatusCode.NotFound) throw new PublicContainerNotFoundException("The specified container does not exist."); throw; } }
public void should_throw_argument_null_exception() { var setPublicContainerDetails = new SetPublicContainerDetails("http://cdnmanagementurl", "containername", true,false, -1); Asserts.AssertHeaders(setPublicContainerDetails,utils.Constants.X_CDN_TTL,null ); }
public void setup() { setPublicContainerDetails = new SetPublicContainerDetails("http://cdnmanagementurl", "containername", true,false ,12345); }
public void should_throw_argument_null_exception() { var setPublicContainerDetails = new SetPublicContainerDetails("http://cdnmanagementurl", "authtoken", "containername", true, -1); Assert.That(setPublicContainerDetails.Headers[utils.Constants.X_CDN_TTL], Is.Null); }
/// <summary> /// This sets the time to live on the public container on the CDN /// </summary> /// <example> /// <code> /// UserCredentials userCredentials = new UserCredentials("username", "api key"); /// IConnection connection = new Connection(userCredentials); /// connection.SetTTLOnPublicContainer("container name", 12345); /// </code> /// </example> /// <param name="containerName">The name of the container to mark public</param> /// <param name="timeToLiveInSeconds">The maximum time (in seconds) content should be kept alive on the CDN before it checks for freshness.</param> /// <exception cref="ArgumentNullException">Thrown when any of the reference parameters are null</exception> public void SetTTLOnPublicContainer(string containerName, int timeToLiveInSeconds) { if (string.IsNullOrEmpty(containerName)) throw new ArgumentNullException(); Log.Info(this, "Setting TTL of " + timeToLiveInSeconds + " seconds on public container " + containerName + " for user " + UserCredentials.Username); try { var request = new SetPublicContainerDetails(CdnManagementUrl, AuthToken, containerName, true, timeToLiveInSeconds); new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(request)); } catch (WebException we) { Log.Error(this, "Error setting TTL of " + timeToLiveInSeconds + " seconds on public container " + containerName + " for user " + UserCredentials.Username, we); var response = (HttpWebResponse)we.Response; if (response != null && response.StatusCode == HttpStatusCode.Unauthorized) throw new UnauthorizedAccessException("Your access credentials are invalid or have expired. "); if (response != null && response.StatusCode == HttpStatusCode.NotFound) throw new PublicContainerNotFoundException("The specified container does not exist."); throw; } }
private void setDetailsOnPublicContainer(string publiccontainer, bool loggingenabled, int ttl, string referreracl, string useragentacl) { var request = new SetPublicContainerDetails(CdnManagementUrl, publiccontainer, true, loggingenabled, ttl, useragentacl, referreracl); _requestfactory.Submit(request, AuthToken); }
//PRIVATE METHODS //TODO: extract to service private void markContainerAsPrivate(string containerName) { var request = new SetPublicContainerDetails(CdnManagementUrl, containerName, false, false, -1, "", ""); _requestfactory.Submit(request, AuthToken); }
private void setDetailsOnPublicContainer(string publiccontainer, bool loggingenabled, int ttl) { if (!HasCDN()) return; var request = new SetPublicContainerDetails(CdnManagementUrl, publiccontainer, true, loggingenabled, ttl); _requestfactory.Submit(request, AuthToken); }