Пример #1
0
 public static TransferQueue CreateDownloadQueue(TransferClient client, int id, string saveName, long length)
 {
     try
     {
         var queue = new TransferQueue();
         queue.Filename = Path.GetFileName(saveName);
         if (saveName.Contains(@"\"))
         {
             String[] pastas = saveName.Split('\\');
             for (int i = 0; i < pastas.Length - 1; i++)
             {
                 String pastaAux = pastas[i];
                 if (i > 0)
                 {
                     pastaAux = "";
                     for (int z = 0; z <= i; z++)
                     {
                         if (z > 0)
                         {
                             pastaAux += @"\";
                         }
                         pastaAux += pastas[z];
                     }
                 }
                 if (!Directory.Exists(pastaAux))
                 {
                     Directory.CreateDirectory(pastaAux);
                 }
             }
         }
         queue.Client = client;
         queue.Type   = QueueType.Download;
         queue.FS     = new FileStream(saveName, FileMode.Create);
         queue.FS.SetLength(length);
         queue.Length = length;
         queue.ID     = id;
         queue.MS     = new MemoryStream();
         queue.MS.SetLength(length);
         return(queue);
     }
     catch
     {
         return(null);
     }
 }
Пример #2
0
 public static TransferQueue CreateUploadQueue(TransferClient client, string fileName, string pasta = null)
 {
     try
     {
         var    queue     = new TransferQueue();
         String nomeFinal = (pasta == null) ? "" : pasta + @"\";
         nomeFinal                += Path.GetFileName(fileName);
         queue.Filename            = nomeFinal;
         queue.Client              = client;
         queue.Type                = QueueType.Upload;
         queue.FS                  = new FileStream(fileName, FileMode.Open, FileAccess.Read);
         queue.Thread              = new Thread(new ParameterizedThreadStart(transferProc));
         queue.Thread.IsBackground = true;
         queue.ID                  = ManterRandom.proximo();
         queue.Length              = queue.FS.Length;
         return(queue);
     }
     catch (Exception e)
     {
         throw e;
     }
 }