Example #1
0
        internal CloudStorage CreateStorage(AuthData _authData, nSupportedCloudConfigurations _providerKey)
        {
            var prms = new object[] { };

            if (!string.IsNullOrEmpty(_authData.Url))
            {
                var uri = _authData.Url;
                if (Uri.IsWellFormedUriString(uri, UriKind.Relative))
                {
                    uri = Uri.UriSchemeHttp + Uri.SchemeDelimiter + uri;
                }
                prms = new object[] { new Uri(uri) };
            }

            var storage = new CloudStorage();
            var config  = CloudStorage.GetCloudConfigurationEasy(_providerKey, prms);

            if (!string.IsNullOrEmpty(_authData.Token))
            {
                if (_providerKey != nSupportedCloudConfigurations.BoxNet)
                {
                    var token = storage.DeserializeSecurityTokenFromBase64(_authData.Token);
                    storage.Open(config, token);
                }
            }
            else
            {
                storage.Open(config, new GenericNetworkCredentials {
                    Password = _authData.Password, UserName = _authData.Login
                });
            }
            return(Storage = storage);
        }
        public SharpBoxProviderInfo(int id, string providerKey, string customerTitle, AuthData authData, Guid owner, FolderType rootFolderType, DateTime createOn)
        {
            if (string.IsNullOrEmpty(providerKey))
                throw new ArgumentNullException("providerKey");
            if (string.IsNullOrEmpty(authData.Token) && string.IsNullOrEmpty(authData.Password))
                throw new ArgumentNullException("token", "Both token and password can't be null");
            if (!string.IsNullOrEmpty(authData.Login) && string.IsNullOrEmpty(authData.Password) && string.IsNullOrEmpty(authData.Token))
                throw new ArgumentNullException("password", "Password can't be null");

            ID = id;
            CustomerTitle = customerTitle;
            Owner = owner == Guid.Empty ? SecurityContext.CurrentAccount.ID : owner;

            _providerKey = (nSupportedCloudConfigurations) Enum.Parse(typeof (nSupportedCloudConfigurations), providerKey, true);
            _authData = authData;
            _rootFolderType = rootFolderType;
            _createOn = createOn;
        }
Example #3
0
        public SharpBoxProviderInfo(int id, string providerKey, string customerTitle, AuthData authData, Guid owner, FolderType rootFolderType, DateTime createOn)
        {
            if (string.IsNullOrEmpty(providerKey))
            {
                throw new ArgumentNullException("providerKey");
            }
            if (string.IsNullOrEmpty(authData.Token) && string.IsNullOrEmpty(authData.Password))
            {
                throw new ArgumentNullException("token", "Both token and password can't be null");
            }
            if (!string.IsNullOrEmpty(authData.Login) && string.IsNullOrEmpty(authData.Password) && string.IsNullOrEmpty(authData.Token))
            {
                throw new ArgumentNullException("password", "Password can't be null");
            }

            ID            = id;
            CustomerTitle = customerTitle;
            Owner         = owner == Guid.Empty ? SecurityContext.CurrentAccount.ID : owner;

            _providerKey    = (nSupportedCloudConfigurations)Enum.Parse(typeof(nSupportedCloudConfigurations), providerKey, true);
            _authData       = authData;
            _rootFolderType = rootFolderType;
            _createOn       = createOn;
        }
        /// <summary>
        /// This method maps a given type of supporte cloud storage provider into a working standard configuration. The parameters
        /// field has to be filled out as follows:
        /// DropBox - nothing
        /// BoxNet - nothing
        /// StoreGate - Use ICredentials for authentication (service will be calculated from this)
        /// SmartDriv - nothing
        /// WebDav - The URL of the webdav service
        /// </summary>
        /// <param name="configtype"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public ICloudStorageConfiguration GetCloudConfiguration(nSupportedCloudConfigurations configtype, params object[] param)
        {
            switch (configtype)
            {
            case nSupportedCloudConfigurations.DropBox:
                return(StorageProvider.DropBox.DropBoxConfiguration.GetStandardConfiguration());

            case nSupportedCloudConfigurations.BoxNet:
                return(StorageProvider.BoxNet.BoxNetConfiguration.GetBoxNetConfiguration());

            case nSupportedCloudConfigurations.StoreGate:
            {
                // check parameters
                if (param.Length < 1 || (param[0] as ICredentials) == null)
                {
                    var e = new Exception("Missing valid credentials for StoreGate in the first parameter");
                    throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidParameters, e);
                }

                // cast creds
                var creds = (ICredentials)param[0];

                // build config
                return(StorageProvider.WebDav.WebDavConfiguration.GetStoreGateConfiguration(creds.GetCredential(null, "")));
            }

            case nSupportedCloudConfigurations.SmartDrive:
                return(StorageProvider.WebDav.WebDavConfiguration.Get1and1Configuration());

            case nSupportedCloudConfigurations.WebDav:
            {
                // check parameters
                if (param.Length < 1 || (param[0] as Uri) == null)
                {
                    var e = new Exception("Missing URL for webdav server in the first parameter");
                    throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidParameters, e);
                }

                // convert to uri
                var uri = (Uri)param[0];

                // create the config
                var cfg = new StorageProvider.WebDav.WebDavConfiguration(uri)
                {
                    TrustUnsecureSSLConnections = true
                };

                // go ahead
                return(cfg);
            }

            case nSupportedCloudConfigurations.CloudMe:
            {
                // check parameters
                if (param.Length < 1 || (param[0] as ICredentials) == null)
                {
                    var e = new Exception("Missing valid credentials for CloudMe in the first parameter");
                    throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidParameters, e);
                }

                // cast creds
                var creds = (ICredentials)param[0];

                // build config
                return(StorageProvider.WebDav.WebDavConfiguration.GetCloudMeConfiguration(creds.GetCredential(null, "")));
            }

            case nSupportedCloudConfigurations.HiDrive:
                return(StorageProvider.WebDav.WebDavConfiguration.GetHiDriveConfiguration());

            case nSupportedCloudConfigurations.Google:
                return(StorageProvider.GoogleDocs.GoogleDocsConfiguration.GetStandartConfiguration());

            case nSupportedCloudConfigurations.Yandex:
                return(StorageProvider.WebDav.WebDavConfiguration.GetYandexConfiguration());

            case nSupportedCloudConfigurations.SkyDrive:
                return(new StorageProvider.SkyDrive.SkyDriveConfiguration());

            default:
            {
                var e = new Exception("Unknow service type");
                throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidParameters, e);
            }
            }
        }
        /// <summary>
        /// This method maps a given type of supporte cloud storage provider into a working standard configuration. The parameters
        /// field has to be filled out as follows:
        /// DropBox - nothing
        /// BoxNet - nothing
        /// StoreGate - Use ICredentials for authentication (service will be calculated from this)
        /// SmartDriv - nothing
        /// WebDav - The URL of the webdav service
        /// </summary>
        /// <param name="configtype"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public static ICloudStorageConfiguration GetCloudConfigurationEasy(nSupportedCloudConfigurations configtype, params object[] param)
        {
            var cl = new CloudStorage();

            return(cl.GetCloudConfiguration(configtype, param));
        }
        /// <summary>
        /// This method maps a given type of supporte cloud storage provider into a working standard configuration. The parameters
        /// field has to be filled out as follows:
        /// DropBox - nothing
        /// BoxNet - nothing
        /// StoreGate - Use ICredentials for authentication (service will be calculated from this)
        /// SmartDriv - nothing
        /// WebDav - The URL of the webdav service
        /// </summary>
        /// <param name="configtype"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public ICloudStorageConfiguration GetCloudConfiguration(nSupportedCloudConfigurations configtype, params object[] param)
        {
            switch (configtype)
            {
                case nSupportedCloudConfigurations.DropBox:
                    return StorageProvider.DropBox.DropBoxConfiguration.GetStandardConfiguration();
                case nSupportedCloudConfigurations.BoxNet:
                    return StorageProvider.BoxNet.BoxNetConfiguration.GetBoxNetConfiguration();
                case nSupportedCloudConfigurations.StoreGate:
                    {
                        // check parameters
                        if (param.Length < 1 || (param[0] as ICredentials) == null)
                        {
                            Exception e = new Exception("Missing valid credentials for StoreGate in the first parameter");
                            throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidParameters, e);
                        }

                        // cast creds
                        ICredentials creds = (ICredentials)param[0];

                        // build config
                        return StorageProvider.WebDav.WebDavConfiguration.GetStoreGateConfiguration(creds.GetCredential(null, ""));
                    }
                case nSupportedCloudConfigurations.SmartDrive:
                    return StorageProvider.WebDav.WebDavConfiguration.Get1and1Configuration();
                case nSupportedCloudConfigurations.WebDav:
                    {
                        // check parameters
                        if (param.Length < 1 || (param[0] as Uri) == null)
                        {
                            Exception e = new Exception("Missing URL for webdav server in the first parameter");
                            throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidParameters, e);
                        }

                        // convert to uri
                        Uri uri = (Uri)param[0];

                        // create the config
                        StorageProvider.WebDav.WebDavConfiguration cfg =new AppLimit.CloudComputing.SharpBox.StorageProvider.WebDav.WebDavConfiguration(uri);
                        cfg.TrustUnsecureSSLConnections = true;

                        // go ahead
                        return cfg;
                    }
                case nSupportedCloudConfigurations.CloudMe:
                    {
                        // check parameters
                        if (param.Length < 1 || (param[0] as ICredentials) == null)
                        {
                            Exception e = new Exception("Missing valid credentials for CloudMe in the first parameter");
                            throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidParameters, e);
                        }

                        // cast creds
                        ICredentials creds = (ICredentials)param[0];

                        // build config
                        return StorageProvider.WebDav.WebDavConfiguration.GetCloudMeConfiguration(creds.GetCredential(null, ""));                        
                    }
                case nSupportedCloudConfigurations.HiDrive:                    
                    return StorageProvider.WebDav.WebDavConfiguration.GetHiDriveConfiguration();
                case nSupportedCloudConfigurations.Google:
                    return StorageProvider.GoogleDocs.GoogleDocsConfiguration.GetStandartConfiguration();
                case nSupportedCloudConfigurations.Yandex:
                    return StorageProvider.WebDav.WebDavConfiguration.GetYandexConfiguration();
                case nSupportedCloudConfigurations.SkyDrive:
                    return new StorageProvider.SkyDrive.SkyDriveConfiguration();
                default:
                    {
                        Exception e = new Exception("Unknow service type");
                        throw new SharpBoxException(SharpBoxErrorCodes.ErrorInvalidParameters, e);
                    }
            }
        }
 /// <summary>
 /// This method maps a given type of supporte cloud storage provider into a working standard configuration. The parameters
 /// field has to be filled out as follows:
 /// DropBox - nothing
 /// BoxNet - nothing
 /// StoreGate - Use ICredentials for authentication (service will be calculated from this)
 /// SmartDriv - nothing
 /// WebDav - The URL of the webdav service
 /// </summary>
 /// <param name="configtype"></param>
 /// <param name="param"></param>
 /// <returns></returns>
 public static ICloudStorageConfiguration GetCloudConfigurationEasy(nSupportedCloudConfigurations configtype, params object[] param)
 {
     CloudStorage cl = new CloudStorage();
     return cl.GetCloudConfiguration(configtype, param);            
 }