コード例 #1
0
ファイル: YandexDriveClient.cs プロジェクト: quadgod/breader
 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 };
 }
コード例 #2
0
        public static WebDavConfiguration GetYandexConfiguration()
        {
            var config = new WebDavConfiguration(new Uri(YaUrl))
            {
                TrustUnsecureSSLConnections = false
            };

            return(config);
        }
コード例 #3
0
        public static WebDavConfiguration GetYandexConfiguration()
        {
            var config = new WebDavConfiguration(new Uri("https://webdav.yandex.ru"))
            {
                TrustUnsecureSSLConnections = false
            };

            return(config);
        }
コード例 #4
0
        /// <summary>
        /// This method returns a standard cofiguration for StoreGate
        /// </summary>
        /// <param name="credentials"></param>
        /// <returns></returns>
        public static WebDavConfiguration GetStoreGateConfiguration(NetworkCredential credentials)
        {
            // set the right url
            WebDavConfiguration config = new WebDavConfiguration(new Uri("https://webdav1.storegate.com/" + credentials.UserName + "/home/" + credentials.UserName));
            config.Limits = new CloudStorageLimits();
            config.Limits.MaxDownloadFileSize = -1;
            config.Limits.MaxUploadFileSize = -1;

            // box.net does not support a valid ssl
            config.TrustUnsecureSSLConnections = false;

            // go ahead
            return config;
        }
コード例 #5
0
        /// <summary>
        /// This method returns a standard configuration for 1and1 
        /// </summary>
        /// <returns></returns>
        public static WebDavConfiguration Get1and1Configuration()
        {
            // set the right url
            WebDavConfiguration config = new WebDavConfiguration(new Uri("https://sd2dav.1und1.de"));
            config.Limits = new CloudStorageLimits();
            config.Limits.MaxDownloadFileSize = 500*1024*1024;
            config.Limits.MaxUploadFileSize = config.Limits.MaxDownloadFileSize;

            // 1and1 does not support a valid ssl
            config.TrustUnsecureSSLConnections = true;

            // go ahead
            return config;
        }
コード例 #6
0
        /// <summary>
        /// This method returns a standard cofiguration for StoreGate
        /// </summary>
        /// <param name="credentials"></param>
        /// <returns></returns>
        static public WebDavConfiguration GetStoreGateConfiguration(NetworkCredential credentials)
        {
            // set the right url
            WebDavConfiguration config = new WebDavConfiguration(new Uri("https://webdav1.storegate.com/" + credentials.UserName + "/home/" + credentials.UserName));

            config.Limits = new CloudStorageLimits();
            config.Limits.MaxDownloadFileSize = -1;
            config.Limits.MaxUploadFileSize   = -1;

            // box.net does not support a valid ssl
            config.TrustUnsecureSSLConnections = false;

            // go ahead
            return(config);
        }
コード例 #7
0
        /// <summary>
        /// This method returns a standard configuration for 1and1
        /// </summary>
        /// <returns></returns>
        static public WebDavConfiguration Get1and1Configuration()
        {
            // set the right url
            WebDavConfiguration config = new WebDavConfiguration(new Uri("https://sd2dav.1und1.de"));

            config.Limits = new CloudStorageLimits();
            config.Limits.MaxDownloadFileSize = 500 * 1024 * 1024;
            config.Limits.MaxUploadFileSize   = config.Limits.MaxDownloadFileSize;

            // 1and1 does not support a valid ssl
            config.TrustUnsecureSSLConnections = true;

            // go ahead
            return(config);
        }
コード例 #8
0
        /// <summary>
        /// This method returns a standard configuration for Strato HiDrive
        /// </summary>
        /// <returns></returns>
        static public WebDavConfiguration GetHiDriveConfiguration()
        {
            // set the right url
            WebDavConfiguration config = new WebDavConfiguration(new Uri("https://webdav.hidrive.strato.com"));

            config.Limits = new CloudStorageLimits();
            config.Limits.MaxDownloadFileSize = -1;
            config.Limits.MaxUploadFileSize   = config.Limits.MaxDownloadFileSize;

            // box.net does not support a valid ssl
            config.TrustUnsecureSSLConnections = false;

            // go ahead
            return(config);
        }
コード例 #9
0
        /// <summary>
        /// This method returns a standard configuration for 1and1
        /// </summary>
        /// <returns></returns>
        public static WebDavConfiguration Get1and1Configuration()
        {
            // set the right url
            var config = new WebDavConfiguration(new Uri("https://sd2dav.1und1.de"))
            {
                Limits = new CloudStorageLimits
                {
                    MaxDownloadFileSize = 500 * 1024 * 1024,
                    MaxUploadFileSize   = 500 * 1024 * 1024
                },

                // 1and1 does not support a valid ssl
                TrustUnsecureSSLConnections = true,
            };

            // go ahead
            return(config);
        }
コード例 #10
0
        /// <summary>
        /// This method returns a standard cofiguration for CloudMe
        /// </summary>
        /// <param name="credentials"></param>
        /// <returns></returns>
        static public WebDavConfiguration GetCloudMeConfiguration(NetworkCredential credentials)
        {
            // set the right url
            WebDavConfiguration config = new WebDavConfiguration(new Uri("http://webdav.cloudme.com/" + credentials.UserName + "/xios"));

            config.Limits = new CloudStorageLimits();
            config.Limits.MaxDownloadFileSize = -1;
            config.Limits.MaxUploadFileSize   = -1;

            // box.net does not support a valid ssl
            config.TrustUnsecureSSLConnections = false;

            // set streambuffered transfer
            config.UploadDataStreambuffered = true;

            // go ahead
            return(config);
        }
コード例 #11
0
        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;
        }
コード例 #12
0
        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();
        }
コード例 #13
0
        /// <summary>
        /// This method returns a standard configuration for Strato HiDrive 
        /// </summary>
        /// <returns></returns>
        public static WebDavConfiguration GetHiDriveConfiguration()
        {
            // set the right url
            WebDavConfiguration config = new WebDavConfiguration(new Uri("https://webdav.hidrive.strato.com"));
            config.Limits = new CloudStorageLimits();
            config.Limits.MaxDownloadFileSize = -1;
            config.Limits.MaxUploadFileSize = config.Limits.MaxDownloadFileSize;

            // box.net does not support a valid ssl
            config.TrustUnsecureSSLConnections = false;

            // go ahead
            return config;
        }
コード例 #14
0
        /// <summary>
        /// This method returns a standard cofiguration for CloudMe
        /// </summary>
        /// <param name="credentials"></param>
        /// <returns></returns>
        public static WebDavConfiguration GetCloudMeConfiguration(NetworkCredential credentials)
        {
            // set the right url
            WebDavConfiguration config = new WebDavConfiguration(new Uri("http://webdav.cloudme.com/" + credentials.UserName + "/xios"));
            config.Limits = new CloudStorageLimits();
            config.Limits.MaxDownloadFileSize = -1;
            config.Limits.MaxUploadFileSize = -1;

            // box.net does not support a valid ssl
            config.TrustUnsecureSSLConnections = false;

            // set streambuffered transfer
            config.UploadDataStreambuffered = true;

            // go ahead
            return config;
        }
コード例 #15
0
 public static WebDavConfiguration GetYandexConfiguration()
 {
     var config = new WebDavConfiguration(new Uri("https://webdav.yandex.ru")) {TrustUnsecureSSLConnections = false};
     return config;
 }
        /// <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);
            }
            }
        }
コード例 #17
0
        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;
        }