Esempio n. 1
0
        protected virtual void OnUpdated(ThreadUpdateEventArgs e)
        {
            if (Updated != null)
            {
                Updated(this, e);
            }

            if (e.Updated)
            {
                int newResesByteCount = System.Text.Encoding.GetEncoding("shift_jis").GetByteCount(e.NewReses);
                GotByteCount += newResesByteCount;
                Common.CurrentSettings.Information.CurrentDownloadByte += newResesByteCount;
                NewResCount = e.NewReses.Count(c => c.Equals('\n'));
                GotResCount += NewResCount;
                LastModified = e.Response.LastModified;
                ETag = e.Response.Headers["ETag"];
                ResSpeed = ThreadUtility.CalculateResSpeed(Since, GotResCount);
                if (Common.Options.DatOptions.LogSaveMode == Options.LogSaveModes.DatOnly ||
                    Common.Options.DatOptions.LogSaveMode == Options.LogSaveModes.BothDatAndHtml)
                {
                    SaveLog(e.NewReses);
                }
                if (!repaired)
                {
                    repaired = true;
                }
                State = ThreadState.Updated;
                InternetClient.PerformResponseRecieved(new InternetClientEventArgs(newResesByteCount, 0));
                Common.ConnectionLimiter.Wait(SourceBoard.Server);
            }
            else
            {
                State = ThreadState.NotUpdate;
            }
        }
Esempio n. 2
0
 protected virtual void OnUpdating(ThreadUpdateEventArgs e)
 {
     if (Updating != null)
     {
         Updating(this, e);
     }
     State = e.Cancel ? ThreadState.NotUpdate : ThreadState.Updating;
 }
Esempio n. 3
0
        /// <summary>
        /// 新着レスを取得します
        /// </summary>
        /// <exception cref="System.Net.WebException">データの取得に失敗しました</exception>
        /// <exception cref="System.IO.IOExeception">DATの保存に失敗しました</exception>
        /// <returns>レスを表す文字列</returns>
        public string Update()
        {
            if (Parent == null)
            {
                throw new InvalidOperationException("巡回設定が指定されていません");
            }

            ThreadUpdateEventArgs e = new ThreadUpdateEventArgs();
            OnUpdating(e);
            if (e.Cancel)
            {
                OnUpdated(e);
                return string.Empty;
            }

            string newReses = string.Empty;
            bool gotData = GotByteCount > 0;
            HttpWebRequest request = InternetClient.Create(
                (!gotData && Common.Options.DatOptions.GetatableBg20Server) ? Bg20DatUrl : DatUrl,
                gotData ? LastModified : DateTime.MinValue, isgzip: !gotData, range: GotByteCount,
                timeout: Common.Options.InternetOptions.Timeout, eTag: ETag, allowRedirect: false);
            try
            {
                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    if (UpdateStatus.Contains(response.StatusCode))
                    {
                        using (Stream responseStream = response.GetResponseStream())
                        using (StreamReader reader = new StreamReader(responseStream,
                            Common.Options.InternetOptions.CurrentEncoding))
                        {
                            newReses = reader.ReadToEnd();
                        }
                        e.Updated = true;
                        e.Response = response;
                        e.NewReses = newReses;
                        OnUpdated(e);
                        return newReses;
                    }
                    else if (LostLogStatus.Contains(response.StatusCode))
                    {
                        OnLost(EventArgs.Empty);
                        return string.Empty;
                    }
                }
            }
            catch (WebException ex)
            {
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    if (ex.Response == null)
                    {
                        throw;
                    }
                    HttpWebResponse errorResponse = (HttpWebResponse)ex.Response;
                    if (AboneStatus.Contains(errorResponse.StatusCode))
                    {
                        OnABoned(EventArgs.Empty);
                    }
                    else if (!IgnoreStatus.Contains(errorResponse.StatusCode))
                    {
                        throw;
                    }
                }
                else
                {
                    throw;
                }
            }

            OnUpdated(e);
            return newReses;
        }