public static void Register(HttpConfiguration config) { config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); // Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type. // To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries. // For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712. //config.EnableQuerySupport(); // To disable tracing in your application, please comment out or remove the following line of code // For more information, refer to: http://www.asp.net/web-api config.EnableSystemDiagnosticsTracing(); Mapper.AddProfile <DomainToModelMappingProfile>(); ODataModelBuilder modelBuilder = new ODataConventionModelBuilder(); modelBuilder.EntitySet <MoviePresentationModel>("Movies"); Microsoft.Data.Edm.IEdmModel model = modelBuilder.GetEdmModel(); config.Routes.MapODataRoute("ODataRoute", "odata", model); }
private void WriteFeed(Edm edm, string absolutUri, string entitySetName, IList <IDictionary <string, object> > dataList) { ODataClient client = new ODataClient(new System.Uri(url)); ODataBatch batch = new ODataBatch(client); foreach (IDictionary <string, object> data in dataList) { batch += c => client.For("Entry").Set(data).InsertEntryAsync(); } System.Threading.Tasks.Task task = batch.ExecuteAsync(); WaitForTaskToComplete(task); Exception e = task.Exception; if (e != null) { if (e.InnerException is Simple.OData.Client.WebRequestException) { // this means we got a response from the server with a specific message. Simple.OData.Client.WebRequestException inner = (Simple.OData.Client.WebRequestException)e.InnerException; throw new System.Exception(inner.Message + " : " + inner.Response); } throw e; } }
private ODataEntry WriteEntity(Edm edm, string url, string entitySetName, IDictionary <string, object> data) { ODataClient client = new ODataClient(new System.Uri(url)); System.Threading.Tasks.Task <IDictionary <string, object> > task = client.For(entitySetName).Set(data).InsertEntryAsync(); WaitForTaskToComplete(task); Exception e = task.Exception; if (e != null) { if (e.InnerException is Simple.OData.Client.WebRequestException) { // this means we got a response from the server with a specific message. Simple.OData.Client.WebRequestException inner = (Simple.OData.Client.WebRequestException)e.InnerException; NeotysAPIException napie = NeotysAPIException.Parse(inner.Response); if (napie != null) { throw napie; } throw inner; } throw e; } IDictionary <string, object> result = task.Result; ODataEntry returnValue = new ODataEntry(result); return(returnValue); }
public static void Register(HttpConfiguration config) { config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); ODataModelBuilder modelBuilder = new ODataConventionModelBuilder(); modelBuilder.EntitySet <Course>("Courses"); modelBuilder.EntitySet <CourseMeeting>("CourseMeetings"); modelBuilder.EntitySet <CourseBreak>("CourseBreaks"); modelBuilder.EntitySet <Assignment>("Assignments"); modelBuilder.EntitySet <Rubric>("Rubric"); modelBuilder.EntitySet <CommentCategoryConfiguration>("CommentCategory"); modelBuilder.EntitySet <Deliverable>("Deliverables"); modelBuilder.EntitySet <AssignmentTeam>("AssignmentTeams"); modelBuilder.EntitySet <DiscussionTeam>("DiscussionTeams"); modelBuilder.EntitySet <DiscussionSetting>("DiscussionSettings"); modelBuilder.EntitySet <ReviewTeam>("ReviewTeams"); modelBuilder.EntitySet <CriticalReviewSettings>("CriticalReviewSettings"); modelBuilder.EntitySet <TeamEvaluationSettings>("TeamEvaluationSettings"); modelBuilder.EntitySet <AbetAssignmentOutcome>("AbetOutcomes"); modelBuilder.EntitySet <Event>("AssociatedEvent"); //is the following needed? modelBuilder.EntitySet <WhiteTable>("WhiteTable"); modelBuilder.Namespace = "OSBLE.Controllers.Odata"; Microsoft.Data.Edm.IEdmModel model = modelBuilder.GetEdmModel(); config.Routes.MapODataRoute("ODataRoute", "odata", model); }
private static Edm ReadEdm(string serviceUrl) { System.IO.Stream content = Execute(serviceUrl + Separator + Metadata); System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(serviceUrl + Separator + Metadata); Edm edm = EdmxReader.Parse(xmlReader); return(edm); }
protected internal NeotysAPIClientOlingo(string url) { this.enabled = CheckArgumentIsEnabled(); if (enabled) { this.edm = ReadEdm(url); this.url = url; } else { this.edm = null; this.url = null; } }
public static void Register(HttpConfiguration config) { config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); //config.Formatters.Insert(0, new JsonpFormatter { }); config.Formatters.Remove(config.Formatters.XmlFormatter); var formatter = GlobalConfiguration.Configuration.Formatters.JsonFormatter; formatter.SerializerSettings = new JsonSerializerSettings() { DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.Indented, DateFormatHandling = DateFormatHandling.IsoDateFormat, //ReferenceLoopHandling = ReferenceLoopHandling.Ignore, //PreserveReferencesHandling = PreserveReferencesHandling.Objects }; // Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type. // To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries. // For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712. config.EnableQuerySupport(); // To disable tracing in your application, please comment out or remove the following line of code // For more information, refer to: http://www.asp.net/web-api config.EnableSystemDiagnosticsTracing(); ODataModelBuilder modelBuilder = new ODataConventionModelBuilder(); modelBuilder.EntitySet <Product>("EntityProducts"); modelBuilder.EntitySet <Product>("ODataProducts"); modelBuilder.EntitySet <ProductType>("ProductTypes"); Microsoft.Data.Edm.IEdmModel model = modelBuilder.GetEdmModel(); config.Routes.MapODataRoute("ODataRoute", "odata", model); }
public static void Register(HttpConfiguration config) { // Web API configuration and services // Web API routes config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); //new route won’t use the /api route, but instead will start with odata ODataModelBuilder modelBuilder = new ODataConventionModelBuilder(); modelBuilder.EntitySet <Post>("Posts"); Microsoft.Data.Edm.IEdmModel model = modelBuilder.GetEdmModel(); config.Routes.MapODataRoute("ODataRoute", "odata", model); config.EnableQuerySupport(); }
private BinaryData WriteBinary(Edm edm, string url, string entitySetName, string apiKey, string jsonContent) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(url + Separator + entitySetName)); request.Method = methodPost; request.ContentType = applicationJson; Stream postStream = request.GetRequestStream(); StringBuilder contentBuilder = new StringBuilder(); contentBuilder.Append(" { \"d\": { ").Append(jsonContent); if (apiKey != null) { contentBuilder.Append(", \"ApiKey\": \"").Append(apiKey).Append("\""); } contentBuilder.Append("}}"); byte[] postBytes = Encoding.UTF8.GetBytes(contentBuilder.ToString()); postStream.Write(postBytes, 0, postBytes.Length); postStream.Flush(); postStream.Close(); WebResponse response; try { response = request.GetResponse(); } catch (WebException exception) { byte[] error = ReadFully(exception.Response.GetResponseStream()); throw NeotysAPIException.Parse(Encoding.UTF8.GetString(error)); } string fileName = ExtractFileNameFromContentDispositionHeader(response.Headers.Get("Content-Disposition")); return(new BinaryData(fileName, ReadFully(response.GetResponseStream()))); }
private static void RegisterOData(HttpConfiguration config) { ODataModelBuilder modelBuilder = new ODataConventionModelBuilder(); modelBuilder.EntitySet <Employee>("EmployeesOData"); modelBuilder.EntitySet <Team>("TeamsOData"); modelBuilder.EntitySet <Office>("OfficesOData"); modelBuilder.EntitySet <EmployeePicture>("EmployeePicturesOData"); modelBuilder.EntitySet <Calendar>("CalendarsOData"); modelBuilder.EntitySet <CalendarHolidays>("CalendarHolidaysOData"); modelBuilder.EntitySet <VacationRequest>("VacationRequestsOData"); modelBuilder.Entity <VacationRequest>().Action("AcceptVacation") .Parameter <string>("Reason"); modelBuilder.Entity <VacationRequest>().Action("RejectVacation") .Parameter <string>("Reason"); Microsoft.Data.Edm.IEdmModel model = modelBuilder.GetEdmModel(); config.Routes.MapODataRoute("ODataRoute", "odata", model); config.EnableQuerySupport(); }
private static void RegisterEndpoint(HttpConfiguration config, string containerName, Microsoft.Data.Edm.IEdmModel edmModel) { config.Routes.MapODataServiceRoute( routeName: String.Format("{0}/{1}", _apiBase, containerName) , routePrefix: String.Format("{0}/{1}", _apiBase, containerName) , model: edmModel , batchHandler: new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer) ); }