コード例 #1
0
        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);
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        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();
        }
コード例 #4
0
        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
        }
コード例 #5
0
        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
        }
コード例 #6
0
        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();
        }
コード例 #7
0
        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();
        }
コード例 #8
0
 public OrderService()
 {
     _entities = new NorthwindModel.NorthwindEntities(new Uri("https://services.odata.org/V3/Northwind/Northwind.svc"));
 }
コード例 #9
0
 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));
 }
コード例 #10
0
 /// <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)));
 }
コード例 #11
0
        public OrderService(IOptions <Configuration.NorthwindServiceConfiguration> northwindServiceConfiguration)
        {
            var uri = northwindServiceConfiguration == null ? throw new ArgumentNullException(nameof(northwindServiceConfiguration)) : northwindServiceConfiguration.Value.Uri;

            this.entities = new NorthwindModel.NorthwindEntities(uri);
        }