Example #1
0
        /// <summary>
        /// Retrieves URL with events in the OnReceiveData event.
        /// </summary>
        /// <param name="Url"></param>
        /// <param name="BufferSize"></param>
        /// <returns></returns>
        public string GetUrlEvents(string Url, long BufferSize)
        {
            StreamReader oHttpResponse = this.GetUrlStream(Url);

            if (oHttpResponse == null)
            {
                return("");
            }

            long lnSize = BufferSize;

            if (this.oWebResponse.ContentLength > 0)
            {
                lnSize = this.oWebResponse.ContentLength;
            }
            else
            {
                lnSize = 0;
            }

            Encoding enc = Encoding.GetEncoding(1252);

            StringBuilder loWriter = new StringBuilder((int)lnSize);

            char[] lcTemp = new char[BufferSize];

            OnReceiveDataEventArgs oArgs = new OnReceiveDataEventArgs();

            oArgs.TotalBytes = lnSize;

            lnSize = 1;
            int  lnCount      = 0;
            long lnTotalBytes = 0;

            while (lnSize > 0)
            {
                lnSize = oHttpResponse.Read(lcTemp, 0, (int)BufferSize);
                if (lnSize > 0)
                {
                    loWriter.Append(lcTemp, 0, (int)lnSize);
                    lnCount++;
                    lnTotalBytes += lnSize;

                    // *** Raise an event if hooked up
                    if (this.OnReceiveData != null)
                    {
                        /// *** Update the event handler
                        oArgs.CurrentByteCount = lnTotalBytes;
                        oArgs.NumberOfReads    = lnCount;
                        oArgs.CurrentChunk     = lcTemp;
                        this.OnReceiveData(this, oArgs);

                        // *** Check for cancelled flag
                        if (oArgs.Cancel)
                        {
                            goto CloseDown;
                        }
                    }
                }
            } // while


CloseDown:
            oHttpResponse.Close();

            // *** Send Done notification
            if (this.OnReceiveData != null && !oArgs.Cancel)
            {
                // *** Update the event handler
                oArgs.Done = true;
                this.OnReceiveData(this, oArgs);
            }

            //			return lcHtml;
            return(loWriter.ToString());
        }
Example #2
0
        /// <summary>
        /// Retrieves URL with events in the OnReceiveData event.
        /// </summary>
        /// <param name="Url"></param>
        /// <param name="BufferSize"></param>
        /// <returns></returns>
        public string GetUrlEvents(string Url, long BufferSize)
        {
            StreamReader oHttpResponse = this.GetUrlStream(Url);
            if (oHttpResponse == null)
                return "";

            long lnSize = BufferSize;
            if (this.oWebResponse.ContentLength > 0)
                lnSize = this.oWebResponse.ContentLength;
            else
                lnSize = 0;

            Encoding enc = Encoding.GetEncoding(1252);

            StringBuilder loWriter = new StringBuilder((int)lnSize);

            char[] lcTemp = new char[BufferSize];

            OnReceiveDataEventArgs oArgs = new OnReceiveDataEventArgs();
            oArgs.TotalBytes = lnSize;

            lnSize = 1;
            int lnCount = 0;
            long lnTotalBytes = 0;

            while (lnSize > 0)
            {
                lnSize = oHttpResponse.Read(lcTemp, 0, (int)BufferSize);
                if (lnSize > 0)
                {
                    loWriter.Append(lcTemp, 0, (int)lnSize);
                    lnCount++;
                    lnTotalBytes += lnSize;

                    // *** Raise an event if hooked up
                    if (this.OnReceiveData != null)
                    {
                        /// *** Update the event handler
                        oArgs.CurrentByteCount = lnTotalBytes;
                        oArgs.NumberOfReads = lnCount;
                        oArgs.CurrentChunk = lcTemp;
                        this.OnReceiveData(this, oArgs);

                        // *** Check for cancelled flag
                        if (oArgs.Cancel)
                            goto CloseDown;
                    }
                }
            } // while

            CloseDown:
            oHttpResponse.Close();

            // *** Send Done notification
            if (this.OnReceiveData != null && !oArgs.Cancel)
            {
                // *** Update the event handler
                oArgs.Done = true;
                this.OnReceiveData(this, oArgs);
            }

            //			return lcHtml;
            return loWriter.ToString();
        }