public void RouteInfoComparisonTest() { // Create route infos and add them to a list out of order. RouteInfo r101Both = new RouteInfo { Name = "101", LrsTypes = LrsTypes.Both }; RouteInfo r005Both = new RouteInfo { Name = "005", LrsTypes = LrsTypes.Both }; RouteInfo r005Inc = new RouteInfo { Name = "005", LrsTypes = LrsTypes.Increase }; List<RouteInfo> routeInfo = new List<RouteInfo>(); routeInfo = new List<RouteInfo>(3); routeInfo.Add(r101Both); routeInfo.Add(r005Both); routeInfo.Add(r005Inc); // Sort the list and test for the expected order. routeInfo.Sort(); Assert.AreEqual(routeInfo[0], r005Inc); Assert.AreEqual(routeInfo[1], r005Both); Assert.AreEqual(routeInfo[2], r101Both); }
public void UrlParameters_Returns_ParametersDefinedOnTheAttribute() { var routeInfo = new RouteInfo(_testMethod); var urlParameters = routeInfo.QueryParameters; var parameters = string.Join(",", urlParameters.Select(a => a.Name)); Assert.Equal("p1,p2,p3,gender,date,list,numbers", parameters); }
public ActionResult OEmbed(string url, int maxwidth = 570, int maxheight = 400, DataFormat format = DataFormat.Json) { if (string.IsNullOrEmpty(url)) return HttpStatusCodeResult(HttpStatusCode.BadRequest, "URL not specified"); var route = new RouteInfo(new Uri(url), AppConfig.HostAddress).RouteData; var controller = route.Values["controller"].ToString().ToLowerInvariant(); if (controller != "song" && controller != "s") { return HttpStatusCodeResult(HttpStatusCode.BadRequest, "Only song embeds are supported"); } int id; if (controller == "s") { var match = Regex.Match(route.Values["action"].ToString(), @"(\d+)"); id = int.Parse(match.Groups[1].Value); } else { id = int.Parse(route.Values["id"].ToString()); } var song = Services.Songs.GetSong(id); var html = string.Format("<iframe src=\"{0}\" width=\"{1}\" height=\"{2}\"></iframe>", VocaUriBuilder.CreateAbsolute(Url.Action("EmbedSong", new {songId = id})), maxwidth, maxheight); return Object(new SongOEmbedResponse(song, maxwidth, maxheight, html), format); }
public RouteDetail(RouteInfo routeInfo, Func<Type, ModelDescription> modelDescriptionCreator) { _routeInfo = routeInfo; _modelDescriptionCreator = modelDescriptionCreator; LoadUrlParameters(); LoadBodyParameter(); LoadReturnParameter(); }
public void ReturnParameter_Returns_ReturnParameter() { var routeInfo = new RouteInfo(_testMethod); var returnParameter = routeInfo.ReturnParameter; Assert.NotNull(returnParameter); Assert.Equal(typeof(TestResult), returnParameter.ParameterType); }
public void HandlesRoutesWithNoConstraints() { var constraints = new RouteValueDictionary(); var routeInfo = new RouteInfo { Constraints = new RouteValueDictionary() }; var processor = new ConstraintsProcessor(); processor.ProcessConstraints(constraints, routeInfo); Assert.AreEqual(0, routeInfo.Constraints.Count); }
public virtual void Begin(HttpRequest req, HttpResponse res, RouteInfo route, Application app) { this.Request = req; this.Response = res; this.RouteInfo = route; this.App = app; // Start the show this.PreHandle(); }
public void IncludesRegExpConstraints() { var constraints = new RouteValueDictionary {{"id", @"\d+"}}; var routeInfo = new RouteInfo { Constraints = new RouteValueDictionary() }; var processor = new ConstraintsProcessor(); processor.ProcessConstraints(constraints, routeInfo); Assert.AreEqual(1, routeInfo.Constraints.Count); Assert.AreEqual(@"\d+", routeInfo.Constraints["id"]); }
public static MvcHtmlString RouteLinkExists(this HtmlHelper helper, RouteInfo routeInfo) { bool isNotAuthType = true; if (routeInfo.AccessType == RouteAccessType.Auth) { foreach (string role in Roles.GetRolesForUser()) { var userType = (WFSUserTypeEnum)Enum.Parse(typeof(WFSUserTypeEnum), role); if (isNotAuthType) isNotAuthType = !((routeInfo.UserType == userType) && routeInfo.AccessType == RouteAccessType.Auth); } } else { isNotAuthType = false; } bool isNotAuth = HttpContext.Current.User.Identity.IsAuthenticated && routeInfo.AccessType == RouteAccessType.NonAuth; bool isAuth = HttpContext.Current.User.Identity.IsAuthenticated && routeInfo.AccessType == RouteAccessType.NonAuth; bool isActive = routeInfo.IsActive(); // auth type filter if (isNotAuth || isNotAuthType || !isActive) { return new MvcHtmlString(string.Empty); } if (helper.RouteCollection[routeInfo.RouteName] == null) { throw new Exception(string.Format(EXC_ROUTE_NOTFOUND, routeInfo.RouteName)); } string area = (((System.Web.Routing.Route)(helper.RouteCollection[routeInfo.RouteName])).DataTokens["area"] ?? "").ToString(); string currentArea = (helper.ViewContext.RouteData.DataTokens["area"] ?? "").ToString(); string url = String.Format("/{0}", ((System.Web.Routing.Route)(helper.RouteCollection[routeInfo.RouteName])).Url); if (routeInfo.IsDisabled()) { return new MvcHtmlString(string.Format(TMP_URL, "disabledMenuItem", "", helper.RouteLink(routeInfo.LinkText, routeInfo.RouteName, routeInfo.RouteValues, routeInfo.HtmlAttributes).ToHtmlString())); } else if (url == HttpContext.Current.Request.Url.AbsolutePath) { return new MvcHtmlString(string.Format(TMP_URL, "active", routeInfo.RouteMatchClass, helper.RouteLink(routeInfo.LinkText, routeInfo.RouteName, routeInfo.RouteValues, routeInfo.HtmlAttributes).ToHtmlString())); } else if (area == currentArea && !routeInfo.ExactMatch) { return new MvcHtmlString(string.Format(TMP_URL, "", "", helper.RouteLink(routeInfo.LinkText, routeInfo.RouteName, routeInfo.RouteValues, routeInfo.HtmlAttributes).ToHtmlString())); } return new MvcHtmlString(string.Format(TMP_URL, "", "", helper.RouteLink(routeInfo.LinkText, routeInfo.RouteName, routeInfo.RouteValues, routeInfo.HtmlAttributes).ToHtmlString())); }
private RouteInfo Parse(string template) { var parser = new RouteTemplateParser(); var parsedTemplate = TemplateParser.Parse(template); var info = new RouteInfo { Defaults = new Dictionary<string, object>(), Optional = new List<string>(), }; parser.Parse(parsedTemplate, info); return info; }
public static MvcHtmlString RouteLinkExists(this HtmlHelper helper, string linkText, string routeName, object routeValues, object htmlAttributes, string routeMatchesClass, bool exactMatch) { RouteInfo routeInfo = new RouteInfo(); routeInfo.AccessType = RouteAccessType.All; routeInfo.ExactMatch = exactMatch; routeInfo.HtmlAttributes = htmlAttributes; routeInfo.LinkText = linkText; routeInfo.RouteMatchClass = routeMatchesClass; routeInfo.RouteName = routeName; routeInfo.RouteValues = routeValues; return helper.RouteLinkExists(routeInfo); }
public void ExcludesCustomConstraints() { var customConstraint = new Mock<IRouteConstraint>(); var constraints = new RouteValueDictionary { { "id", @"\d+" }, { "awesome", customConstraint }, }; var routeInfo = new RouteInfo { Constraints = new RouteValueDictionary() }; var processor = new ConstraintsProcessor(); processor.ProcessConstraints(constraints, routeInfo); Assert.AreEqual(1, routeInfo.Constraints.Count); }
private static IEnumerable<RouteInfo> GetRouteInfo() { var items = new List<RouteInfo>(); foreach (var route in RouteTable.Routes.Cast<Route>()) { var item = new RouteInfo { Url = route.Url }; if (route.Defaults != null) { foreach (var @default in route.Defaults) item.Defaults.Add(@default.Key, @default.Value.ToString()); } if (route.Constraints != null) { foreach (var constraint in route.Constraints) { if (constraint.Value == null) continue; if (constraint.Value.GetType() == typeof(RestfulHttpMethodConstraint)) item.HttpMethod = String.Join(", ", ((RestfulHttpMethodConstraint)constraint.Value).AllowedMethods); else if (constraint.Value.GetType() == typeof(RegexRouteConstraint)) item.Constraints.Add(constraint.Key, ((RegexRouteConstraint)constraint.Value).Pattern); else item.Constraints.Add(constraint.Key, constraint.Value.ToString()); } } if (route.DataTokens != null) { foreach (var token in route.DataTokens) { if (token.Key.ValueEquals("namespaces")) item.DataTokens.Add(token.Key, ((string[])token.Value).Aggregate((n1, n2) => n1 + ", " + n2)); else item.DataTokens.Add(token.Key, token.Value.ToString()); } } items.Add(item); } return items; }
public ActionResult EntryToolTip(string url, string callback) { var route = new RouteInfo(new Uri(url), AppConfig.HostAddress).RouteData; var controller = route.Values["controller"].ToString(); var id = int.Parse(route.Values["id"].ToString()); string data = string.Empty; switch (controller) { case "Album": data = RenderPartialViewToString("AlbumWithCoverPopupContent", Services.Albums.GetAlbum(id)); break; case "Artist": data = RenderPartialViewToString("ArtistPopupContent", Services.Artists.GetArtist(id)); break; } return Json(data, callback); }
protected void OnTableListingRequest(TableListingRequest listingRequest, RouteInfo routeInfo) { TableListingResponse listingResponse = new TableListingResponse(); listingResponse.ResponseId = listingRequest.RequestId; listingResponse.TableSummaries = Manager.Tables.GetTableSummaries(); ClientBoundSeverEnvelopeObject envelope = new ClientBoundSeverEnvelopeObject(); envelope.InnerData = Manager.Serializer.GetBytes(listingResponse); envelope.InnerOperationCode = (int)GameMessageType.Client_ReceiveTableListingResponse; envelope.SenderServerId = Manager.ServerInfo.ServerId; envelope.PlayerNames = listingRequest.PlayerName.ToList(); OutgoingMessage outgoingMessage = ServerMessageFormatter.CreateOutgoingMessage( (int)ServerMessageType.ReceiveForwardMessageToClientRequest, Manager.Serializer.GetBytes(envelope), Manager.ResolveServers(routeInfo.GatewayServerId.ToList())); Manager.InternalOutgoingMessageQueue.Add(outgoingMessage); }
public GisDataPump() { Task.Factory.StartNew(() => { ril = new List<RouteInfo>(); //read all route-files into RouteInfoObjects. foreach (var routeFile in Directory.GetFiles(routeDictionary, "*.json")) { var file = new FileInfo(routeFile); //Send data to client when movement is detected (or faked in this case) var ri = new RouteInfo(file, (id, geodata) => { this.InvokeToAll<GeoCars>(new { id, geodata },"pos"); }); ril.Add(ri); var r = new Random(42); ri.Start(r.Next(1000,5000)); } }); }
public ActionResult EntryToolTip(string url, string callback) { if (string.IsNullOrWhiteSpace(url)) return HttpStatusCodeResult(HttpStatusCode.BadRequest, "URL must be specified"); var route = new RouteInfo(new Uri(url), AppConfig.HostAddress, HttpContext).RouteData; var controller = route.Values["controller"].ToString(); var id = int.Parse(route.Values["id"].ToString()); string data = string.Empty; switch (controller) { case "Album": data = RenderPartialViewToString("AlbumWithCoverPopupContent", Services.Albums.GetAlbum(id)); break; case "Artist": data = RenderPartialViewToString("ArtistPopupContent", Services.Artists.GetArtist(id)); break; case "Song": data = RenderPartialViewToString("SongPopupContent", Services.Songs.GetSongWithPVAndVote(id)); break; } return Json(data, callback); }
private static RouteInfo GetRouteInfo( IInlineConstraintResolver constraintResolver, Dictionary<string, RouteTemplate> templateCache, ActionDescriptor action) { var constraint = action.RouteConstraints .Where(c => c.RouteKey == AttributeRouting.RouteGroupKey) .FirstOrDefault(); if (constraint == null || constraint.KeyHandling != RouteKeyHandling.RequireKey || constraint.RouteValue == null) { // This can happen if an ActionDescriptor has a route template, but doesn't have one of our // special route group constraints. This is a good indication that the user is using a 3rd party // routing system, or has customized their ADs in a way that we can no longer understand them. // // We just treat this case as an 'opt-out' of our attribute routing system. return null; } var routeInfo = new RouteInfo() { ActionDescriptor = action, RouteGroup = constraint.RouteValue, RouteTemplate = action.AttributeRouteInfo.Template, }; try { RouteTemplate parsedTemplate; if (!templateCache.TryGetValue(action.AttributeRouteInfo.Template, out parsedTemplate)) { // Parsing with throw if the template is invalid. parsedTemplate = TemplateParser.Parse(action.AttributeRouteInfo.Template); templateCache.Add(action.AttributeRouteInfo.Template, parsedTemplate); } routeInfo.ParsedTemplate = parsedTemplate; } catch (Exception ex) { routeInfo.ErrorMessage = ex.Message; return routeInfo; } foreach (var kvp in action.RouteValueDefaults) { foreach (var parameter in routeInfo.ParsedTemplate.Parameters) { if (string.Equals(kvp.Key, parameter.Name, StringComparison.OrdinalIgnoreCase)) { routeInfo.ErrorMessage = Resources.FormatAttributeRoute_CannotContainParameter( routeInfo.RouteTemplate, kvp.Key, kvp.Value); return routeInfo; } } } routeInfo.Order = action.AttributeRouteInfo.Order; routeInfo.Precedence = AttributeRoutePrecedence.Compute(routeInfo.ParsedTemplate); routeInfo.Name = action.AttributeRouteInfo.Name; var constraintBuilder = new RouteConstraintBuilder(constraintResolver, routeInfo.RouteTemplate); foreach (var parameter in routeInfo.ParsedTemplate.Parameters) { if (parameter.InlineConstraints != null) { if (parameter.IsOptional) { constraintBuilder.SetOptional(parameter.Name); } foreach (var inlineConstraint in parameter.InlineConstraints) { constraintBuilder.AddResolvedConstraint(parameter.Name, inlineConstraint.Constraint); } } } routeInfo.Constraints = constraintBuilder.Build(); routeInfo.Defaults = routeInfo.ParsedTemplate.Parameters .Where(p => p.DefaultValue != null) .ToDictionary(p => p.Name, p => p.DefaultValue, StringComparer.OrdinalIgnoreCase); return routeInfo; }
public RouteSummary(RouteInfo routeInfo, string helpModulePath) { _helpModulePath = RouteInfo.CleanPath(helpModulePath); Name = RouteInfo.CleanPath(routeInfo.Name); HttpMethod = routeInfo.HttpMethod; }
protected void OnJoinTableRequestReceived(JoinTableRequest jtr, RouteInfo routeInfo) { var myEvent = JoinTableRequestReceived; if (myEvent != null) { myEvent(this, new JoinTableEventArgs(jtr, routeInfo)); } }
public virtual void SendEnvelopeObjectToServer(GameMessageType messageType, byte[] innerData, List<IPEndPoint> receivers, RouteInfo routeInfo) { ServerEnvelopeObject envelope = new ServerEnvelopeObject(); envelope.InnerOperationCode = (int)messageType; envelope.InnerData = innerData; envelope.SenderServerId = ServerId; envelope.RouteInfo = routeInfo; OutgoingMessage com = ServerMessageFormatter.CreateOutgoingMessage( (int)ServerMessageType.ReceiveForwardedMessageFromClient, Serializer.GetBytes(envelope), receivers); InternalOutgoingMessageQueue.Add(com); }
/// <summary> /// creating a default route under the creating area /// </summary> public void RouteNACreateUnderTheArea() { try { RouteBll BllRoute = new RouteBll(); RouteInfo infoRoute = new RouteInfo(); infoRoute.RouteName = "NA"; infoRoute.AreaId = decAreaId; infoRoute.Narration = txtNarration.Text.Trim(); infoRoute.Extra1 = string.Empty; infoRoute.Extra2 = string.Empty; infoRoute.ExtraDate = DateTime.Today; BllRoute.RouteAdd(infoRoute); } catch (Exception ex) { MessageBox.Show("AR2" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// On double clicking on the datagridview, It displays the details of the rack to edit or delete /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvRoute_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { try { if (e.RowIndex != -1) { if (dgvRoute.Rows[e.RowIndex].Cells["dgvtxtRouteName"].Value.ToString() != "NA") { RouteBll BllRoute = new RouteBll(); RouteInfo infoRoute = new RouteInfo(); infoRoute = BllRoute.RouteView(Convert.ToDecimal(dgvRoute.CurrentRow.Cells["dgvtxtRouteId"].Value.ToString())); decRouteId = Convert.ToDecimal(dgvRoute.CurrentRow.Cells["dgvtxtRouteId"].Value.ToString()); txtRouteName.Text = infoRoute.RouteName; cmbArea.SelectedValue = infoRoute.AreaId.ToString(); txtNarration.Text = infoRoute.Narration; btnSave.Text = "Update"; btnDelete.Enabled = true; txtRouteName.Focus(); } else { Messages.InformationMessage("Default Route cannot update or delete"); Clear(); } } } catch (Exception ex) { MessageBox.Show("RT19" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Function to save the new route /// </summary> public void SaveFunction() { try { RouteBll BllRoute = new RouteBll(); RouteInfo infoRoute = new RouteInfo(); infoRoute.RouteName = txtRouteName.Text.Trim(); infoRoute.AreaId = Convert.ToDecimal(cmbArea.SelectedValue.ToString()); infoRoute.Narration = txtNarration.Text.Trim(); infoRoute.Extra1 = String.Empty; infoRoute.Extra2 = String.Empty; if (BllRoute.RouteCheckExistence(txtRouteName.Text.Trim(), 0, Convert.ToDecimal(cmbArea.SelectedValue.ToString())) == false) { decRoute = BllRoute.RouteAddParticularFields(infoRoute); { Messages.SavedMessage(); Clear(); GridFill(); if (frmCustomerobj != null) { this.Close(); } } } else { Messages.InformationMessage(" Route name already exist"); txtRouteName.Focus(); } } catch (Exception ex) { MessageBox.Show("RT4" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Function to edit already existing route /// </summary> public void EditFunction() { try { RouteBll BllRoute = new RouteBll(); RouteInfo infoRoute = new RouteInfo(); infoRoute.RouteName = txtRouteName.Text.Trim(); infoRoute.AreaId = Convert.ToDecimal(cmbArea.SelectedValue.ToString()); infoRoute.Narration = txtNarration.Text.Trim(); infoRoute.Extra1 = String.Empty; infoRoute.Extra2 = String.Empty; infoRoute.RouteId = decRouteId; if (BllRoute.RouteCheckExistence(txtRouteName.Text.Trim(), decRouteId, Convert.ToDecimal(cmbArea.SelectedValue.ToString())) == false) { if (BllRoute.RouteEditing(infoRoute)) { Messages.UpdatedMessage(); GridFill(); Clear(); } else if (infoRoute.RouteId == 1) { Messages.InformationMessage("Cannot update"); Clear(); txtRouteName.Focus(); } } else { Messages.InformationMessage(" Route name already exist"); txtRouteName.Focus(); } } catch (Exception ex) { MessageBox.Show("RT5" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private RouteCost RequestRouteCost(RouteType routeType) { _routeDetails = new RouteDetails(); _routeDetails.descriptionType = Config.DesciptionType; _routeDetails.optimizeRoute = true; _routeDetails.routeType = Convert.ToInt32(routeType); _routeOptions.routeDetails = _routeDetails; using (var routeSoapClient = new RouteSoapClient()) { _routeInfo = routeSoapClient.getRoute(GenerateRouteStop(), _routeOptions, _token); } return new RouteCost { TotalDistance = _routeInfo.routeTotals.totalDistance, TotalFuelCost = _routeInfo.routeTotals.totalfuelCost, TotalCostWithToll = _routeInfo.routeTotals.totalCost, TotalTimeRote = _routeInfo.routeTotals.totalTime }; }
public JoinTableEventArgs(JoinTableRequest request, RouteInfo routeInfo) { Request = request; RouteInfo = routeInfo; }
public static void Map(this RouteCollection collection, RouteInfo rootRoute) { foreach (RouteInfo ri in rootRoute.TreeStructureToList()) collection.MapPageRoute(ri.GetRouteName(), ri.GetRouteUrl(), string.Empty); }
public void RouteInfoEqualityTest() { RouteInfo r1, r2; // Test two values that should be equal. r1 = new RouteInfo { Name = "005", LrsTypes = LrsTypes.Both }; r2 = new RouteInfo { Name = "005", LrsTypes = LrsTypes.Both }; Assert.AreEqual<RouteInfo>(r1, r2, "{0} should equal {1}.", r1, r2); r2.LrsTypes = LrsTypes.Decrease; Assert.AreNotEqual<RouteInfo>(r1, r2, "{0} should not equal {1}", r1, r2); }
public static RouteInfo ToRouteInfo(this ConnectionRecord record, string gatewayServerId) { RouteInfo routeInfo = new RouteInfo(); routeInfo.GatewayServerId = gatewayServerId; routeInfo.GameServerId = record.GameServerId; routeInfo.TableId = record.TableId; return routeInfo; }