public GoogleDocsStorageProviderSession(IStorageProviderService service, ICloudStorageConfiguration configuration, OAuthConsumerContext context, ICloudStorageAccessToken token) { Service = service; ServiceConfiguration = configuration; Context = context; SessionToken = token; }
public override IStorageProviderSession CreateSession(ICloudStorageAccessToken token, ICloudStorageConfiguration configuration) { var skydriveToken = token as OAuth20Token; if (skydriveToken == null) throw new ArgumentException("Cannot create skydrive session with given token", "token"); if (skydriveToken.IsExpired) token = SkyDriveAuthorizationHelper.RefreshToken(skydriveToken); return new SkyDriveStorageProviderSession(token, this, configuration); }
/// <summary> /// Calling this method with vendor specific configuration settings and token based credentials /// to get access to the cloud storage. The following exceptions are possible: /// /// - System.UnauthorizedAccessException when the user provides wrong credentials /// - AppLimit.CloudComputing.SharpBox.Exceptions.SharpBoxException when something /// happens during cloud communication /// /// </summary> /// <param name="configuration">Vendor specific configuration of the cloud storage</param> /// <param name="token">Vendor specific authorization token</param> /// <returns>A valid access token or null</returns> public ICloudStorageAccessToken Open(ICloudStorageConfiguration configuration, ICloudStorageAccessToken token) { // check state if (IsOpened) { return(null); } // ensures that the right provider will be used SetProviderByConfiguration(configuration); // save the configuration _configuration = configuration; // verify the ssl config if (configuration.TrustUnsecureSSLConnections) { System.Net.ServicePointManager.ServerCertificateValidationCallback = ValidateAllServerCertificates; } // update the max connection settings ServicePointManager.DefaultConnectionLimit = 250; // disable the not well implementes Expected100 header settings ServicePointManager.Expect100Continue = false; // open the cloud connection token = _provider.Open(configuration, token); // ok without Exception every is good IsOpened = true; // return the token return(token); }
public GoogleDocsStorageProviderSession(IStorageProviderService service, ICloudStorageConfiguration configuration, OAuthConsumerContext context, ICloudStorageAccessToken token) { Service = service; ServiceConfiguration = configuration; Context = context; SessionToken = token; }
public override IStorageProviderSession CreateSession(ICloudStorageAccessToken token, ICloudStorageConfiguration configuration) { // get the user credentials var userToken = token as DropBoxToken; var svcConfig = configuration as DropBoxConfiguration; // get the session return this.Authorize(userToken, svcConfig); }
private void SetProviderByConfiguration(ICloudStorageConfiguration configuration) { // check if (configuration == null && _provider == null) { throw new InvalidOperationException("It's only allowed to set the configuration parameter to null when a provider was set before"); } // read out the right provider type SetProviderByConfigurationTypeName(configuration.GetType().FullName); }
/// <summary> /// Starts the async open request /// </summary> /// <param name="callback"></param> /// <param name="configuration"></param> /// <param name="token"></param> /// <returns></returns> public IAsyncResult BeginOpenRequest(AsyncCallback callback, ICloudStorageConfiguration configuration, ICloudStorageAccessToken token) { // build the request data structure OpenRequest request = new OpenRequest(); request.callback = callback; request.result = new AsyncResultEx(request); request.config = configuration; request.token = token; // add to threadpool ThreadPool.QueueUserWorkItem(OpenRequestCallback, request); // return the result return request.result; }
public static string GetUrlString(string urltemplate, ICloudStorageConfiguration configuration) { if (urltemplate.Contains("{0}")) { if (configuration == null || !(configuration is DropBoxConfiguration)) { return(string.Format(urltemplate, ((int)DropBoxAPIVersion.Stable).ToString())); } var versionValue = (int)((DropBoxConfiguration)configuration).APIVersion; return(string.Format(urltemplate, versionValue.ToString())); } return(urltemplate); }
/// <summary> /// copy ctor /// </summary> /// <param name="src"></param> /// <param name="OpenIfSourceWasOpen"></param> public CloudStorage(CloudStorage src, Boolean OpenIfSourceWasOpen) : this() { // copy all registered provider from src _configurationProviderMap = src._configurationProviderMap; // open the provider if (src.IsOpened && OpenIfSourceWasOpen) { Open(src._configuration, src.CurrentAccessToken); } else { _configuration = src._configuration; } }
/// <summary> /// Starts the async open request /// </summary> /// <param name="callback"></param> /// <param name="configuration"></param> /// <param name="token"></param> /// <returns></returns> public IAsyncResult BeginOpenRequest(AsyncCallback callback, ICloudStorageConfiguration configuration, ICloudStorageAccessToken token) { // build the request data structure OpenRequest request = new OpenRequest(); request.callback = callback; request.result = new AsyncResultEx(request); request.config = configuration; request.token = token; // add to threadpool ThreadPool.QueueUserWorkItem(OpenRequestCallback, request); // return the result return(request.result); }
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; }
/// <summary> /// This method opens a session for the implemented storage provider based on an existing /// security token. /// </summary> /// <param name="configuration"></param> /// <param name="token"></param> /// <returns></returns> public ICloudStorageAccessToken Open(ICloudStorageConfiguration configuration, ICloudStorageAccessToken token) { // Verify the compatibility of the credentials if (!_Service.VerifyAccessTokenType(token)) throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidCredentialsOrConfiguration); // create a new session _Session = _Service.CreateSession(token, configuration); // check the session if (_Session == null) throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidCredentialsOrConfiguration); // return the accesstoken token return _Session.SessionToken; }
public override IStorageProviderSession CreateSession(ICloudStorageAccessToken token, ICloudStorageConfiguration configuration) { // check if url available if (!Directory.Exists(configuration.ServiceLocator.LocalPath)) { try { Directory.CreateDirectory(configuration.ServiceLocator.LocalPath); } catch (Exception) { return null; } } return new CIFSStorageProviderSession(token, configuration as CIFSConfiguration, this); }
public CloudService(IConfigService configService) { _configService = configService; var config = _configService.Current; // currently using DropBox, but this could be made configurable _cloudStorageConfiguration = DropBoxConfiguration.GetStandardConfiguration(); _cloudeStorageCredentials = new DropBoxCredentials { ConsumerKey = config.Cloud.ConsumerKey, ConsumerSecret = config.Cloud.ConsumerSecret, UserName = config.Cloud.UserName, Password = config.Cloud.Password }; }
public CloudService(IConfigService configService) { _configService = configService; var config = _configService.Current; // currently using DropBox, but this could be made configurable _cloudStorageConfiguration = DropBoxConfiguration.GetStandardConfiguration(); _cloudeStorageCredentials = new DropBoxCredentials { ConsumerKey = config.Cloud.ConsumerKey, ConsumerSecret = config.Cloud.ConsumerSecret, UserName = config.Cloud.UserName, Password = config.Cloud.Password }; }
/// <summary> /// This method generates a session to a webdav share via username and password /// </summary> /// <param name="token"></param> /// <param name="configuration"></param> /// <returns></returns> public override IStorageProviderSession CreateSession(ICloudStorageAccessToken token, ICloudStorageConfiguration configuration) { // cast the creds to the right type WebDavConfiguration config = configuration as WebDavConfiguration; // build service DavService svc = new DavService(); // check if url available int status = (int) HttpStatusCode.OK; WebException e = null; svc.PerformSimpleWebCall(config.ServiceLocator.ToString(), WebRequestMethodsEx.WebDAV.Options, (token as ICredentials).GetCredential(null, null), null, out status, out e); if (status == (int) HttpStatusCode.Unauthorized) throw new UnauthorizedAccessException(); else if (HttpUtilityEx.IsSuccessCode(status)) return new WebDavStorageProviderSession(token, config, this); else return null; }
/// <summary> /// This method opens a session for the implemented storage provider based on an existing /// security token. /// </summary> /// <param name="configuration"></param> /// <param name="token"></param> /// <returns></returns> public ICloudStorageAccessToken Open(ICloudStorageConfiguration configuration, ICloudStorageAccessToken token) { // Verify the compatibility of the credentials if (!_Service.VerifyAccessTokenType(token)) { throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidCredentialsOrConfiguration); } // create a new session _Session = _Service.CreateSession(token, configuration); // check the session if (_Session == null) { throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidCredentialsOrConfiguration); } // return the accesstoken token return(_Session.SessionToken); }
public SkyDriveStorageProviderSession(ICloudStorageAccessToken token, IStorageProviderService service, ICloudStorageConfiguration configuration) { SessionToken = token; Service = service; ServiceConfiguration = configuration; }
public static String GetUrlString(String urltemplate, ICloudStorageConfiguration configuration) { if (urltemplate.Contains("{0}")) { if (configuration == null || !(configuration is DropBoxConfiguration)) return String.Format(urltemplate, ((int) DropBoxAPIVersion.Stable).ToString()); else { int versionValue = (int) ((DropBoxConfiguration) configuration).APIVersion; return String.Format(urltemplate, versionValue.ToString()); } } else return urltemplate; }
public override IStorageProviderSession CreateSession(ICloudStorageAccessToken token, ICloudStorageConfiguration configuration) { var gdToken = token as GoogleDocsToken; return new GoogleDocsStorageProviderSession(this, configuration, new OAuthConsumerContext(gdToken.ConsumerKey, gdToken.ConsumerSecret), gdToken); }
public SkyDriveStorageProviderSession(ICloudStorageAccessToken token, IStorageProviderService service, ICloudStorageConfiguration configuration) { SessionToken = token; Service = service; ServiceConfiguration = configuration; }
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); } }
private void SetProviderByConfiguration(ICloudStorageConfiguration configuration) { // check if (configuration == null && _provider == null) throw new InvalidOperationException("It's only allowed to set the configuration parameter to null when a provider was set before"); // read out the right provider type SetProviderByConfigurationTypeName(configuration.GetType().FullName); }
public IStorageProviderSession CreateSession(ICloudStorageAccessToken token, ICloudStorageConfiguration configuration) { return _service.CreateSession(token, configuration); }
public IStorageProviderSession CreateSession(ICloudStorageAccessToken token, ICloudStorageConfiguration configuration) { return(_service.CreateSession(token, configuration)); }
/// <summary> /// This method generates a session to a webdav share via access token /// </summary> /// <param name="token"></param> /// <param name="configuration"></param> /// <returns></returns> public abstract IStorageProviderSession CreateSession(ICloudStorageAccessToken token, ICloudStorageConfiguration configuration);
public override IStorageProviderSession CreateSession(ICloudStorageAccessToken token, ICloudStorageConfiguration configuration) { // get the user credentials var userToken = token as DropBoxToken; var svcConfig = configuration as DropBoxConfiguration; // get the session return(this.Authorize(userToken, svcConfig)); }
public override IStorageProviderSession CreateSession(ICloudStorageAccessToken token, ICloudStorageConfiguration configuration) { var skydriveToken = token as OAuth20Token; if (skydriveToken == null) { throw new ArgumentException("Cannot create skydrive session with given token", "token"); } if (skydriveToken.IsExpired) { token = SkyDriveAuthorizationHelper.RefreshToken(skydriveToken); } return(new SkyDriveStorageProviderSession(token, this, configuration)); }
/// <summary> /// This method generates a session to a webdav share via username and password /// </summary> /// <param name="token"></param> /// <param name="configuration"></param> /// <returns></returns> public override IStorageProviderSession CreateSession(ICloudStorageAccessToken token, ICloudStorageConfiguration configuration) { // cast the creds to the right type var config = configuration as WebDavConfiguration; // build service var svc = new DavService(); // check if url available int status; WebException e; svc.PerformSimpleWebCall(config.ServiceLocator.ToString(), WebRequestMethodsEx.WebDAV.Options, (token as ICredentials).GetCredential(null, null), null, out status, out e); if (status == (int)HttpStatusCode.Unauthorized) { throw new UnauthorizedAccessException(); } if (HttpUtilityEx.IsSuccessCode(status)) { return(new WebDavStorageProviderSession(token, config, this)); } return(null); }
public override IStorageProviderSession CreateSession(ICloudStorageAccessToken token, ICloudStorageConfiguration configuration) { return(new SkyDriveStorageProviderSession(token, this, configuration)); }
public override IStorageProviderSession CreateSession(ICloudStorageAccessToken token, ICloudStorageConfiguration configuration) { // check if url available if (!Directory.Exists(configuration.ServiceLocator.LocalPath)) { try { Directory.CreateDirectory(configuration.ServiceLocator.LocalPath); } catch (Exception) { return(null); } } return(new CIFSStorageProviderSession(token, configuration as CIFSConfiguration, this)); }
/// <summary> /// copy ctor /// </summary> /// <param name="src"></param> /// <param name="OpenIfSourceWasOpen"></param> public CloudStorage(CloudStorage src, Boolean OpenIfSourceWasOpen) : this() { // copy all registered provider from src _configurationProviderMap = src._configurationProviderMap; // open the provider if (src.IsOpened && OpenIfSourceWasOpen) Open(src._configuration, src.CurrentAccessToken); else _configuration = src._configuration; }
public override IStorageProviderSession CreateSession(ICloudStorageAccessToken token, ICloudStorageConfiguration configuration) { var gdToken = token as GoogleDocsToken; return(new GoogleDocsStorageProviderSession(this, configuration, new OAuthConsumerContext(gdToken.ConsumerKey, gdToken.ConsumerSecret), gdToken)); }
/// <summary> /// Calling this method with vendor specific configuration settings and token based credentials /// to get access to the cloud storage. The following exceptions are possible: /// /// - System.UnauthorizedAccessException when the user provides wrong credentials /// - AppLimit.CloudComputing.SharpBox.Exceptions.SharpBoxException when something /// happens during cloud communication /// /// </summary> /// <param name="configuration">Vendor specific configuration of the cloud storage</param> /// <param name="token">Vendor specific authorization token</param> /// <returns>A valid access token or null</returns> public ICloudStorageAccessToken Open(ICloudStorageConfiguration configuration, ICloudStorageAccessToken token) { // check state if (IsOpened) return null; // ensures that the right provider will be used SetProviderByConfiguration(configuration); // save the configuration _configuration = configuration; #if !WINDOWS_PHONE && !MONODROID // verify the ssl config if (configuration.TrustUnsecureSSLConnections) System.Net.ServicePointManager.ServerCertificateValidationCallback = ValidateAllServerCertificates; // update the max connection settings ServicePointManager.DefaultConnectionLimit = 250; // disable the not well implementes Expected100 header settings ServicePointManager.Expect100Continue = false; #endif // open the cloud connection token = _provider.Open(configuration, token); // ok without Exception every is good IsOpened = true; // return the token return token; }
/// <summary> /// This method generates a session to a webdav share via access token /// </summary> /// <param name="token"></param> /// <param name="configuration"></param> /// <returns></returns> public abstract IStorageProviderSession CreateSession(ICloudStorageAccessToken token, ICloudStorageConfiguration configuration);
public override IStorageProviderSession CreateSession(ICloudStorageAccessToken token, ICloudStorageConfiguration configuration) { return new SkyDriveStorageProviderSession(token, this, configuration); }