Ejemplo n.º 1
0
        void prov_DownloadCompleted(ISearchProvider provider, NzbItem item, string TempFileName, string ErrorMessage)
        {
            try
            {
                if (TempFileName != null && ErrorMessage == null)
                {
                    if (!_NzbItems.Contains(item)) //nothing to do?
                        throw new Exception("NzbItem not contained within list");

                    //combine existing NZB's with eachother
                    CombineNZBs(_CombinedTempFileName, TempFileName);

                    _NzbItems.Remove(item);
                    _DownloadedNzbItems.Add(item);
                    EnableControls(true);

                    if (_NzbItems.Count > 0) //still items left to download?
                    {
                        _prov.DownloadNZB_Async(_NzbItems[0]);
                        return; //wait until next is downloaded
                    }

                    Global.HandleDownloadedNZB(_CombinedTempFileName, txtFriendlyName.Text, cboCategories.Text);

                    foreach(NzbItem DownloadedItem in _DownloadedNzbItems)
                        provider.MarkAsDownloaded(DownloadedItem);

                    this.DialogResult = DialogResult.OK;
                    this.Close();
                    return; //we're done
                }
            }
            catch(Exception e)
            {
                ErrorMessage = e.Message;
            }

            if (ErrorMessage != null)
            {
                //we need to start over, so do cleanup, reset to start
                _NzbItems.AddRange(_DownloadedNzbItems);
                _DownloadedNzbItems.Clear();
                if (File.Exists(_CombinedTempFileName))
                    File.Delete(_CombinedTempFileName);

                MessageBox.Show(ErrorMessage);
            }

            EnableControls(false);
        }