Exemplo n.º 1
0
        public static Html.Element Scrape(string url, string from, string to, Bamboo.DataStructures.BufferPool bufferPool)
        {
            try
            {
                System.IO.Stream       stream = Bamboo.Http.HttpClient.Get(url, bufferPool);
                System.IO.StreamReader reader = new System.IO.StreamReader(stream);
                string html = reader.ReadToEnd();
                stream.Close();

                int index = html.IndexOf(from);
                html  = html.Substring(index);
                index = html.IndexOf(to);
                html  = html.Substring(0, index);
                html  = "<html>" + html + "</html>";

                Bamboo.Html.HtmlReader htmlReader = new Bamboo.Html.HtmlReader(new System.IO.StringReader(html));
                Bamboo.Html.Element    element    = htmlReader.Read(html);
                htmlReader.Close();

                return(element);
            }
            catch (System.Exception exception)
            {
                //System.IO.StreamWriter writer = System.IO.File.CreateText(@"C:\Documents and Settings\matt\Desktop\abc.html");
                //writer.Write(html);
                //writer.Flush();
                //writer.Close();

                return(null);
            }
        }
Exemplo n.º 2
0
        public static System.IO.Stream Get(string url, Bamboo.DataStructures.BufferPool bufferPool)
        {
            System.Net.WebRequest request = System.Net.HttpWebRequest.Create(url);
            request.Method = "GET";
            System.Net.WebResponse response = request.GetResponse();

            System.IO.Stream responseStream = new Bamboo.DataStructures.MemoryStream(bufferPool);
            Copy(response.GetResponseStream(), responseStream, (int)response.ContentLength, bufferPool);
            response.Close();
            responseStream.Position = 0;
            return(responseStream);
        }
Exemplo n.º 3
0
        public static System.IO.Stream Post(string url, System.IO.Stream stream, Bamboo.DataStructures.BufferPool bufferPool)
        {
            System.Net.WebRequest request = System.Net.HttpWebRequest.Create(url);
            request.Method = "POST";
            System.IO.Stream requestStream = request.GetRequestStream();
            Copy(stream, requestStream, (int)stream.Length, bufferPool);
            requestStream.Close();
            System.Net.WebResponse response = request.GetResponse();

            if (response.ContentLength == 0)
            {
                response.Close();
                return(null);
            }

            System.IO.Stream responseStream = new Bamboo.DataStructures.MemoryStream(bufferPool);
            Copy(response.GetResponseStream(), responseStream, (int)response.ContentLength, bufferPool);
            response.Close();
            if (responseStream.Length > 0)
            {
                responseStream.Position = 0;
            }
            return(responseStream);
        }
Exemplo n.º 4
0
 public HttpServer(int port, Bamboo.Threading.ThreadPool threadPool, Bamboo.DataStructures.BufferPool bufferPool)
 {
     this._dictionaryHttpProcessor = new DictionaryHttpProcessor(bufferPool);
     this._errorHttpProcessor      = new ErrorHttpProcessor(this._dictionaryHttpProcessor, bufferPool);
     this._tcpServer = new TcpServer(port, threadPool, this._errorHttpProcessor);
 }
Exemplo n.º 5
0
 public DictionaryHttpProcessor(Bamboo.DataStructures.BufferPool bufferPool)
     : base(bufferPool)
 {
 }
Exemplo n.º 6
0
 public ErrorHttpProcessor(HttpProcessor processor, Bamboo.DataStructures.BufferPool bufferPool)
     : base(bufferPool)
 {
     this._processor  = processor;
     this._bufferPool = bufferPool;
 }
Exemplo n.º 7
0
 public ResourceHttpProcessor(string contentType, byte[] bytes, Bamboo.DataStructures.BufferPool bufferPool)
     : base(bufferPool)
 {
     this._contentType = contentType;
     this._bytes       = bytes;
 }
Exemplo n.º 8
0
 protected HttpProcessor(Bamboo.DataStructures.BufferPool bufferPool)
     : base(bufferPool)
 {
     this._bufferPool = bufferPool;
 }
Exemplo n.º 9
0
 protected TcpProcessor(Bamboo.DataStructures.BufferPool bufferPool)
 {
     this._bufferPool = bufferPool;
 }
Exemplo n.º 10
0
 public HttpResponse(Bamboo.DataStructures.BufferPool bufferPool)
 {
     this.Status  = 200;
     this.Content = new Bamboo.DataStructures.MemoryStream(bufferPool);
     this.Writer  = new System.IO.StreamWriter(this.Content);
 }
Exemplo n.º 11
0
 private static void Copy(System.IO.Stream from, System.IO.Stream to, int length, Bamboo.DataStructures.BufferPool bufferPool)
 {
     if (length == -1)
     {
         byte[] buffer = bufferPool.Dequeue();
         while (true)
         {
             int bytesRead = from.Read(buffer, 0, buffer.Length);
             if (bytesRead == 0)
             {
                 break;
             }
             to.Write(buffer, 0, bytesRead);
         }
         bufferPool.Enqueue(buffer);
     }
     else
     {
         int    remaining = length;
         byte[] buffer    = bufferPool.Dequeue();
         while (remaining > 0)
         {
             int bytesRead = from.Read(buffer, 0, Math.Min(buffer.Length, remaining));
             to.Write(buffer, 0, bytesRead);
             remaining -= bytesRead;
         }
         bufferPool.Enqueue(buffer);
     }
 }