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
                // we will remove the pause if it was set more than 12 hours ago
                // the pause is initiated when banned from AniDB or manually by the user
                if (Paused)
                {
                    try
                    {
                        if (workerCommands.CancellationPending)
                        {
                            return;
                        }

                        TimeSpan ts = DateTime.Now - pauseTime.Value;
                        if (ts.TotalHours >= 12)
                        {
                            Paused = false;
                        }
                    }
                    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();
            }
        }
        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;
                        }

                        //logger.Trace("Images Queue is paused: {0}", pauseTime.Value);
                        TimeSpan ts = DateTime.Now - pauseTime.Value;
                        if (ts.TotalHours >= 6)
                        {
                            Paused = false;
                        }
                    }
                    catch
                    {
                    }
                    Thread.Sleep(5000);
                    continue;
                }

                //logger.Trace("Looking for next command request (images)...");

                CommandRequestRepository repCR = new CommandRequestRepository();
                CommandRequest           crdb  = repCR.GetNextDBCommandRequestImages();
                if (crdb == null)
                {
                    return;
                }

                QueueCount = repCR.GetQueuedCommandCountImages();
                //logger.Trace("{0} commands remaining in queue (images)", QueueCount);

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

                //logger.Trace("Next command request (images): {0}", crdb.CommandID);

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

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

                QueueState = icr.PrettyDescription;

                //logger.Trace("Processing command request (images): {0}", crdb.CommandID);
                icr.ProcessCommand();

                //logger.Trace("Deleting command request (images): {0}", crdb.CommandID);
                repCR.Delete(crdb.CommandRequestID);
                QueueCount = repCR.GetQueuedCommandCountImages();
            }
        }
        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.Delete(crdb.CommandRequestID);
                QueueCount = Repo.Instance.CommandRequest.GetQueuedCommandCountImages();
            }
        }
Example #4
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.GetNextDBCommandRequestHasher();
                if (crdb == null)
                {
                    if (QueueCount > 0)
                    {
                        logger.Error($"No command returned from repo, but there are {QueueCount} commands left");
                    }
                    return;
                }

                if (workerCommands.CancellationPending)
                {
                    return;
                }

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

                QueueState = icr.PrettyDescription;

                if (workerCommands.CancellationPending)
                {
                    return;
                }

                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.GetQueuedCommandCountHasher();
            }
        }
        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 12 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;
                        }

                        //logger.Trace("Queue is paused: {0}", pauseTime.Value);
                        TimeSpan ts = DateTime.Now - pauseTime.Value;
                        if (ts.TotalHours >= 12)
                        {
                            Paused = false;
                        }
                    }
                    catch
                    {
                    }
                    Thread.Sleep(200);
                    continue;
                }


                //logger.Trace("Looking for next command request...");

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

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

                QueueCount = RepoFactory.CommandRequest.GetQueuedCommandCountGeneral();
                //logger.Trace("{0} commands remaining in queue", QueueCount);

                //logger.Trace("Next command request: {0}", crdb.CommandID);

                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)
                    {
                        e.Cancel = true;
                        return;
                    }

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

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

                QueueCount = RepoFactory.CommandRequest.GetQueuedCommandCountGeneral();
            }
        }
        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.GetNextDBCommandRequestHasher();
                if (crdb == null)
                {
                    if (QueueCount > 0)
                    {
                        logger.Error($"No command returned from repo, but there are {QueueCount} commands left");
                    }
                    return;
                }

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

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

                QueueState = icr.PrettyDescription;

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

                icr.ProcessCommand();

                RepoFactory.CommandRequest.Delete(crdb.CommandRequestID);
                QueueCount = RepoFactory.CommandRequest.GetQueuedCommandCountHasher();
            }
        }
Example #7
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.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);
                Repo.Instance.CommandRequest.Delete(crdb);

                QueueCount = Repo.Instance.CommandRequest.GetQueuedCommandCountGeneral();
            }
        }
        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
                // 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)
                        {
                            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)
                {
                    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;
                }

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