static void Main(string[] args) { Console.WriteLine(); if (ParseArguments(args)) { DirectoryInfo directory = null; try { directory = new DirectoryInfo(Source); if (!directory.Exists) { throw new Exception(String.Format("Source directory does not exist\n{0}", Source)); } } catch (Exception ex) { PrintException(ex); } Console.WriteLine(String.Format("Source directory: {0}", Source)); Console.WriteLine(String.Format("Destination container: {0}", Container)); Console.WriteLine("Logging in..."); Console.WriteLine(); if (Login()) { var cloudFiles = new CloudFilesProvider(auth); try { switch (cloudFiles.CreateContainer(Container)) { case ObjectStore.ContainerCreated: case ObjectStore.ContainerExists: foreach (var file in directory.GetFiles()) { Console.WriteLine(String.Format("{0,3:0}% Uploading: {1}", 0, file.Name)); cloudFiles.CreateObjectFromFile(Container, file.FullName, progressUpdated: delegate(long p) { Console.SetCursorPosition(0, Console.CursorTop -1); Console.WriteLine(String.Format("{0,3:0}% Uploading: {1}", ((float)p / (float)file.Length) * 100, file.Name)); }); } break; default: throw new Exception(String.Format("Unknown error when creating container {0}", Container)); } } catch (Exception ex) { PrintException(ex); } } } Console.WriteLine(); Console.Write("Press any key to exit"); Console.ReadKey(); }
public void Should_Return_Container_List_With_Internal_Url() { var provider = new CloudFilesProvider(); var containerList = provider.ListContainers(useInternalUrl:true, identity: _testIdentity); Assert.IsNotNull(containerList); Assert.IsTrue(containerList.Any()); }
public void Should_Return_Container_List() { var provider = new CloudFilesProvider(); var containerList = provider.ListContainers(identity: _testIdentity); Assert.IsNotNull(containerList); Assert.IsTrue(containerList.Any()); }
protected void CFProvidersCreateContainer(string cfcreatecontainername, string dcregion, bool dcsnet = true) { var identity = new RackspaceCloudIdentity() { Username = CFUsernameText.Text, APIKey = CFApiKeyText.Text }; CloudIdentityProvider identityProvider = new net.openstack.Providers.Rackspace.CloudIdentityProvider(identity); CloudFilesProvider CloudFilesProvider = new net.openstack.Providers.Rackspace.CloudFilesProvider(identity); var CfCreateContainer = CloudFilesProvider.CreateContainer(cfcreatecontainername, dcregion, dcsnet); }
protected void CFProvidersCreateObjectFromFile(string cfcontainername, string cfcreateobjfilepath, string cfcreateobjfilename, int cfcreateobjchunksize, string dcregion, bool dcsnet = true) { var identity = new RackspaceCloudIdentity() { Username = CFUsernameText.Text, APIKey = CFApiKeyText.Text }; CloudIdentityProvider identityProvider = new net.openstack.Providers.Rackspace.CloudIdentityProvider(identity); CloudFilesProvider CloudFilesProvider = new net.openstack.Providers.Rackspace.CloudFilesProvider(identity); CloudFilesProvider.CreateObjectFromFile(cfcontainername, cfcreateobjfilepath, cfcreateobjfilename, cfcreateobjchunksize, null, dcregion, null, dcsnet); }
protected void CFProvidersDeleteContainerObject(string cfcontainername, string cfdeletecontainerobject, string dcregion, bool dcsnet = true) { var identity = new RackspaceCloudIdentity() { Username = CFUsernameText.Text, APIKey = CFApiKeyText.Text }; CloudIdentityProvider identityProvider = new net.openstack.Providers.Rackspace.CloudIdentityProvider(identity); CloudFilesProvider CloudFilesProvider = new net.openstack.Providers.Rackspace.CloudFilesProvider(identity); var Cfdeletecontainerobject = CloudFilesProvider.DeleteObject(cfcontainername, cfdeletecontainerobject, null, dcregion, dcsnet); }
public CloudFilesContainerNode(CloudFilesProvider provider, Container container, ContainerCDN containerCdn) { if (provider == null) throw new ArgumentNullException("provider"); if (container == null) throw new ArgumentNullException("container"); _provider = provider; _container = container; _containerCdn = containerCdn; }
public CloudFilesTests(ITestOutputHelper testLog) { var testOutput = new XunitTraceListener(testLog); Trace.Listeners.Add(testOutput); OpenStackNet.Tracing.Http.Listeners.Add(testOutput); var authenticationProvider = TestIdentityProvider.GetIdentityProvider(); authenticationProvider.Authenticate(); _cloudFiles = new CloudFilesProvider(null, authenticationProvider); }
public CloudFilesObjectNode(CloudFilesProvider provider, Container container, ContainerObject containerObject) { if (provider == null) throw new ArgumentNullException("provider"); if (container == null) throw new ArgumentNullException("container"); if (containerObject == null) throw new ArgumentNullException("containerObject"); _provider = provider; _container = container; _containerObject = containerObject; }
protected void CFProviderListContainers(string dcregion, bool dcsnet = true) { var identity = new RackspaceCloudIdentity() { Username = CFUsernameText.Text, APIKey = CFApiKeyText.Text }; CloudIdentityProvider identityProvider = new net.openstack.Providers.Rackspace.CloudIdentityProvider(identity); CloudFilesProvider CloudFilesProvider = new net.openstack.Providers.Rackspace.CloudFilesProvider(identity); var CfContainers = CloudFilesProvider.ListContainers(null, null, null, dcregion, dcsnet); CFContainerDDL.DataSource = CfContainers; CFContainerDDL.DataTextField = "Name"; CFContainerDDL.DataBind(); }
protected CloudFilesProvider filesProvider() { string CloudIdentityUserName = (string)(Session["CloudIdentityUserName"]); string CloudIdentityApiKey = (string)(Session["CloudIdentityApiKey"]); RackspaceCloudIdentity identity = new RackspaceCloudIdentity() { Username = CloudIdentityUserName, APIKey = CloudIdentityApiKey }; CloudFilesProvider CloudFilesProvider = new net.openstack.Providers.Rackspace.CloudFilesProvider(identity); return(CloudFilesProvider); }
public static CloudFilesProvider filesProvider() { string CloudIdentityUserName = (string)(HttpContext.Current.Session["CloudIdentityUserName"]); string CloudIdentityApiKey = (string)(HttpContext.Current.Session["CloudIdentityApiKey"]); RackspaceCloudIdentity identity = new RackspaceCloudIdentity() { Username = CloudIdentityUserName, APIKey = CloudIdentityApiKey }; CloudFilesProvider CloudFilesProvider = new net.openstack.Providers.Rackspace.CloudFilesProvider(identity); return(CloudFilesProvider); }
private IEnumerable<ContainerObject> ListContainer(CloudIdentity cloudIdentity, string container, int? limit = null, string prefix = null, string region = null, bool useInternalUrl = false) { var provider = new CloudFilesProvider(cloudIdentity); ContainerObject lastContainerObject = null; do { string marker = lastContainerObject != null ? lastContainerObject.Name : null; IEnumerable<ContainerObject> containerObjects = provider.ListObjects(container, limit, marker, null, prefix, region, useInternalUrl, cloudIdentity); lastContainerObject = null; foreach (ContainerObject containerObject in containerObjects) { lastContainerObject = containerObject; yield return containerObject; } } while (lastContainerObject != null); }
public bool DownloadFromRackSpaceCloudFiles() { bool syncSucceeded = true; try { var cloudIdentity = new CloudIdentity() { APIKey = this.apiKey, Username = this.username }; var cloudFilesProvider = new CloudFilesProvider(cloudIdentity); IEnumerable<ContainerObject> containerObjectList = cloudFilesProvider.ListObjects(container); foreach (ContainerObject containerObject in containerObjectList) { cloudFilesProvider.GetObjectSaveToFile(container, localSource, containerObject.Name, containerObject.Name); } } catch (Exception e) { Console.WriteLine("Exception in downloading from rackspace: " + e); syncSucceeded = false; } return syncSucceeded; }
public RackspaceCloudFilesSynchronizer(RemoteInfo ri, string container, SynchronizeDirection syncDirection) { this.disposed = false; this.username = ri.accountName; this.apiKey = ri.accountKey; this.syncDirection = syncDirection; this.container = container; try { var cloudIdentity = new CloudIdentity() { APIKey = this.apiKey, Username = this.username }; var cloudFilesProvider = new CloudFilesProvider(cloudIdentity); ObjectStore createContainerResponse = cloudFilesProvider.CreateContainer(container);// assume default region for now if (!createContainerResponse.Equals(ObjectStore.ContainerCreated) && !createContainerResponse.Equals(ObjectStore.ContainerExists)) Console.WriteLine("Container creation failed! Response: " + createContainerResponse.ToString()); } catch (Exception e) { Console.WriteLine("Exception in creating container: " + e); } }
//Method to Authenticate the credentials and obtain token public void Authenticate() { try { //Creating an instance of CloudIdentityProvider providing the CloudIdentity object and urls in the constructor provider = new CloudIdentityProvider(identity, "https://identity.api.rackspacecloud.com/v1.0", "https://lon.identity.api.rackspacecloud.com/v1.0"); //Calling the authenticate method which returns an UserAccess object containing token and user details UserAccess access = provider.Authenticate(identity); token = access.Token; userdetails = access.User; //Set the TokenId property TokenId = token.Id; //Verify with other programmers to make this method void cloudFiles = new CloudFilesProvider(identity); //return token.Id; } catch (UserAuthenticationException ex) { Console.WriteLine(ex.Message); throw ex; } catch (UserAuthorizationException ex) { Console.WriteLine(ex.Message); throw ex; } catch (UserNotAuthorizedException ex) { Console.WriteLine(ex.Message); throw ex; } catch (Exception ex) { Console.WriteLine(ex.Message); throw ex; } }
public ActionResult CKEditorUpload(string CKEditorFuncNum) { var m = new AccountModel(); string baseurl = null; if (Request.Files.Count == 0) return Content(""); var file = Request.Files[0]; var fn = $"{DbUtil.Db.Host}.{DateTime.Now:yyMMddHHmm}.{m.CleanFileName(Path.GetFileName(file.FileName))}"; var error = string.Empty; var rackspacecdn = ConfigurationManager.AppSettings["RackspaceUrlCDN"]; if (rackspacecdn.HasValue()) { baseurl = rackspacecdn; var username = ConfigurationManager.AppSettings["RackspaceUser"]; var key = ConfigurationManager.AppSettings["RackspaceKey"]; var cloudIdentity = new CloudIdentity {APIKey = key, Username = username}; var cloudFilesProvider = new CloudFilesProvider(cloudIdentity); cloudFilesProvider.CreateObject("AllFiles", file.InputStream, fn); } else // local server { baseurl = $"{Request.Url.Scheme}://{Request.Url.Authority}/Upload/"; try { var path = Server.MapPath("/Upload/"); path += fn; path = m.GetNewFileName(path); file.SaveAs(path); } catch (Exception ex) { error = ex.Message; baseurl = string.Empty; } } return Content($"<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction( {CKEditorFuncNum}, '{baseurl + fn}', '{error}' );</script>"); }
public ActionResult FroalaUpload(HttpPostedFileBase file) { var m = new AccountModel(); string baseurl = null; var fn = $"{DbUtil.Db.Host}.{DateTime.Now:yyMMddHHmm}.{m.CleanFileName(Path.GetFileName(file.FileName))}"; var error = string.Empty; var rackspacecdn = ConfigurationManager.AppSettings["RackspaceUrlCDN"]; if (rackspacecdn.HasValue()) { baseurl = rackspacecdn; var username = ConfigurationManager.AppSettings["RackspaceUser"]; var key = ConfigurationManager.AppSettings["RackspaceKey"]; var cloudIdentity = new CloudIdentity {APIKey = key, Username = username}; var cloudFilesProvider = new CloudFilesProvider(cloudIdentity); cloudFilesProvider.CreateObject("AllFiles", file.InputStream, fn); } else // local server { baseurl = $"{Request.Url.Scheme}://{Request.Url.Authority}/Upload/"; try { var path = Server.MapPath("/Upload/"); path += fn; path = m.GetNewFileName(path); file.SaveAs(path); } catch (Exception ex) { error = ex.Message; baseurl = string.Empty; } } return Json(new {link = baseurl + fn, error}, JsonRequestBehavior.AllowGet); }
public bool UploadToRackSpaceCloudFiles() { bool syncSucceeded = true; try { var cloudIdentity = new CloudIdentity() { APIKey = this.apiKey, Username = this.username }; var cloudFilesProvider = new CloudFilesProvider(cloudIdentity); List<string> fileList = AmazonS3Helper.ListFiles(localSource); foreach (string file in fileList) { cloudFilesProvider.CreateObjectFromFile(container, file, Path.GetFileName(file)); // assuming this overwrites file if it exists. } } catch (Exception e) { Console.WriteLine("Exception in uploading to rackspace: "+e); syncSucceeded = false; } return syncSucceeded; }
public void Should_Throw_An_Exception_When_Deleting_Object() { // TODO: Also need to make 404 as an acceptable status. var headers = new Dictionary<string, string>(); var provider = new CloudFilesProvider(); var deleteResponse = provider.DeleteObject(containerName, objectName, headers, identity: _testIdentity); Assert.Fail("Expected exception was not thrown."); }
public void Should_Copy_Object_When_Not_Passing_Content_Length() { var provider = new CloudFilesProvider(); var copyResponse = provider.CopyObject(sourceContainerName, sourceObjectName, destinationContainerName, destinationObjectName, identity: _testIdentity); Assert.AreEqual(ObjectStore.ObjectCreated, copyResponse); }
private CloudFilesProvider CreateProvider() { CloudFilesProvider provider = new CloudFilesProvider(Identity, Endpoint.Region, null, null); provider.ConnectionLimit = 50; return provider; }
private CloudFilesContainerNode CreateContainerNode(CloudFilesProvider provider, Container container, ContainerCDN containerCdn) { return new CloudFilesContainerNode(provider, container, containerCdn); }
public void Should_Get_MetaData_For_Object1() { var provider = new CloudFilesProvider(); var objectHeadersResponse = provider.GetObjectMetaData(containerName, objectName, identity: _testIdentity); Assert.IsNotNull(objectHeadersResponse); //Assert.AreEqual("Christian Bale", objectHeadersResponse.Where(x => x.Key.Equals("X-Object-Meta-Actor", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault().Value); }
public void Should_Return_Container_List_With_Limit() { var provider = new CloudFilesProvider(); var containerList = provider.ListContainers(1, identity: _testIdentity); Assert.IsNotNull(containerList); Assert.AreEqual(1, containerList.Count()); }
public void Should_Delete_Object_On_Destination_Container() { var headers = new Dictionary<string, string>(); var provider = new CloudFilesProvider(); var deleteResponse = provider.DeleteObject(destinationContainerName, destinationObjectName, headers, identity: _testIdentity); Assert.AreEqual(ObjectStore.ObjectDeleted, deleteResponse); }
public void Should_Get_MetaData_For_Account() { var provider = new CloudFilesProvider(); var accountHeadersResponse = provider.GetAccountMetaData(identity: _testIdentity); Assert.IsNotNull(accountHeadersResponse); Assert.IsTrue(accountHeadersResponse.ContainsKey("Temp-Url-Key")); }
public void Should_Get_Headers_For_Account() { var provider = new CloudFilesProvider(); var accountHeadersResponse = provider.GetAccountHeaders(identity: _testIdentity); Assert.IsNotNull(accountHeadersResponse); Assert.IsTrue(accountHeadersResponse.ContainsKey("x-account-object-count")); }
public void Should_Purge_CDN_Enabled_Object_Multiple_Email_Notification() { var provider = new CloudFilesProvider(); var objectDeleteResponse = provider.PurgeObjectFromCDN(containerName, objectName, emailToList, identity: _testIdentity); Assert.AreEqual(ObjectStore.ObjectPurged, objectDeleteResponse); }
public void Should_Copy_Object_When_Passing_Content_Length() { Dictionary<string, string> header = new Dictionary<string, string>(); header.Add(CloudFilesProvider.ContentLength, "62504"); var provider = new CloudFilesProvider(); var copyResponse = provider.CopyObject(sourceContainerName, sourceObjectName, destinationContainerName, destinationObjectName, header, identity: _testIdentity); Assert.AreEqual(ObjectStore.ObjectCreated, copyResponse); }
public void Should_Update_Headers_For_Account() { var headers = new Dictionary<string, string>(); headers.Add("X-Account-Meta-Test-Accountmetadata", "Test1"); var provider = new CloudFilesProvider(); provider.UpdateAccountHeaders(headers, identity: _testIdentity); var accountHeadersResponse = provider.GetAccountMetaData(identity: _testIdentity); Assert.IsNotNull(accountHeadersResponse); Assert.IsTrue(accountHeadersResponse.ContainsKey("Test-Accountmetadata")); Assert.AreEqual("Test1", accountHeadersResponse.Where(x => x.Key.Equals("Test-Accountmetadata", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault().Value); }
public void Should_Copy_Object_When_Not_Passing_Content_Length_And_Passing_Expiring_Header() { // Object will expire 2 days from now. int epoch = (int)(DateTime.UtcNow.AddDays(2) - new DateTime(1970, 1, 1)).TotalSeconds; Dictionary<string, string> header = new Dictionary<string, string>(); header.Add(CloudFilesProvider.ObjectDeleteAt, epoch.ToString()); var provider = new CloudFilesProvider(); var copyResponse = provider.CopyObject(sourceContainerName, sourceObjectName, destinationContainerName, destinationObjectName, header, identity: _testIdentity); Assert.AreEqual(ObjectStore.ObjectCreated, copyResponse); }