Exemplo n.º 1
0
        private Task SendToDatabase(DownloadInfo info, State state)
        {
            return(Task.Run(() =>
            {
                using (var context = new AppContext())
                {
                    var elements = context.DownloadInfos.Where(downloadInfo => downloadInfo.Id == info.Id);
                    if (elements is null)
                    {
                        context.DownloadInfos.Add(info);
                        context.SaveChanges();
                    }

                    context.States.Add(state);
                    context.SaveChanges();
                }
            }));
        }
Exemplo n.º 2
0
        private async void DownloadButtonClick(object sender, RoutedEventArgs e)
        {
            _info.Url       = urlTextBox.Text;
            _info.LocalPath = $"{Guid.NewGuid().ToString()}_File";

            try
            {
                await SendToDatabase(_info, new State { DownloadInfo = _info, Status = "Begin", DateTime = DateTime.Now });

                await DownloadFile(_info.Url, _info.LocalPath);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }

            MessageBox.Show("Файл установлен!");
            _info = new DownloadInfo();
        }
Exemplo n.º 3
0
 public MainWindow()
 {
     InitializeComponent();
     _info = new DownloadInfo();
 }