Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace AttributeRouting.Tests.Web.Areas.Api.Controllers
public class PlainController : BaseApiController
{
// GET /api/plain
[GET("")]
[GET("", MinVer = "1.0")]
public IEnumerable<string> GetAll()
{
return new [] { "value1", "value2" };
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Web.Http;
using AttributeRouting.Tests.Web.Models;
using AttributeRouting.Web.Http;

namespace AttributeRouting.Tests.Web.Areas.Api.Controllers
{
[RouteVersioned(MinVer = "1.0")]
public class VersionedController : BaseApiController
{
//
// GET: /Versioned/
[HttpGet, GET("Versioned", MaxVer = "1.1")]
public VersionedModel_old Index_old()
{
return new VersionedModel_old() {Text = "This is /versioned (up to 1.1)", GeneratedTime = DateTime.Now};
}

[HttpGet, GET("Versioned", MinVer = "1.2")]
public VersionedModel Index()
{
return new VersionedModel()
{
Title = "This is /versioned",
Body = "This model is added in 1.2, and returns title/body isntead of just text",
GeneratedTime = DateTime.Now
};
}

[HttpGet, GET("Versioned/{id}", MinVer = "1.1")]
public string Show(int id)
{
return string.Format("This is /versioned/id with id = {0}", id);
}

[HttpGet, GET("Versioned/SingleVersion", MinVer = "1.0", MaxVer = "1.0")]
public string New()
{
return "This should only work with version 1.0";
}

[HttpGet, GET("Versioned/BeforeV1", MinVer = "0.0")]
public string BeforeV1()
{
return "This existed in versions even prior to 1.0 (overrides class-level version)";
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
<Compile Include="Controllers\RenderActionController.cs" />
<Compile Include="Controllers\RestfulController.cs" />
<Compile Include="Controllers\RestfulConventionController.cs" />
<Compile Include="Areas\Api\Controllers\VersionedController.cs" />
<Compile Include="CultureAwareRouteHandler.cs" />
<Compile Include="CustomWebHostBufferPolicySelector.cs" />
<Compile Include="Global.asax.cs">
Expand Down Expand Up @@ -191,10 +192,6 @@
<Folder Include="Areas\Subdomain\Views\Shared\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AttributeRouting.Web\AttributeRouting.Web.csproj">
<Project>{C91C065B-A821-4890-9F31-F9E245D804D1}</Project>
<Name>AttributeRouting.Web</Name>
</ProjectReference>
<ProjectReference Include="..\AttributeRouting.Web.Http\AttributeRouting.Web.Http.csproj">
<Project>{CCDE9AD7-3822-4B0B-AA19-DF6698A85D3D}</Project>
<Name>AttributeRouting.Web.Http</Name>
Expand All @@ -207,6 +204,10 @@
<Project>{A018FEC5-45F8-44FB-BB6C-33697B418434}</Project>
<Name>AttributeRouting.Web.Http.WebHost</Name>
</ProjectReference>
<ProjectReference Include="..\AttributeRouting.Web\AttributeRouting.Web.csproj">
<Project>{C91C065B-A821-4890-9F31-F9E245D804D1}</Project>
<Name>AttributeRouting.Web</Name>
</ProjectReference>
<ProjectReference Include="..\AttributeRouting\AttributeRouting.csproj">
<Project>{871A79CF-C705-4C6B-8938-F9AA1E02AEA4}</Project>
<Name>AttributeRouting</Name>
Expand Down
4 changes: 3 additions & 1 deletion src/AttributeRouting.Tests.Web/Global.asax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public static void RegisterRoutes(RouteCollection routes)
config.AddRoutesFromAssemblyOf<MvcApplication>();
config.AddDefaultRouteConstraint(@"[Ii]d$", new RegexRouteConstraint(@"^\d+$"));
config.UseRouteHandler(() => new HttpCultureAwareRoutingHandler());
config.AddTranslationProvider(translationProvider);
config.AddTranslationProvider(translationProvider);
config.AddVersions("0.9","1.0","1.1","1.2");
config.UseLowercaseRoutes = true;
config.InheritActionsFromBaseController = true;
config.AutoGenerateRouteNames = true;
Expand All @@ -79,6 +80,7 @@ public static void RegisterRoutes(RouteCollection routes)
config.AddRoutesFromAssemblyOf<MvcApplication>();
config.AddDefaultRouteConstraint(@"[Ii]d$", new RegexRouteConstraint(@"^\d+$"));
config.AddTranslationProvider(translationProvider);
config.AddVersions("0.9", "1.0", "1.1", "1.2");
config.UseRouteHandler(() => new CultureAwareRouteHandler());
config.UseLowercaseRoutes = true;
config.InheritActionsFromBaseController = true;
Expand Down
20 changes: 20 additions & 0 deletions src/AttributeRouting.Tests.Web/Models/VersionedModels.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AttributeRouting.Tests.Web.Models
{
public class VersionedModel_old
{
public string Text { get; set; }
public DateTime GeneratedTime { get; set; }
}

public class VersionedModel
{
public string Title { get; set; }
public string Body { get; set; }
public DateTime GeneratedTime { get; set; }
}
}
4 changes: 2 additions & 2 deletions src/AttributeRouting.Tests.Web/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@
</namespaces>
</pages>
<httpHandlers>
<add path="routes.axd" verb="*" type="AttributeRouting.Web.Logging.LogRoutesHandler, AttributeRouting.Web, Version=1.0.0.0, Culture=neutral" />
<add path="routes.axd" verb="*" type="AttributeRouting.Web.Logging.LogRoutesHandler, AttributeRouting.Web" />
</httpHandlers>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<add name="AttributeRouting" path="routes.axd" verb="*" type="AttributeRouting.Web.Logging.LogRoutesHandler, AttributeRouting.Web, Version=1.0.0.0, Culture=neutral" />
<add name="AttributeRouting" path="routes.axd" verb="*" type="AttributeRouting.Web.Logging.LogRoutesHandler, AttributeRouting.Web" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
Expand Down
9 changes: 7 additions & 2 deletions src/AttributeRouting.Web.Http/Framework/HttpAttributeRoute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ public string Url

public bool? PreserveCaseForUrlParameters { get; set; }

public bool? AppendTrailingSlash { get; set; }
public bool? AppendTrailingSlash { get; set; }

public SemanticVersion MinVersion { get; set; }

public SemanticVersion MaxVersion { get; set; }


IDictionary<string, object> IAttributeRoute.DataTokens
{
Expand Down Expand Up @@ -109,6 +114,6 @@ public override IHttpVirtualPathData GetVirtualPath(HttpRequestMessage request,
var virtualPath = this.GetFinalVirtualPath(virtualPathData.VirtualPath, _configuration);

return new HttpVirtualPathData(virtualPathData.Route, virtualPath);
}
}
}
}
26 changes: 25 additions & 1 deletion src/AttributeRouting.Web.Http/HttpRouteAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,29 @@ public bool AppendTrailingSlash
public bool IgnoreRoutePrefix { get; set; }

public bool IgnoreAreaUrl { get; set; }
}

public bool IsVersioned { get; set; }

public SemanticVersion MinVersion { get; set; }

public SemanticVersion MaxVersion { get; set; }

/// <summary>
/// Shortcut to set <see cref="MinVersion"/> with a string
/// </summary>
public string MinVer
{
get { return MinVersion.ToString(); }
set { MinVersion = SemanticVersion.Parse(value, allowNull: true); }
}

/// <summary>
/// Shortcut to set <see cref="MaxVersion"/> with a string
/// </summary>
public string MaxVer
{
get { return MaxVersion.ToString(); }
set { MaxVersion = SemanticVersion.Parse(value, allowNull: true); }
}
}
}
6 changes: 5 additions & 1 deletion src/AttributeRouting.Web.Mvc/Framework/AttributeRoute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ public AttributeRoute(string url,

public bool? PreserveCaseForUrlParameters { get; set; }

public bool? AppendTrailingSlash { get; set; }
public bool? AppendTrailingSlash { get; set; }

public SemanticVersion MinVersion { get; set; }

public SemanticVersion MaxVersion { get; set; }

IDictionary<string, object> IAttributeRoute.DataTokens
{
Expand Down
25 changes: 25 additions & 0 deletions src/AttributeRouting.Web.Mvc/RouteAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,30 @@ public override bool IsValidForRequest(ControllerContext controllerContext, Meth

return HttpMethods.Any(m => m.ValueEquals(httpMethod));
}

public bool IsVersioned { get; set; }

public SemanticVersion MinVersion { get; set; }

public SemanticVersion MaxVersion { get; set; }

/// <summary>
/// Shortcut to set <see cref="MinVersion"/> with a string
/// </summary>
public string MinVer
{
get { return MinVersion.ToString(); }
set { MinVersion = SemanticVersion.Parse(value, allowNull: true); }
}

/// <summary>
/// Shortcut to set <see cref="MaxVersion"/> with a string
/// </summary>
public string MaxVer
{
get { return MaxVersion.ToString(); }
set { MaxVersion = SemanticVersion.Parse(value, allowNull: true); }
}

}
}
3 changes: 3 additions & 0 deletions src/AttributeRouting/AttributeRouting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand Down Expand Up @@ -109,6 +110,8 @@
<Compile Include="Framework\RouteSpecification.cs" />
<Compile Include="Framework\RouteReflector.cs" />
<Compile Include="Framework\SubdomainParsers.cs" />
<Compile Include="RouteVersionedAttribute.cs" />
<Compile Include="SemanticVersion.cs" />
</ItemGroup>
<ItemGroup>
<None Include="AttributeRouting.snk" />
Expand Down
33 changes: 31 additions & 2 deletions src/AttributeRouting/ConfigurationBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ protected ConfigurationBase()
Assemblies = new List<Assembly>();
OrderedControllerTypes = new List<Type>();

InheritActionsFromBaseController = false;
InheritActionsFromBaseController = false;

ApiVersions = new List<SemanticVersion>();

// Constraint setting initialization
DefaultRouteConstraints = new Dictionary<string, object>();
Expand Down Expand Up @@ -134,7 +136,14 @@ protected ConfigurationBase()
/// Constrains translated routes by the thread's current UI culture.
/// The default is false.
/// </summary>
public bool ConstrainTranslatedRoutesByCurrentUICulture { get; set; }
public bool ConstrainTranslatedRoutesByCurrentUICulture { get; set; }


/// <summary>
/// List of supported API versions
/// </summary>
public List<SemanticVersion> ApiVersions { get; set; }


/// <summary>
/// Returns a utility for configuring areas when initializing AttributeRouting framework.
Expand Down Expand Up @@ -278,5 +287,25 @@ where typeof(TRouteConstraint).IsAssignableFrom(t)
InlineRouteConstraints.Add(name, inlineConstraintType);
}
}

/// <summary>
/// Adds to the list of supported <see cref="ApiVersions"/>.
/// </summary>
public void AddVersions(params string[] versions)
{
foreach (var version in versions)
{
ApiVersions.Add(SemanticVersion.Parse(version));
}
}


/// <summary>
/// Adds to the list of supported <see cref="ApiVersions"/>.
/// </summary>
public void AddVersions(params SemanticVersion[] versions)
{
ApiVersions.AddRange(versions);
}
}
}
12 changes: 12 additions & 0 deletions src/AttributeRouting/Framework/IAttributeRoute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ public interface IAttributeRoute

/// <summary>
/// Default route container back-reference, used to organize route translations.
/// Minimum supported version, or null for no minimum
/// </summary>
SemanticVersion MinVersion { get; set; }

/// <summary>
/// Maximum supported version, or null for no maximum
/// </summary>
SemanticVersion MaxVersion { get; set; }


/// <summary>
/// Default route container back-reference
/// </summary>
IAttributeRoute DefaultRouteContainer { get; set; }
}
Expand Down
Loading