Exemplo n.º 1
0
        private async void pickerBtb_Click(object sender, RoutedEventArgs e)
        {
            //Set a result to return to the caller
            var returnMessage = new ValueSet();
            server = new HttpServer(8080);
            server.StartServer();
            returnMessage.Add("Status", "Success");

            // var myPictures = await StorageLibrary.GetLibraryAsync(Windows.Storage.KnownLibraryId.Pictures);
            var picker = new Windows.Storage.Pickers.FileOpenPicker();
            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");

            StorageFile file = await picker.PickSingleFileAsync();
            if (file != null)
            {
                // Application now has read/write access to the picked file
                Log("Picked photo: " + file.Path, "Success");
                server.FilePath = file.Path;
            }
            else
            {
                Log("Operation cancelled.", "Error");
            }
        }
Exemplo n.º 2
0
 public void Start()
 {
     lock (synclock)
     {
         if (!isRunning)
         {
             shouldBeRunning = true;
             if (!CanStartServer())
             { return; }
             if (server == null)
             {
                 server = new HttpServer(port);
                 initServer();
             }
             server.Start();
             isRunning = true;
         }
     }
 }
Exemplo n.º 3
0
        private async void pickerVideoBtn_Click(object sender, RoutedEventArgs e)
        {
            //Set a result to return to the caller
            var returnMessage = new ValueSet();
            server = new HttpServer(8080);
            server.StartServer();
            returnMessage.Add("Status", "Success");

            Windows.Storage.Pickers.FileOpenPicker picker = new Windows.Storage.Pickers.FileOpenPicker();
            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.HomeGroup;
            picker.FileTypeFilter.Clear();
            picker.FileTypeFilter.Add(".mp4");
            picker.FileTypeFilter.Add(".wmv");
            StorageFile file = await picker.PickSingleFileAsync();
            if (file != null)
            {
                // Application now has read/write access to the picked file
                Log("Picked video: " + file.Path, "Success");
                server.FilePath = file.Path;
            }
            else
            {
                Log("Operation cancelled.", "Error");
            }
        }
Exemplo n.º 4
0
        static void Main()
        {
            connectionStringBuilder.DataSource = "./database.db";

            Route.Add("/", (request, response, args) => {
                response.AsText("Hello, World!");
            }, "GET");

//**********************************

            Route.Add("/items", (request, response, args) => {
                response.AsText($"{style}{getItems()}");
            }, "GET");

            Route.Add("/items", (request, response, args) => {
                request.ParseBody(args);
                RunQuery($@"
                    INSERT into items (name, price, container_id)
                    VALUES ('{args["name"]}', '{args["price"]}', {args["container_id"]});
                ");
                response.AsText($"{style}{getItems()}");
            }, "POST");

//**********************************

            Route.Add("/containers", (request, response, args) => {
                response.AsText($"{style}{getContainers()}");
            }, "GET");

            Route.Add("/containers", (request, response, args) => {
                request.ParseBody(args);
                RunQuery($@"
                    INSERT into containers (name, warehouse_id)
                    VALUES ('{args["name"]}', {args["warehouse_id"]});
                ");
                response.AsText($"{style}{getContainers()}");
            }, "POST");


// //**********************************

            Route.Add("/warehouses", (request, response, args) => {
                response.AsText($"{style}{getWarehouses()}");
            }, "GET");

            Route.Add("/warehouses", (request, response, args) => {
                request.ParseBody(args);
                RunQuery($@"
                    INSERT into warehouses (company_id, location)
                    VALUES ({args["company_id"]}, '{args["location"]}');
                ");
                response.AsText($"{style}{getWarehouses()}");
            }, "POST");


// //**********************************

            Route.Add("/companies", (request, response, args) => {
                response.AsText($"{style}{getCompanies()}");
            }, "GET");

            Route.Add("/companies", (request, response, args) => {
                request.ParseBody(args);
                RunQuery($@"
                    INSERT into companies (name)
                    VALUES ('{args["name"]}');
                ");
                response.AsText($"{style}{getCompanies()}");
            }, "POST");



            //run the server
            int port = 8000;

            Console.WriteLine($"Running Server On http://127.0.0.1:{port}");
            HttpServer.ListenAsync(port, CancellationToken.None, Route.OnHttpRequestAsync).Wait();
        }
Exemplo n.º 5
0
        static void Main()
        {
            connectionStringBuilder.DataSource = "./database.db";

            Route.Add("/", (request, response, args) => {
                response.AsText("Hello, World!");
            }, "GET");

            Route.Add("/items", (request, response, args) => {
                response.AsText($"{style}{getItems()}");
            }, "GET");

            Route.Add("/items", (request, response, args) => {
                request.ParseBody(args);
                if (args.ContainsKey("_method") && args["_method"] == "DELETE")
                {
                    RunQuery($@"
                        DELETE FROM items 
                        WHERE id = {args["id"]};
                    ");
                }
                else if (args.ContainsKey("_method") && args["_method"] == "UPDATE")
                {
                    RunQuery($@"
                        UPDATE items
                        SET price = {args["price"]}
                        WHERE id = {args["id"]};
                    ");
                }
                else
                {
                    RunQuery($@"
                        INSERT into items (name, price, container_id)
                        VALUES ('{args["name"]}', '{args["price"]}', {args["container_id"]});
                    ");
                }
                response.AsText($"{style}{getItems()}");
            }, "POST");

            Route.Add("/items/update", (request, response, args) => {
                var results = RunQuery($@"  
                    SELECT *
                    FROM items;
                ");
                string html = $@"
                    {String.Join("", results.Select(item => $@"
                        <form method='POST' action='/items'>
                            <input type='hidden' name='id' value='{item["id"]}'>
                            <input type='hidden' name='_method' value='UPDATE'>
                            <label>{item["name"]}: ${item["price"]}; New price:
                                $<input type='text' name='price'>
                            </label>
                            <input type='submit' value='Update'>
                        </form>
                    "))}
                ";
                response.AsText(html);
            }, "GET");

            // WHY DOES THE BELOW POST ROUTE THROW KEY NOT FOUND IN DICTIONARY ERROR?

            // Route.Add("/items/update", (request, response, args) => {
            //     var results = RunQuery($@"
            //         SELECT *
            //         FROM items
            //         WHERE id = {args["id"]}; <-- THIS VARIABLE IS THE CULPRIT, BUT WHY?
            //     ");
            //     string html = $@"
            //         {String.Join("", results.Select(item => $@"
            //             <form method='POST' action='/items'>
            //                 <input type='hidden' name='id' value='{item["id"]}'>
            //                 <input type='hidden' name='_method' value='UPDATE'>
            //                 <label>{item["name"]}: ${item["price"]}; New price:
            //                     $<input type='text' name='price'>
            //                 </label>
            //                 <input type='submit' value='Update'>
            //             </form>
            //         "))}
            //     ";
            //     response.AsText(html);
            // }, "POST");


            //run the server
            int port = 8000;

            Console.WriteLine($"Running Server On http://127.0.0.1:{port}");
            HttpServer.ListenAsync(port, CancellationToken.None, Route.OnHttpRequestAsync).Wait();
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            var server = new HttpServer(1234);

            server.Start();
        }