Exemple #1
0
 /// <summary>
 /// Create file (not folder) instance.
 /// Create folder or file instance.
 /// </summary>
 /// <param name="id">
 /// </param>
 /// <param name="isFolder"></param>
 /// <param name="pathName"></param>
 /// <param name="isRoot"></param>
 public GlacierFile(Glacier storage, string id, bool isFolder, string pathName, bool isRoot = false)
     : base(storage)
 {
     this.id = id;
     this.isFolder = isFolder;
     FolderPath = pathName;
     var lastSlashIndex = pathName.LastIndexOf('/');
     name = lastSlashIndex >= 0 ? pathName.Substring(lastSlashIndex + 1) : pathName;
     this.isRoot = isRoot;
 }
 public ICollection <string> GetValidationErrors()
 {
     return(Glacier.GetValidationErrors().Union(Avalanche.GetValidationErrors()).ToList());
 }
 public IEnumerable <string> GetValidationErrors()
 {
     return(Glacier.GetValidationErrors().Union(Avalanche.GetValidationErrors()));
 }
Exemple #4
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);
        }
Exemple #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;
        }