Пример #1
0
 public static async Task DownloadSpectraAsync(string spectra, string path, CancellationToken ct)
 {
     try
     {
         using (var ssc = new RegataContext())
         {
             var sharedSpectra = ssc.SharedSpectra.Where(ss => ss.fileS == spectra).FirstOrDefault();
             if (sharedSpectra == null)
             {
                 Report.Notify(new Message(Codes.ERR_CLD_DWLD_FNFND));
                 return;
             }
             await WebDavClientApi.DownloadFileAsync(sharedSpectra.token, $"{path}/{spectra}.cnf", ct);
         }
     }
     catch (Exception ex)
     {
         Report.Notify(new Message(Codes.ERR_CLD_DWLD_UNREG)
         {
             DetailedText = ex.Message
         });
     }
 }
Пример #2
0
        public static async Task <bool> UploadFileToCloudAsync(string file, CancellationToken Token)
        {
            try
            {
                Report.Notify(new Message(Codes.INFO_CLD_UPL_FILE));

                if (Token.IsCancellationRequested)
                {
                    return(false);
                }

                var result = false;
                var token  = "";
                result = await WebDavClientApi.UploadFileAsync(file, Token);

                if (result)
                {
                    token = await WebDavClientApi.MakeShareableAsync(file, Token);
                }
                else
                {
                    Report.Notify(new Message(Codes.ERR_CLD_UPL_FILE));
                    return(false);
                }

                if (string.IsNullOrEmpty(token))
                {
                    Report.Notify(new Message(Codes.ERR_CLD_GEN_TKN));
                    return(false);
                }

                var ss = new SharedSpectrum()
                {
                    fileS = Path.GetFileNameWithoutExtension(file),
                    token = token
                };

                using (var ic = new RegataContext())
                {
                    bool IsExists = await ic.SharedSpectra.Where(s => s.fileS == ss.fileS).AnyAsync();

                    if (IsExists)
                    {
                        ic.SharedSpectra.Update(ss);
                    }
                    else
                    {
                        await ic.SharedSpectra.AddAsync(ss, Token);
                    }

                    await ic.SaveChangesAsync(Token);

                    return(result);
                }
            }
            catch (TaskCanceledException)
            {
                Report.Notify(new Message(Codes.WRN_CLD_UPL_FILE_CNCL));
                return(false);
            }
            catch (Exception ex)
            {
                Report.Notify(new Message(Codes.ERR_CLD_UPL_UNREG)
                {
                    DetailedText = ex.Message
                });
                return(false);
            }
        }