/// <summary>
 ///     Default Constructor of Route
 /// </summary>
 /// <param name="rt">Route Type</param>
 /// <param name="end">destination block given PointRoute</param>
 /// <param name="ID">DB ID of route given DefinedRoute</param>
 /// <param name="blocks">List of blocks contained by that route</param>
 public Route(RouteTypes rt, IBlock end, int ID, List <IBlock> blocks)
 {
     _routeType   = rt;
     _endBlock    = end;
     _routeID     = ID;
     _routeBlocks = blocks;
 }
 /// <summary>
 ///     Default Constructor of Route
 /// </summary>
 /// <param name="rt">Route Type</param>
 /// <param name="end">destination block given PointRoute</param>
 /// <param name="ID">DB ID of route given DefinedRoute</param>
 /// <param name="blocks">List of blocks contained by that route</param>
 public Route(RouteTypes rt, IBlock end, int ID, List<IBlock> blocks)
 {
     _routeType = rt;
     _endBlock = end;
     _routeID = ID;
     _routeBlocks = blocks;
 }
Exemple #3
0
    internal void Initialize(Chapter chapter)
    {
        if (NodeCategory.Count == 0)
        {
            foreach (string str in Enum.GetNames(typeof(NodeTypes)))
            {
                NodeTypes type = (NodeTypes)Enum.Parse(typeof(NodeTypes), str);
                NodeCategory.Add(type, new List <int>());
            }
        }

        if (RouteCategory.Count == 0)
        {
            foreach (string str in Enum.GetNames(typeof(RouteTypes)))
            {
                RouteTypes type = (RouteTypes)Enum.Parse(typeof(RouteTypes), str);
                RouteCategory.Add(type, new List <int>());
            }
        }

        Reset();

        Cur_Chapter = chapter;

        DrawMap(chapter.ChapterMapRoundCount);

        SetPicForNodes();

        SetLevels(Cur_Chapter.Levels);
    }
Exemple #4
0
 /// <summary>View departures for all routes from a stop</summary>
 /// <param name="routeType">Number identifying transport mode; values returned via RouteTypes API</param>
 /// <param name="stopId">Identifier of stop; values returned by Stops API</param>
 /// <param name="platformNumbers">Filter by platform number at stop</param>
 /// <param name="directionId">
 ///     Filter by identifier of direction of travel; values returned by Directions API -
 ///     /v3/directions/route/{route_id}
 /// </param>
 /// <param name="dateUtc">Filter by the date and time of the request (ISO 8601 UTC format)</param>
 /// <param name="maxResults">Maximum number of results returned</param>
 /// <param name="gtfs">Indicates that stop_id parameter will accept "GTFS stop_id" data</param>
 /// <param name="includeCancelled">
 ///     Indicates if cancelled services (if they exist) are returned (default = false) -
 ///     metropolitan train only
 /// </param>
 /// <param name="expand">
 ///     List objects to be returned in full (i.e. expanded) - options include: all, stop, route, run,
 ///     direction, disruption
 /// </param>
 /// <returns>
 ///     Service departures from the specified stop for all routes of the specified route type; departures are
 ///     timetabled and real-time (if applicable).
 /// </returns>
 /// <exception cref="SwaggerException">A server side error occurred.</exception>
 public DeparturesResponse GetForStop(RouteTypes routeType, int stopId,
                                      IEnumerable <int> platformNumbers, int?directionId, DateTime?dateUtc,
                                      int?maxResults, bool?gtfs, bool?includeCancelled,
                                      IEnumerable <ExpandableParameter> expand)
 {
     return(Task.Run(async() => await GetForStopAsync(routeType, stopId,
                                                      platformNumbers, directionId, dateUtc, maxResults, gtfs, includeCancelled, expand, CancellationToken.None)).GetAwaiter().GetResult());
 }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            RouteTypes routeTypes = await db.RouteTypes.FindAsync(id);

            db.RouteTypes.Remove(routeTypes);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Exemple #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WebRouteAttribute"/> class.
        /// </summary>
        /// <param name="routeTypes">The route type.</param>
        /// <param name="controllerRoute">The controller route.</param>
        /// <param name="actionRoute">The action route.</param>
        public WebRouteAttribute(RouteTypes routeTypes, string controllerRoute, string actionRoute)
        {
            if (routeTypes != RouteTypes.ControllerAndAction)
            {
                throw new ArgumentException("Too many route parameters");
            }

            this.ControllerRoute = controllerRoute;
            this.ActionRoute     = actionRoute;
        }
        public async Task <ActionResult> Edit([Bind(Include = "Id,Name")] RouteTypes routeTypes)
        {
            if (ModelState.IsValid)
            {
                db.Entry(routeTypes).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(routeTypes));
        }
Exemple #8
0
 /// <summary>
 /// Returns a route depending on its type
 /// </summary>
 /// <param name="session">Data access object</param>
 /// <param name="type">The route type of interest</param>
 /// <returns>route object</returns>
 public static IRoute GetRouteByType(IDalSession session, RouteTypes type)
 {
     IRoute route = null;
     List<ICriterion> expressions = new List<ICriterion>();
     expressions.Add(Expression.Eq("Type", type));
     IList list = session.GetList(typeof(Route), expressions);
     if (list != null && list.Count > 0)
     {
         route = (IRoute)list[0];
     }
     return route;
 }
        public async Task <ActionResult> Create([Bind(Include = "Id,Name")] RouteTypes routeTypes)
        {
            if (ModelState.IsValid)
            {
                db.RouteTypes.Add(routeTypes);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(routeTypes));
        }
Exemple #10
0
        private int GetIndexOf(RouteTypes routeType)
        {
            string Route = routeType.ToString().ToLower(); //convert the enum type to string and go with lower case to match with the entries

            for (int i = 0; i < RouteTemplate.Length; i++) //loop thru the list
            {
                if (RouteTemplate[i] == Route)
                {
                    return(i);                           // if the enum matches with the route url return the position of it
                }
            }
            return(-1);//otherwise return -1
        }
Exemple #11
0
        public static List <RouteID> GetRoutesOfType(RouteTypes routeType)
        {
            List <RouteID> routesIDList = new List <RouteID>();

            foreach (RouteID id in Routes.Keys)
            {
                if (Routes[id].RouteType == routeType)
                {
                    routesIDList.Add(id);
                }
            }

            return(routesIDList);
        }
        // GET: Guides/RouteTypes/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RouteTypes routeTypes = await db.RouteTypes.FindAsync(id);

            if (routeTypes == null)
            {
                return(HttpNotFound());
            }
            return(View(routeTypes));
        }
Exemple #13
0
        public string GetUrlFor(RouteTypes routeType, string value)
        {
            List <string> CopiedRouteValues = new List <string>(RouteValues); //copy the default route parameters to make sure that those don't change
            string        UrlToReturn       = string.Empty;                   //empty the url to make sure those don't stack
            int           index             = GetIndexOf(routeType);          //get the index of the route type

            if (index != -1)
            {
                CopiedRouteValues[index] = value;         //make sure it's a valid number
            }
            foreach (var routeValue in CopiedRouteValues) //loop thru the copied route
            {
                UrlToReturn += $"/{routeValue}";          //add every value to the route
            }
            return(UrlToReturn);                          //and then return it
        }
Exemple #14
0
        public WebRouteAttribute(RouteTypes routeTypes, string route)
        {
            if (routeTypes == RouteTypes.ControllerAndAction)
            {
                throw new ArgumentException("Can't set up a route with route type 'ControllerAndAction' without two route parameters");
            }

            if (routeTypes.HasFlag(RouteTypes.Controller))
            {
                this.ControllerRoute = route;
            }

            if (routeTypes.HasFlag(RouteTypes.Action))
            {
                this.ActionRoute = route;
            }
        }
Exemple #15
0
 /// <summary>View facilities at a specific stop (Metro and V/Line stations only)</summary>
 /// <param name="stopId">Identifier of stop; values returned by Stops API</param>
 /// <param name="routeType">Number identifying transport mode; values returned via RouteTypes API</param>
 /// <param name="stopLocation">Indicates if stop location information will be returned (default = false)</param>
 /// <param name="stopAmenities">Indicates if stop amenity information will be returned (default = false)</param>
 /// <param name="stopAccessibility">Indicates if stop accessibility information will be returned (default = false)</param>
 /// <returns>
 ///     Stop location, amenity and accessibility facility information for the specified stop (metropolitan and V/Line
 ///     stations only).
 /// </returns>
 /// <exception cref="SwaggerException">A server side error occurred.</exception>
 public Task <StopResponse> StopDetailsAsync(int stopId, RouteTypes routeType,
                                             bool?stopLocation, bool?stopAmenities, bool?stopAccessibility)
 {
     return(StopDetailsAsync(stopId, routeType, stopLocation, stopAmenities, stopAccessibility, CancellationToken.None));
 }
Exemple #16
0
 /// <summary>View facilities at a specific stop (Metro and V/Line stations only)</summary>
 /// <param name="stopId">Identifier of stop; values returned by Stops API</param>
 /// <param name="routeType">Number identifying transport mode; values returned via RouteTypes API</param>
 /// <param name="stopLocation">Indicates if stop location information will be returned (default = false)</param>
 /// <param name="stopAmenities">Indicates if stop amenity information will be returned (default = false)</param>
 /// <param name="stopAccessibility">Indicates if stop accessibility information will be returned (default = false)</param>
 /// <returns>
 ///     Stop location, amenity and accessibility facility information for the specified stop (metropolitan and V/Line
 ///     stations only).
 /// </returns>
 /// <exception cref="SwaggerException">A server side error occurred.</exception>
 public StopResponse StopDetails(int stopId, RouteTypes routeType, bool?stopLocation, bool?stopAmenities,
                                 bool?stopAccessibility)
 {
     return(Task.Run(async() => await StopDetailsAsync(stopId, routeType,
                                                       stopLocation, stopAmenities, stopAccessibility, CancellationToken.None)).GetAwaiter().GetResult());
 }
Exemple #17
0
        /// <summary>View departures for a specific route from a stop</summary>
        /// <param name="routeType">Number identifying transport mode; values returned via RouteTypes API</param>
        /// <param name="stopId">Identifier of stop; values returned by Stops API</param>
        /// <param name="routeId">Identifier of route; values returned by Routes API - v3/routes</param>
        /// <param name="directionId">
        ///     Filter by identifier of direction of travel; values returned by Directions API -
        ///     /v3/directions/route/{route_id}
        /// </param>
        /// <param name="dateUtc">Filter by the date and time of the request (ISO 8601 UTC format)</param>
        /// <param name="maxResults">Maximum number of results returned</param>
        /// <param name="gtfs">Indicates that stop_id parameter will accept "GTFS stop_id" data</param>
        /// <param name="includeCancelled">
        ///     Indicates if cancelled services (if they exist) are returned (default = false) -
        ///     metropolitan train only
        /// </param>
        /// <param name="expand">
        ///     List objects to be returned in full (i.e. expanded) - options include: all, stop, route, run,
        ///     direction, disruption
        /// </param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of
        ///     cancellation.
        /// </param>
        /// <returns>
        ///     Service departures from the specified stop for the specified route (and route type); departures are timetabled
        ///     and real-time (if applicable).
        /// </returns>
        /// <exception cref="SwaggerException">A server side error occurred.</exception>
        public async Task <DeparturesResponse> GetForStopAndRouteAsync(RouteTypes routeType,
                                                                       int stopId, string routeId, int?directionId, DateTime?dateUtc, int?maxResults, bool?gtfs,
                                                                       bool?includeCancelled, IEnumerable <ExpandableParameter> expand, CancellationToken cancellationToken)
        {
            var urlBuilder = new StringBuilder();

            urlBuilder
            .Append("/v3/departures/route_type/{route_type}/stop/{stop_id}/route/{route_id}?");
            urlBuilder.Replace("{route_type}", Uri.EscapeDataString(((int)routeType).ToString()));
            urlBuilder.Replace("{stop_id}", Uri.EscapeDataString(stopId.ToString()));
            urlBuilder.Replace("{route_id}", Uri.EscapeDataString(routeId));
            if (directionId != null)
            {
                urlBuilder.Append("direction_id=").Append(Uri.EscapeDataString(directionId.Value.ToString())).Append("&");
            }
            if (dateUtc != null)
            {
                urlBuilder.Append("date_utc=").Append(Uri.EscapeDataString(dateUtc.Value.ToString("s", CultureInfo.InvariantCulture))).Append("&");
            }
            if (maxResults != null)
            {
                urlBuilder.Append("max_results=").Append(Uri.EscapeDataString(maxResults.Value.ToString())).Append("&");
            }
            if (gtfs != null)
            {
                urlBuilder.Append("gtfs=").Append(Uri.EscapeDataString(gtfs.Value.ToString())).Append("&");
            }
            if (includeCancelled != null)
            {
                urlBuilder.Append("include_cancelled=").Append(Uri.EscapeDataString(includeCancelled.Value.ToString())).Append("&");
            }
            if (expand != null)
            {
                urlBuilder.Append("expand=").Append(Uri.EscapeDataString(string.Join(",", expand))).Append("&");
            }

            var client = new HttpClient();

            try
            {
                using (var request = new HttpRequestMessage())
                {
                    request.Method = new HttpMethod("GET");
                    request.Headers.Accept.Add(
                        new MediaTypeWithQualityHeaderValue("application/json"));

                    PrepareRequest(client, request, urlBuilder);
                    var url = urlBuilder.ToString();
                    request.RequestUri = new Uri(BaseUrl + url, UriKind.RelativeOrAbsolute);
                    PrepareRequest(client, request, url);

                    var response = await client.SendAsync(request,
                                                          HttpCompletionOption.ResponseHeadersRead, cancellationToken)
                                   .ConfigureAwait(false);

                    try
                    {
                        var headers =
                            response.Headers.ToDictionary(h => h.Key, h => h.Value);
                        foreach (var item in response.Content.Headers)
                        {
                            headers[item.Key] = item.Value;
                        }

                        ProcessResponse(client, response);

                        var status = ((int)response.StatusCode).ToString();
                        if (status == "200")
                        {
                            var responseData = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                            var result = default(DeparturesResponse);
                            try
                            {
                                result =
                                    JsonConvert.DeserializeObject <DeparturesResponse>(responseData);
                                return(result);
                            }
                            catch (Exception exception)
                            {
                                throw new SwaggerException("Could not deserialize the response body.", status,
                                                           responseData, headers, exception);
                            }
                        }
                        else if (status == "400")
                        {
                            var responseData = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                            var result = default(ErrorResponse);
                            try
                            {
                                result = JsonConvert.DeserializeObject <ErrorResponse>(responseData);
                            }
                            catch (Exception exception)
                            {
                                throw new SwaggerException("Could not deserialize the response body.", status,
                                                           responseData, headers, exception);
                            }
                            throw new SwaggerException <ErrorResponse>("Invalid Request", status, responseData,
                                                                       headers, result, null);
                        }
                        else if (status == "403")
                        {
                            var responseData = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                            var result = default(ErrorResponse);
                            try
                            {
                                result = JsonConvert.DeserializeObject <ErrorResponse>(responseData);
                            }
                            catch (Exception exception)
                            {
                                throw new SwaggerException("Could not deserialize the response body.", status,
                                                           responseData, headers, exception);
                            }
                            throw new SwaggerException <ErrorResponse>("Access Denied", status, responseData, headers,
                                                                       result, null);
                        }
                        else if (status != "200" && status != "204")
                        {
                            var responseData = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                            throw new SwaggerException(
                                      "The HTTP status code of the response was not expected (" + (int)response.StatusCode +
                                      ").", status, responseData, headers, null);
                        }

                        return(default(DeparturesResponse));
                    }
                    finally
                    {
                        response?.Dispose();
                    }
                }
            }
            finally
            {
                client?.Dispose();
            }
        }
Exemple #18
0
 /// <summary>View departures for a specific route from a stop</summary>
 /// <param name="routeType">Number identifying transport mode; values returned via RouteTypes API</param>
 /// <param name="stopId">Identifier of stop; values returned by Stops API</param>
 /// <param name="routeId">Identifier of route; values returned by Routes API - v3/routes</param>
 /// <param name="directionId">
 ///     Filter by identifier of direction of travel; values returned by Directions API -
 ///     /v3/directions/route/{route_id}
 /// </param>
 /// <param name="dateUtc">Filter by the date and time of the request (ISO 8601 UTC format)</param>
 /// <param name="maxResults">Maximum number of results returned</param>
 /// <param name="gtfs">Indicates that stop_id parameter will accept "GTFS stop_id" data</param>
 /// <param name="includeCancelled">
 ///     Indicates if cancelled services (if they exist) are returned (default = false) -
 ///     metropolitan train only
 /// </param>
 /// <param name="expand">
 ///     List objects to be returned in full (i.e. expanded) - options include: all, stop, route, run,
 ///     direction, disruption
 /// </param>
 /// <returns>
 ///     Service departures from the specified stop for the specified route (and route type); departures are timetabled
 ///     and real-time (if applicable).
 /// </returns>
 /// <exception cref="SwaggerException">A server side error occurred.</exception>
 public Task <DeparturesResponse> GetForStopAndRouteAsync(RouteTypes routeType,
                                                          int stopId, string routeId, int?directionId, DateTime?dateUtc, int?maxResults, bool?gtfs,
                                                          bool?includeCancelled, IEnumerable <ExpandableParameter> expand)
 {
     return(GetForStopAndRouteAsync(routeType, stopId, routeId, directionId, dateUtc, maxResults, gtfs, includeCancelled, expand, CancellationToken.None));
 }
Exemple #19
0
 private IRoute getSpecificRoute(RouteTypes type)
 {
     foreach (IRoute route in routes)
     {
         if (route.Type == type)
         {
             return route;
         }
     }
     throw new ApplicationException(string.Format("Could not find the route of type {0}", type.ToString()));
 }
Exemple #20
0
 /// <summary>View the stopping pattern for a specific trip/service run</summary>
 /// <param name="runId">
 ///     Identifier of a trip/service run; values returned by Runs API - /v3/route/{route_id} and Departures
 ///     API
 /// </param>
 /// <param name="routeType">Number identifying transport mode; values returned via RouteTypes API</param>
 /// <param name="stopId">Filter by stop_id; values returned by Stops API</param>
 /// <param name="dateUtc">Filter by the date and time of the request (ISO 8601 UTC format)</param>
 /// <returns>The stopping pattern of the specified trip/service run and route type.</returns>
 /// <exception cref="SwaggerException">A server side error occurred.</exception>
 public Task <StoppingPattern> GetPatternByRunAsync(int runId, RouteTypes routeType, int?stopId, DateTime?dateUtc)
 {
     return(GetPatternByRunAsync(runId, routeType, stopId, dateUtc, CancellationToken.None));
 }
Exemple #21
0
 /// <summary>View the trip/service run for a specific run ID and route type</summary>
 /// <param name="runId">
 ///     Identifier of a trip/service run; values returned by Runs API - /v3/route/{route_id} and Departures
 ///     API
 /// </param>
 /// <param name="routeType">Number identifying transport mode; values returned via RouteTypes API</param>
 /// <returns>The trip/service run details for the run ID and route type specified.</returns>
 /// <exception cref="SwaggerException">A server side error occurred.</exception>
 public RunResponse ForRunAndRouteType(int runId, RouteTypes routeType)
 {
     return(Task.Run(async() => await ForRunAndRouteTypeAsync(runId, routeType, CancellationToken.None)).GetAwaiter().GetResult());
 }
Exemple #22
0
 /// <summary>View the trip/service run for a specific run ID and route type</summary>
 /// <param name="runId">
 ///     Identifier of a trip/service run; values returned by Runs API - /v3/route/{route_id} and Departures
 ///     API
 /// </param>
 /// <param name="routeType">Number identifying transport mode; values returned via RouteTypes API</param>
 /// <returns>The trip/service run details for the run ID and route type specified.</returns>
 /// <exception cref="SwaggerException">A server side error occurred.</exception>
 public Task <RunResponse> ForRunAndRouteTypeAsync(int runId, RouteTypes routeType)
 {
     return(ForRunAndRouteTypeAsync(runId, routeType, CancellationToken.None));
 }
Exemple #23
0
 /// <summary>View all routes of a particular type for a direction of travel</summary>
 /// <param name="directionId">
 ///     Identifier of direction of travel; values returned by Directions API -
 ///     /v3/directions/route/{route_id}
 /// </param>
 /// <param name="routeType">Number identifying transport mode; values returned via RouteTypes API</param>
 /// <returns>All routes of the specified route type that travel in the specified direction.</returns>
 /// <exception cref="SwaggerException">A server side error occurred.</exception>
 public Task <DirectionsResponse> ForDirectionAndTypeAsync(int directionId, RouteTypes routeType)
 {
     return(ForDirectionAndTypeAsync(directionId, routeType,
                                     CancellationToken.None));
 }
Exemple #24
0
 /// <summary>View all stops on a specific route</summary>
 /// <param name="routeId">Identifier of route; values returned by Routes API - v3/routes</param>
 /// <param name="routeType">Number identifying transport mode; values returned via RouteTypes API</param>
 /// <returns>All stops on the specified route.</returns>
 /// <exception cref="SwaggerException">A server side error occurred.</exception>
 public StopsOnRouteResponse StopsForRoute(int routeId, RouteTypes routeType)
 {
     return(Task.Run(async() => await StopsForRouteAsync(routeId, routeType, CancellationToken.None)).GetAwaiter().GetResult());
 }
Exemple #25
0
 /// <summary>View all routes of a particular type for a direction of travel</summary>
 /// <param name="directionId">
 ///     Identifier of direction of travel; values returned by Directions API -
 ///     /v3/directions/route/{route_id}
 /// </param>
 /// <param name="routeType">Number identifying transport mode; values returned via RouteTypes API</param>
 /// <returns>All routes of the specified route type that travel in the specified direction.</returns>
 /// <exception cref="SwaggerException">A server side error occurred.</exception>
 public DirectionsResponse ForDirectionAndType(int directionId, RouteTypes routeType)
 {
     return(Task.Run(async() => await ForDirectionAndTypeAsync(directionId, routeType, CancellationToken.None)).GetAwaiter().GetResult());
 }
Exemple #26
0
 public ChangeRouteTypeTravelEvent(double _distance,RouteTypes _type)
     : base(_distance)
 {
     System.Diagnostics.Debug.WriteLine("Added ChangeRouteTypeEvent");
      this._type = _type;
 }
Exemple #27
0
        /// <summary>View the trip/service run for a specific run ID and route type</summary>
        /// <param name="runId">
        ///     Identifier of a trip/service run; values returned by Runs API - /v3/route/{route_id} and Departures
        ///     API
        /// </param>
        /// <param name="routeType">Number identifying transport mode; values returned via RouteTypes API</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of
        ///     cancellation.
        /// </param>
        /// <returns>The trip/service run details for the run ID and route type specified.</returns>
        /// <exception cref="SwaggerException">A server side error occurred.</exception>
        public async Task <RunResponse> ForRunAndRouteTypeAsync(int runId, RouteTypes routeType, CancellationToken cancellationToken)
        {
            var urlBuilder = new StringBuilder();

            urlBuilder.Append("/v3/runs/{run_id}/route_type/{route_type}?");
            urlBuilder.Replace("{run_id}", Uri.EscapeDataString(runId.ToString()));
            urlBuilder.Replace("{route_type}", Uri.EscapeDataString(((int)routeType).ToString()));

            var client = new HttpClient();

            try
            {
                using (var request = new HttpRequestMessage())
                {
                    request.Method = new HttpMethod("GET");
                    request.Headers.Accept.Add(
                        new MediaTypeWithQualityHeaderValue("application/json"));

                    PrepareRequest(client, request, urlBuilder);
                    var url = urlBuilder.ToString();
                    request.RequestUri = new Uri(BaseUrl + url, UriKind.RelativeOrAbsolute);
                    PrepareRequest(client, request, url);

                    var response = await client.SendAsync(request,
                                                          HttpCompletionOption.ResponseHeadersRead, cancellationToken)
                                   .ConfigureAwait(false);

                    try
                    {
                        var headers = response.Headers.ToDictionary(h => h.Key, h => h.Value);
                        foreach (var item in response.Content.Headers)
                        {
                            headers[item.Key] = item.Value;
                        }

                        ProcessResponse(client, response);

                        var status = ((int)response.StatusCode).ToString();
                        if (status == "200")
                        {
                            var responseData = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                            var result = default(RunResponse);
                            try
                            {
                                result = JsonConvert.DeserializeObject <RunResponse>(responseData);
                                return(result);
                            }
                            catch (Exception exception)
                            {
                                throw new SwaggerException("Could not deserialize the response body.", status,
                                                           responseData, headers, exception);
                            }
                        }
                        else if (status == "400")
                        {
                            var responseData = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                            var result = default(ErrorResponse);
                            try
                            {
                                result = JsonConvert.DeserializeObject <ErrorResponse>(responseData);
                            }
                            catch (Exception exception)
                            {
                                throw new SwaggerException("Could not deserialize the response body.", status,
                                                           responseData, headers, exception);
                            }
                            throw new SwaggerException <ErrorResponse>("Invalid Request", status, responseData,
                                                                       headers, result, null);
                        }
                        else if (status == "403")
                        {
                            var responseData = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                            var result = default(ErrorResponse);
                            try
                            {
                                result = JsonConvert.DeserializeObject <ErrorResponse>(responseData);
                            }
                            catch (Exception exception)
                            {
                                throw new SwaggerException("Could not deserialize the response body.", status,
                                                           responseData, headers, exception);
                            }
                            throw new SwaggerException <ErrorResponse>("Access Denied", status, responseData, headers,
                                                                       result, null);
                        }
                        else if (status != "200" && status != "204")
                        {
                            var responseData = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                            throw new SwaggerException(
                                      "The HTTP status code of the response was not expected (" + (int)response.StatusCode +
                                      ").", status, responseData, headers, null);
                        }

                        return(default(RunResponse));
                    }
                    finally
                    {
                        response?.Dispose();
                    }
                }
            }
            finally
            {
                client?.Dispose();
            }
        }
Exemple #28
0
 /// <summary>View all stops on a specific route</summary>
 /// <param name="routeId">Identifier of route; values returned by Routes API - v3/routes</param>
 /// <param name="routeType">Number identifying transport mode; values returned via RouteTypes API</param>
 /// <returns>All stops on the specified route.</returns>
 /// <exception cref="SwaggerException">A server side error occurred.</exception>
 public Task <StopsOnRouteResponse> StopsForRouteAsync(int routeId, RouteTypes routeType)
 {
     return(StopsForRouteAsync(routeId, routeType, CancellationToken.None));
 }
Exemple #29
0
 /// <summary>View the stopping pattern for a specific trip/service run</summary>
 /// <param name="runId">
 ///     Identifier of a trip/service run; values returned by Runs API - /v3/route/{route_id} and Departures
 ///     API
 /// </param>
 /// <param name="routeType">Number identifying transport mode; values returned via RouteTypes API</param>
 /// <param name="stopId">Filter by stop_id; values returned by Stops API</param>
 /// <param name="dateUtc">Filter by the date and time of the request (ISO 8601 UTC format)</param>
 /// <returns>The stopping pattern of the specified trip/service run and route type.</returns>
 /// <exception cref="SwaggerException">A server side error occurred.</exception>
 public StoppingPattern GetPatternByRun(int runId, RouteTypes routeType, int?stopId, DateTime?dateUtc)
 {
     return(Task.Run(async() => await GetPatternByRunAsync(runId, routeType, stopId, dateUtc, CancellationToken.None)).GetAwaiter().GetResult());
 }