Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        /// <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);
        }
Esempio n. 3
0
 /// <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);
     }
 }
Esempio n. 4
0
        /// <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);
        }
Esempio n. 5
0
        /// <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);
        }
Esempio n. 6
0
 public void AddServable(IServable serving)
 {
     m_Servings.Add(serving);
     m_Servings.Sort();
 }
Esempio n. 7
0
 public void Set500Handler(IServable handler)
 {
     m_500Handler = handler;
 }
Esempio n. 8
0
 public void Set404Handler(IServable handler)
 {
     m_404Handler = handler;
 }
Esempio n. 9
0
 public void AddHandler(string uri, IServable handler)
 {
     m_handlers[uri] = handler;
 }
Esempio n. 10
0
 /// <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);
 }
Esempio n. 11
0
 public static void addFuel(IServable vehicle)
 {
     Vehicle     servable_vehicle = vehicle.GetVehicle();
     bling bling tidluk
 }