Beispiel #1
0
        /// <summary>
        /// Handles the keyup event of the imput field (waiting for Enter).
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void input_KeyUp(object sender, KeyEventArgs e)
        {
            // Enter triggers the search
            if (e.KeyCode != Keys.Enter)
            {
                return;
            }

            string command = input.Text.ToLower().Trim();

            // Exit requested?
            if (command == "exit")
            {
                _server.Stop();
                Application.Exit();
            }

            // Trigger the launch of pdf the requested by the given command
            bool result = _launcher.Launch(command);

            if (result)
            {
                // Success -> PDF was opened
                input.Text = "";
                ColorChangeInput(Color.LightGreen);
            }
            else
            {
                // Failed -> PDF not found
                ColorChangeInput(Color.LightCoral);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Start the server thread.
        /// </summary>
        private async Task StartListenerThread()
        {
            _listener = new HttpListener();
            _listener.Prefixes.Add("http://*:" + _port + "/");
            _listener.Start();
            var token = _serverCancellationTokenSource.Token;

            while (!token.IsCancellationRequested)
            {
                try
                {
                    HttpListenerContext context = _listener.GetContext();
                    string book = context.Request.QueryString["book"];
                    int.TryParse(context.Request.QueryString["page"], out var page);

                    context.Response.StatusCode = (int)HttpStatusCode.OK;
                    string s     = "<script>window.close();</script>";
                    byte[] bytes = Encoding.UTF8.GetBytes(s);

                    context.Response.OutputStream.Write(bytes, 0, bytes.Length);
                    context.Response.OutputStream.Close();

                    _launcher.Launch($"{book} {page}");
                }
                catch (Exception)
                {
                }
            }
            _listener.Stop();
        }