Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,File,Modified,SizeKb,ProductName")] Download download)
        {
            if (id != download.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(download);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DownloadExists(download.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(download));
        }
Esempio n. 2
0
        public IActionResult Reset(int id)
        {
            DownloadItem  item  = _context.Items.Single(i => i.ID == id);
            DownloadGroup group = _context.Groups.Single(g => g.ID == item.DownloadGroupID);

            string filePath = System.IO.Path.Combine(_settings.DownloadFolder, group.Name, "files", item.Name);

            try
            {
                System.IO.File.Delete(filePath);
            }
            catch { }

            SocketHandler.Instance.SendIDReset(item);

            item.State = DownloadItem.States.Waiting;
            _context.Update(item);
            _context.SaveChanges();

            return(RedirectToAction("Show", "Downloads", new { id = group.ID }));
        }
Esempio n. 3
0
        public async void CheckQuery(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                await Task.Delay(5000);

                if (queryUpdate.Count == 0 && queryAdd.Count == 0)
                {
                    continue;
                }

                object[] temp;

                if (queryUpdate.Count > 0)
                {
                    temp = new object[queryUpdate.Count + 10];
                    queryUpdate.CopyTo(temp);
                    queryUpdate.Clear();

                    foreach (object obj in temp)
                    {
                        if (obj != null)
                        {
                            _context.Update(obj);
                        }
                    }
                }

                if (queryAdd.Count > 0)
                {
                    temp = new object[queryAdd.Count + 10];
                    queryAdd.CopyTo(temp);
                    queryAdd.Clear();

                    foreach (object obj in temp)
                    {
                        if (obj != null)
                        {
                            _context.Add(obj);
                        }
                    }
                }

                int x = 0;
                while (true)
                {
                    try
                    {
                        _context.SaveChanges();
                        break;
                    }
                    catch
                    {
                    }

                    x++;
                    if (x >= 10)
                    {
                        Log("Query Too many tries");
                        break;
                    }
                    await Task.Delay(500);
                }
            }
        }