public async static Task<List<Folder>> GetFakesFolders()
        {
            var folders = new List<Folder>();

            Folder folder1 = new Folder();
            folder1.CreationDate = DateTime.Now;
            folder1.UpdateDate = DateTime.Now;
            folder1.Name = "Documents";
            folder1.Permission = PermissionRight.read_write;
            //folder1.Size = 2546978230;
            List<File> files = new List<File>();
            File file1 = new File();
            File file2 = new File();
            files.Add(file1);
            files.Add(file2);
            folder1.Files = files;

            Folder folder2 = new Folder();
            folder2.CreationDate = DateTime.Now;
            folder2.UpdateDate = DateTime.Now;
            folder2.Name = "Shared";
            folder2.Permission = PermissionRight.read_write;
            //folder2.Size = 45789362145;
            List<File> files2 = new List<File>();
            File file12 = new File();
            File file22 = new File();
            files.Add(file12);
            files.Add(file22);
            folder2.Files = files;

            folders.Add(folder1);
            folders.Add(folder2);
            return folders;
        }
Esempio n. 2
0
 public Folder(Folder folder) : base(folder)
 {
     this.ParentId = folder.ParentId;
     this.Files = folder.Files;
 }
 public async void CreateFolder(string folderName)
 {
     Folder newFolder = new Folder();
     newFolder.ParentId = _rootFolder.Id;
     newFolder.Name = folderName;
     Folder folderResult = await _folderApi.CreateRootFolder(newFolder, _user.Token);
     var foldertest = DetermineIcon(folderResult);
     Entities.Add(foldertest);
 }
Esempio n. 4
0
        public async Task<List<Permission>> GetSharedUsers(Folder folder, string token)
        {
            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri(this.BaseAddress.ToString() + folder.Id + "/share/");           
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(token);

            HttpResponseMessage response = await client.GetAsync(client.BaseAddress);
            string responseContent = await response.Content.ReadAsStringAsync();
            try
            {
                response.EnsureSuccessStatusCode();
            }
            catch (Exception)
            {
                if (ErrorReceived != null)
                {
                    var newError = new Error(true, responseContent);
                    this.ErrorReceived(this, new ErrorEventArgs(newError));
                    return null;
                }
            }
            List<Permission> result = null;
            try
            {
                result = JsonConvert.DeserializeObject<List<Permission>>(responseContent);
            }
            catch (Exception)
            {
                if (ErrorReceived != null)
                {
                    var newError = new Error(true, responseContent);
                    this.ErrorReceived(this, new ErrorEventArgs(newError));
                    return null;
                }
            }
            return result;
        }
Esempio n. 5
0
        public async Task<bool> ShareFolder(Folder folder, string recipientEmail, PermissionRight permission, string token)
        {
            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri(this.BaseAddress.ToString().Replace("folders/", "sharedfolders/"));

            var content = "{\"folder_id\":" + folder.Id + ",\"email\":\"" + recipientEmail + "\",\"permission\":\"" + permission + "\"}";
            HttpContent httpContent = new StringContent(content, Encoding.UTF8, "application/json");
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(token);

            HttpResponseMessage response = await client.PostAsync(client.BaseAddress, httpContent);
            string responseContent = await response.Content.ReadAsStringAsync();
            try
            {
                response.EnsureSuccessStatusCode();
            }
            catch (Exception)
            {
                if (ErrorReceived != null)
                {
                    var newError = new Error(true, responseContent);
                    this.ErrorReceived(this, new ErrorEventArgs(newError));
                    return false;
                }
            }
            return true;
        }
Esempio n. 6
0
 public Uri GetAnonymousShareLink(Folder folder)
 {
     return new Uri(this.BaseAddress.ToString().Replace("/folders/", ":8080/anon/") + folder.Url + "/");            
 }
Esempio n. 7
0
        public async Task<bool> DeleteFolder(Folder folder, string token)
        {
            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri(this.BaseAddress.ToString() + folder.Id + "/");

            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(token);

            HttpResponseMessage response = await client.DeleteAsync(client.BaseAddress);
            string responseContent = await response.Content.ReadAsStringAsync();
            try
            {
                response.EnsureSuccessStatusCode();
            }
            catch (Exception)
            {
                if (ErrorReceived != null)
                {
                    var newError = new Error(true, responseContent);
                    this.ErrorReceived(this, new ErrorEventArgs(newError));
                    return false;
                }
            }
            return true;
        }
Esempio n. 8
0
        public async Task<Folder> UpdateFolder(Folder folder, string token)
        {
            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri(this.BaseAddress.ToString() + folder.Id + "/");

            var content = JsonConvert.SerializeObject(folder);
            HttpContent httpContent = new StringContent(content, Encoding.UTF8, "application/json");
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(token);

            HttpResponseMessage response = await client.PutAsync(client.BaseAddress, httpContent);
            string responseContent = await response.Content.ReadAsStringAsync();
            try
            {
                response.EnsureSuccessStatusCode();
            }
            catch (Exception)
            {
                if (ErrorReceived != null)
                {
                    var newError = new Error(true, responseContent);
                    this.ErrorReceived(this, new ErrorEventArgs(newError));
                    return null;
                }
            }

            Folder result = null;
            try
            {
                result = JsonConvert.DeserializeObject<Folder>(responseContent);
            }
            catch (Exception)
            {
                if (ErrorReceived != null)
                {
                    var newError = new Error(true, responseContent);
                    this.ErrorReceived(this, new ErrorEventArgs(newError));
                    return null;
                }
            }
            return result;
        }