Пример #1
0
        public void Indexing(BoardInfo bi, string[] datFiles, DatIndexingCallback callback)
        {
            LocalThreadReader reader = new LocalThreadReader(new X2chThreadParser());
            float             length = datFiles.Length, current = 0;

            if (length == 0)
            {
                return;
            }

            foreach (string path in datFiles)
            {
                ThreadHeader header = new X2chThreadHeader();
                header.BoardInfo = bi;
                header.Key       = Path.GetFileNameWithoutExtension(path);
                int parsed;

                try
                {
                    if (!reader.__Open(path))
                    {
                        continue;
                    }

                    ResSetCollection buffer = new ResSetCollection();
                    int byteCount           = 0;

                    while (reader.Read(buffer, out parsed) != 0)
                    {
                        byteCount += parsed;
                    }

                    if (buffer.Count > 0)
                    {
                        header.GotByteCount = byteCount;
                        header.ResCount     = buffer.Count;
                        header.GotResCount  = buffer.Count;
                        header.LastModified = File.GetLastWriteTime(path);
                        header.UseGzip      = false;
                        header.Subject      = buffer[0].Tag as String;

                        ThreadIndexer.Write(
                            Path.ChangeExtension(path, ".idx"), header);
                    }

                    if (callback != null)
                    {
                        callback(++current / length * 100f);
                    }
                }
                finally
                {
                    reader.Close();
                }
            }
        }
        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);
            }
        }