Esempio n. 1
0
 public async Task CreateImageFolderForGeocaches(List <Framework.Data.Geocache> gcList, string folder)
 {
     using (CopyToFolderForm dlg = new CopyToFolderForm(folder))
     {
         if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             _gcList = (from a in gcList select a).ToList();
             if (PluginSettings.Instance.DownloadBeforeCreate)
             {
                 List <Framework.Data.Geocache>    tmpList = (from a in _gcList select a).ToList();
                 System.Windows.Forms.DialogResult dr      = System.Windows.Forms.MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_GRABNEW), Utils.LanguageSupport.Instance.GetTranslation(STR_GRABIMAGES), System.Windows.Forms.MessageBoxButtons.YesNoCancel);
                 _grabOnlyNew = (dr == System.Windows.Forms.DialogResult.Yes);
                 if (dr != System.Windows.Forms.DialogResult.Cancel)
                 {
                     using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_GRABBING_IMAGES, STR_GRABBING_IMAGES, _gcList.Count, 0, true))
                     {
                         int cnt = _gcList.Count;
                         _orgListCount = cnt;
                         Thread[] thrd = new Thread[4];
                         for (int i = 0; i < thrd.Length; i++)
                         {
                             thrd[i] = new Thread(new ThreadStart(this.getImagesThreadMethod));
                             thrd[i].Start();
                         }
                         while (cnt > 0)
                         {
                             Thread.Sleep(500);
                             System.Windows.Forms.Application.DoEvents();
                             lock (_gcList)
                             {
                                 cnt = _gcList.Count;
                             }
                             if (!progress.UpdateProgress(STR_GRABBING_IMAGES, STR_GRABBING_IMAGES, _orgListCount, _orgListCount - cnt))
                             {
                                 lock (_gcList)
                                 {
                                     _gcList.Clear();
                                     cnt = 0;
                                 }
                             }
                         }
                         for (int i = 0; i < thrd.Length; i++)
                         {
                             thrd[i].Join();
                         }
                     }
                 }
                 _gcList = tmpList;
             }
             await Task.Run(() =>
             {
                 this.copyToFolderThreadMethod();
             });
         }
     }
 }
Esempio n. 2
0
        public async override Task <bool> ActionAsync(string action)
        {
            bool result = base.Action(action);

            if (result)
            {
                if (action == ACTION_GRAB_ACTIVE || action == ACTION_GRAB_DELETE_ACTIVE || action == ACTION_CREATE_ACTIVE || action == ACTION_DELETEFOLDER_ACTIVE)
                {
                    if (Core.ActiveGeocache != null)
                    {
                        _gcList = new List <Framework.Data.Geocache>();
                        _gcList.Add(Core.ActiveGeocache);
                    }
                }
                else if (action == ACTION_GRAB_SELECTED || action == ACTION_GRAB_DELETE_SELECTED || action == ACTION_CREATE_SELECTED || action == ACTION_DELETEFOLDER_SELECTED)
                {
                    _gcList = Utils.DataAccess.GetSelectedGeocaches(Core.Geocaches);
                }
                else if (action == ACTION_GRAB_DELETE_ALL)
                {
                    _gcList = (from Framework.Data.Geocache w in Core.Geocaches select w).ToList();
                }
                if (_gcList == null || _gcList.Count == 0)
                {
                    System.Windows.Forms.MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_NOCACHESSELECTED), Utils.LanguageSupport.Instance.GetTranslation("Information"), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                }
                else
                {
                    if (action == ACTION_CREATE_ACTIVE || action == ACTION_CREATE_SELECTED)
                    {
                        using (CopyToFolderForm dlg = new CopyToFolderForm())
                        {
                            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                            {
                                if (PluginSettings.Instance.DownloadBeforeCreate)
                                {
                                    List <Framework.Data.Geocache> tmpList = (from a in _gcList select a).ToList();
                                    Action(action == ACTION_CREATE_ACTIVE ? ACTION_GRAB_ACTIVE : ACTION_GRAB_SELECTED);
                                    _gcList = tmpList;
                                }
                                await Task.Run(() =>
                                {
                                    this.copyToFolderThreadMethod();
                                });
                            }
                        }
                    }
                    else if (action == ACTION_GRAB_ACTIVE || action == ACTION_GRAB_SELECTED)
                    {
                        System.Windows.Forms.DialogResult dr = System.Windows.Forms.MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_GRABNEW), Utils.LanguageSupport.Instance.GetTranslation(STR_GRABIMAGES), System.Windows.Forms.MessageBoxButtons.YesNoCancel);
                        _grabOnlyNew = (dr == System.Windows.Forms.DialogResult.Yes);
                        if (dr != System.Windows.Forms.DialogResult.Cancel)
                        {
                            using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_GRABBING_IMAGES, STR_GRABBING_IMAGES, _gcList.Count, 0, true))
                            {
                                int cnt = _gcList.Count;
                                _orgListCount = cnt;
                                Thread[] thrd = new Thread[4];
                                for (int i = 0; i < thrd.Length; i++)
                                {
                                    thrd[i] = new Thread(new ThreadStart(this.getImagesThreadMethod));
                                    thrd[i].Start();
                                }
                                while (cnt > 0)
                                {
                                    Thread.Sleep(500);
                                    System.Windows.Forms.Application.DoEvents();
                                    lock (_gcList)
                                    {
                                        cnt = _gcList.Count;
                                    }
                                    if (!progress.UpdateProgress(STR_GRABBING_IMAGES, STR_GRABBING_IMAGES, _orgListCount, _orgListCount - cnt))
                                    {
                                        lock (_gcList)
                                        {
                                            _gcList.Clear();
                                            cnt = 0;
                                        }
                                    }
                                }
                                for (int i = 0; i < thrd.Length; i++)
                                {
                                    thrd[i].Join();
                                }
                            }
                        }
                    }
                    else if (action == ACTION_GRAB_DELETE_ACTIVE || action == ACTION_GRAB_DELETE_SELECTED || action == ACTION_GRAB_DELETE_ALL)
                    {
                        await Task.Run(() =>
                        {
                            this.deleteImagesThreadMethod();
                        });
                    }
                    else if (action == ACTION_DELETEFOLDER_ACTIVE || action == ACTION_DELETEFOLDER_SELECTED)
                    {
                        using (System.Windows.Forms.FolderBrowserDialog dlg = new System.Windows.Forms.FolderBrowserDialog())
                        {
                            if (!string.IsNullOrEmpty(PluginSettings.Instance.CreateFolderPath))
                            {
                                dlg.SelectedPath = PluginSettings.Instance.CreateFolderPath;
                            }
                            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                            {
                                _imgFolder = dlg.SelectedPath;
                                await Task.Run(() =>
                                {
                                    this.deleteImagesFromFolderThreadMethod();
                                });
                            }
                        }
                    }
                }
            }
            return(result);
        }
Esempio n. 3
0
 public async override Task<bool> ActionAsync(string action)
 {
     bool result = base.Action(action);
     if (result)
     {
         if (action == ACTION_GRAB_ACTIVE || action == ACTION_GRAB_DELETE_ACTIVE || action == ACTION_CREATE_ACTIVE || action==ACTION_DELETEFOLDER_ACTIVE)
         {
             if (Core.ActiveGeocache != null)
             {
                 _gcList = new List<Framework.Data.Geocache>();
                 _gcList.Add(Core.ActiveGeocache);
             }
         }
         else if (action == ACTION_GRAB_SELECTED || action == ACTION_GRAB_DELETE_SELECTED || action == ACTION_CREATE_SELECTED || action == ACTION_DELETEFOLDER_SELECTED)
         {
             _gcList = Utils.DataAccess.GetSelectedGeocaches(Core.Geocaches);
         }
         else if (action == ACTION_GRAB_DELETE_ALL)
         {
             _gcList = (from Framework.Data.Geocache w in Core.Geocaches select w).ToList();
         }
         if (_gcList == null || _gcList.Count == 0)
         {
             System.Windows.Forms.MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_NOCACHESSELECTED), Utils.LanguageSupport.Instance.GetTranslation("Information"), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);                    
         }
         else
         {
             if (action == ACTION_CREATE_ACTIVE || action == ACTION_CREATE_SELECTED)
             {
                 using (CopyToFolderForm dlg = new CopyToFolderForm())
                 {
                     if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                     {
                         if (PluginSettings.Instance.DownloadBeforeCreate)
                         {
                             List<Framework.Data.Geocache> tmpList = (from a in _gcList select a).ToList();
                             Action(action == ACTION_CREATE_ACTIVE ? ACTION_GRAB_ACTIVE : ACTION_GRAB_SELECTED);
                             _gcList = tmpList;
                         }
                         await Task.Run(() =>
                             {
                                 this.copyToFolderThreadMethod();
                             });
                     }
                 }
             }
             else if (action == ACTION_GRAB_ACTIVE || action == ACTION_GRAB_SELECTED)
             {
                 System.Windows.Forms.DialogResult dr = System.Windows.Forms.MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_GRABNEW), Utils.LanguageSupport.Instance.GetTranslation(STR_GRABIMAGES), System.Windows.Forms.MessageBoxButtons.YesNoCancel);
                 _grabOnlyNew = (dr == System.Windows.Forms.DialogResult.Yes);                        
                 if (dr != System.Windows.Forms.DialogResult.Cancel)
                 {
                     using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_GRABBING_IMAGES, STR_GRABBING_IMAGES, _gcList.Count, 0, true))
                     {
                         int cnt = _gcList.Count;
                         _orgListCount = cnt;
                         Thread[] thrd = new Thread[4];
                         for (int i = 0; i < thrd.Length; i++)
                         {
                             thrd[i] = new Thread(new ThreadStart(this.getImagesThreadMethod));
                             thrd[i].Start();
                         }
                         while (cnt > 0)
                         {
                             Thread.Sleep(500);
                             System.Windows.Forms.Application.DoEvents();
                             lock (_gcList)
                             {
                                 cnt = _gcList.Count;
                             }
                             if (!progress.UpdateProgress(STR_GRABBING_IMAGES, STR_GRABBING_IMAGES, _orgListCount, _orgListCount - cnt))
                             {
                                 lock (_gcList)
                                 {
                                     _gcList.Clear();
                                     cnt = 0;
                                 }
                             }
                         }
                         for (int i = 0; i < thrd.Length; i++)
                         {
                             thrd[i].Join();
                         }
                     }
                 }
             }
             else if (action == ACTION_GRAB_DELETE_ACTIVE || action == ACTION_GRAB_DELETE_SELECTED || action == ACTION_GRAB_DELETE_ALL)
             {
                 await Task.Run(() =>
                 {
                     this.deleteImagesThreadMethod();
                 });
             }
             else if (action == ACTION_DELETEFOLDER_ACTIVE || action == ACTION_DELETEFOLDER_SELECTED)
             {
                 using (System.Windows.Forms.FolderBrowserDialog dlg = new System.Windows.Forms.FolderBrowserDialog())
                 {
                     if (!string.IsNullOrEmpty(PluginSettings.Instance.CreateFolderPath))
                     {
                         dlg.SelectedPath = PluginSettings.Instance.CreateFolderPath;
                     }
                     if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                     {
                         _imgFolder = dlg.SelectedPath;
                         await Task.Run(() =>
                         {
                             this.deleteImagesFromFolderThreadMethod();
                         });
                     }
                 }
             }
         }
     }
     return result;
 }
Esempio n. 4
0
 public async Task CreateImageFolderForGeocaches(List<Framework.Data.Geocache> gcList, string folder)
 {
     using (CopyToFolderForm dlg = new CopyToFolderForm(folder))
     {
         if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             _gcList = (from a in gcList select a).ToList();
             if (PluginSettings.Instance.DownloadBeforeCreate)
             {
                 List<Framework.Data.Geocache> tmpList = (from a in _gcList select a).ToList();
                 System.Windows.Forms.DialogResult dr = System.Windows.Forms.MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_GRABNEW), Utils.LanguageSupport.Instance.GetTranslation(STR_GRABIMAGES), System.Windows.Forms.MessageBoxButtons.YesNoCancel);
                 _grabOnlyNew = (dr == System.Windows.Forms.DialogResult.Yes);
                 if (dr != System.Windows.Forms.DialogResult.Cancel)
                 {
                     using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_GRABBING_IMAGES, STR_GRABBING_IMAGES, _gcList.Count, 0, true))
                     {
                         int cnt = _gcList.Count;
                         _orgListCount = cnt;
                         Thread[] thrd = new Thread[4];
                         for (int i = 0; i < thrd.Length; i++)
                         {
                             thrd[i] = new Thread(new ThreadStart(this.getImagesThreadMethod));
                             thrd[i].Start();
                         }
                         while (cnt > 0)
                         {
                             Thread.Sleep(500);
                             System.Windows.Forms.Application.DoEvents();
                             lock (_gcList)
                             {
                                 cnt = _gcList.Count;
                             }
                             if (!progress.UpdateProgress(STR_GRABBING_IMAGES, STR_GRABBING_IMAGES, _orgListCount, _orgListCount - cnt))
                             {
                                 lock (_gcList)
                                 {
                                     _gcList.Clear();
                                     cnt = 0;
                                 }
                             }
                         }
                         for (int i = 0; i < thrd.Length; i++)
                         {
                             thrd[i].Join();
                         }
                     }
                 }
                 _gcList = tmpList;
             }
             await Task.Run(() =>
                 {
                     this.copyToFolderThreadMethod();
                 });
         }
     }
 }