public override void Execute(NntpSession session) { switch (state) { case RequestState.StartingRequest: state = RequestState.ReceivingHeaders; session.Connection.SendLine("340 Send article to be posted"); break; case RequestState.RequestFinished: using (INntpConnection connection = session.Repository.CreateConnection()) { INntpArticle article = connection.CreateArticle(); SetOverviewHeaders(article); SetOtherHeaders(article); article.Body = body.ToString(); connection.PostArticle(article); } session.Connection.SendLine("240 Article received OK"); break; } }
private void SetOtherHeaders(INntpArticle article) { Dictionary <string, string> headers = new Dictionary <string, string>(this.headers); headers.Remove(NntpHeaderName.Subject); headers.Remove(NntpHeaderName.From); headers.Remove(NntpHeaderName.Date); headers.Remove(NntpHeaderName.Newsgroups); headers.Remove(NntpHeaderName.References); foreach (KeyValuePair <string, string> header in headers) { article.Headers[header.Key] = header.Value; } }
private void SetOverviewHeaders(INntpArticle article) { article.Subject = headers[NntpHeaderName.Subject]; article.From = headers[NntpHeaderName.From]; if (headers.ContainsKey(NntpHeaderName.Date)) { article.Date = headers[NntpHeaderName.Date]; } article.Newsgroups = headers[NntpHeaderName.Newsgroups]; if (headers.ContainsKey(NntpHeaderName.References)) { article.References = headers[NntpHeaderName.References]; } }
void INntpConnection.PostArticle(INntpArticle article) { session.Save(article); transaction.Commit(); }
void INntpConnection.PostArticle(INntpArticle article) { throw new Exception("The method or operation is not implemented."); }