public static void ResetAsync(int epid, bool auto)
        {
            lock (DbUpdateLock)
            {
                string errorCount = string.Empty;

                if (!auto)
                {
                    errorCount = ", errorcount=0";
                }

                using (SQLiteCommand command = new SQLiteCommand("update downloads set status=@newstatus, errortype=null, errortime=null, errordetails=null" + errorCount + " where epid=@epid and status=@oldstatus", FetchDbConn()))
                {
                    command.Parameters.Add(new SQLiteParameter("@oldstatus", DownloadStatus.Errored));
                    command.Parameters.Add(new SQLiteParameter("@newstatus", DownloadStatus.Waiting));
                    command.Parameters.Add(new SQLiteParameter("@epid", epid));

                    if (command.ExecuteNonQuery() == 0)
                    {
                        // Download has already been reset, or is missing
                        return;
                    }
                }
            }

            lock (sortCacheLock)
            {
                sortCache = null;
            }

            Updated?.Invoke(epid);
            DownloadManager.AddDownloads(new int[] { epid });
        }
Exemple #2
0
        private static void AddAsync(int[] epids)
        {
            List <int> added = new List <int>();

            lock (DbUpdateLock)
            {
                using (SQLiteMonTransaction transMon = new SQLiteMonTransaction(FetchDbConn().BeginTransaction()))
                {
                    using (SQLiteCommand command = new SQLiteCommand("insert into downloads (epid) values (@epid)", FetchDbConn()))
                    {
                        SQLiteParameter epidParam = new SQLiteParameter("@epid");
                        command.Parameters.Add(epidParam);

                        foreach (int epid in epids)
                        {
                            epidParam.Value = epid;

                            try
                            {
                                command.ExecuteNonQuery();
                            }
                            catch (SQLiteException sqliteExp)
                            {
                                if (sqliteExp.ErrorCode == SQLiteErrorCode.Constraint)
                                {
                                    // Already added while this was waiting in the threadpool
                                    continue;
                                }

                                throw;
                            }

                            added.Add(epid);
                        }
                    }

                    transMon.Trans.Commit();
                }
            }

            if (Added != null)
            {
                foreach (int epid in added)
                {
                    Added(epid);
                }
            }

            DownloadManager.AddDownloads(added.ToArray());
        }