コード例 #1
0
        public async Task <Employee> SaveAsync(Employee employee)
        {
            var request = new ProtocolBuffers.EmployeeRequest
            {
                Employee = _employeeConverter.ToMessage(employee)
            };

            var response = await _employeeServiceClient.SaveAsync(request);

            return(_employeeConverter.ToModel(response.Employee));
        }
コード例 #2
0
        public async Task <List <Models.Employee> > SaveAllAsync(List <Models.Employee> employees)
        {
            var result = new List <Models.Employee>();
            var _mutex = new Mutex();

            using (var call = _employeeServiceClient.SaveAll())
            {
                var responseReaderTask = Task.Run(async() =>
                {
                    while (await call.ResponseStream.MoveNext())
                    {
                        _mutex.WaitOne();

                        result.Add(_employeeConverter.ToModel(call.ResponseStream.Current.Employee));

                        _mutex.ReleaseMutex();
                    }
                });

                foreach (var emp in employees)
                {
                    var request = new ProtocolBuffers.EmployeeRequest
                    {
                        Employee = _employeeConverter.ToMessage(emp)
                    };
                    await call.RequestStream.WriteAsync(request);
                }
                ;

                await call.RequestStream.CompleteAsync();

                await responseReaderTask;
            }


            return(result);
        }