Пример #1
0
        void WorkerCommands_DoWork(object sender, DoWorkEventArgs e)
        {
            while (true)
            {
                if (workerCommands.CancellationPending)
                {
                    return;
                }

                // if paused we will sleep for 5 seconds, and the try again
                if (Paused)
                {
                    try
                    {
                        if (workerCommands.CancellationPending)
                        {
                            return;
                        }
                    }
                    catch
                    {
                        // ignore
                    }
                    Thread.Sleep(200);
                    continue;
                }

                CommandRequest crdb = RepoFactory.CommandRequest.GetNextDBCommandRequestGeneral();
                if (crdb == null)
                {
                    if (QueueCount > 0 && !ShokoService.AnidbProcessor.IsHttpBanned && !ShokoService.AnidbProcessor.IsUdpBanned)
                    {
                        logger.Error($"No command returned from database, but there are {QueueCount} commands left");
                    }
                    return;
                }

                if (workerCommands.CancellationPending)
                {
                    return;
                }

                ICommandRequest icr = CommandHelper.GetCommand(crdb);
                if (icr == null)
                {
                    logger.Error("No implementation found for command: {0}-{1}", crdb.CommandType, crdb.CommandID);
                }
                else
                {
                    QueueState = icr.PrettyDescription;

                    if (workerCommands.CancellationPending)
                    {
                        return;
                    }

                    logger.Trace("Processing command request: {0}", crdb.CommandID);
                    try
                    {
                        CurrentCommand = crdb;
                        icr.ProcessCommand();
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex, "ProcessCommand exception: {0}\n{1}", crdb.CommandID, ex);
                    }
                    finally
                    {
                        CurrentCommand = null;
                    }
                }

                logger.Trace("Deleting command request: {0}", crdb.CommandID);
                RepoFactory.CommandRequest.Delete(crdb.CommandRequestID);

                QueueCount = RepoFactory.CommandRequest.GetQueuedCommandCountGeneral();
            }
        }
Пример #2
0
        void WorkerCommands_DoWork(object sender, DoWorkEventArgs e)
        {
            while (true)
            {
                if (workerCommands.CancellationPending)
                {
                    return;
                }

                // if paused we will sleep for 5 seconds, and the try again
                if (Paused)
                {
                    try
                    {
                        if (workerCommands.CancellationPending)
                        {
                            return;
                        }
                    }
                    catch
                    {
                        // ignore
                    }
                    Thread.Sleep(200);
                    continue;
                }

                CommandRequest crdb = Repo.Instance.CommandRequest.GetNextDBCommandRequestImages();
                if (crdb == null)
                {
                    return;
                }

                if (workerCommands.CancellationPending)
                {
                    return;
                }

                ICommandRequest icr = CommandHelper.GetCommand(crdb);
                if (icr == null)
                {
                    return;
                }

                if (workerCommands.CancellationPending)
                {
                    return;
                }

                QueueState = icr.PrettyDescription;

                try
                {
                    CurrentCommand = crdb;
                    icr.ProcessCommand();
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "ProcessCommand exception: {0}\n{1}", crdb.CommandID, ex);
                }
                finally
                {
                    CurrentCommand = null;
                }

                Repo.Instance.CommandRequest.FindAndDelete(() => Repo.Instance.CommandRequest.GetByCommandID(crdb.CommandID));
                QueueCount = Repo.Instance.CommandRequest.GetQueuedCommandCountImages();
            }
        }
        void WorkerCommands_DoWork(object sender, DoWorkEventArgs e)
        {
            while (true)
            {
                if (workerCommands.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                // if paused we will sleep for 5 seconds, and the try again
                // we will remove the pause if it was set more than 6 hours ago
                // the pause is initiated when banned from AniDB or manually by the user
                if (Paused)
                {
                    try
                    {
                        if (workerCommands.CancellationPending)
                        {
                            e.Cancel = true;
                            return;
                        }

                        TimeSpan ts = DateTime.Now - pauseTime.Value;
                        if (ts.TotalHours >= 6)
                        {
                            Paused = false;
                        }
                    }
                    catch
                    {
                        // ignore
                    }
                    Thread.Sleep(200);
                    continue;
                }

                CommandRequest crdb = RepoFactory.CommandRequest.GetNextDBCommandRequestImages();
                if (crdb == null)
                {
                    return;
                }

                if (workerCommands.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                ICommandRequest icr = CommandHelper.GetCommand(crdb);
                if (icr == null)
                {
                    return;
                }

                if (workerCommands.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                QueueState = icr.PrettyDescription;

                icr.ProcessCommand();

                RepoFactory.CommandRequest.Delete(crdb.CommandRequestID);
                QueueCount = RepoFactory.CommandRequest.GetQueuedCommandCountImages();
            }
        }