Esempio n. 1
0
        private async Task UpdateCurrentReigster()
        {
            try
            {
                using (var r = new RegataContext())
                {
                    var ir = r.Irradiations.Where(ir => ir.Id == mainForm.MainRDGV.CurrentDbSet.Local.Select(m => m.IrradiationId).Min()).FirstOrDefault();
                    CurrentMeasurementsRegister.IrradiationDate = ir.DateTimeStart.Value.Date;
                    CurrentMeasurementsRegister.Name            = ir.DateTimeStart.Value.Date.ToShortDateString();
                    CurrentMeasurementsRegister.LoadNumber      = ir.LoadNumber;
                    CurrentMeasurementsRegister.DateTimeStart   = mainForm.MainRDGV.CurrentDbSet.Local.Select(m => m.DateTimeStart).Min();
                    CurrentMeasurementsRegister.DateTimeFinish  = mainForm.MainRDGV.CurrentDbSet.Local.Select(m => m.DateTimeFinish).Max();
                    CurrentMeasurementsRegister.SamplesCnt      = mainForm.MainRDGV.CurrentDbSet.Local.Where(m => m.FileSpectra != null).Count();
                    CurrentMeasurementsRegister.Detectors       = string.Join(',', mainForm.MainRDGV.CurrentDbSet.Local.Select(m => m.Detector).Distinct().ToArray());
                    // TODO: https://github.com/regata-jinr/Measurements.Desktop/issues/46
                    //CurrentMeasurementsRegister.Assistant = GlobalSettings.User;

                    r.MeasurementsRegisters.Update(CurrentMeasurementsRegister);
                    await r.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                Report.Notify(new RCM.Message(Codes.ERR_UI_WF_UPD_CUR_MEAS_REG)
                {
                    DetailedText = ex.ToString()
                });
            }
        }
Esempio n. 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);
            }
        }