private void lvThreads_MouseClick(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Right)
     {
         int selectedCount = lvThreads.SelectedItems.Count;
         if (selectedCount != 0)
         {
             bool anyRunning        = false;
             bool anyStopped        = false;
             bool anyCanPostprocess = false;
             foreach (ThreadWatcher watcher in SelectedThreadWatchers)
             {
                 bool isRunning = watcher.IsRunning;
                 anyRunning        |= isRunning;
                 anyStopped        |= !isRunning;
                 anyCanPostprocess |= !isRunning && SiteHelper.CreateByUrl(watcher.PageUrl) is IFilePostprocessor;
             }
             miEditDescription.Visible       = selectedCount == 1;
             miStop.Visible                  = anyRunning;
             miStart.Visible                 = anyStopped;
             miCheckNow.Visible              = anyRunning;
             miCheckEvery.Visible            = anyRunning;
             miRemove.Visible                = anyStopped;
             miRemoveAndDeleteFolder.Visible = anyStopped;
             miPostprocessFiles.Visible      = anyCanPostprocess;
             cmThreads.Show(lvThreads, e.Location);
         }
     }
 }
        private bool AddThread(string pageUrl, string pageAuth, string imageAuth, int checkIntervalSeconds, bool oneTimeDownload, string description, UrlTransformResult urlTransformResult)
        {
            if (urlTransformResult != null)
            {
                pageUrl = urlTransformResult.TransformedUrl;
            }
            SiteHelper    siteHelper     = SiteHelper.CreateByUrl(pageUrl);
            string        globalThreadID = siteHelper.GetGlobalThreadID();
            ThreadWatcher watcher        = ThreadList.Items.FirstOrDefault(w => w.GlobalThreadID.Equals(globalThreadID, StringComparison.OrdinalIgnoreCase));

            if (watcher == null)
            {
                description ??= urlTransformResult?.DefaultDescription ?? siteHelper.GetDefaultDescription();
                watcher = ThreadWatcher.Create(siteHelper, pageUrl, pageAuth, imageAuth, oneTimeDownload, checkIntervalSeconds, description);

                AttachWatcherToUI(watcher);
                DisplayDescription(watcher);
                DisplayAddedOn(watcher);

                ThreadList.Add(watcher);
            }
            else
            {
                if (watcher.IsRunning)
                {
                    return(false);
                }

                watcher.PageAuth             = pageAuth;
                watcher.ImageAuth            = imageAuth;
                watcher.CheckIntervalSeconds = checkIntervalSeconds;
                watcher.OneTimeDownload      = oneTimeDownload;

                if (description != null)
                {
                    watcher.Description = description;
                    DisplayDescription(watcher);
                }
            }

            watcher.Start();

            _saveThreadList = true;

            return(true);
        }
Exemplo n.º 3
0
        public static ThreadWatcher Create(ThreadWatcherConfig config)
        {
            SiteHelper siteHelper = SiteHelper.CreateByUrl(config.PageUrl);

            return(new ThreadWatcher(siteHelper, config));
        }