static void Main(string[] args) { NorthwindModel.NorthwindEntities entities = new NorthwindModel.NorthwindEntities(new Uri("https://services.odata.org/V3/Northwind/Northwind.svc")); var customers = entities.Customers.ToArray(); Console.WriteLine("{0} customers in the service found.", customers.Length); }
static void Main(string[] args) { const string serviceUri = "https://services.odata.org/V3/Northwind/Northwind.svc/"; var entities = new NorthwindModel.NorthwindEntities(new Uri(serviceUri)); // breakpoint #1.1 ManualResetEventSlim mre = new ManualResetEventSlim(); // (1) - Инициализация примитива синхронизации "событие". IAsyncResult asyncResult = entities.Employees.BeginExecute((ar) => { Console.WriteLine("Employees in Northwind service:"); var employees = entities.Employees.EndExecute(ar); foreach (var person in employees) { Console.WriteLine("\t{0} {1}", person.FirstName, person.LastName); } mre.Set(); // (2) - Отправить сигнал методу WaitAll. }, null); WaitHandle.WaitAny(new[] { mre.WaitHandle }); // (3) - Блокировать поток выполнения, пока не будет получен сигнал. Console.WriteLine("Press any key to continue."); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine(".NET Core console app."); const string serviceUri = "https://services.odata.org/V3/Northwind/Northwind.svc/"; var entities = new NorthwindModel.NorthwindEntities(new Uri(serviceUri)); ManualResetEventSlim mre = new ManualResetEventSlim(); IAsyncResult asyncResult = entities.Employees.BeginExecute((ar) => { var employees = entities.Employees.EndExecute(ar); Console.WriteLine("Employees in Northwind service:"); foreach (var person in employees) { Console.WriteLine("\t{0} {1}", person.FirstName, person.LastName); } mre.Set(); }, null); WaitHandle.WaitAny(new[] { mre.WaitHandle }); Console.WriteLine("Press any key to continue."); Console.ReadLine(); }
static async Task Main(string[] args) { NorthwindModel.NorthwindEntities entities = new NorthwindModel.NorthwindEntities(new Uri("https://services.odata.org/V3/Northwind/Northwind.svc")); var taskFactory = new TaskFactory <IEnumerable <NorthwindModel.Customer> >(); var customers = (await taskFactory.FromAsync(entities.Customers.BeginExecute(null, null), (iar) => // breakpoint #2.1 { return(entities.Customers.EndExecute(iar)); // breakpoint #2.2 })).ToArray(); Console.WriteLine("{0} customers in the service found.", customers.Length); Console.ReadLine(); // breakpoint #2.3 }
static async Task Main(string[] args) { //1 //NorthwindModel.NorthwindEntities entities = new NorthwindModel.NorthwindEntities(new Uri("https://services.odata.org/V3/Northwind/Northwind.svc")); //IAsyncResult asyncResult; //asyncResult = entities.Customers.BeginExecute((ar) => //{ // var customers = entities.Customers.EndExecute(ar).ToArray(); // Console.WriteLine("{0} customers in the service found.", customers.Length); //}, null); //WaitHandle.WaitAny(new[] { asyncResult.AsyncWaitHandle }); //Console.ReadLine(); //2 //NorthwindModel.NorthwindEntities entities = new NorthwindModel.NorthwindEntities(new Uri("https://services.odata.org/V3/Northwind/Northwind.svc")); //var taskFactory = new TaskFactory<IEnumerable<NorthwindModel.Customer>>(); //var customers = (await taskFactory.FromAsync(entities.Customers.BeginExecute(null, null), iar => entities.Customers.EndExecute(iar))).ToArray(); //Console.WriteLine("{0} customers in the service found.", customers.Length); //Console.ReadLine(); //3 NorthwindModel.NorthwindEntities entities = new NorthwindModel.NorthwindEntities(new Uri("https://services.odata.org/V3/Northwind/Northwind.svc")); IAsyncResult asyncResult; asyncResult = entities.Customers.BeginExecute((ar) => // breakpoint #1.1 { var customers = entities.Customers.EndExecute(ar).ToArray(); // breakpoint #1.2 Console.WriteLine("{0} customers in the service found.", customers.Length); }, null); WaitHandle.WaitAny(new[] { asyncResult.AsyncWaitHandle }); Console.ReadLine(); // breakpoint #1.3 //4 //NorthwindModel.NorthwindEntities entities = new NorthwindModel.NorthwindEntities(new Uri("https://services.odata.org/V3/Northwind/Northwind.svc")); //var taskFactory = new TaskFactory<IEnumerable<NorthwindModel.Customer>>(); //var customers = (await taskFactory.FromAsync(entities.Customers.BeginExecute(null, null), (iar) => // breakpoint #2.1 //{ // return entities.Customers.EndExecute(iar); // breakpoint #2.2 //})).ToArray(); //Console.WriteLine("{0} customers in the service found.", customers.Length); //Console.ReadLine(); // breakpoint #2.3 }
static void Main(string[] args) { const string serviceUri = "https://services.odata.org/V3/Northwind/Northwind.svc/"; var entities = new NorthwindModel.NorthwindEntities(new Uri(serviceUri)); var employees = entities.Employees; Console.WriteLine("Employees in Northwind service:"); foreach (var person in employees) { Console.WriteLine("\t{0} {1}", person.FirstName, person.LastName); } Console.WriteLine("Press any key to continue."); Console.ReadLine(); }
static async Task Main(string[] args) { Console.WriteLine(".NET Core async console app."); const string serviceUri = "https://services.odata.org/V3/Northwind/Northwind.svc/"; var entities = new NorthwindModel.NorthwindEntities(new Uri(serviceUri)); var employees = await Task <IEnumerable <NorthwindModel.Employee> > .Factory.FromAsync(entities.Employees.BeginExecute(null, null), (iar) => entities.Employees.EndExecute(iar)); Console.WriteLine("Employees in Northwind service:"); foreach (var person in employees) { Console.WriteLine("\t{0} {1}", person.FirstName, person.LastName); } Console.WriteLine("Press any key to continue."); Console.ReadLine(); }
public OrderService() { _entities = new NorthwindModel.NorthwindEntities(new Uri("https://services.odata.org/V3/Northwind/Northwind.svc")); }
public OrderService(IOptions <Configuration.NorthwindServiceConfiguration> northwindServiceConfiguration, ILogger <OrderService> logger) { this.uri = northwindServiceConfiguration == null ? throw new ArgumentNullException(nameof(northwindServiceConfiguration)) : northwindServiceConfiguration.Value.Uri; this.entities = new NorthwindModel.NorthwindEntities(uri); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
/// <summary> /// Initializes a new instance of the <see cref="ProductReportService"/> class. /// </summary> /// <param name="northwindServiceUri">An URL to Northwind OData service.</param> public ProductReportService(Uri northwindServiceUri) { this.entities = new NorthwindModel.NorthwindEntities(northwindServiceUri ?? throw new ArgumentNullException(nameof(northwindServiceUri))); }
public OrderService(IOptions <Configuration.NorthwindServiceConfiguration> northwindServiceConfiguration) { var uri = northwindServiceConfiguration == null ? throw new ArgumentNullException(nameof(northwindServiceConfiguration)) : northwindServiceConfiguration.Value.Uri; this.entities = new NorthwindModel.NorthwindEntities(uri); }