Exemplo n.º 1
0
    private void handleReply(FetchHandler handler)
    {
        Debug.Assert(reader != null);

        handle_first_line(reader.readLine(), handler);
        golden_retriever.handleParametersAndBody(handler, reader);
        reader.close();
    }
Exemplo n.º 2
0
 public ResultThread(Fetch init_fetch, FetchHandler init_handler,
                     HTTPRawReader init_reader)
 {
     fetch     = init_fetch;
     handler   = init_handler;
     reader    = init_reader;
     exception = null;
 }
        private static void FetchCallbackImpl(IntPtr ptr, Result result, ImageHandle handleResult)
        {
            GCHandle     h        = GCHandle.FromIntPtr(ptr);
            FetchHandler callback = (FetchHandler)h.Target;

            h.Free();
            callback(result, handleResult);
        }
Exemplo n.º 4
0
 public void startPost(string method, FetchHandler handler)
 {
     incremental_handler = handler;
     setParameter("Transfer-Encoding", "chunked");
     doHeader(method);
     Debug.Assert(reader != null);
     Debug.Assert(writer != null);
     result_thread = new Thread(
         new ThreadStart(new ResultThread(this, handler, reader).run));
     result_thread.Start();
 }
Exemplo n.º 5
0
        public void Setup()
        {
            var innerJsonifier = new Jsonifier();

            _jsonifier = Substitute.For <IJsonifier>();
            _jsonifier
            .ParseJson <List <FetchedQuote> >(Arg.Any <string>())
            .Returns(args => innerJsonifier.ParseJson <List <FetchedQuote> >((string)args[0]));

            _sut = new FetchHandler(_jsonifier);
        }
Exemplo n.º 6
0
 public void post(int contentByteCount, byte[] contentBytes,
                  FetchHandler handler)
 {
     setParameter("Content-Length", string.Format("{0}", contentByteCount));
     doHeader("POST");
     Debug.Assert(reader != null);
     Debug.Assert(writer != null);
     writer.write(contentBytes, contentByteCount);
     writer.close();
     writer = null;
     handleReply(handler);
 }
Exemplo n.º 7
0
    public static void get(FetchHandler handler, string url, string user_agent,
                           double timeout_seconds, Method method)
    {
        Fetch fetch = new Fetch(url);

        if (user_agent != null)
        {
            fetch.setUserAgent(user_agent);
        }
        fetch.setTimeoutSeconds(timeout_seconds);
        fetch.get(handler, method);
    }
Exemplo n.º 8
0
    public static void post(int contentByteCount, byte[] contentBytes,
                            FetchHandler handler, string url, string user_agent,
                            double timeout_seconds)
    {
        Fetch fetch = new Fetch(url);

        if (user_agent != null)
        {
            fetch.setUserAgent(user_agent);
        }
        fetch.setTimeoutSeconds(timeout_seconds);
        fetch.post(contentByteCount, contentBytes, handler);
    }
Exemplo n.º 9
0
    public void get(FetchHandler handler, Method method)
    {
        string method_name;

        switch (method)
        {
        case Method.OPTIONS:
            method_name = "OPTIONS";
            break;

        case Method.GET:
            method_name = "GET";
            break;

        case Method.HEAD:
            method_name = "HEAD";
            break;

        case Method.POST:
            method_name = "POST";
            break;

        case Method.PUT:
            method_name = "PUT";
            break;

        case Method.DELETE:
            method_name = "DELETE";
            break;

        case Method.TRACE:
            method_name = "TRACE";
            break;

        case Method.CONNECT:
            method_name = "CONNECT";
            break;

        default:
            Debug.Assert(false);
            method_name = null;
            break;
        }
        doHeader(method_name);
        Debug.Assert(reader != null);
        Debug.Assert(writer != null);
        writer.close();
        writer = null;
        handleReply(handler);
    }
Exemplo n.º 10
0
        public JoinQuitHandler()
        {
            // Reset command
            new CommandHandler("jqresetcache", ResetDatabaseCommandHandler, true, false);
            // Database
            database = new DatabaseHandler();
            fetch    = new FetchHandler();

            // event subscribe
            Player.OnJoin += JoinHandler;
            foreach (Player player in Player.All)
            {
                HandlePlayerJoined(player);
                player.OnQuit += QuitHandler;
            }
        }
Exemplo n.º 11
0
 public void finishPost(FetchHandler handler)
 {
     Debug.Assert((incremental_handler == null) ||
                  (incremental_handler == handler));
     writer.write("0\r\n\r\n");
     writer.close();
     writer = null;
     result_thread.Join();
     if (incremental_handler == null)
     {
         handleReply(handler);
     }
     else
     {
         incremental_handler.handleContentEnd();
         reader.close();
     }
 }
Exemplo n.º 12
0
    private void handle_first_line(string first_line, FetchHandler handler)
    {
        int follow = 0;

        while ((follow >= first_line.Length) || (first_line[follow] != ' '))
        {
            if (follow >= first_line.Length)
            {
                reader.check_for_errors();
                error("Bad first line in response: {0}.", first_line);
            }
            ++follow;
        }
        handler.handleHTTPVersion(first_line.Substring(0, follow));
        ++follow;
        int code = 0;

        for (int num = 0; num < 3; ++num)
        {
            if ((follow >= first_line.Length) || (first_line[follow] < '0') ||
                (first_line[follow] > '9'))
            {
                throw new Exception("Bad first line in response.");
            }
            code = ((code * 10) + (first_line[follow] - '0'));
            ++follow;
        }
        handler.handleStatusCode(code);
        golden_retriever.have_content_length = (code == 204);
        if ((follow >= first_line.Length) || (first_line[follow] != ' '))
        {
            throw new Exception("Bad first line in response.");
        }
        ++follow;
        handler.handleReasonPhrase(first_line.Substring(follow));
    }
Exemplo n.º 13
0
 public void Fetch(ImageHandle handle, FetchHandler callback)
 {
     Fetch(handle, false, callback);
 }
Exemplo n.º 14
0
 public static void post(int contentByteCount, byte[] contentBytes,
                         FetchHandler handler, string url, string user_agent)
 {
     post(contentByteCount, contentBytes, handler, url, user_agent,
          default_timeout_seconds);
 }
Exemplo n.º 15
0
 public static void post(int contentByteCount, byte[] contentBytes,
                         FetchHandler handler, string url)
 {
     post(contentByteCount, contentBytes, handler, url, null);
 }
Exemplo n.º 16
0
 public void get(FetchHandler handler)
 {
     get(handler, Method.GET);
 }
Exemplo n.º 17
0
 public static void get(FetchHandler handler, string url)
 {
     get(handler, url, null);
 }
Exemplo n.º 18
0
 public static void get(FetchHandler handler, string url, string user_agent)
 {
     get(handler, url, user_agent, default_timeout_seconds);
 }
Exemplo n.º 19
0
 public static void get(FetchHandler handler, string url, string user_agent,
                        double timeout_seconds)
 {
     get(handler, url, user_agent, timeout_seconds, Method.GET);
 }
        /// <summary>
        ///     Prepares an image to later retrieve data about it.
        /// </summary>
        /// <param name="handle"></param>
        /// <param name="refresh"></param>
        /// <param name="callback"></param>
        public void Fetch(ImageHandle handle, bool refresh, FetchHandler callback)
        {
            GCHandle wrapped = GCHandle.Alloc(callback);

            Methods.Fetch(methodsPtr, handle, refresh, GCHandle.ToIntPtr(wrapped), FetchCallbackImpl);
        }