Beispiel #1
0
        public DownloadTask Create(Uri uri, string defaultFileExtension)
        {
            DownloadTask newTask = null;

            lock (_lock_)
            {
                if (Find(uri) != null)
                {
                    throw new ArgumentException("already in queue");
                }

                Guid newId = GenerateUniqueId();
                newTask = new DownloadTask(uri, newId, defaultFileExtension);
            }
            return(newTask);
        }
Beispiel #2
0
        // "http:\\blabla\toto.ext" {Guid}
        /// <summary>
        /// Analyse une ligne qui provient du fichier
        /// "downloads.lst" grâce à l'expression régulière
        /// donnée par la propriété DownloadListPattern.
        /// Les informations ainsi obtenues permettent de
        /// créer une DownloadTask, qui est ensuite retournée.
        /// </summary>
        /// <param name="text">une ligne de "downloads.lst" à analyser</param>
        /// <returns>un objet DownloadTask correspondant aux infos de la ligne passée en paramètre. La valeur null
        /// sera retournée si l'analyse échoue.</returns>
        /// <remarks>method called from the constructor, which is synchronized with the "_lock_" object.</remarks>
        private DownloadTask CreateTaskFromString(string text)
        {
            Match m = DownloadListPattern.Match(text);

            if (m.Success == false)
            {
                return(null);
            }

            string url          = m.Groups[1].Value;
            string guidAsString = m.Groups[2].Value;
            string extension    = (m.Groups.Count >= 4)? m.Groups[3].Value:null;


            Guid         guid = Guid.Parse(guidAsString);
            Uri          uri  = new Uri(url, UriKind.Absolute);
            DownloadTask task = new DownloadTask(uri, guid, extension);

            return(task);
        }
Beispiel #3
0
        private DownloadTask GetNextTask()
        {
            DownloadTask task = null;

            taskIndex++;

            if (downloads.Count == 0)
            {
                // Cas où il n'y a aucune tâche dans
                // la liste:
                taskIndex      = INDEX_NO_TASK;
                priorityFilter = MIN_PRIO_FILTER;
                //activeDownloads = 0;
                return(null);
            }


            // Retour au début de la liste des tâches
            // en cas de dépassement de la taille de
            // cette liste:
            if (taskIndex >= downloads.Count)
            {
                taskIndex = 0;

                // Après un tour complet dans la liste des tâches:
                // - remettre à zéro le compteur de tâches actives
                // - changer le filtre de priorité
                //activeDownloads = 0;
                priorityFilter++;
                if (priorityFilter > MAX_PRIO_FILTER)
                {
                    priorityFilter = MIN_PRIO_FILTER;
                }
            }


            task = downloads[taskIndex];

            return(task);
        }
Beispiel #4
0
 public bool Exists(DownloadTask t)
 {
     lock (_lock_)
     {
         foreach (DownloadTask task in downloads)
         {
             if (task == t)
             {
                 return(true);
             }
             //if (string.Compare(task.Url, t.Url, true) == 0) return true;
             if (task.Uri == t.Uri)
             {
                 return(true);
             }
             if (task.Guid == t.Guid)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Beispiel #5
0
        private DownloadTask GetNextActivableTask()
        {
            DownloadTask task = GetNextTask();

            // ignorer la tache si elle est finie:
            if (task != null)
            {
                if (task.IsFinished)
                {
                    task = null;
                }
            }

            // ignorer la tache si elle n'est pas à la bonne priorité
            if (task != null)
            {
                if ((priorityFilter % task.Priority) != 0)
                {
                    task = null;
                }
            }

            return(task);
        }