Ejemplo n.º 1
0
        public async Task <IActionResult> UploadFile(ICollection <IFormFile> files)
        {
            var    uploads  = Path.Combine(_environment.WebRootPath, "uploads");
            string fileName = null;

            Directory.CreateDirectory(uploads);

            foreach (var file in files)
            {
                if (file.Length > 0)
                {
                    fileName = Path.Combine(uploads, file.FileName);
                    using (var fileStream = new FileStream(fileName, FileMode.Create))
                    {
                        await file.CopyToAsync(fileStream);
                    }
                }
            }
            try
            {
                var torrent = new TorrentTransfer(fileName, uploads);
                torrent.Start();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
            return(Accepted());
        }
Ejemplo n.º 2
0
 public void Run()
 {
     try
     {
         _torrent = new TorrentTransfer(Path, @"D:\Temp\Torrents");
         _torrent.StateChanged += Torrent_StateChanged;
         _torrent.ReportStats  += TorrentOnReportStats;
         _torrent.Start();
     }
     finally
     {
         Console.Read();
     }
 }
Ejemplo n.º 3
0
 private void Run()
 {
     try
     {
         while (true)
         {
             torrent           = new TorrentTransfer(Console.ReadLine());
             torrent.GotPeers += torrent_GotPeers;
             torrent.Start();
             for (; ;)
             {
                 ;
             }
         }
     }
     finally
     {
         Console.Read();
     }
 }
Ejemplo n.º 4
0
        public void GetPeers(string path)
        {
            try
            {
                Peers.Clear();
                Announces.Clear();
                Files.Clear();
                AddMessage("Attempting to open torrent file.");
                torrent     = new TorrentTransfer(path);
                PieceLength = torrent.Data.PieceLength;
                PieceCount  = torrent.Data.Checksums.Count;
                Name        = torrent.Data.Name;
                Hash        = BitConverter.ToString(torrent.Data.InfoHash).Replace("-", string.Empty);
                PieceLength = torrent.Data.PieceLength;
                AnnounceURL = torrent.Data.AnnounceURL;

                torrent.Data.Files.ForEach(f => Files.Add(f));
                if (torrent.Data.AnnounceList != null)
                {
                    torrent.Data.AnnounceList.ForEach(a => Announces.Add(a));
                }

                filesSize = 0;
                foreach (var file in files)
                {
                    filesSize += file.Length;
                }
                totalSize = Global.Instance.FileSizeFormat(filesSize);

                torrent.RaisedException += torrent_RaisedException;
                torrent.ReportStats     += torrent_ReportStatsChanged;
                torrent.StateChanged    += torrent_StateChanged;
                torrent.Start();
            }
            catch (Exception e)
            {
                HandleException(e);
                System.Windows.MessageBox.Show("Damn: " + e);
            }
        }
Ejemplo n.º 5
0
 public void Start()
 {
     TorrentTransfer.Start();
     Error = null;
 }