예제 #1
0
 public TorrentViewModel(Torrent torrentModel, UTorrentClient client)
 {
     _torrentModel = torrentModel;
     //_client = client;
     _savePath = PathManager.GetTorrentPathForEpisode(_torrentModel.Episode);
     State = TorrentManager.CreateTorrentState(torrentModel);
 }
예제 #2
0
        public void Update()
        {
            lock (_clientLock)
            {
                try
                {
                    _client = new UTorrentClient(new Uri(_url), _user, _password);
                }
                catch (Exception ex)
                {
                    // set  all to unknown state
                }

                foreach (var r in _tracked)
                {
                    if (r.IsAlive)
                    {
                        var torrentState = (TorrentState)r.Target;
                        if (_client.Torrents.Contains(torrentState.Hash))
                            torrentState.UpdateTorrent(_client.Torrents[torrentState.Hash]);
                        else
                        {
                            torrentState.UpdateTorrent(null);
                        }
                    }
                }

                _tracked.RemoveAll(wr => !wr.IsAlive);

            }
        }
예제 #3
0
        public Command Execute()
        {
            try
            {
                var process = Process.GetProcesses().Any(x => x.ProcessName.StartsWith("uTorrent"));
                if (!process)
                {
                    command.Message = "Utorrent Not Running";
                    Notify();
                }
                else
                {
                    var uClient = new UTorrentClient(uUriRemote, SUsername, SPassword, 1000000);

                    switch (utorrentCommand.command)
                    {
                        case (int)TorrentCommand.StartById:
                            uClient.Torrents.First(x => utorrentCommand.Hash == x.Hash).Start();
                            break;
                        case (int)TorrentCommand.StopById:
                            uClient.Torrents.First(x => utorrentCommand.Hash == x.Hash).Stop();
                            break;
                        case (int)TorrentCommand.RemoveById:
                            uClient.Torrents.Remove(utorrentCommand.Hash, TorrentRemovalOptions.Job);
                            break;
                        case (int)TorrentCommand.StartAll:
                            uClient.Torrents.ToList().ForEach(x => x.Start());
                            break;
                        case (int)TorrentCommand.StopAll:
                            uClient.Torrents.ToList().ForEach(x => x.Stop());
                            break;
                        case (int)TorrentCommand.SetLimits:
                            var commands = utorrentCommand.Hash.Split(',');
                            int download = Convert.ToInt32(commands[0]);
                            int upload = Convert.ToInt32(commands[1]);
                            uClient.SetDownloadSpeed(download);
                            uClient.SetUploadSpeed(upload);
                            break;

                    }

                    command.Message = "Refreshed Utorrent";
                    Notify();
                }

            }
            catch (Exception ex)
            {

            }
            return command;
        }
예제 #4
0
        public TorrentCollection GetTorrentJobs()
        {
            if (!TorrentIsRunning())
            {
                _client = null;
            }
            else if (_client == null)
            {
                Connect();
            }

            if (_client != null)
                return _client.Torrents;
            else
                return null;
        }
        public void AddTorrentstoClient(string torrClientUri, string userName, string password, string torrInPath, string torrOutPath)
        {
            var uri = new Uri(torrClientUri);
            var uClient = new UTorrentClient(uri, userName, password);
            var files = GetTorrentsFromDirectory(torrInPath);
            foreach (var file in files)
            {
                var fileName = Path.GetFileName(file);
                var filePath = torrInPath + @"\" + fileName;
                //File.SetAttributes(file, FileAttributes.Normal);
                var directoryName = torrOutPath + CreateOutputDirectory(fileName);
                if (!DirExists(directoryName))
                {
                    CreateDirs(directoryName);
                }
                uClient.Torrents.AddFile(filePath, directoryName);

            }
        }
예제 #6
0
        public Command Execute()
        {
            try
            {
                int i = 0;
                UTorrentClient uClient = new UTorrentClient(uUriRemote, SUsername, SPassword, 1000000);
                var busy = (TorrentStatus.Started | TorrentStatus.Checked | TorrentStatus.Queued | TorrentStatus.Loaded);
                var regex = new Regex(@"/\[.*\]/");

                UtorrentDataList =
                    uClient.Torrents.Where(x => command.Parameter != "1" || x.Status == busy)
                           .Select(
                               x =>
                               new UtorrentData
                                   {
                                       Id = i++,
                                       Hash = x.Hash,
                                       Eta = GetEta(x),
                                       Remaining = Math.Round(x.RemainingBytes * 0.000001m, 2) + "MB",
                                       Name = RemoveBetween(x.Name, '[', ']').TrimStart(' ', '-'),
                                       Progress = (x.ProgressInMils * 0.1m).ToString() + "%",
                                       Speed = Math.Truncate(x.DownloadBytesPerSec * 0.001m) + "kB/s"
                                   })
                                   .OrderBy(x => x.Name)
                           .ToList();
                command.UtorrentDataList = UtorrentDataList;
                command.Message = "Refreshed Utorrent";
                Notify();

            }
            catch (Exception ex)
            {
                 command.UtorrentDataList = new List<UtorrentData>();
                command.Message = "Refreshed Utorrent";
                return command;
            }
            return command;
        }
예제 #7
0
 private void Connect()
 {
     if (TorrentIsRunning())
         _client = new UTorrentClient(new System.Uri("http://localhost:54307/gui/"), _userName, _password);
 }