Example #1
0
        public IFileSystem Connect(Window owner)
        {
            if (string.IsNullOrEmpty(Provider))
            {
                throw new Exception("Empty provider supplied");
            }

            Dictionary <string, object> auth = AuthInstance.AuthorizationProvider.Get(Provider);

            if (auth == null)
            {
                throw new Exception("Application Authorization Not Found");
            }
            _plugin = CloudFileSystemPluginFactory.Instance.List.FirstOrDefault(a => a.Name == Provider);
            if (_plugin == null)
            {
                throw new Exception("Cannot find cloud provider '" + Provider + "'");
            }
            Icon = _plugin.CreateIconImage();
            FileSystemResult <IFileSystem> res = _plugin.Init(Name, new AuthProvider(owner), auth, ConnectionString);

            if (!res.IsOk)
            {
                throw new Exception("Unable to connect to '" + Provider + "'");
            }
            string userauth = res.Result.GetUserAuthorization();

            if (ConnectionString != userauth)
            {
                NeedSave         = true;
                ConnectionString = userauth;
            }
            return(res.Result);
        }
Example #2
0
        public IFileSystem Connect()
        {
            if (string.IsNullOrEmpty(Provider))
            {
                throw new Exception("Empty provider supplied");
            }

            Dictionary <string, object> auth = AuthInstance.AuthorizationProvider.Get(Provider);

            if (auth == null)
            {
                throw new Exception("Application Authorization Not Found");
            }
            _plugin = CloudFileSystemPluginFactory.Instance.List.FirstOrDefault(a => a.Name.EqualsInvariantIgnoreCase(Provider));
            if (_plugin == null)
            {
                throw new Exception("Cannot find cloud provider '" + Provider + "'");
            }
            FileSystemResult <IFileSystem> res = _plugin.Init(Name, ShokoServer.Instance.OAuthProvider, auth, ConnectionString);

            if (res == null || !res.IsOk)
            {
                throw new Exception("Unable to connect to '" + Provider + "'");
            }
            string userauth = res.Result.GetUserAuthorization();

            if (ConnectionString != userauth)
            {
                NeedSave         = true;
                ConnectionString = userauth;
            }
            return(res.Result);
        }
Example #3
0
        public static BitmapImage CreateIconImage(this ICloudPlugin plugin)
        {
            return Application.Current.Dispatcher.Invoke(() =>
            {
                if (plugin?.Icon == null)
                    return null;

                MemoryStream ms = new MemoryStream(plugin.Icon);
                ms.Seek(0, SeekOrigin.Begin);
                BitmapImage icon = new BitmapImage();
                icon.BeginInit();
                icon.StreamSource = ms;
                icon.EndInit();
                return icon;
            });
        }
Example #4
0
 public static string ToString(this ICloudPlugin plugin)
 {
     return(plugin.Name);
 }
        public IFileSystem Connect(string code, string uri)
        {
            if (string.IsNullOrEmpty(Provider))
            {
                throw new Exception("Empty provider supplied");
            }

            //TODO:
            Dictionary <string, object> auth = default;//AuthInstance.AuthorizationProvider.Get(Provider);

            if (auth == null)
            {
                throw new Exception("Application Authorization Not Found");
            }
            _plugin = CloudFileSystemPluginFactory.Instance.List.FirstOrDefault(a => a.Name == Provider);
            if (_plugin == null)
            {
                throw new Exception("Cannot find cloud provider '" + Provider + "'");
            }

            LocalUserSettings userSettings = new LocalUserSettings();

            if (ConnectionString != string.Empty)
            {
                userSettings = new LocalUserSettingWithCode();
                ((LocalUserSettingWithCode)userSettings).Code = code;
                ((LocalUserSettingWithCode)userSettings).OriginalRedirectUri = uri;
            }
            if (auth.ContainsKey("ClientId"))
            {
                userSettings.ClientId = (string)auth["ClientId"];
            }
            if (auth.ContainsKey("ClientSecret"))
            {
                userSettings.ClientSecret = (string)auth["ClientSecret"];
            }
            if (auth.ContainsKey("Scopes"))
            {
                userSettings.Scopes = (List <string>)auth["Scopes"];
            }
            if (auth.ContainsKey("UserAgent"))
            {
                userSettings.UserAgent = (string)auth["UserAgent"];
            }
            if (auth.ContainsKey("AcknowledgeAbuse"))
            {
                userSettings.AcknowledgeAbuse = (bool)auth["AcknowledgeAbuse"];
            }
            if (auth.ContainsKey("ClientAppFriendlyName"))
            {
                userSettings.ClientAppFriendlyName = (string)auth["ClientAppFriendlyName"];
            }
            IFileSystem res = _plugin.Init(Name, userSettings, ConnectionString);

            if (res.Status == Status.Ok)
            {
                string userauth = res.GetUserAuthorization();
                if (ConnectionString != userauth)
                {
                    NeedSave         = true;
                    ConnectionString = userauth;
                }
            }

            return(res);
        }
 public static FileSystemResult <IFileSystem> Init(this ICloudPlugin plugin, string filesystemname, IOAuthProvider oAuthProvider, Dictionary <string, object> settings, string userauthorization = null)
 {
     return(Task.Run(async() => await plugin.InitAsync(filesystemname, oAuthProvider, settings, userauthorization)).Result);
 }