示例#1
0
文件: MainForm.cs 项目: fiftin/oblqo
 private void addNewAccountToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (var accountForm = new AccountForm(true))
     {
         if (accountForm.ShowDialog() != DialogResult.OK) return;
         btnNewConnection.Visible = false;
         var info = new AccountInfo
         {
             AccountName = accountForm.AccountName,
             StorageAccessKeyId = accountForm.StorageAccessTokenId,
             StorageSecretAccessKey = accountForm.StorageSecretAccessKey,
             StorageVault = accountForm.GlacierVault,
             StorageRegionSystemName = accountForm.StorageRegionSystemName,
         };
         info.Drives.Clear();
         info.Drives.AddRange(accountForm.GetDrives());
         accountManager.Add(info);
         var node = treeView1.Nodes.Add("", info.AccountName, AccountImageKey);
         node.SelectedImageKey = AccountImageKey;
         node.Tag = new NodeInfo(info);
         accountManager.Save();
         DisconnectAccount(node);
     }
 }
示例#2
0
 public void Add(AccountInfo account)
 {
     accounts.Add(account);
 }
示例#3
0
        public async Task <Account> CreateAccountAsync(AccountInfo info)
        {
            var token   = new CancellationToken();
            var storage = new Glacier(info.StorageVault, info.StorageRootPath, info.StorageAccessKeyId, info.StorageSecretAccessKey, info.StorageRegionEndpoint);
            await storage.InitAsync(token);

            var account         = new Account(storage);
            var accountCredPath = "accounts/" + info.AccountName + "/drive-credentials/";

            foreach (var d in info.Drives)
            {
                switch (d.DriveType)
                {
                case DriveType.GoogleDrive:

                    var drive =
                        await
                        GoogleDrive.CreateInstance(account, d.DriveId,
                                                   GoogleClientSecrets.Load(new MemoryStream(Resources.client_secret)).Secrets,
                                                   d.DriveRootPath,
                                                   accountCredPath + d.DriveId,
                                                   token);

                    drive.ImageMaxSize = d.DriveImageMaxSize;
                    await drive.GetServiceAsync(token);

                    account.Drives.Add(drive);
                    break;

                case DriveType.LocalDrive:
                    var localDrive = new Local.LocalDrive(account, d.DriveId, d.DriveRootPath)
                    {
                        ImageMaxSize = d.DriveImageMaxSize
                    };
                    account.Drives.Add(localDrive);
                    break;

                default:
                    throw new NotSupportedException("Drive with this type is not supported");
                }
            }

            var accountInventoryPath = "accounts/" + info.AccountName + "/glacier-inventory.xml";

            using (var store = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null))
            {
                if (store.FileExists(accountInventoryPath))
                {
                    using (var input = store.OpenFile(accountInventoryPath, FileMode.Open))
                    {
                        var reader = new StreamReader(input);
                        var xml    = await reader.ReadToEndAsync();

                        var doc          = XDocument.Load(new XmlTextReader(new StringReader(xml)));
                        var glacierDrive = new GlacierPseudoDrive(account, "inventory", doc);
                        account.Drives.Add(glacierDrive);
                    }
                }
            }
            return(account);
        }
示例#4
0
 public void Add(AccountInfo account)
 {
     accounts.Add(account);
 }
示例#5
0
        public async Task<Account> CreateAccountAsync(AccountInfo info)
        {
            var token = new CancellationToken();
            var storage = new Glacier(info.StorageVault, info.StorageRootPath, info.StorageAccessKeyId, info.StorageSecretAccessKey, info.StorageRegionEndpoint);
            await storage.InitAsync(token);
            var account = new Account(storage);
            var accountCredPath = "accounts/" + info.AccountName + "/drive-credentials/";

            foreach (var d in info.Drives)
            {
                switch (d.DriveType)
                {
                    case DriveType.GoogleDrive:

                        var drive =
                            await
                                GoogleDrive.CreateInstance(account, d.DriveId,
                                    GoogleClientSecrets.Load(new MemoryStream(Resources.client_secret)).Secrets,
                                    d.DriveRootPath,
                                    accountCredPath + d.DriveId,
                                    token);

                        drive.ImageMaxSize = d.DriveImageMaxSize;
                        await drive.GetServiceAsync(token);
                        account.Drives.Add(drive);
                        break;
                    case DriveType.LocalDrive:
                        var localDrive = new Local.LocalDrive(account, d.DriveId, d.DriveRootPath)
                        {
                            ImageMaxSize = d.DriveImageMaxSize
                        };
                        account.Drives.Add(localDrive);
                        break;
                    default:
                        throw new NotSupportedException("Drive with this type is not supported");
                }
            }

            var accountInventoryPath = "accounts/" + info.AccountName + "/glacier-inventory.xml";
            using (var store = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null))
            {
                if (store.FileExists(accountInventoryPath))
                {
                    using (var input = store.OpenFile(accountInventoryPath, FileMode.Open))
                    {
                        var reader = new StreamReader(input);
                        var xml = await reader.ReadToEndAsync();
                        var doc = XDocument.Load(new XmlTextReader(new StringReader(xml)));
                        var glacierDrive = new GlacierPseudoDrive(account, "inventory", doc);
                        account.Drives.Add(glacierDrive);
                    }
                }
            }
            return account;
        }
示例#6
0
 public async Task ClearAuthAsync(AccountInfo info)
 {
     using (var store = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null))
     {
         await Task.Run(() =>
         {
             var dirs = store.GetDirectoryNames("accounts/" + info.AccountName + "/drive-credentials/*");
             foreach (var dir in dirs)
             {
                 DeleteAllFilesInDirectory(store, "accounts/" + info.AccountName + "/drive-credentials/" + dir);
             }
         });
     }
 }