Exemple #1
0
        public bool Connect()
        {
            if (IsAlive)
                return true;

            //Get Number of connections that should be created
            //Create a ConnectionModel

            var servers = _server.GetEnabled().Where(s => !s.Backup);

            foreach (var server in servers)
            {
                for (int i = 0; i < server.Connections; i++)
                {
                    var connection = new ConnectionModel();
                    connection.Server = server.Hostname;
                    connection.Id = Guid.NewGuid();
                    connection.Connection = new NntpConnectionProvider(Guid.NewGuid());

                    if (connection.Connection.Connect(server.Hostname, server.Port, server.Ssl, server.Username, server.Password))
                    {
                        connection.Connection.ArticleFinished += new ArticleFinishedHandler(Connection_ArticleFinished);
                    }
                    _connections.Add(connection);
                }
            }

            if (_connections.Count > 0)
            {
                //Set _isAlive to true, calculate the speed limit for each connection, start downloading
                _isAlive = true;
                if (SpeedLimit > 0)
                {
                    var limit = CalculateSpeedLimit();
                    _connections.ForEach(c => SpeedLimit = limit);
                }

                _connections.ForEach(Download);
                return true;
            }

            return false;
        }
Exemple #2
0
        private void Download(ConnectionModel connection)
        {
            //Get the next article to download
            var article = GetNextArticle();

            if (article == null)
            {
                connection.Connection.Disconnect();
                _connections.Remove(connection);
            }

            connection.Article = article;
            connection.Connection.GetArticle(article);
        }