Exemplo n.º 1
0
 // aFilePath must only be the path of the directory
 public FolderThumbCacher(string aFilePath, bool aOverWriteExisting)
 {
   lock (aFilePath)
   {
     _filename = aFilePath;
     _overWrite = aOverWriteExisting;
     work = new Work(new DoWorkHandler(this.PerformRequest));
     work.ThreadPriority = ThreadPriority.Lowest;
     GlobalServiceProvider.Get<IThreadPool>().Add(work, QueuePriority.Low);
   }
 }
Exemplo n.º 2
0
    // Filename is a full path+file
    public FolderThumbCreator(string Filename, MusicTag FileTag)
    {
      lock (_filename)
      {
        _filename = Filename;
        _filetag = FileTag;
        work = new Work(new DoWorkHandler(this.PerformRequest));
        work.ThreadPriority = ThreadPriority.Lowest;

        GlobalServiceProvider.Get<IThreadPool>().Add(work, QueuePriority.Low);
      }
    }
      public CreateThumbsAndAddPictureToDBFolderThread(string Filepath)
      {
        _filepath = Filepath;

        work = new Work(new DoWorkHandler(this.PerformRequest));
        work.ThreadPriority = ThreadPriority.BelowNormal;
        GlobalServiceProvider.Get<IThreadPool>().Add(work, QueuePriority.Low);
      }
Exemplo n.º 4
0
 public void TestAddWorkWhileStopped()
 {
   Console.Out.WriteLine("----=<TestAddWorkWhileStopped>=----");
   Work w = new Work(new DoWorkHandler(delegate() { Thread.Sleep(300); }));
   _pool.Stop();
   try
   {
     _pool.Add(w);
     Assert.Fail("InvalidOperationException not thrown");
   }
   catch (InvalidOperationException) {}
 }
Exemplo n.º 5
0
 public void TestAddWorkInvalidState()
 {
   Console.Out.WriteLine("----=<TestAddWorkInvalidState>=----");
   Work w = new Work();
   w.State = WorkState.INPROGRESS;
   try
   {
     _pool.Add(w);
     Assert.Fail("InvalidOperationException not thrown");
   }
   catch (InvalidOperationException) {}
 }
Exemplo n.º 6
0
    public void TestStrongTypeCallback()
    {
      Console.Out.WriteLine("----=<TestStrongTypeCallback>=----");
      Work w = _testStrongTypeCallbackWork = new Work();
      w.ThreadPriority = ThreadPriority.Normal;
      w.WorkLoad = new DoWorkHandler(delegate()
                                       {
                                         _testStrongTypeCallbackWork.State = WorkState.INPROGRESS;
                                         List<int> result = new List<int>();
                                         for (int i = 0; i < 10; i++)
                                         {
                                           result.Add(i);
                                         }
                                         _testStrongTypeCallbackWork.EventArgs.SetResult<List<int>>(result);
                                         _testStrongTypeCallbackWork.State = WorkState.FINISHED;
                                         _testStrongTypeCallbackWork.WorkCompleted(_testStrongTypeCallbackWork.EventArgs);
                                       });
      w.WorkCompleted = new WorkEventHandler(delegate(WorkEventArgs args)
                                               {
                                                 _testStrongTypeCallbackResult = args.GetResult<List<int>>();
                                                 lock (_waitHandle)
                                                   Monitor.Pulse(_waitHandle);
                                               });

      lock (_waitHandle)
      {
        _pool.Add(w);
        Monitor.Wait(_waitHandle);
      }

      if (_testStrongTypeCallbackResult != null)
      {
        if (_testStrongTypeCallbackResult.Count != 10)
        {
          Assert.Fail("received {0} results instead of 10", _testStrongTypeCallbackResult.Count);
        }
        else
        {
          for (int i = 0; i < _testStrongTypeCallbackResult.Count; i++)
          {
            Assert.AreEqual(i, _testStrongTypeCallbackResult[i]);
          }
        }
      }
      else
      {
        Assert.Fail("no results were received");
      }
    }
Exemplo n.º 7
0
    /// <summary>
    /// Starts MusicDBreorg
    /// </summary>
    public void Start()
    {
      Log.Info("MusicDBReorg: schedule: {0}:{1}", _runHours, _runMinutes);
      Log.Info(
        "MusicDBReorg: run on: monday:{0}, tuesday:{1}, wednesday:{2}, thursday:{3}, friday:{4}, saturday:{5}, sunday:{6}",
        _runMondays, _runTuesdays, _runWednesdays, _runThursdays, _runFridays, _runSaturdays, _runSundays);

      // Establish Handler to catch reorg events, when the reorg is from within the Settings GUI
      MusicDatabase.DatabaseReorgChanged += new MusicDBReorgEventHandler(ReorgStatusChange);

      _run = true;
      Work work = new Work(new DoWorkHandler(this.Run));
      work.ThreadPriority = ThreadPriority.Lowest;
      work.Description = "MusicDBReorg Thread";
      GlobalServiceProvider.Get<IThreadPool>().Add(work, QueuePriority.Low);
      Log.Info("MusicDBReorg: started");
    }
Exemplo n.º 8
0
 /// <summary>
 /// Add work to be performed by the threadpool.
 /// Can throw ArgumentNullException and InvalidOperationException.
 /// </summary>
 /// <param name="work">DoWorkHandler which contains the work to perform</param>
 /// <param name="description">description for this work</param>
 /// <param name="queuePriority">QueuePriority for this work</param>
 /// <param name="threadPriority">System.Threading.ThreadPriority for this work</param>
 /// <param name="workCompletedHandler">WorkEventHandler to be called on completion</param>
 /// <returns>IWork reference to work object</returns>
 public IWork Add(DoWorkHandler work, string description, QueuePriority queuePriority, ThreadPriority threadPriority,
                  WorkEventHandler workCompletedHandler)
 {
   IWork w = new Work(work, description, threadPriority, workCompletedHandler);
   Add(w, queuePriority);
   return w;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Add work to be performed by the threadpool.
 /// Can throw ArgumentNullException and InvalidOperationException.
 /// </summary>
 /// <param name="work">Work object to process</param>
 /// <param name="queuePriority">QueuePriority for this work</param>
 public void Add(Work work, QueuePriority queuePriority)
 {
   if (work == null)
   {
     throw new ArgumentNullException("work", "cannot be null");
   }
   IWork w = work as IWork;
   if (w != null)
   {
     Add(w, queuePriority);
   }
   else
   {
     throw new InvalidOperationException("Work does not implement IWork interface");
   }
 }
Exemplo n.º 10
0
 /// <summary>
 /// Add work to be performed by the threadpool.
 /// Can throw ArgumentNullException and InvalidOperationException.
 /// </summary>
 /// <param name="work">DoWorkHandler which contains the work to perform</param>
 /// <param name="description">description for this work</param>
 /// <param name="queuePriority">QueuePriority for this work</param>
 /// <returns>IWork reference to work object</returns>
 public IWork Add(DoWorkHandler work, string description, QueuePriority queuePriority)
 {
   IWork w = new Work(work, description, _startInfo.DefaultThreadPriority);
   Add(w, queuePriority);
   return w;
 }
Exemplo n.º 11
0
 /// <summary>
 /// Add work to be performed by the threadpool.
 /// Can throw ArgumentNullException and InvalidOperationException.
 /// </summary>
 /// <param name="work">DoWorkHandler which contains the work to perform</param>
 /// <param name="workCompletedHandler">WorkEventHandler to be called on completion</param>
 /// <returns>IWork reference to work object</returns>
 public IWork Add(DoWorkHandler work, WorkEventHandler workCompletedHandler)
 {
   IWork w = new Work(work, workCompletedHandler);
   Add(w);
   return w;
 }
Exemplo n.º 12
0
 /// <summary>
 /// Add work to be performed by the threadpool.
 /// Can throw ArgumentNullException and InvalidOperationException.
 /// </summary>
 /// <param name="work">DoWorkHandler which contains the work to perform</param>
 /// <param name="threadPriority">System.Threading.ThreadPriority for this work</param>
 /// <returns>IWork reference to work object</returns>
 public IWork Add(DoWorkHandler work, ThreadPriority threadPriority)
 {
   IWork w = new Work(work, threadPriority);
   Add(w);
   return w;
 }
Exemplo n.º 13
0
 /// <summary>
 /// Add work to be performed by the threadpool.
 /// Can throw ArgumentNullException and InvalidOperationException.
 /// </summary>
 /// <param name="work">DoWorkHandler which contains the work to perform</param>
 /// <returns>IWork reference to work object</returns>
 public IWork Add(DoWorkHandler work)
 {
   IWork w = new Work(work, _startInfo.DefaultThreadPriority);
   Add(w);
   return w;
 }
Exemplo n.º 14
0
    public override bool OnMessage(GUIMessage message)
    {
      switch (message.Message)
      {
        case GUIMessage.MessageType.GUI_MSG_WINDOW_INIT:
          {
            base.OnMessage(message);
            LoadSettings();

            if (m_bAutoShuffle)
            {
              GUIControl.SelectControl(GetID, (int)Controls.CONTROL_AUTOSHUFFLE);
            }
            return true;
          }

        case GUIMessage.MessageType.GUI_MSG_WINDOW_DEINIT:
          {
            SaveSettings();
          }
          break;

        case GUIMessage.MessageType.GUI_MSG_CLICKED:
          {
            int iControl = message.SenderControlId;

            if (iControl == (int)Controls.CONTROL_AUTOSHUFFLE)
            {
              m_bAutoShuffle = !m_bAutoShuffle;
            }

            if (iControl == (int)Controls.CONTROL_BTNDELALBUMINFO)
            {
              MusicDatabaseReorg dbreorg = new MusicDatabaseReorg();
              dbreorg.DeleteAlbumInfo();
            }
            if (iControl == (int)Controls.CONTROL_BTNDELALBUM)
            {
              MusicDatabaseReorg dbreorg = new MusicDatabaseReorg();
              dbreorg.DeleteSingleAlbum();
            }

            if (iControl == (int)Controls.CONTROL_BTNREORGDB)
            {
              GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_YES_NO);
              if (null != dlgYesNo)
              {
                dlgYesNo.SetHeading(333);
                dlgYesNo.SetLine(1, "");
                dlgYesNo.SetLine(2, "");
                dlgYesNo.SetLine(3, "");
                dlgYesNo.DoModal(GetID);

                if (dlgYesNo.IsConfirmed)
                {
                  MusicDatabaseReorg reorg = new MusicDatabaseReorg(GetID);
                  Work work = new Work(new DoWorkHandler(reorg.ReorgAsync));
                  work.ThreadPriority = ThreadPriority.Lowest;
                  GlobalServiceProvider.Get<IThreadPool>().Add(work, QueuePriority.Low);
                }
              }
            }
          }
          break;
      }
      return base.OnMessage(message);
    }