/// <summary> /// Takes a route and a series of functions to construct a server for the given route. /// The server will reference the series of functions and pass the request through each function /// </summary> /// <param name="route">Route with given path and description</param> /// <param name="middleWareItems">Series of middle ware functions to parse a request</param> public void AddServer(string path, string description, params MiddleWareOperation <T>[] middleWareItems) { if (path == null) { throw new ArgumentNullException(); } IServable <T> server = DefineServer(description, middleWareItems); DefinedRoutes.Add(path, server); }
/// <summary> /// Compares the current Dish object with another Dish object. /// </summary> /// <param name="other">An Dish to compare with this Dish object.</param> /// <returns>A value that indicates the relative order of the objects being compared. The /// return value has the following meanings: Value Meaning Less than zero This object /// is less than the other parameter.Zero This object is equal to other. Greater /// than zero This object is greater than other.</returns> public int CompareTo(IServable other) { Dish otherDish = other as Dish; if (otherDish == null) { return(1); } return((int)this.DishType - (int)otherDish.DishType); }
/// <summary> /// Attempts to parse passed request with the routes middleware. /// Throw a custom exception if the function fails /// </summary> /// <param name="req">Request to be parsed</param> /// <param name="server">Server containing functionality to be used</param> /// <returns>A parsed request or an exception</returns> IResponsable <T> ValidateRouteProcesses(IRequestable <T> req, IServable <T> server) { try { IResponsable <T> res = server.Process(req); return(res); } catch (Exception) { throw new Router400BadRequestException <T>(req); } }
/// <summary> /// Returns whether this Dish instance represents an equal type as the provided IServable instance. /// </summary> /// <param name="other">The other IServable instance to compare with.</param> /// <returns>Whether the objects are equal (not reference equal)</returns> public virtual bool Equals(IServable other) { Dish dish = other as Dish; if (dish == null) { return(false); } if (m_DishType == dish.DishType) { return(true); } return(false); }
/// <summary> /// constructs a response from the parsed user request /// </summary> /// <param name="req">Request passed on the instance of the Router query. Will constantly change for the route</param> /// <param name="middleWareItems">Middle ware saved to the instance of a server. The middle ware will be constant</param> /// <returns>A response constructed from a parsed request body</returns> public IResponsable <T> GetResponseFromServer(IRequestable <T> req) { if (req == null) { throw new ArgumentNullException(); } IServable <T> server = GetServer(req.Path); var res = ValidateRouteProcesses(req, server); if (res == null) { throw new Router400ErrorNoResponseDefined <T>(req); } return(res); }
public void AddServable(IServable serving) { m_Servings.Add(serving); m_Servings.Sort(); }
public void Set500Handler(IServable handler) { m_500Handler = handler; }
public void Set404Handler(IServable handler) { m_404Handler = handler; }
public void AddHandler(string uri, IServable handler) { m_handlers[uri] = handler; }
/// <summary> /// Returns whether this NightDish instance represents an equal type as the provided IServable instance. /// </summary> /// <param name="other">The other IServable instance to compare with.</param> /// <returns>Whether the objects are equal (not reference equal).</returns> public override bool Equals(IServable other) { return(base.Equals(other) && other is NightDish); }
public static void addFuel(IServable vehicle) { Vehicle servable_vehicle = vehicle.GetVehicle(); bling bling tidluk }