Linux Commands on BeagleBone Black

On BeagleBone Black, I mainly work with the command shell. For that reason, I will enumerate important commands to type at LXTerminal:

  • shutdown the system: sudo poweroff
  • find a file: sudo find / -name FILENAME
  • shows what’s inside a directory: ls -lah
  • find out what USB device are connected: lsusb
  • get information about connected devices: cat /proc/bus/input/devices
  • get your version of system: lsb release -a
  • find out running processes: top
  • shows disk space: df -h
  • update your package list: sudo apt-get update
  • try to reconfigure specific application that failed to install: sudo dpkg –configure APP_NAME
  • try to fix a specific broken package: sudo apt-get install APP_NAME -f

Using a Route in Forms and Hyperlink

Using a Route in Forms

To use a route in forms, you need to change from:

@using(Html.BeginForm("Index","Products",FormMethod.Get))

to

@using(Html.BeginRouteForm("ProductsIndex",FormMethod.Get))

Using a Route in Hyperlink

To use a route in hyperlink, you need to change from:

<li>Html.ActionLink("View all our Products","Index","Products")</li>

to

<li>Html.ActionLink("View all our Products","ProductsIndex")</li>

If you want pass extra parameters via a URL that targets a route, you simply add them into the link as an anonymous object in the same way that HTML attributes are passed. For example:

<li>Html.ActionLink("View all our Products","ProductsbyCategory",new {category = "Clothes"})</li>

Source: ASP.NET MVC with Entity Framework and CSS, Naylor L., pp.103 – 104

Routing

Introduction

The URLs follow the standard format such as

 /Products?category=Sleeping&page=2 

, and although functional, these URLs can be improved upon by using the ASP.NET Routing feature. It generates URLs in a more “friendly” format that is more meaningful to users and search engines.

One of the most important things about routing is that routes have to be added in order to most specific first, with more general routes further down the list. The routing system searches down the routes until it finds anything that matches the current URL and then it stops. If there is a general route that matches a URL and a more specific route that also matches, but it is defined below the more general route then the more specific route will never be used.

Adding routes

How to add routes to ASP.NET application? It is necessary to obey the following format and you have to write routes to App_Start/RouteConfig:

routes.MapRoute(
    name: "Name",
    url: "Rule",
    defaults: DefaultValues
);

The name parameter represents the name of the route and can be left blank.

The url parameter contains a rule for matching the route to a URL format. This can contain several format and arguments, as follows:

  • The url parameter is divided into segments, with each segment matching sections of the URL.
  • A URL has to have the same number of segments as the url parameter in order to match it, unless either defaults or a wildcard is specified (see the following bullet points for an explanation of each of these).
  • Each segment can be:
    • A static element URL, such as “Products”. This will simply match the URL /Products and will call the relevant controller and action method.
    • A variable element that is able to match anything. For example, “Products/{category}” will match anything after Products in a URL and assign it to {category} and {category} can then be used in the action method targeted by the route.
    • A combination of static and variable elements that will match anything in the same URL segment matching the format specified. For example, “Products/Page{Page}” will match URLs such as Products/Page2 or Products/Page99 and assign the value of the part of the URL following Page to {page}.
    • A catch-all wildcard element, for example “Products/{*everything}, will map everything following the Products section of the URL into the everything variable segment. This is done regardless of whether it contains slashes or not. We won’t use wildcard matches in this project.
  • Each segment can also be specified as being optional or having a default value if the correspoding element of the URL is blank. A good example of this is the default route specified when the project was created. This route uses the following code to specify default values for the controller and action method to be used. It also defines the id element as being optional:
    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index",
        id = UrlParameter.Optional }
    );
    

Next, you can see the examples of routing:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace BabyStore
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "ProductsCreate",
                url: "Products/Create",
                defaults: new { controller = "Products", action = "Create" }
            );

            routes.MapRoute(
                name: "ProductsbyCategorybyPage",
                url: "Products/{category}/Page{page}",
                defaults: new { controller = "Products", action = "Index" }
            );

            routes.MapRoute(
                name: "ProductsbyPage",
                url: "Products/Page{page}",
                defaults: new { controller = "Products", action = "Index" }
            );

            routes.MapRoute(
                name: "ProductsbyCategory",
                url: "Products/{category}",
                defaults: new { controller = "Products", action = "Index" }
            );

            routes.MapRoute(
                name: "ProductsIndex",
                url: "Products",
                defaults: new { controller = "Products", action = "Index" }
            );
            
            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
    }
}

Now, the web site displays friendly URLs for categories and paging.

Source: ASP.NET MVC with Entity Framework and CSS, Naylor L., pp.95 – 103