Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to RESTier 1.0 #217

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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 @@ -125,7 +125,7 @@ public IQueryable<Airport> Airports
/// <returns>
/// <see cref="Person">
/// </returns>
[Operation(EntitySet = "People")]
[UnboundOperation(EntitySet ="People")]
public Person GetPersonWithMostFriends()
{
Person result = null;
Expand Down Expand Up @@ -158,7 +158,7 @@ public Person GetPersonWithMostFriends()
/// <returns>
/// <see cref="Airport">
/// </returns>
[Operation(EntitySet = "Airports")]
[UnboundOperation(EntitySet = "Airports")]
public Airport GetNearestAirport(double lat, double lon)
{
var startPoint = GeographyPoint.Create(lat, lon);
Expand All @@ -178,7 +178,7 @@ public Airport GetNearestAirport(double lat, double lon)
return nearestAirport;
}

[Operation(IsBound = true)]
[BoundOperation()]
public Airline GetFavoriteAirline(Person person)
{
var countDict = new Dictionary<string, int>();
Expand Down Expand Up @@ -216,7 +216,7 @@ public Airline GetFavoriteAirline(Person person)
/// <summary>
/// Bound Function, get the trips of one friend with userName
/// </summary>
[Operation(IsBound = true)]
[BoundOperation()]
public ICollection<Trip> GetFriendsTrips(Person person, string userName)
{
var friends = person.Friends.Where(p => p.UserName.Equals(userName)).ToArray();
Expand All @@ -231,7 +231,7 @@ public ICollection<Trip> GetFriendsTrips(Person person, string userName)
}
}

[Operation(IsBound = true)]
[BoundOperation()]
public ICollection<Person> GetInvolvedPeople(Trip trip)
{
var shareID = trip.ShareId;
Expand All @@ -258,7 +258,7 @@ public ICollection<Person> GetInvolvedPeople(Trip trip)
/// <summary>
/// Unbound action, reset datasource.
/// </summary>
[Operation(OperationType = OperationType.Action)]
[UnboundOperation(OperationType = OperationType.Action)]
public void ResetDataSource()
{
DataStoreManager.ResetDataStoreInstance(Key);
Expand All @@ -270,7 +270,7 @@ public void ResetDataSource()
/// <param name="person">The person to be updated.</param>
/// <param name="lastName">The value of last name to be updated.</param>
/// <returns>True if update successfully.</returns>
[Operation(IsBound = true, OperationType = OperationType.Action)]
[BoundOperation(OperationType = OperationType.Action)]
public bool UpdateLastName(Person person, string lastName)
{
if (person != null)
Expand All @@ -284,7 +284,7 @@ public bool UpdateLastName(Person person, string lastName)
}
}

[Operation(IsBound = true, OperationType = OperationType.Action)]
[BoundOperation(OperationType = OperationType.Action)]
public void ShareTrip(Person personInstance, string userName, int tripId)
{
if (personInstance == null)
Expand Down Expand Up @@ -343,15 +343,15 @@ private static double CalculateDistance(GeographyPoint p1, GeographyPoint p2)

internal class ModelBuilder : IModelBuilder
{
public Task<IEdmModel> GetModelAsync(ModelContext context, CancellationToken cancellationToken)
public IEdmModel GetModel(ModelContext context)
{
var modelBuilder = new ODataConventionModelBuilder();
modelBuilder.Namespace = "Trippin";
modelBuilder.EntitySet<Person>("People");
modelBuilder.EntitySet<Airline>("Airlines");
modelBuilder.EntitySet<Airport>("Airports");
modelBuilder.Singleton<Person>("Me");
return Task.FromResult(modelBuilder.GetEdmModel());
return modelBuilder.GetEdmModel();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static void Register(HttpConfiguration config)
config.SetUrlKeyDelimiter(ODataUrlKeyDelimiter.Slash);
config.EnableCors(new EnableCorsAttribute("*", "*", "*"));
config.Routes.MapHttpRoute("Options", "{*OPTIONS}", new { controller = "CORS", action = "Options" }, new { Options = new myHttpRouteConstraint()});
config.UseRestier<TrippinApi>((services) =>
config.UseRestier((builder) =>
{
Func<IServiceProvider, IDataStoreManager<string, TripPinDataSource>> defaultDataStoreManager =
sp => new DefaultDataStoreManager<string, TripPinDataSource>()
Expand All @@ -49,16 +49,20 @@ public static void Register(HttpConfiguration config)
MaxExpansionDepth = 4
};

services.AddSingleton<ODataValidationSettings>(validationSettingFactory);
services.AddChainedService<IModelBuilder>((sp, next) => new TrippinApi.ModelBuilder());
services.AddChainedService<IChangeSetInitializer>((sp, next) => new ChangeSetInitializer<TripPinDataSource>());
services.AddChainedService<ISubmitExecutor>((sp, next) => new SubmitExecutor());
services.AddSingleton(defaultDataStoreManager);
builder.AddRestierApi<TrippinApi>((services) =>
{
services.AddSingleton<ODataValidationSettings>(validationSettingFactory);
services.AddChainedService<IModelBuilder>((sp, next) => new TrippinApi.ModelBuilder());
services.AddChainedService<IChangeSetInitializer>((sp, next) => new ChangeSetInitializer<TripPinDataSource>());
services.AddChainedService<ISubmitExecutor>((sp, next) => new SubmitExecutor());
services.AddSingleton(defaultDataStoreManager);

// Add custom TrippinBatchHandler
ODataBatchHandler trippinBatchHandler = new TrippinBatchHandler(GlobalConfiguration.DefaultServer);
trippinBatchHandler.ODataRouteName = routeName;
services.AddSingleton(trippinBatchHandler);
// Add custom TrippinBatchHandler
ODataBatchHandler trippinBatchHandler = new TrippinBatchHandler(GlobalConfiguration.DefaultServer);
trippinBatchHandler.ODataRouteName = routeName;
services.AddSingleton(trippinBatchHandler);
}
);
});

RegisterTrippin(config, GlobalConfiguration.DefaultServer);
Expand All @@ -71,10 +75,12 @@ public static void RegisterTrippin(
// enable query options for all properties
config.Filter().Expand().Select().OrderBy().MaxTop(null).Count();
config.SetTimeZoneInfo(TimeZoneInfo.Utc);
config.MapRestier<TrippinApi>(
config.MapRestier((builder) =>
builder.MapApiRoute<TrippinApi>(
routeName,
"",
false); // Custom TrippinBatchHandler registered in UseRestier
false) // Custom TrippinBatchHandler registered in UseRestier
);
}
}
public class myHttpRouteConstraint : IHttpRouteConstraint
Expand Down
Loading