Esempio n. 1
0
        /// <summary>
        /// Posts a comment to a newsgroup using NNTP
        /// </summary>
        /// <param name="item2post">An NNTP item that will be posted to the website</param>
        /// <param name="postTarget">An feed that is the post target</param>
        /// <param name="credentials">Credentials to use</param>
        /// <returns>The NNTP Status code returned</returns>
        /// <exception cref="WebException">If an error occurs when the POSTing the
        /// comment</exception>
        public static void PostCommentViaNntp(INewsItem item2post, INewsFeed postTarget, ICredentials credentials)
        {
            string   comment = item2post.ToString(NewsItemSerializationFormat.NntpMessage);
            Encoding enc = Encoding.UTF8, unicode = Encoding.Unicode;

            byte[] encBytes = Encoding.Convert(unicode, enc, unicode.GetBytes(comment));             //enc.GetBytes(comment); enough ???


            NntpWebRequest request = (NntpWebRequest)WebRequest.Create(postTarget.link);

            request.Method = "POST";

            if (credentials != null)
            {
                request.Credentials = credentials;
            }

            Stream myWriter = null;

            try{
                myWriter = request.GetRequestStream();
                myWriter.Write(encBytes, 0, encBytes.Length);

                request.GetResponse();
            } catch (Exception e) {
                throw new WebException(e.Message, e);
            }finally{
                if (myWriter != null)
                {
                    myWriter.Close();
                }
            }
        }
Esempio n. 2
0
 public string Name()
 {
     return(item.ToString());
 }
Esempio n. 3
0
        /// <summary>
        /// Transform a NewsItem, FeedInfo or FeedInfoList using the specified stylesheet
        /// </summary>
        /// <param name="stylesheet">The stylesheet to use for transformation</param>
        /// <param name="transformTarget">The object to transform</param>
        /// <param name="xslArgs"></param>
        /// <returns>The results of the transformation</returns>
        public virtual string ToHtml(string stylesheet, object transformTarget, XsltArgumentList xslArgs)
        {
            string link = String.Empty, content = String.Empty;

            if (transformTarget == null)
            {
                return("<html><head><title>empty</title></head><body></body></html>");
            }

            // use a streamed output to get the "disable-output-escaping"
            // working:
            StringWriter swr = new StringWriter();

            try     {
                XPathDocument doc;

                if (transformTarget is INewsItem)
                {
                    INewsItem item = (INewsItem)transformTarget;
                    link    = item.FeedLink;
                    content = item.Content;
                    doc     = new XPathDocument(new XmlTextReader(new StringReader(item.ToString(NewsItemSerializationFormat.NewsPaper, false))), XmlSpace.Preserve);
                }
                else if (transformTarget is IFeedDetails)
                {
                    IFeedDetails feed = (IFeedDetails)transformTarget;
                    link = feed.Link;
                    doc  = new XPathDocument(new XmlTextReader(new StringReader(feed.ToString(NewsItemSerializationFormat.NewsPaper, false))), XmlSpace.Preserve);
                }
                else if (transformTarget is FeedInfoList)
                {
                    FeedInfoList feeds = (FeedInfoList)transformTarget;
                    doc = new XPathDocument(new XmlTextReader(new StringReader(feeds.ToString())), XmlSpace.Preserve);
                }
                else
                {
                    throw new ArgumentException("transformTarget");
                }

                XslCompiledTransform transform;

                if (this.stylesheetTable.ContainsKey(stylesheet))
                {
                    transform = this.stylesheetTable[stylesheet].CompiledTransform;
                }
                else
                {
                    transform = this.stylesheetTable[String.Empty].CompiledTransform;
                }

                // support simple localizations (some common predefined strings to display):
                xslArgs.AddExtensionObject("urn:localization-extension", new LocalizerExtensionObject());
                transform.Transform(doc, xslArgs, swr);
            } catch (ThreadAbortException) {
                // ignored
            }       catch (Exception e)     {
                this.OnTransformationError(this, new FeedExceptionEventArgs(e, link, SR.ExceptionNewsItemTransformation));
                return(content);                // try to display unformatted simple text
            }

            return(swr.ToString());
        }