public void Save(ISession session)
		{
			CommandRequestRepository repCR = new CommandRequestRepository();
			CommandRequest crTemp = repCR.GetByCommandID(session, this.CommandID);
			if (crTemp != null)
			{
				// we will always mylist watched state changes
				// this is because the user may be toggling the status in the client, and we need to process
				// them all in the order they were requested
				if (CommandType != (int)CommandRequestType.AniDB_UpdateWatchedUDP)
				{
					//logger.Trace("Command already in queue with identifier so skipping: {0}", this.CommandID);
					return;
				}
			}

			CommandRequest cri = this.ToDatabaseObject();
			repCR.Save(session, cri);

			if (CommandType == (int)CommandRequestType.HashFile)
				JMMService.CmdProcessorHasher.NotifyOfNewCommand();
			else if (CommandType == (int)CommandRequestType.ImageDownload)
				JMMService.CmdProcessorImages.NotifyOfNewCommand();
			else
				JMMService.CmdProcessorGeneral.NotifyOfNewCommand();
		}
Exemple #2
0
		void btnHasherClear_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				this.Cursor = Cursors.Wait;
				JMMService.CmdProcessorHasher.Stop();

				// wait until the queue stops
				while (JMMService.CmdProcessorHasher.ProcessingCommands)
				{
					Thread.Sleep(200);
				}
				Thread.Sleep(200);

				CommandRequestRepository repCR = new CommandRequestRepository();
				foreach (CommandRequest cr in repCR.GetAllCommandRequestHasher())
					repCR.Delete(cr.CommandRequestID);

				JMMService.CmdProcessorHasher.Init();
			}
			catch (Exception ex)
			{
				Utils.ShowErrorMessage(ex.Message);
			}
			this.Cursor = Cursors.Arrow;
		}
		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("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...");

				CommandRequestRepository repCR = new CommandRequestRepository();
				CommandRequest crdb = repCR.GetNextDBCommandRequestGeneral();
				if (crdb == null) return;

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

				QueueCount = repCR.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);
				    icr.ProcessCommand();
                }

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

				QueueCount = repCR.GetQueuedCommandCountGeneral();
			}
		}
Exemple #4
0
        public void ClearImagesQueue()
        {
            try
            {
                JMMService.CmdProcessorImages.Stop();

                // wait until the queue stops
                while (JMMService.CmdProcessorImages.ProcessingCommands)
                {
                    Thread.Sleep(200);
                }
                Thread.Sleep(200);

                CommandRequestRepository repCR = new CommandRequestRepository();
                foreach (CommandRequest cr in repCR.GetAllCommandRequestImages())
                    repCR.Delete(cr.CommandRequestID);

                JMMService.CmdProcessorImages.Init();
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
        }