示例#1
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);
        }
        public async void ShareEntity(DiskEntity selectedEntity, string recipientEmail, string permissionString)
        {
            PermissionRight permission = (PermissionRight)Enum.Parse(typeof(PermissionRight), permissionString);

            if (selectedEntity.GetType().Equals(typeof(Folder)))
            {
                var result = await _folderApi.ShareFolder(selectedEntity as Folder, recipientEmail, permission, _user.Token);
            }
            else
            {
                var result = await _fileApi.ShareFile(selectedEntity as File, recipientEmail, permission, _user.Token);
            }
        }
示例#3
0
        public async Task<bool> ShareFile(File file, string recipientEmail, PermissionRight permission, string token)
        {
            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri(this.BaseAddress.ToString() + "sharedresources/");

            var content = "{\"resource_id\":" + file.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;
        }