Exemplo n.º 1
0
        /// <summary>
        /// Creates environmant with next drive FS structure:
        //  c:
        //      documents
        //          resume.txt
        //          my-photos.jpg
        //      photos
        //          photos2015
        //              lenovo
        //              turkey
        //              PHOTO1.jpg
        //              PHOTO2.jpg
        //              PHOTO3.jpg
        //              info.txt
        //
        //  Root directory: c:/photos.
        /// </summary>
        public static async Task<TestEnvironment> CreateSimpleAsync()
        {
            byte[] info_txt = Encoding.ASCII.GetBytes("Hello, World!");
            byte[] photo1_jpg = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            var storage = new MockStorage("mock-1");
            storage.AddFile(new MockStorageFile(storage, "PHOTO1.jpg") { content = photo1_jpg });
            storage.AddFile(new MockStorageFile(storage, "info.txt") { content = info_txt });

            var account = new Account(storage);
            var drive = new MockDrive(account);
            var root = new MockDriveFile(drive, "c:", isFolder: true);

            var docs = root.Add(new MockDriveFile(drive, "documents", isFolder: true));
            docs.Add(new MockDriveFile(drive, "resume.txt"));
            docs.Add(new MockDriveFile(drive, "my-photo.jpg"));
            var photos = root.Add(new MockDriveFile(drive, "photos", isFolder: true));
            var photos2015 = photos.Add(new MockDriveFile(drive, "photos2015", isFolder: true));
            var lenovo = photos.Add(new MockDriveFile(drive, "lenovo", isFolder: true));
            var turkey = photos.Add(new MockDriveFile(drive, "turkey", isFolder: true));
            await photos2015.Add(new MockDriveFile(drive, "PHOTO1.jpg", isImage: true) { content = photo1_jpg }).SetStorageFileIdAsync("photo1-jpg", CancellationToken.None);
            var image2 = new MockDriveFile(drive, "PHOTO2.jpg", isImage: true);
            image2.content = new byte[] {
                1, 1, 1, 1, 1,
                0, 0, 0, 0, 0,
                1, 1, 1, 1, 1
            };
            photos2015.Add(image2); // unsync
            photos2015.Add(new MockDriveFile(drive, "PHOTO3.jpg", isImage: true)); // unsync
            await photos2015.Add(new MockDriveFile(drive, "info.txt") { content = info_txt }).SetStorageFileIdAsync("info-txt", CancellationToken.None);
            drive.root = root;
            drive.rootFolder = photos;
            return new TestEnvironment(storage, drive);
        }
Exemplo n.º 2
0
 public AccountFile(Account account, StorageFile storageFile, IEnumerable<DriveFile> driveFiles, AccountFile parent)
 {
     DriveFiles.AddRange(driveFiles);
     this.StorageFile = storageFile;
     Parent = parent;
     Account = account;
 }
Exemplo n.º 3
0
 public LockTask(Account account = null,
     int priority = 10,
     AsyncTask[] parents = null,
     AsyncTaskParentsMode parentsMode = AsyncTaskParentsMode.CancelIfAnyErrorOrCanceled)
     : base(account, "", priority, parents ?? new AsyncTask[0], parentsMode)
 {
     this.delay = 0; // no delay
     locker = new AutoResetEvent(false);
 }
Exemplo n.º 4
0
 public LockTask(
     int delay,
     Account account = null,
     int priority = 10,
     AsyncTask[] parents = null,
     AsyncTaskParentsMode parentsMode = AsyncTaskParentsMode.CancelIfAnyErrorOrCanceled)
     : base(account, "", priority, parents ?? new AsyncTask[0], parentsMode)
 {
     this.delay = delay;
     locker = new ManualResetEvent(true); // always unlocked
 }
Exemplo n.º 5
0
 public bool TryGetValue(string name, out Account account)
 {
     return accounts.TryGetValue(name, out account);
 }
Exemplo n.º 6
0
 public static async Task<AsyncTask> LoadFromXmlAsync(Account account, string id, XElement xml, CancellationToken token)
 {
     var type = Type.GetType(xml.Attribute("type").Value);
     var ctor = type.GetConstructor(Type.EmptyTypes);
     if (ctor == null)
     {
         throw new Exception("Task has no empty constructor: " + type.Name);
     }
     var task = (AsyncTask)ctor.Invoke(new object[0]);
     await task.LoadAsync(account, id, xml, token);
     return task;
 }
Exemplo n.º 7
0
 public virtual Task LoadAsync(Account account, string id, XElement xml, CancellationToken token)
 {
     Account = account;
     AccountName = xml.Attribute("accountName").Value;
     State = AsyncTaskState.Waiting;
     Priority = int.Parse(xml.Attribute("priority").Value);
     ParentsMode = (AsyncTaskParentsMode)Enum.Parse(typeof(AsyncTaskParentsMode), xml.Attribute("parentsMode").Value);
     ID = id;
     return Task.FromResult(0);
 }
Exemplo n.º 8
0
 protected AsyncTask(Account account, string accountName, int priority, 
     AsyncTask[] parents, 
     AsyncTaskParentsMode parentsMode = AsyncTaskParentsMode.CancelIfAnyErrorOrCanceled)
 {
     Account = account;
     AccountName = accountName;
     State = AsyncTaskState.Waiting;
     Priority = priority;
     Parents = parents;
     ParentsMode = parentsMode;
     ID = Guid.NewGuid().ToString();
 }
Exemplo n.º 9
0
 public string GetName(Account account)
 {
     return (from x in accounts where x.Value == account select x.Key).First();
 }
Exemplo n.º 10
0
 public void Add(string name, Account account)
 {
     accounts.Add(name, account);
 }
Exemplo n.º 11
0
 public override Task<IEnumerable<AsyncTask>> GetTasksAsync(Account account, string accountName, CancellationToken token)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 12
0
 public ConnectionException(Account account, string message)
     : base(message)
 {
     Account = account;
 }
Exemplo n.º 13
0
 public AccountFile(Account account, StorageFile storageFile, AccountFile parent)
 {
     this.StorageFile = storageFile;
     Parent = parent;
     Account = account;
 }
Exemplo n.º 14
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;
        }
Exemplo n.º 15
0
 public TestEnvironment(MockStorage storage, IEnumerable<MockDrive> drives)
 {
     Account = new Account(storage);
     Account.Drives.AddRange(drives);
 }
Exemplo n.º 16
0
 public TestEnvironment(MockStorage storage, params MockDrive[] drives)
 {
     Account = new Account(storage);
     Account.Drives.AddRange(drives);
 }
Exemplo n.º 17
0
 public abstract Task<IEnumerable<AsyncTask>> GetTasksAsync(Account account, string accountName, System.Threading.CancellationToken token);
Exemplo n.º 18
0
 protected Drive(Account owner, string id)
 {
     Owner = owner;
     Id = id;
 }
Exemplo n.º 19
0
        public bool Remove(Account account)
        {
			return accounts.Remove(GetName(account));
        }
Exemplo n.º 20
0
 public ConnectionException(Account account, string message, Exception innerException)
     : base(message, innerException)
 {
     Account = account;
 }
Exemplo n.º 21
0
 public MockDrive(Account owner) : base(owner, Guid.NewGuid().ToString())
 {
 }