/// <summary>
        /// メッセージを投稿
        /// </summary>
        /// <param name="header">投稿先のスレッド</param>
        /// <param name="res">投稿する内容</param>
        public override void Post(ThreadHeader header, PostRes res)
        {
            if (header == null)
            {
                throw new ArgumentNullException("header");
            }

            try {
                // 投稿時刻を作成
                int time = GetTime(header.LastModified);

                // 送信データを作成
                bool retried = false;

                string        uri = String.Format("http://{0}/cgi-bin/test/bbs.cgi", header.BoardInfo.Server);
                StringBuilder sb  = new StringBuilder();
                sb.Append("submit=" + UrlEncode("つっこむ"));
                sb.Append("&FROM=" + UrlEncode(res.From));
                sb.Append("&mail=" + UrlEncode(res.Email));
                sb.Append("&MESSAGE=" + UrlEncode(res.Body));
                sb.Append("&bbs=" + header.BoardInfo.Path);
                sb.Append("&key=" + header.Key);
                sb.Append("&time=" + time);

                byte[] bytes = Encoding.GetBytes(sb.ToString());
                Posting(header.BoardInfo, bytes, uri, ref retried);
            }
            catch (Exception ex) {
                TwinDll.Output(ex);
                throw ex;
            }
        }
Exemple #2
0
 /// <summary>
 /// Draftクラスのインスタンスを初期化
 /// </summary>
 /// <param name="header">投稿先のスレッド情報</param>
 /// <param name="res">投稿メッセージ</param>
 public Draft(ThreadHeader header, PostRes res)
 {
     //
     // TODO: コンストラクタ ロジックをここに追加してください。
     //
     this.headerInfo = header;
     this.postRes    = res;
 }
        /// <summary>
        /// メッセージを投稿
        /// </summary>
        /// <param name="header">投稿先のスレッド</param>
        /// <param name="res">投稿する内容</param>
        public override void Post(ThreadHeader header, PostRes res)
        {
            if (header == null)
            {
                throw new ArgumentNullException("header");
            }

            try {
                // 投稿時刻を作成
                int time = GetTime(header.LastModified);

                // 送信データを作成
                bool retried = false;
Retry:
                if (retried)
                {
                    Thread.Sleep(100);
                }

                string        uri = String.Format("http://{0}/{1}", header.BoardInfo.Server, postCGIPath);
                StringBuilder sb  = new StringBuilder();
//				sb.Append("submit=" + (retried ? UrlEncode("全責任を負うことを承諾して書き込む") : UrlEncode("書き込む")));
                sb.Append("submit=" + UrlEncode("書き込む"));
                sb.Append("&FROM=" + UrlEncode(res.From));
                sb.Append("&mail=" + UrlEncode(res.Email));
                sb.Append("&MESSAGE=" + UrlEncode(res.Body));
                sb.Append("&bbs=" + header.BoardInfo.Path);
                sb.Append("&key=" + header.Key);
                sb.Append("&time=" + time);
//				sb.Append("&hana=mogera");

                sb.Append(TwinDll.AditionalAgreementField);
                sb.Append(TwinDll.AddWriteSection);

                AddSessionId(sb);

                byte[] bytes = Encoding.GetBytes(sb.ToString());
                Posting(header.BoardInfo, bytes, uri, ref retried);

                if (retried)
                {
                    goto Retry;
                }
            }
            catch (Exception ex) {
                TwinDll.Output(ex);
                throw ex;
            }
        }
        /// <summary>
        /// 指定した板に存在する草稿を取得
        /// </summary>
        /// <param name="filePath"></param>
        public Draft[] Load(BoardInfo board)
        {
            if (board == null)
            {
                throw new ArgumentNullException("board");
            }

            XmlDocument doc       = new XmlDocument();
            ArrayList   arrayList = new ArrayList();

            string filePath = cache.GetFolderPath(board);

            filePath = Path.Combine(filePath, DraftFileName);

            try {
                doc.Load(filePath);

                // 草稿要素をすべて取得
                XmlNodeList nodeList = doc.SelectNodes("draft/thread");

                foreach (XmlNode node in nodeList)
                {
                    ThreadHeader header = TypeCreator.CreateThreadHeader(board.Bbs);
                    header.BoardInfo = board;
                    header.Key       = node.Attributes.GetNamedItem("key").Value;

                    if (ThreadIndexer.Read(cache, header) != null)
                    {
                        string name  = node.SelectSingleNode("from").InnerText;
                        string email = node.SelectSingleNode("email").InnerText;
                        string body  = node.SelectSingleNode("message").InnerText;

                        // 草稿情報を作成
                        PostRes res   = new PostRes(name, email, body);
                        Draft   draft = new Draft(header, res);
                        arrayList.Add(draft);
                    }
                }
            }
            catch (FileNotFoundException) {}

            return((Draft[])arrayList.ToArray(typeof(Draft)));
        }
Exemple #5
0
        /// <summary>
        /// メッセージを投稿
        /// </summary>
        /// <param name="header">投稿先のスレッド</param>
        /// <param name="res">投稿する内容</param>
        public override void Post(ThreadHeader header, PostRes res)
        {
            if (header == null)
            {
                throw new ArgumentNullException("header");
            }

            try {
                BoardInfo board = header.BoardInfo;

                // 投稿時刻を作成
                int time = GetTime(header.LastModified);

                // BoardInfo.PathをBBSとDIRに分割
                string[] dirbbs = board.Path.Split('/');
                Trace.Assert(dirbbs.Length == 2);

                // 送信データを作成
                string        uri = String.Format("http://{0}/bbs/write.cgi/{1}/{2}/", board.Server, board.Path, header.Key);
                StringBuilder sb  = new StringBuilder();
                sb.Append("submit=" + UrlEncode("書き込む"));
                sb.Append("&NAME=" + UrlEncode(res.From));
                sb.Append("&MAIL=" + UrlEncode(res.Email));
                sb.Append("&MESSAGE=" + UrlEncode(res.Body));
                sb.Append("&DIR=" + dirbbs[0]);
                sb.Append("&BBS=" + dirbbs[1]);
                sb.Append("&KEY=" + header.Key);
                sb.Append("&TIME=" + time);

                bool   retried = false;
                byte[] bytes   = Encoding.GetBytes(sb.ToString());

                Posting(header.BoardInfo, bytes, uri, ref retried);
            }
            catch (Exception ex) {
                TwinDll.Output(ex);
                throw ex;
            }
        }
        /// <summary>
        /// 指定したスレッドの草稿を取得
        /// </summary>
        /// <param name="header"></param>
        /// <returns></returns>
        public Draft Load(ThreadHeader header)
        {
            if (header == null)
            {
                throw new ArgumentNullException("header");
            }

            Draft draft = null;

            string filePath = cache.GetFolderPath(header.BoardInfo);

            filePath = Path.Combine(filePath, DraftFileName);

            if (File.Exists(filePath))
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(filePath);

                // 同じスレッド番号を持つ草稿要素を検索するためのXPath
                string  xpath = String.Format("draft/thread[@key=\"{0}\"]", header.Key);
                XmlNode node  = doc.SelectSingleNode(xpath);

                if (node != null && ThreadIndexer.Read(cache, header) != null)
                {
                    string name  = node.SelectSingleNode("from").InnerText;
                    string email = node.SelectSingleNode("email").InnerText;
                    string body  = node.SelectSingleNode("message").InnerText;

                    // 草稿情報を作成
                    PostRes res = new PostRes(name, email, body);
                    draft = new Draft(header, res);
                }
            }

            return(draft);
        }
 /// <summary>
 /// メッセージを投稿
 /// </summary>
 /// <param name="header">投稿先のスレッド</param>
 /// <param name="res">投稿する内容</param>
 public override void Post(ThreadHeader header, PostRes res)
 {
     throw new NotSupportedException("過去ログには書き込みできません");
 }
        private void WriteToThread()
        {
            var board  = new BoardInfo(this.Settings.ServerName, this.Settings.BoardPath, "板名");
            var thread = new X2chThreadHeader
            {
                BoardInfo = board,
                Key       = this.Settings.ThreadKey
            };

            var songInfo = this.SongInfo.Value;
            var str      = songInfo.IsSpecialItem
                                        ? this.ResultText.Value
                                        : string.Format("{0:D4}{1}", this.SongNumber.Value, this.ResultText.Value);

            var res = new PostRes
            {
                Body = str,
            };

            if (this.Settings.WriteAsSage)
            {
                res.Email = "sage";
            }
            var post = new X2chPost();

            post.Posted += (s, e) =>
            {
                Console.WriteLine("Response: ", e.Response);
                switch (e.Response)
                {
                case PostResponse.Success:
                    MessageService.Current.ShowMessage(string.Format("書き込み成功! ( {0} )",
                                                                     str.Length > 40 ? str.Substring(0, 40) + "..." : str));

                    this.AddCurrentSongToList();

                    // 曲番号インクリメント
                    if (!songInfo.IsSpecialItem && this.Settings.IncrementSongNumberWhenCopied)
                    {
                        this.SongNumber.Value++;
                    }

                    // 入力欄クリア
                    if (this.Settings.ClearInputAutomatically)
                    {
                        this.EventAggregator.GetEvent <ClearSearchInputEvent>().Publish();
                    }
                    break;

                case PostResponse.Cookie:
                    e.Retry = true;
                    break;

                case PostResponse.Error:
                case PostResponse.Samba:
                case PostResponse.Timeout:
                    MessageBox.Show(e.Text, "書き込み失敗", MessageBoxButton.OK, MessageBoxImage.Warning);
                    e.Retry = false;
                    break;

                default:
                    MessageService.Current.ShowMessage(e.Response.ToString() + "  " + e.Text);
                    break;
                }
            };
            post.Error += (s, e) =>
            {
                MessageService.Current.ShowMessage("書き込み失敗orz");
                MessageBox.Show(
                    string.Format("投稿に失敗しました。\n\n【例外情報】\n{0}", e.Exception),
                    "エラー", MessageBoxButton.OK, MessageBoxImage.Stop);
            };

            try
            {
                MessageService.Current.ShowMessage("書き込んでいます...");
                post.Post(thread, res);
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    string.Format("投稿に失敗しました。\n\n【例外情報】\n{0}", ex),
                    "エラー", MessageBoxButton.OK, MessageBoxImage.Stop);
            }
        }