Ejemplo n.º 1
0
        public void ProcessRequest(HttpContext context)
        {
            string[] path   = context.Request.Path.Split('/');
            string   server = path[1];
            string   group  = path[2];
            int      days   = int.Parse(context.Request.QueryString["days"]);

            using (Rfc977NntpClientWithExtensions nntp = new Rfc977NntpClientWithExtensions())
            {
                nntp.Connect(server);
                nntp.SelectNewsgroup(group);

                using (XmlWriter rss = XmlWriter.Create(context.Response.Output))
                {
                    rss.WriteStartDocument();
                    rss.WriteStartElement("rss");
                    rss.WriteAttributeString("version", "2.0");
                    {
                        rss.WriteStartElement("channel");
                        rss.WriteElementString("title", "aa");

                        ArticleBodyTextCollection body    = new ArticleBodyTextCollection();
                        ArticleHeadersDictionary  headers = new ArticleHeadersDictionary();
                        nntp.RetrieveArticle(nntp.CurrentGroup.LastArticleId, headers, body);

                        while (true)
                        {
                            DateTime date = DateTime.Parse(headers["Date"][0]);

                            if (DateTime.Now - date > TimeSpan.FromDays(days))
                            {
                                break;
                            }

                            rss.WriteStartElement("item");
                            rss.WriteElementString("title", headers["Subject"][0]);
                            rss.WriteElementString("description", body[0]);
                            rss.WriteEndElement();

                            ArticleResponseIds ids = nntp.SetPreviousArticle();

                            if (ids == null)
                            {
                                break;
                            }

                            headers.Clear();
                            body.Clear();
                            nntp.RetrieveArticle(headers, body);
                        }

                        rss.WriteEndElement();
                    }
                    rss.WriteEndElement();
                    rss.WriteEndDocument();
                }
            }
        }
Ejemplo n.º 2
0
 public bool Connect()
 {
     try
     {
         client = ConnectUsenet();
         return(true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 3
0
        public Rfc977NntpClientWithExtensions ConnectUsenet()
        {
            Rfc977NntpClientWithExtensions tmpClient = new Rfc977NntpClientWithExtensions();

            tmpClient.ConnectionTimeout = 30000;
            tmpClient.Connect(serverAddress, port, useSSL, proxyClient);
            if (username != null && password != null)
            {
                tmpClient.AuthenticateUser(username, password);
            }
            var newsgroup = this.newsgroup;

            tmpClient.SelectNewsgroup(newsgroup);
            return(tmpClient);
        }
Ejemplo n.º 4
0
        public Rfc977NntpClientWithExtensions ConnectUsenet()
        {
            var client1 = new Rfc977NntpClientWithExtensions();

            client1.Connect(this.serverAddress, this.port, this.useSSL);
            if (this.username != null && this.password != null)
            {
                client1.AuthenticateUser(this.username, this.password);
            }

            var newsgroup = this.newsgroup;

            client1.SelectNewsgroup(newsgroup);

            return(client1);
        }
Ejemplo n.º 5
0
        public bool Upload(UsenetChunk chunk, string posterEmail)
        {
            if (CheckConnexion() == false)
            {
                return(false);
            }

            ArticleHeadersDictionary headers = CreateHeader(chunk.Id, chunk.Subject, posterEmail);

            Rfc977NntpClientWithExtensions nntpClient = client;

            var rawData = chunk.Data;

            try
            {
                try
                {
                    nntpClient.PostArticle(new ArticleHeadersDictionaryEnumerator(headers), Upload(rawData).ToList());
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                    if (nntpClient.LastNntpResponse.StartsWith("441 "))
                    {
                        return(false);
                    }
                    //throw ex;
                }

                //if (!nntpClient.LastNntpResponse.StartsWith("240 ") && nntpClient.LastNntpResponse.Split('<')[1].Split('>')[0] == null)
                //{
                //    throw new Exception(nntpClient.LastNntpResponse);
                //}
                if (nntpClient.LastNntpResponse.StartsWith("240 "))
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                //nothing todo
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            return(false);
        }
Ejemplo n.º 6
0
        public bool Upload(Chunk chunk)
        {
            ArticleHeadersDictionary headers = CreateHeader(IdToMessageId(chunk.ID), chunk.Subject);

            Rfc977NntpClientWithExtensions nntpClient = client;

            var rawData = chunk.Data;

            try
            {
                using (MemoryStream ms = new MemoryStream(rawData))
                {
                    nntpClient.PostArticle(new ArticleHeadersDictionaryEnumerator(headers), Upload(rawData.Length, ms));
                }
            }
            catch (Exception ex)
            {
                if (nntpClient.LastNntpResponse.StartsWith("441 Posting Failed"))
                {
                    return(false);
                }
                throw ex;
            }

            try
            {
                if (!nntpClient.LastNntpResponse.StartsWith("240 Article Posted") && nntpClient.LastNntpResponse.Split('<')[1].Split('>')[0] == null)
                {
                    throw new Exception(nntpClient.LastNntpResponse);
                }
            }
            catch
            {
                throw new Exception(nntpClient.LastNntpResponse);
            }

            return(true);
        }
Ejemplo n.º 7
0
        //Fonction qui verifie si un article est present sur le reseau
        public bool CheckArticle(string chunkId)
        {
            if (CheckConnexion() == false)
            {
                return(false);
            }
            string messageId = IdToMessageId(chunkId);
            Rfc977NntpClientWithExtensions nntpClient = client;

            try
            {
                ArticleHeadersDictionary dico = nntpClient.RetrieveArticleHeader(messageId);
                if (dico.ContainsKey("Message-ID"))
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                string k = ex.Message;
            }

            return(false);
        }