protected override IEnumerable <CommandParameters> Execute(IEnumerable <CommandParameters> inParametersList) { foreach (var inParameters in inParametersList) { //inParameters = GetCurrentInParameters(); string file = inParameters.GetValue <string>("File"); string url = inParameters.GetValue <string>("Url"); string passWord = inParameters.GetValue <string>("Password"); string user = inParameters.GetValue <string>("User"); string remoteDirectory = inParameters.GetValueOrDefault <string>("RemoteDirectory", "/"); var cloudConfig = CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.WebDav, new Uri(url)); var cloudCredentials = new GenericNetworkCredentials() { UserName = user, Password = passWord }; this.cloudStorage.Open(cloudConfig, cloudCredentials); this.WriteData(remoteDirectory, file); var outParameters = this.GetCurrentOutParameters(); outParameters.SetOrAddValue("File", file); yield return(outParameters); this.cloudStorage.Close(); } }
public virtual StorageFileStreamResult Execute(WebDavConfigurationModel model, string filePath) { model = model.With(m => !string.IsNullOrEmpty(m.ServerUrl)) .With(m => !string.IsNullOrEmpty(m.AccountLogin)) .With(m => !string.IsNullOrEmpty(m.AccountPassword)); if (model == null) { throw new PluginException(PluginErrorCodes.InvalidCredentialsOrConfiguration); } if (string.IsNullOrEmpty(filePath)) { throw new PluginException(PluginErrorCodes.InvalidFileOrDirectoryName); } else { filePath = filePath.TrimEnd('/').RemoveCharDuplicates('/'); } if (string.IsNullOrEmpty(filePath)) { throw new PluginException(PluginErrorCodes.InvalidFileOrDirectoryName); } StorageFileStreamResult result = new StorageFileStreamResult(); Uri uri = new Uri(model.ServerUrl); ICloudStorageConfiguration config = new WebDavConfiguration(uri); GenericNetworkCredentials cred = new GenericNetworkCredentials(); cred.UserName = model.AccountLogin; cred.Password = model.AccountPassword; CloudStorage storage = null; try { storage = new CloudStorage(); ICloudStorageAccessToken storageToken = storage.Open(config, cred); var file = storage.GetFile(filePath, null); result.FileName = file.Name; result.FileStream = file.GetDataTransferAccessor().GetDownloadStream(); } finally { if (storage != null) { storage.Close(); } } return(result); }
public override FileSystem.NetworkFileSystem CreateConnection() { GenericNetworkCredentials gnc = new GenericNetworkCredentials(); gnc.UserName = _username; gnc.Password = _password; WebDavConfiguration webdav = new WebDavConfiguration(new Uri(_server)); CloudStorage storage = new CloudStorage(); storage.Open(webdav, gnc); return(null); }
protected override IEnumerable <CommandParameters> Execute(IEnumerable <CommandParameters> inParametersList) { foreach (var inParameters in inParametersList) { //inParameters = GetCurrentInParameters(); string url = inParameters.GetValue <string>("Url"); string user = inParameters.GetValue <string>("User"); string passWord = inParameters.GetValue <string>("Password"); string remoteDirectory = inParameters.GetValueOrDefault <string>("RemoteDirectory", "/"); string localDirectory = inParameters.GetValue <string>("LocalDirectory"); var cloudConfig = CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.WebDav, new Uri(url)); var cloudCredentials = new GenericNetworkCredentials() { UserName = user, Password = passWord }; this.cloudStorage.Open(cloudConfig, cloudCredentials); this.LogDebugFormat("Start reading files from Url='{0}', RemoteDirectory='{1}'", url, remoteDirectory); int fileIdx = 0; foreach (var localFileName in this.ReadData(remoteDirectory, localDirectory)) { fileIdx++; var outParameters = this.GetCurrentOutParameters(); outParameters.SetOrAddValue("File", localFileName); yield return(outParameters); } this.LogDebugFormat("End reading files from Url='{0}', RemoteDirectory='{1}': FilesCount={2}", url, remoteDirectory, fileIdx); this.cloudStorage.Close(); } }
public override IStorageProviderSession CreateSession(ICloudStorageAccessToken token, ICloudStorageConfiguration configuration) { // cast the creds to the right type GenericNetworkCredentials creds = token as GenericNetworkCredentials; // check if url available int status = (int)FtpStatusCode.CommandOK; WebException e = null; _ftpService.PerformSimpleWebCall(configuration.ServiceLocator.ToString(), WebRequestMethods.Ftp.ListDirectory, creds.GetCredential(null, null), null, out status, out e); if (status == (int)FtpStatusCode.NotLoggedIn) { throw new UnauthorizedAccessException(); } else if (status >= 100 && status < 400) { return(new FtpStorageProviderSession(token, configuration as FtpConfiguration, this)); } else { return(null); } }
public StorageFolderResult Execute(WebDavConfigurationModel model, string path, int accountId) { model = model.With(m => !string.IsNullOrEmpty(m.ServerUrl)) .With(m => !string.IsNullOrEmpty(m.AccountLogin)) .With(m => !string.IsNullOrEmpty(m.AccountPassword)); if (model == null) { throw new PluginException(PluginErrorCodes.InvalidCredentialsOrConfiguration); } StorageFolderResult result = new StorageFolderResult(); Uri uri = new Uri(model.ServerUrl); ICloudStorageConfiguration config = new WebDavConfiguration(uri); GenericNetworkCredentials cred = new GenericNetworkCredentials(); cred.UserName = model.AccountLogin; cred.Password = model.AccountPassword; if (string.IsNullOrEmpty(path)) { path = "/"; } else { path = path.RemoveCharDuplicates('/'); } if (!path.Equals("/", StringComparison.OrdinalIgnoreCase)) { path = path.TrimEnd('/'); } CloudStorage storage = null; try { storage = new CloudStorage(); ICloudStorageAccessToken storageToken = storage.Open(config, cred); ICloudDirectoryEntry directory = storage.GetFolder(path, true); result.CurrentFolderName = directory.Name; result.CurrentFolderUrl = path; path = path.TrimEnd('/'); foreach (var entry in directory) { var dirEntry = entry as ICloudDirectoryEntry; string entryPath = string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", path, "/", entry.Name); if (dirEntry != null) { result.AddItem(new StorageFolder { Name = dirEntry.Name, Path = entryPath, StorageAccountId = accountId }); } else { result.AddItem(new StorageFile { Name = entry.Name, Path = entryPath, StorageAccountId = accountId }); } } StoragePathItem rootPath = new StoragePathItem { Name = "/", Url = "/" }; string relativePath = path.Trim('/').RemoveCharDuplicates('/'); if (relativePath.Length > 0) { string[] pathItems = relativePath.Split('/'); StringBuilder pathUrlsBuilder = new StringBuilder("/"); foreach (var pathItem in pathItems) { pathUrlsBuilder.Append(pathItem); rootPath.AppendItem(new StoragePathItem { Name = pathItem, Url = pathUrlsBuilder.ToString() }); pathUrlsBuilder.Append("/"); } } result.CurrentPath = rootPath; } finally { if (storage != null) { storage.Close(); } } return(result); }