private void Download(Seed seed, BackgroundItemType type, object value)
        {
            if (seed == null) return;

            lock (this.ThisLock)
            {
                if (_settings.BackgroundDownloadItems.Any(n => n.Seed == seed)) return;

                if (seed.Rank == 0)
                {
                    BackgroundDownloadItem item = new BackgroundDownloadItem();

                    item.Rank = 0;
                    item.Seed = seed;
                    item.State = BackgroundDownloadState.Completed;
                    item.Type = type;

                    if (item.Type == BackgroundItemType.Link)
                    {
                        item.Value = new Link();
                    }
                    else if (item.Type == BackgroundItemType.Store)
                    {
                        item.Value = new Store();
                    }
                    else
                    {
                        throw new FormatException();
                    }

                    _settings.BackgroundDownloadItems.Add(item);
                }
                else
                {
                    if (seed.Key == null) return;

                    BackgroundDownloadItem item = new BackgroundDownloadItem();

                    item.Rank = 1;
                    item.Seed = seed;
                    item.State = BackgroundDownloadState.Downloading;
                    item.Type = type;
                    item.Value = value;

                    if (item.Seed.Key != null)
                    {
                        _cacheManager.Lock(item.Seed.Key);
                    }

                    _settings.BackgroundDownloadItems.Add(item);
                }
            }
        }
Пример #2
0
        private void Download(Seed seed, BackgroundItemType type, object value)
        {
            if (seed == null)
            {
                return;
            }

            lock (this.ThisLock)
            {
                if (_settings.BackgroundDownloadItems.Any(n => n.Seed == seed))
                {
                    return;
                }

                if (seed.Rank == 0)
                {
                    BackgroundDownloadItem item = new BackgroundDownloadItem();

                    item.Rank  = 0;
                    item.Seed  = seed;
                    item.State = BackgroundDownloadState.Completed;
                    item.Type  = type;

                    if (item.Type == BackgroundItemType.Link)
                    {
                        item.Value = new Link();
                    }
                    else if (item.Type == BackgroundItemType.Store)
                    {
                        item.Value = new Store();
                    }
                    else
                    {
                        throw new FormatException();
                    }

                    _settings.BackgroundDownloadItems.Add(item);
                }
                else
                {
                    if (seed.Key == null)
                    {
                        return;
                    }

                    BackgroundDownloadItem item = new BackgroundDownloadItem();

                    item.Rank  = 1;
                    item.Seed  = seed;
                    item.State = BackgroundDownloadState.Downloading;
                    item.Type  = type;
                    item.Value = value;

                    if (item.Seed.Key != null)
                    {
                        _cacheManager.Lock(item.Seed.Key);
                    }

                    _settings.BackgroundDownloadItems.Add(item);
                }
            }
        }