This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); | |
builder.EntitySet<EfContext>("EfContext"); | |
IEdmModel model = builder.GetEdmModel(); | |
var odataFormatters = ODataMediaTypeFormatters.Create(model); | |
var delta = content.ReadAsAsync(type, odataFormatters).Result; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Dictionary<string, Tuple<object, object>> GetChanges(TEntityType original) | |
{ | |
if (original == null) | |
{ | |
throw new ArgumentNullException("original"); | |
} | |
if (!_entityType.IsAssignableFrom(original.GetType())) | |
{ | |
throw new InvalidOperationException(string.Format("Entity mismatch exception between {0} and {1}", _entityType, original.GetType())); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
config.MessageHandlers.Add(new CachingHandler | |
{ | |
UriTrimmer = (uri) => uri.LocalPath, | |
LinkedRoutePatternProvider = LinkedRoutePatternProvider | |
}); | |
public static IEnumerable<string> LinkedRoutePatternProvider(string s, HttpMethod httpMethod) | |
{ | |
var appAware = new Regex("/Api/[0-9]+/([a-z]|[A-Z])+/[0-9]+"); | |
if (appAware.IsMatch(s)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var timer = new Stopwatch(); | |
timer.Start(); | |
var configuration = GlobalConfiguration.Configuration; | |
var explorer = new ApiExplorer(configuration); | |
var descriptions = explorer.ApiDescriptions; | |
var controllerDescriptors = descriptions.Select(o => o.ActionDescriptor.ControllerDescriptor).Distinct().ToList(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Base route | |
config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new { id = RouteParameter.Optional }); | |
// Nested route (must be distinguishable by param names from above) - Deisgnated by leading _ | |
config.Routes.MapHttpRoute("NestedRoute", "_/{controller}/{rootId}"); | |
// Root controller signature: | |
public class AppDataController : ApiController | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void RegisterCors(HttpConfiguration httpConfiguration) | |
{ | |
WebApiCorsConfiguration corsConfig = new WebApiCorsConfiguration(); | |
corsConfig.RegisterGlobal(httpConfiguration); | |
corsConfig.ForAllOrigins().AllowMethods("GET", "POST", "PUT", "PATCH", "DELETE").AllowAllRequestHeaders(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void Application_BeginRequest(object sender, EventArgs e) | |
{ | |
if (this.Context.Request.Path.Contains("signalr/")) | |
{ | |
this.Context.Response.AddHeader("Access-Control-Allow-Headers", "accept,origin,authorization,content-type"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I have a URI used to manipulate data records: | |
http://api/{AppId}/AppData/ | |
There is also the ability to retrieve several report dataviews based on the records. | |
http://api/{AppId}/ChartData/{chartId} | |
I need a mechanism so that when I POST to http://api/{AppId}/AppData/, or DELETE\PATCH to http://api/{AppId}/AppData/{id} then any cached route starting with http://api/{AppId}/ChartData/ gets invalidated. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace PhantomExpress | |
{ | |
using System; | |
using System.Diagnostics; | |
using System.Threading.Tasks; | |
internal class Program | |
{ | |
private static int Main(string[] args) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The route state machine defined in pseudo code below is able to handle the following routes: | |
/Api/Products/ | |
/Api/Products/1 | |
/Api/Categories | |
/Api/Categories/1 | |
/Api/Products/1/Categories | |
/Api/Products/1/Categories/2 |
OlderNewer