Esempio n. 1
0
        internal static async Task <IDownloadedFile> GetFile(Common.FileInfo fileInfo, string uri)
        {
            var request = new HttpRequestMessage(HttpMethod.Post, uri);

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(uri);
                request.Content    = new StringContent(Serialization.DataContractSerializeObject <Common.FileInfo>(fileInfo),
                                                       Encoding.UTF8, "application/xml");

                var response = await client.SendAsync(request);

                var stream = await response.Content.ReadAsStreamAsync();

                var buffer = new byte[stream.Length];

                var result = await stream.ReadAsync(buffer, 0, (int)stream.Length);

                var downloadedFileInfo = new DownloadedFileInfo()
                {
                    Path   = Paths.DownloadPath + response.Content.Headers.ContentDisposition.FileName,
                    Name   = response.Content.Headers.ContentDisposition.FileName,
                    Buffor = buffer
                };
                return(downloadedFileInfo);
            }
        }
Esempio n. 2
0
 internal bool Delete(Common.FileInfo file)
 {
     try
     {
         File.Delete(file.Path);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Esempio n. 3
0
        internal static async Task <HttpResponseMessage> DeleteFile(Common.FileInfo fileInfo, string uri)
        {
            var request = new HttpRequestMessage(HttpMethod.Delete, uri);

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(uri);
                request.Content    = new StringContent(Serialization.DataContractSerializeObject <Common.FileInfo>(fileInfo),
                                                       Encoding.UTF8, "application/xml");

                return(await client.SendAsync(request));
            }
        }
Esempio n. 4
0
 public void Delete([FromBody] Common.FileInfo file)
 {
     model.Delete(file);
 }
Esempio n. 5
0
 public HttpResponseMessage GetFile([FromBody] Common.FileInfo file)
 {
     return(FileAsAttachment(file.Path, file.Name));
 }
Esempio n. 6
0
 public async Task <IDownloadedFile> GetFile(Common.FileInfo file)
 {
     return(await HttpMessageSender.GetFile(file, _endPoint + "get"));
 }
Esempio n. 7
0
 public async Task <HttpResponseMessage> DeleteFile(Common.FileInfo file)
 {
     return(await HttpMessageSender.DeleteFile(file, _endPoint + "delete"));
 }