Exemplo n.º 1
0
 /// <summary>
 /// Save all changed data
 /// </summary>
 public void SaveChangedData()
 {
     _SaveResult             = "";
     _NumberOfPicturesToSave = 0;
     _PicturesToSave         = new Queue <PictureComparer>();
     foreach (KeyValuePair <string, PictureComparer> kvp in _ChangesPendingList)
     {
         _NumberOfPicturesToSave++;
         kvp.Value.Saved += new PictureComparer.OnSaved(Value_Saved);
         _PicturesToSave.Enqueue(kvp.Value);
     }
     if (_NumberOfPicturesToSave == 0)
     { // nothing to save! finish!
         if (Saved != null)
         {
             Saved(this, new OnPictureListSavedEventArgs(_SaveResult));
         }
         return;
     }
     lock (_PicturesToSave)
     {
         _TotalNumberOfPictures = _PicturesToSave.Count;
         Debug.WriteLine(_TotalNumberOfPictures.ToString() + " Pictures in Save-Queue (Starting)");
         // start with maximal four threads
         for (int i = 0; i < 4 && i < _PicturesToSave.Count; i++)
         {
             PictureComparer pc = _PicturesToSave.Dequeue();
             pc.Save();
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Value was saved. Collect info, then finish
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        void Value_Saved(object sender, OnSavedEventArgs args)
        {
            lock (_PicturesToSave)
            {
                PictureComparer pc = sender as PictureComparer;
                if (pc != null)
                {
                    _SaveResult += pc.FileName + ":" + Environment.NewLine;
                }
                _SaveResult += args.ToolOutput;
                _NumberOfPicturesToSave--;

                if (PictureSaved != null)
                {
                    PictureSaved(this, new OnPictureSavedEventArgs(pc.FileName, (int)(100 - 100 * (float)((float)_NumberOfPicturesToSave / (float)_TotalNumberOfPictures))));
                }

                // one more in the queue? -> dequeue, start saving
                if (_PicturesToSave.Count > 0)
                {
                    PictureComparer pic = _PicturesToSave.Dequeue();
                    pic.Save();
                }

                Debug.WriteLine(_PicturesToSave.Count.ToString() + " Pictures in Save-Queue");

                // finished?
                if (_NumberOfPicturesToSave == 0)
                {
                    if (Saved != null)
                    {
                        Saved(this, new OnPictureListSavedEventArgs(_SaveResult));
                    }
                }
            }
        }