private async Task ListFilesFromProvider()
        {
            IEnumerable <CloudProvider> providers = CloudProviders.Instance.Providers.Where(cp => cp.ID == _providerID);

            if (providers.Any())
            {
                CloudStorageProviderBase storageProvider = null;
                CloudProvider            provider        = providers.First();
                switch (provider.AuthType)
                {
                case ProviderType.AuthenticationType.OAuth:
                {
                    string providerKey = (string)((App)App.Current).GetProviderValue(_providerID, "ProviderKey");
                    string accessToken = ((App)App.Current).GetCredential(_providerID);
                    Dictionary <string, string> createParams = new Dictionary <string, string>();
                    createParams.Add("AuthType", "OAuth");
                    createParams.Add("ProviderKey", providerKey);
                    createParams.Add("AccessToken", accessToken);
                    storageProvider = CloudStorageProviderBase.Create(
                        App.AppLogger.Logger,
                        createParams);
                    break;
                }

                case ProviderType.AuthenticationType.Amazon:
                {
                    string         providerKey  = (string)((App)App.Current).GetProviderValue(_providerID, "ProviderKey");
                    string         secret       = ((App)App.Current).GetCredential(_providerID);
                    JObject        s3ConfigJSON = JObject.Parse(secret);
                    AmazonS3Config s3Config     = AmazonS3Config.FromJSON(s3ConfigJSON);
                    Dictionary <string, string> createParams = s3Config.ToDictionary();
                    createParams.Add("ProviderKey", providerKey);
                    storageProvider = CloudStorageProviderBase.Create(
                        App.AppLogger.Logger,
                        createParams);
                    break;
                }

                default:
                {
                    throw new NotSupportedException(String.Format("Cloud provider authentication type '{0}' is not supported.", provider.AuthType));
                }
                }

                CloudProviderResponse <List <CloudStorageProviderFileBase> > response = await storageProvider.ListFiles();

                if (response.ResponseValue == CloudProviderResponse <List <CloudStorageProviderFileBase> > .Response.Success)
                {
                    CreateTreeNodes(response.Result);
                }
            }
        }
Beispiel #2
0
        public async Task <bool> CheckCredentialAccessAsync()
        {
            Dictionary <string, string> cred = devoctomy.cachy.Framework.Native.Native.PasswordVault.GetCredential(ID);

            _credentialError = (cred == null);
            if (!_credentialError)
            {
                string secret = cred["Password"];

                switch (AuthType)
                {
                case ProviderType.AuthenticationType.OAuth:
                {
                    Dictionary <string, string> parameters = new Dictionary <string, string>();
                    parameters.Add("AuthType", "OAuth");
                    parameters.Add("ProviderKey", ProviderKey);
                    parameters.Add("AccessToken", secret);

                    CloudStorageProviderBase provider = CloudStorageProviderBase.Create(
                        App.AppLogger.Logger,
                        parameters);
                    try
                    {
                        CloudProviderResponse <CloudStorageProviderUserBase> accountUserResponse = await provider.GetAccountUser();

                        _credentialError = !(accountUserResponse.ResponseValue == CloudProviderResponse <CloudStorageProviderUserBase> .Response.Success);
                        _username        = String.Empty;
                    }
                    catch (Exception)
                    {
                        _credentialError = true;
                    }
                    break;
                }

                case ProviderType.AuthenticationType.Amazon:
                {
                    JObject        s3ConfigJSON = JObject.Parse(secret);
                    AmazonS3Config s3Config     = AmazonS3Config.FromJSON(s3ConfigJSON);

                    Dictionary <string, string> parameters = s3Config.ToDictionary();
                    parameters.Add("ProviderKey", ProviderKey);
                    CloudStorageProviderBase provider = CloudStorageProviderBase.Create(
                        App.AppLogger.Logger,
                        parameters);
                    try
                    {
                        CloudProviderResponse <CloudStorageProviderUserBase> accountUserResponse = await provider.GetAccountUser();

                        _credentialError = !(accountUserResponse.ResponseValue == CloudProviderResponse <CloudStorageProviderUserBase> .Response.Success);
                        _username        = String.Empty;
                    }
                    catch (Exception)
                    {
                        _credentialError = true;
                    }
                    break;
                }
                }
            }
            NotifyPropertyChanged("CredentialError");
            NotifyPropertyChanged("UserName");
            return(_credentialError);
        }
Beispiel #3
0
        public void OnClosePopup(View item, object parameter)
        {
            if (item is CloudProviderFileSelectView)
            {
                if (parameter != null)
                {
                    CloudStorageProviderFileBase cloudFile = parameter as CloudStorageProviderFileBase;
                    if (cloudFile != null)
                    {
                        String appDataPath = String.Empty;
                        Directory.ResolvePath("{AppData}", out appDataPath);
                        if (!appDataPath.EndsWith(DLoggerManager.PathDelimiter))
                        {
                            appDataPath += DLoggerManager.PathDelimiter;
                        }
                        String vaultFullPath = String.Format("{0}{1}", appDataPath, String.Format(@"LocalVaults{0}{1}", DLoggerManager.PathDelimiter, cloudFile.Name));

                        string cloudFilePath = cloudFile.Path;

                        IEnumerable <CloudProvider> providers = cachy.Config.CloudProviders.Instance.Providers.Where(cp => cp.ID == SelectedCloudProvider.ID);
                        if (providers.Any())
                        {
                            CloudProvider provider = providers.First();
                            switch (provider.AuthType)
                            {
                            case ProviderType.AuthenticationType.Amazon:
                            {
                                string         secret       = ((App)App.Current).GetCredential(SelectedCloudProvider.ID);
                                JObject        s3ConfigJSON = JObject.Parse(secret);
                                AmazonS3Config s3Config     = AmazonS3Config.FromJSON(s3ConfigJSON);

                                if (cloudFilePath.StartsWith(s3Config.Path))
                                {
                                    cloudFilePath = cloudFilePath.Substring(s3Config.Path.Length);
                                }

                                break;
                            }
                            }
                        }

                        VaultIndex index = VaultIndexFile.Instance.CreateLocalVaultStoreIndex("Name",
                                                                                              "Description",
                                                                                              Common.SyncMode.CloudProvider,
                                                                                              SelectedCloudProvider.ID,
                                                                                              vaultFullPath,
                                                                                              cloudFilePath);

                        ClearSelectedProvider(true);
                        ((App)App.Current).NavigateToVaultsList();
                    }
                }
                else
                {
                    ClearSelectedProvider(true);
                }
            }
            else if (item is AddCloudProviderView)
            {
                if (parameter != null)
                {
                    SelectedCloudProvider = (CloudProvider)parameter;
                }
            }
        }