Esempio n. 1
0
        public async Task <string> UploadImageToServer(MediaFile f, GroupHistoryItemDTO model)
        {
            try
            {
                using (var httpClient = GetHttpClient())
                {
                    var strFileName  = Path.GetFileName(f.Path);
                    var content      = new MultipartFormDataContent();
                    var imageContent = new StreamContent(f.GetStream());
                    content.Add(imageContent, "FILE", strFileName);
                    CancellationTokenSource tokenSource = new CancellationTokenSource();
                    CancellableTasks.Add(model, tokenSource);
                    var response = await httpClient.PostAsync(ServerURL.UploadImageGroupEntryURL, content, tokenSource.Token);

                    CancellableTasks.Remove(model);

                    if (response.StatusCode == System.Net.HttpStatusCode.OK)
                    {
                        string retVal = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                        var responseItem = JsonConvert.DeserializeObject <CommonResponse>(retVal);
                        if (!responseItem.RESULT)
                        {
                            return(null);
                        }
                        return(responseItem.MSG);
                    }
                }
            }
            catch (Exception except) {}
            return(null);
        }
Esempio n. 2
0
 public async Task <bool> StopUploading(GroupHistoryItemDTO dto)
 {
     return(await Task.Factory.StartNew <bool>(() =>
     {
         CancellationTokenSource workingUploadngProgress;
         if (CancellableTasks.TryGetValue(dto, out workingUploadngProgress))
         {
             workingUploadngProgress.Cancel();
             return true;
         }
         return false;
     }));
 }
Esempio n. 3
0
        public async Task <string> UploadAudioToServer(string FileName, byte[] bArray, GroupHistoryItemDTO Dto)
        {
            try
            {
                using (var httpClient = GetHttpClient())
                {
                    var stringContent = new List <KeyValuePair <string, string> >();
                    var content       = new MultipartFormDataContent();
                    var imageContent  = new ByteArrayContent(bArray);
                    content.Add(imageContent, "FILE", FileName);

                    CancellationTokenSource tokenSource = new CancellationTokenSource();
                    CancellableTasks.Add(Dto, tokenSource);
                    var response = await httpClient.PostAsync(ServerURL.UploadImageGroupEntryURL, content, tokenSource.Token);

                    CancellableTasks.Remove(Dto);
                    if (response.StatusCode == System.Net.HttpStatusCode.OK)
                    {
                        string retVal = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                        var responseItem = JsonConvert.DeserializeObject <CommonResponse>(retVal);
                        if (!responseItem.RESULT)
                        {
                            return(null);
                        }
                        return(responseItem.MSG);
                    }
                }
            }catch (Exception exp) {}
            return(null);
        }