예제 #1
0
        private void LoadSubReply(frm_ReplyList frm, ReplyInfo info)
        {
            if (frm.InvokeRequired)
            {
                while (!(frm.IsDisposed || frm.IsHandleCreated))
                {
                    return;
                }
                frm.Invoke(new LoadSubReplyCallBack(LoadSubReply), new object[] { frm, info });
            }
            else
            {
                frm.tb_thread_title.Text = info.ReplyTitle;
                frm.tb_thread_name.Text = info.ReplySubmitter;
                frm.tb_thread_email.Text = info.ReplyEmail;
                frm.tb_thread_tid.Text = info.ReplyId;
                frm.rtb_thread_main.Text = info.ReplyMain;
                frm.tb_ReplyDate.Text = ReplyInfo.ToJPDate(info.ReplyTime);
                if (info.FcSet != null)
                {
                    frm.rtb_thread_main.Font = info.FcSet.TextFont;
                    frm.rtb_thread_main.ForeColor = info.FcSet.TextColor;
                    frm.rtb_thread_main.BackColor = info.FcSet.BackColor;
                }
                else
                {
                    frm.rtb_thread_main.Font = FontSet.defaultSet.TextFont;
                    frm.rtb_thread_main.ForeColor = FontSet.defaultSet.TextColor;
                    frm.rtb_thread_main.BackColor = FontSet.defaultSet.BackColor;
                }
                if (info.HttpLinks != null)
                {
                    if (info.HttpLinks.Length > 0)
                    {
                        btn_ReadImage.Tag = info.HttpLinks;
                        btn_ReadImage.Enabled = true;
                    }
                    else
                    {
                        btn_ReadImage.Tag = null;
                        btn_ReadImage.Enabled = false;
                    }
                }
                else
                {
                    btn_ReadImage.Tag = null;
                    btn_ReadImage.Enabled = false;
                }

                frm.Text = "リプライをロード完了しました。";
                frm.SetControlEnabled(frm.tv_ReplyList, true);
                frm.SetControlEnabled(frm.btn_ByReply, true);
                frm.SetControlEnabled(frm.btn_Reload, true);
                frm.SetControlEnabled(frm.dtp_Before, true);
                frm.SetControlEnabled(frm.dtp_After, true);

            }
        }
예제 #2
0
        private void ReadingReply(object tid)
        {
            string titleString = string.Empty;
            string authorString = string.Empty;
            string textString = string.Empty;
            string mailString = string.Empty;
            string dateString = string.Empty;
            SortedDictionary<int, ReplyInfo> selectedThread = new SortedDictionary<int, ReplyInfo>();
            try
            {
                GZipStream gzipDec = new GZipStream(new System.IO.MemoryStream(Webclient.DownloadData(urlString + (string)tid)), CompressionMode.Decompress);
                System.IO.MemoryStream tempMemory = new System.IO.MemoryStream();
                int count = 0;
                byte[] tempByte = new byte[1000];
                while ((count = gzipDec.Read(tempByte, 0, tempByte.Length)) > 0)
                {
                    tempMemory.Write(tempByte, 0, count);
                }
                gzipDec.Close();

                document.LoadHtml(UTF8Encoding.UTF8.GetString(tempMemory.ToArray()));
                var titleNode = document.DocumentNode.SelectSingleNode(subReplyTitleXpath);
                if (titleNode != null)
                {
                    titleString = titleNode.InnerText;
                }
                int tempCount = 1;
                while (document.DocumentNode.SelectSingleNode(subReplyMainStartAuthorXpath(tempCount)) != null)
                {
                    tempCount++;
                }
                //HtmlAgilityPack.HtmlNode authorNode;
                //HtmlAgilityPack.HtmlNode dateNode;
                //HtmlAgilityPack.HtmlNode textNode;

                for (int i = 1; i < tempCount; i++)
                {
                    HtmlAgilityPack.HtmlNode authorNode = document.DocumentNode.SelectSingleNode(subReplyMainStartAuthorXpath(i));
                    HtmlAgilityPack.HtmlNode textNode = document.DocumentNode.SelectSingleNode(subReplyMainStartTextXpath(i));
                    HtmlAgilityPack.HtmlNode dateNode = document.DocumentNode.SelectSingleNode(subReplyMainStartDateXpath(i));
                    List<string> linkCollection = new List<string>();
                    if (dateNode != null)
                    {
                        if (dateNode.HasChildNodes)
                        {
                            var date = dateNode.ChildNodes["p"];
                            if (date != null)
                            {
                                dateString = date.InnerText;
                            }
                        }
                    }
                    if (authorNode != null)
                    {
                        authorString = authorNode.InnerText;

                        if (authorNode.HasChildNodes)
                        {

                            var mailNode = authorNode.ChildNodes["a"];
                            if (mailNode != null)
                            {
                                if (mailNode.Attributes["href"] != null)
                                {
                                    string mailadd = mailNode.Attributes["href"].Value;
                                    if (mailadd.Contains("@"))
                                    {
                                        mailString = mailadd.Replace(@"mailto:", string.Empty);
                                    }
                                }

                            }
                            else
                            {
                                mailString = string.Empty;
                            }
                        }
                    }
                    string fontSetString = null;
                    if (textNode != null)
                    {
                        string mainString = textNode.InnerText.Trim();
                        string noCovString = mainString.Replace("\r", string.Empty).Replace("\n", string.Empty).Replace("\t", string.Empty);
                        if (noCovString.Contains("##bAsisFontStyle"))
                        {
                            textString = mainString.Remove(mainString.Replace("\r\n", string.Empty).LastIndexOf("##bAsisFontStyle"));
                            fontSetString = noCovString.Substring(noCovString.LastIndexOf("##bAsisFontStyle"));
                        }
                        else
                        {
                            textString = mainString;
                        }

                        if (textNode.HasChildNodes)
                        {
                            var linkChildNodes = textNode.ChildNodes;

                            if (linkChildNodes != null)
                            {
                                foreach (var child in linkChildNodes)
                                {
                                    if (child.OriginalName.Equals("a"))
                                    {
                                        if (child.HasAttributes)
                                        {
                                            if (child.Attributes["href"] != null)
                                            {
                                                linkCollection.Add(child.Attributes["href"].Value);
                                            }
                                        }
                                    }
                                }
                            }
                        }

                    }
                    ReplyInfo tInfo = new ReplyInfo(i, titleString, authorString, ((string)tid).Substring(((string)tid).LastIndexOf("=") + 1), mailString, textString, ReplyInfo.ToJPDate(dateString));
                    if (!string.IsNullOrEmpty(fontSetString))
                    {
                        tInfo.FcSet = FontSet.ReadFontSet(fontSetString);
                    }
                    if (linkCollection.Count > 0)
                    {
                        tInfo.HttpLinks = linkCollection.ToArray();
                    }
                    //Console.WriteLine(titleString);
                    //Console.WriteLine(authorString);
                    //Console.WriteLine(mailString);
                    //Console.WriteLine(textString);
                    selectedThread.Add(tInfo.SubReplyId, tInfo);
                }
                if (ReplyLst != null)
                {
                    if (!ReplyLst.IsDisposed)
                    {
                        if (ReplyLst.IsHandleCreated)
                        {
                            ReplyLst.LoadSubReply(ReplyLst, selectedThread);
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp.Message);
                GetDatas.QuitExit();
            }
        }