Esempio n. 1
0
        public static MultiTask Create(Uri sourceURI, string destinationPATH, string fileName = null, int connection = 0x2)
        {
            var FileName = fileName ?? Task.FileName(sourceURI);
            var _ret     = Serialler <MultiTask> .ReadObject(Path.Combine(destinationPATH, FileName) + ".xml");

            return(_ret ?? new MultiTask(sourceURI, destinationPATH, FileName, connection));
        }
Esempio n. 2
0
 public void Dispose()
 {
     foreach (var task in Tasks)
     {
         task.Dispose();
     }
     if (!TotalyDownloaded)
     {
         Serialler <MultiTask> .WriteObject(FullName + ".xml", this);
     }
 }
Esempio n. 3
0
        public bool Begin()
        {
            foreach (var task in tasks)
            {
                BeginTask(task);
            }
            foreach (var task in tasks)
            {
db:
                Console.Clear();
                foreach (var task1 in tasks)
                {
                    Console.WriteLine("task 1: IsComplete({0}) ::{1}  :::::{2}", task1.IsComplete, task1.Percent, task1.Thread.IsAlive);
                }
                if (task.IsComplete || !task.Thread.IsAlive)
                {
                    continue;
                }
                Thread.Sleep(500);
                Serialler <MultiTask> .WriteObject(FullName + ".xml", this);

                goto db;
            }
            var complete = true;
            var re       = new FileStream(FullName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Inheritable,
                                          (int)Size, FileOptions.WriteThrough);

            for (var i = 0; i < tasks.Count; i++)
            {
                var task = tasks[i];
                if (task.Percent < 100)
                {
                    complete = false;
                    break;
                }
                if (!task.CopyTo(re))
                {
                    continue;
                }
                tasks.RemoveAt(i);
                i--;
            }
            re.Close();
            if (!complete)
            {
                return(false);
            }
            TotalyDownloaded = true;
            File.Delete(FullName + ".xml");
            return(true);
        }