/// <summary> /// Reads the token information /// </summary> /// <param name="tokendata"></param> /// <returns></returns> public virtual ICloudStorageAccessToken LoadToken(Dictionary <String, String> tokendata) { ICloudStorageAccessToken at = null; String type = tokendata[CloudStorage.TokenCredentialType]; if (type.Equals(typeof(GenericNetworkCredentials).ToString())) { var username = tokendata[TokenGenericCredUsername]; var password = tokendata[TokenGenericCredPassword]; GenericNetworkCredentials bc = new GenericNetworkCredentials(); bc.UserName = username; bc.Password = password; at = bc; } #if !WINDOWS_PHONE else if (type.Equals(typeof(GenericCurrentCredentials).ToString())) { at = new GenericCurrentCredentials(); } #endif return(at); }
public YandexDriveClient(string login, string pass) { config = new WebDavConfiguration(new Uri(yandexWebDavUrl)); config.Limits = new CloudStorageLimits(-1, -1); config.TrustUnsecureSSLConnections = false; config.UploadDataStreambuffered = true; credentials = new GenericNetworkCredentials { UserName = login, Password = pass }; }
/// <summary> /// Writes a generic token onto the storage collection /// </summary> /// <param name="session"></param> /// <param name="tokendata"></param> /// <param name="token"></param> public virtual void StoreToken(IStorageProviderSession session, Dictionary <String, String> tokendata, ICloudStorageAccessToken token) { if (token is GenericNetworkCredentials) { GenericNetworkCredentials creds = token as GenericNetworkCredentials; tokendata.Add(TokenGenericCredUsername, creds.UserName); tokendata.Add(TokenGenericCredPassword, creds.Password); } }
protected GenericNetworkCredentials CheckAuthenticationToken(IAuthenticationSettings authenticationSettings) { var credentials = new GenericNetworkCredentials { UserName = authenticationSettings.BoxNetUsername, Password = authenticationSettings.BoxNetPassword }; return credentials; }
protected GenericNetworkCredentials CheckAuthenticationToken(string username, string password) { var credentials = new GenericNetworkCredentials { UserName = username, Password = password }; return credentials; }
protected void ExecuteUpload(IExecuteBoxNetUploaderWorkflowMessage message, GenericNetworkCredentials authenticationToken, FileInfo inputFilePath) { var cancellationTokenSource = new CancellationTokenSource(); var cancellationToken = cancellationTokenSource.Token; var task = Task.Factory.StartNew(() => { }); task.ContinueWith((t) => { BoxNetUploaderService.Uploaders.Add(message, new CancellableTask { Task = task, CancellationTokenSource = cancellationTokenSource }); var configuration = GetBoxNetConfiguration(); var storage = new CloudStorage(); var accessToken = storage.Open(configuration, authenticationToken); var folder = string.IsNullOrEmpty(message.Settings.Folder) ? storage.GetRoot() : storage.GetFolder(message.Settings.Folder); if (folder == null) { throw new Exception(string.Format("Folder does not exist - {0}", message.Settings.Folder)); } else { var file = storage.CreateFile(folder, inputFilePath.Name); var uploader = file.GetDataTransferAccessor(); using (var inputFileStream = inputFilePath.OpenRead()) { uploader.Transfer(inputFileStream, nTransferDirection.nUpload, FileOperationProgressChanged, task); } } if (storage.IsOpened) { storage.Close(); } } , cancellationToken) .ContinueWith((t) => { var executedBoxNetUploaderWorkflowMessage = new ExecutedBoxNetUploaderWorkflowMessage() { CorrelationId = message.CorrelationId, Cancelled = t.IsCanceled, Error = t.Exception }; var bus = BusDriver.Instance.GetBus(BoxNetUploaderService.BusName); bus.Publish(executedBoxNetUploaderWorkflowMessage); BoxNetUploaderService.Uploaders.Remove(message); }); }
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 void Test() { Uri u = new Uri("https://webdav.yandex.ru"); ICloudStorageConfiguration config = new WebDavConfiguration(u); GenericNetworkCredentials cred = new GenericNetworkCredentials(); cred.UserName = "******"; cred.Password = "******"; CloudStorage storage = new CloudStorage(); ICloudStorageAccessToken storageToken = storage.Open(config, cred); // storage.GetCloudConfiguration(nSupportedCloudConfigurations.WebDav); // After successful login you may do the necessary Directory/File manipulations by the SharpBox API // Here is the most often and simplest one ICloudDirectoryEntry root = storage.GetRoot(); var f =storage.GetFolder("/"); //f.First(). //var c =storage.GetCloudConfiguration(nSupportedCloudConfigurations.WebDav); //storage. storage.Close(); }
/// <summary> /// Reads the token information /// </summary> /// <param name="tokendata"></param> /// <returns></returns> public virtual ICloudStorageAccessToken LoadToken(Dictionary <string, string> tokendata) { ICloudStorageAccessToken at = null; var type = tokendata[CloudStorage.TokenCredentialType]; if (type.Equals(typeof(GenericNetworkCredentials).ToString())) { var username = tokendata[TokenGenericCredUsername]; var password = tokendata[TokenGenericCredPassword]; var bc = new GenericNetworkCredentials { UserName = username, Password = password }; at = bc; } else if (type.Equals(typeof(GenericCurrentCredentials).ToString())) { at = new GenericCurrentCredentials(); } return(at); }
/// <summary> /// Reads the token information /// </summary> /// <param name="tokendata"></param> /// <returns></returns> public virtual ICloudStorageAccessToken LoadToken(Dictionary<String, String> tokendata) { ICloudStorageAccessToken at = null; String type = tokendata[CloudStorage.TokenCredentialType]; if (type.Equals(typeof(GenericNetworkCredentials).ToString())) { var username = tokendata[TokenGenericCredUsername]; var password = tokendata[TokenGenericCredPassword]; GenericNetworkCredentials bc = new GenericNetworkCredentials(); bc.UserName = username; bc.Password = password; at = bc; } #if !WINDOWS_PHONE else if (type.Equals(typeof(GenericCurrentCredentials).ToString())) { at = new GenericCurrentCredentials(); } #endif return at; }
private void ConnectBoxNet(String username, String password) { // get the configuration for dropbox var boxnetConfig = CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.BoxNet); // Use GenericNetworkCredentials class for Box.Net. var cred = new GenericNetworkCredentials {Password = password, UserName = username}; // open the connection try { _storage.Open(boxnetConfig, cred); } catch (Exception ex) { throw new Exception("Could not connect to Box.\nCheck if you username and password are correct."); } if (_storage.IsOpened) { //Try to create the app folder _storage.CreateFolder("Savegames"); // get a specific directory in the cloud storage, e.g. /Public var publicFolder = _storage.GetRoot(); if (publicFolder == null) throw new Exception("Could not get the root folder."); // enumerate all child (folder and files) foreach (var fof in publicFolder) { // check if we have a directory var bIsDirectory = fof is ICloudDirectoryEntry; // output the info Console.WriteLine(@"{0}: {1}", bIsDirectory ? "DIR" : "FIL", fof.Name); } } }
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; }