Ejemplo n.º 1
0
        public static async Task ListFeatures()
        {
            Channel channel = new Channel("127.0.0.1:50051", ChannelCredentials.Insecure);
            var     client  = new EmployeeService.EmployeeServiceClient(channel);

            try
            {
                using (var call = client.GetEmployees(new EmployeeRequest {
                    Id = 1
                }))
                {
                    var           responseStream = call.ResponseStream;
                    StringBuilder responseLog    = new StringBuilder("Result: ");

                    while (await responseStream.MoveNext())
                    {
                        Employee employee = responseStream.Current;
                        responseLog.Append(employee.ToString());
                    }
                    Console.WriteLine(responseLog.ToString());
                }
            }
            catch (RpcException e)
            {
                Console.WriteLine("RPC failed " + e);
                throw;
            }
        }
Ejemplo n.º 2
0
        public static async Task GetByNoAsync(EmployeeService.EmployeeServiceClient client)
        {
            try
            {
                if (!NeedToken() || await GetTokenAsync(client))
                {
                    var headers = new Metadata
                    {
                        { "Authorization", $"Bearer {_token}" }
                    };

                    var response = await client.GetByNoAsync(new GetByNoRequest
                    {
                        No = 1994
                    }, headers);

                    Console.WriteLine($"Response messages: {response}");
                }
            }
            catch (RpcException e)
            {
                if (e.StatusCode == StatusCode.DataLoss)
                {
                    Log.Logger.Error($"{JsonConvert.SerializeObject(e.Trailers)}");
                }

                Log.Logger.Error(e.Message);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 一元消息
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        public static async Task GetByNoAsync(EmployeeService.EmployeeServiceClient client)
        {
            if (!NeedToken() || await GetTokenAsync(client))
            {
                try
                {
                    var headers = new Metadata()
                    {
                        { "Authorization", $"Bearer {_token}" },
                        { "username", "kael.tian" },
                        { "age", "18" },
                    };
                    headers.Add(new Metadata.Entry("level", "GL8"));
                    var response = await client.GetByNoAsync(new GetByNoRequest
                    {
                        No = 1994
                    }, headers);

                    Console.WriteLine($"Response messages: {response}");
                }
                catch (RpcException e)
                {
                    if (e.StatusCode == StatusCode.PermissionDenied)
                    {
                        Log.Logger.Error($"{e.Trailers}");
                        foreach (var pair in e.Trailers)
                        {
                            Log.Logger.Error($"Key:{pair.Key},Value:{pair.Value}");
                        }
                    }
                    Log.Logger.Error(e.Message);
                }
            }
        }
Ejemplo n.º 4
0
        static async Task Main(string[] args)
        {
            using var channel = GrpcChannel.ForAddress("https://localhost:5001");
            var client = new EmployeeService.EmployeeServiceClient(channel);
            var option = 5;

            switch (option)
            {
            case 1:
                await GetByNoAsync(client);

                break;

            case 2:
                await GetAllAsync(client);

                break;

            case 3:
                await AddPhotoAsync(client);

                break;

            case 5:
                await SaveAllAsync(client);

                break;
            }
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
Ejemplo n.º 5
0
        protected async void SaveEmployees()
        {
            Response5         = string.Empty; //清空前台显示
            using var channel = GrpcChannel.ForAddress(ServerAdderss);
            var client = new EmployeeService.EmployeeServiceClient(channel);
            var serverStreamingCall = client.SaveEmployees();
            //因为是双向流的方式,我们需要同时操作“请求流”和“响应流”
            var requestStream  = serverStreamingCall.RequestStream;
            var responseStream = serverStreamingCall.ResponseStream;
            //获取员工数据
            var employees = GetNewEmployees(Request5.Trim());

            //依次将员工数据写入请求流中
            foreach (var employee in employees)
            {
                await requestStream.WriteAsync(new EmployeeRequest { Employee = employee });
            }
            //告知服务端数据传递完毕
            await requestStream.CompleteAsync();

            //读取服务端返回的流式数据
            await Task.Run(async() =>
            {
                while (await responseStream.MoveNext(new CancellationToken()))
                {
                    Response5 += $"New Employee “{responseStream.Current.Employee.Name}” is Saved"
                                 + Environment.NewLine;
                }
            });
        }
Ejemplo n.º 6
0
        public static async Task GetByNoAsync(EmployeeService.EmployeeServiceClient client)
        {
            try
            {
                if (!NeedToken() || await GetTokenAsync(client))
                {
                    var header = new Metadata
                    {
                        { "Authorization", $"Bearer {_token}" },
                    };

                    var response = await client.GetByNoAsync(new GetByNoRequest
                    {
                        No = 111
                    }, header);

                    Log.Logger.Debug($"response message : {response}");
                    Console.WriteLine($"response message : {response}");
                }
            }
            catch (RpcException re)
            {
                if (re.StatusCode == StatusCode.NotFound)
                {
                    Log.Logger.Error($"trailer: {re.Trailers}");
                }
                Log.Logger.Error(re.Message);
            }
            catch (Exception e)
            {
                Log.Logger.Error(e.Message);
            }
        }
Ejemplo n.º 7
0
        private static async Task AddPhotoRequestAsync(EmployeeService.EmployeeServiceClient client)
        {
            var md = new Metadata();

            md.Add("badgenumber", "1");
            var fs = File.OpenRead(@"emp.jpg");

            using (var call = client.AddPhoto(md))
            {
                var stream = call.RequestStream;
                while (true)
                {
                    var buffer  = new byte[64 * 1024];
                    int numRead = await fs.ReadAsync(buffer, 0, buffer.Length);

                    if (numRead == 0)
                    {
                        break;
                    }
                    if (numRead < buffer.Length)
                    {
                        Array.Resize(ref buffer, numRead);
                    }
                    await stream.WriteAsync(new AddPhotoRequest { Data = ByteString.CopyFrom(buffer) });
                }
                await stream.CompleteAsync();

                var res = await call.ResponseAsync;
                Console.WriteLine(res.IsOk);
            }
        }
Ejemplo n.º 8
0
    protected void btnGetEmployee_Click(object sender, EventArgs e)
    {
        EmployeeService.EmployeeServiceClient client = new EmployeeService.EmployeeServiceClient();
        EmployeeService.Employee employee            = client.GetEmployee(Convert.ToInt32(txtID.Text));

        if (employee.Type == EmployeeService.EmployeeType.FullTimeEmployee)
        {
            txtAnnualSalary.Text   = ((EmployeeService.FullTimeEmployee)employee).AnnualSalary.ToString();
            trAnnualSalary.Visible = true;
            trHourlyPay.Visible    = false;
            trHoursWorked.Visible  = false;
        }
        else
        {
            txtHourlyPay.Text      = ((EmployeeService.PartTimeEmployee)employee).HourlyPay.ToString();
            txtHoursWorked.Text    = ((EmployeeService.PartTimeEmployee)employee).HoursWorked.ToString();
            trAnnualSalary.Visible = false;
            trHourlyPay.Visible    = true;
            trHoursWorked.Visible  = true;
        }

        txtName.Text                  = employee.Name;
        txtGender.Text                = employee.Gender;
        txtDateOfBirth.Text           = employee.DateOfBirth.ToShortDateString();
        ddlEmployeeType.SelectedValue = ((int)employee.Type).ToString();
        lblMessage.Text               = "Employee retrieved";
    }
Ejemplo n.º 9
0
        private static async Task SaveAllAsync(EmployeeService.EmployeeServiceClient client)
        {
            var employees = new List <Employee>
            {
                new Employee {
                    BadgeNumber = 2, FirstName = "Sunny", LastName = "Hook", Id = 22, VacationAccurateRate = 2.1F, VacationAccured = 1.2F
                },
                new Employee {
                    BadgeNumber = 3, FirstName = "Cheese", LastName = "Burger", Id = 33, VacationAccurateRate = 2.1F, VacationAccured = 1.2F
                }
            };

            using (var call = client.SaveAll())
            {
                var requestStream  = call.RequestStream;
                var responseStream = call.ResponseStream;
                var responseTask   = Task.Run(async() =>
                {
                    while (await responseStream.MoveNext())
                    {
                        Console.WriteLine("Saved: " + responseStream.Current.Employee);
                    }
                });
                foreach (var e in employees)
                {
                    await requestStream.WriteAsync(new EmployeeRequest { Employee = e });
                }
                await requestStream.CompleteAsync();

                await responseTask; //order is important.
            }
        }
Ejemplo n.º 10
0
 static void Main(string[] args)
 {
     try
     {
         Channel      channel = new Channel("127.0.0.1:50051", ChannelCredentials.Insecure);
         var          client  = new EmployeeService.EmployeeServiceClient(channel);
         EmployeeName empName = client.GetEmployeeName(new EmployeeNameRequest {
             EmpId = "1"
         });
         if (empName == null || string.IsNullOrWhiteSpace(empName.FirstName) || string.IsNullOrWhiteSpace(empName.LastName))
         {
             Console.WriteLine("Employee not found.");
         }
         else
         {
             Console.WriteLine($"The employee name is {empName.FirstName} {empName.LastName}.");
         }
         channel.ShutdownAsync().Wait();
         Console.WriteLine("Press any key to exit...");
         Console.ReadKey();
     }
     catch (Exception ex)
     {
         Console.WriteLine($"Exception encountered: {ex}");
     }
 }
Ejemplo n.º 11
0
        public IActionResult Index()
        {
            var          client   = new EmployeeService.EmployeeServiceClient(channel);
            EmployeeList employee = client.GetAll(new Empty());

            return(View(employee));
        }
 protected void btnGetEmployee_Click(object sender, EventArgs e)
 {
     EmployeeService.EmployeeServiceClient client = new EmployeeService.EmployeeServiceClient("BasicHttpBinding_IEmployeeService");
     EmployeeService.Employee employee = client.GetEmployee(Convert.ToInt32(txtID.Text));
     if(employee.Type==EmployeeService.EmployeeType.FullTimeEmployee)
     {
         txtAnnualSalary.Text = ((EmployeeService.FullTimeEmployee)employee).AnnualSalary.ToString();
         trAnnualSalary.Visible = true;
         trHourlyPay.Visible = false;
         trHoursWorked.Visible = false;
     }
     else
     {
         txtHourlyPay.Text = ((EmployeeService.PartTimeEmployee)employee).Hourlypay.ToString();
         txtHoursWorked.Text = ((EmployeeService.PartTimeEmployee)employee).HoursWorked.ToString();
         trAnnualSalary.Visible = false;
         trHourlyPay.Visible = true;
         trHoursWorked.Visible = true;
     }
     ddlEmployeeType.SelectedValue = ((int)employee.Type).ToString();
     txtName.Text = employee.Name;
     txtGender.Text = employee.Gender;
     txtDateOfBirth.Text = employee.DateOfBirth.ToShortDateString();
     lblMessage.Text = "Employee retrieved";
 }
Ejemplo n.º 13
0
        protected void BtnGet_Click(object sender, EventArgs e)
        {
            int employeeId = Convert.ToInt32(TxtEmployeeID.Text);

            //EmployeeService.EmployeeServiceClient client = new EmployeeService.EmployeeServiceClient();
            //EmployeeService.Employee employee = client.GetEmployee(employeeId);
            EmployeeService.IEmployeeService client = new EmployeeService.EmployeeServiceClient();
            EmployeeService.EmployeeRequest request = new EmployeeService.EmployeeRequest("QWERTY", Convert.ToInt32(TxtEmployeeID.Text));
            EmployeeService.EmployeeInfo employee = client.GetEmployee(request);

            TxtEmployeeName.Text = employee.Name;
            //TxtEmployeeDateOfBirth.Text = employee.DateOfBirth.ToShortDateString();
            TxtEmployeeDateOfBirth.Text = employee.DOB.ToShortDateString();

            // Show the employee type data
            hideWhenEmployeeType();
            if (employee.Type == EmployeeService.EmployeeType.FullTimeEmployee)
            {
                trAnnualSalary.Visible = true;
                TxtAnnualSalary.Text = employee.AnnualSalary.ToString(); //((EmployeeService.FullTimeEmployee)employee).AnnualSalary.ToString();
            }
            else
            {
                trHourlyPay.Visible = true;
                trHoursWorked.Visible = true;
                TxtHourlyPay.Text = employee.HourlyPay.ToString(); //((EmployeeService.PartTimeEmployee)employee).HourlyPay.ToString();
                TxtHoursWorked.Text = employee.HoursWorked.ToString(); //((EmployeeService.PartTimeEmployee)employee).HoursWorked.ToString();
            }

            CbxEmployeeType.SelectedValue = ((int)employee.Type).ToString();
        }
Ejemplo n.º 14
0
        protected void BtnSave_Click(object sender, EventArgs e)
        {
            //EmployeeService.EmployeeServiceClient client = new EmployeeService.EmployeeServiceClient();
            EmployeeService.IEmployeeService client = new EmployeeService.EmployeeServiceClient();
            EmployeeService.EmployeeInfo employee = new EmployeeService.EmployeeInfo();

            int _Id = Convert.ToInt32(TxtEmployeeID.Text);
            DateTime _DateOfBirth = Convert.ToDateTime(TxtEmployeeDateOfBirth.Text.ToString());
            EmployeeService.EmployeeType _Type = ((EmployeeService.EmployeeType)Convert.ToInt32(CbxEmployeeType.SelectedValue.ToString()));

            if (((EmployeeService.EmployeeType)(Convert.ToInt32(CbxEmployeeType.SelectedValue))) == EmployeeService.EmployeeType.FullTimeEmployee)
            {
                employee.AnnualSalary = Convert.ToInt32(TxtAnnualSalary.Text.ToString());
            }
            else if(((EmployeeService.EmployeeType)Convert.ToInt32(CbxEmployeeType.SelectedValue)) == EmployeeService.EmployeeType.PartTimeEmployee)
            {
                employee.HourlyPay = Convert.ToInt32(TxtHourlyPay.Text);
                employee.HoursWorked = Convert.ToInt32(TxtHoursWorked.Text);
            }
            else
            {

            }

            employee.Id = _Id;
            employee.Name = TxtEmployeeName.Text.ToString();
            employee.DOB = _DateOfBirth;
            employee.Type = _Type;

            client.SetEmployee(employee);
        }
Ejemplo n.º 15
0
        public static async Task GetAllAsync(EmployeeService.EmployeeServiceClient client)
        {
            try
            {
                if (!NeedToken() || await GetTokenAsync(client))
                {
                    var headers = new Metadata
                    {
                        { "Authorization", $"Bearer {_token}" }
                    };

                    using var call = client.GetAll(new GetAllRequest(), headers);
                    var responseStream = call.ResponseStream;
                    while (await responseStream.MoveNext())
                    {
                        Console.WriteLine(responseStream.Current.Employee);
                    }
                }
            }
            catch (RpcException e)
            {
                Log.Logger.Error($"{JsonConvert.SerializeObject(e.Trailers)}");
                Log.Logger.Error(e.Message);
            }
        }
Ejemplo n.º 16
0
        public ActionResult Index(IList <EmployeeService.Employee> employees)
        {
            ViewBag.Connection = GetServerName();
            if (employees == null)
            {
                return(RedirectToAction("Index"));
            }
            EmployeeService.EmployeeServiceClient client = new EmployeeService.EmployeeServiceClient();

            if (ModelState.IsValid)
            {
                client.DeleteEmployee(0);
                foreach (var employee in employees)
                {
                    if (employee.Id == 0)
                    {
                        continue;  //If employee with Id=0 has been entered in the view, ignore he/she, will not be stored in db and will disapear in next page load
                    }
                    if (client.GetEmployee(employee.Id) == null)
                    {
                        client.SaveEmployee(employee);   //employee doesn't exist in Db, Create new
                    }
                    else
                    {
                        client.UpdateEmployee(employee);   //employee do exist in Db, Update
                    }
                }
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 17
0
        private const string ServerAdderss = "https://localhost:5001";  //服务端的地址
        protected void GetEmployeeById()
        {
            Response1 = string.Empty;   //清空前台显示
            var metaData = new Metadata //元数据都是一些 key-value对
            {
                { "myKey", "myValue" }  //随便假装一点 key-value对
            };

            if (int.TryParse(Request1, out var id))
            {
                //*****************************主要是这里********************************
                using var channel = GrpcChannel.ForAddress(ServerAdderss,
                                                           new GrpcChannelOptions
                {
                    HttpClient = _httpClient
                });              //创建通道
                var client = new EmployeeService.EmployeeServiceClient(channel);
                try
                {
                    var response = client.GetEmployeeById(
                        new GetEmployeeByIdRequest {
                        Id = id
                    }                                   //参数一:request参数(员工Id)
                        , metaData);                    //参数二:用户自定义的元数据
                    Response1 = response.ToString();    //将响应信息输出前台显示
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }
                //*********************************************************************
                return;
            }
            MessageBox.Show("request is unValid");
        }
Ejemplo n.º 18
0
        public static async Task SaveAllAsync(EmployeeService.EmployeeServiceClient client)
        {
            var employes = new List <Employee>
            {
                new Employee
                {
                    No        = 111,
                    FirstName = "monica",
                    LastName  = "Geller",
                    //Salary = 7916.1f
                    MonthSalary = new MonthSalary
                    {
                        Basic = 5000f,
                        Bonus = 125.5f
                    },
                    Status       = EmployeeStatus.Resigned,
                    LastModified = Timestamp.FromDateTime(DateTime.UtcNow)
                },
                new Employee
                {
                    No        = 112,
                    FirstName = "Joey",
                    LastName  = "Tribbiani",
                    //Salary = 500
                    MonthSalary = new MonthSalary
                    {
                        Basic = 5000f,
                        Bonus = 125.5f
                    },
                    Status       = EmployeeStatus.Resigned,
                    LastModified = Timestamp.FromDateTime(DateTime.UtcNow)
                }
            };

            using var call = client.SaveAll();
            var resquestStream = call.RequestStream;
            var responseStream = call.ResponseStream;


            var responseTask = Task.Run(async() =>
            {
                while (await responseStream.MoveNext())
                {
                    Console.WriteLine($"Saved: {responseStream.Current.Employee}");
                }
            });

            foreach (var employee in employes)
            {
                await resquestStream.WriteAsync(new EmployeeRequest
                {
                    E = employee
                });
            }

            await resquestStream.CompleteAsync();

            await responseTask;
        }
Ejemplo n.º 19
0
        public EmployeeRepositoryRpc(EmployeeConverter employeeConverter)
        {
            var channel = new Channel("localhost:8080", ChannelCredentials.Insecure);

            _employeeServiceClient = new ProtocolBuffers.EmployeeService.EmployeeServiceClient(channel);

            _employeeConverter = employeeConverter;
        }
Ejemplo n.º 20
0
        // GET: Employee
        public ActionResult Index()
        {
            ViewBag.Connection = GetServerName();
            EmployeeService.EmployeeServiceClient client = new EmployeeService.EmployeeServiceClient();
            var employees = client.GetEmployees().OrderBy(e => e.Id).ToList();

            return(View(employees));
        }
Ejemplo n.º 21
0
        public static async Task SaveAllAsync(EmployeeService.EmployeeServiceClient client)
        {
            var employees = new List <Employee>
            {
                new Employee
                {
                    No          = 111,
                    FirstName   = "CC",
                    LastName    = "DD",
                    MonthSalary = new MonthSalary
                    {
                        Basic = 5000f,
                        Bouns = 125.5f
                    },
                    Status       = EmployeeStatus.Normal,
                    LastModified = Timestamp.FromDateTime(DateTime.UtcNow)
                },
                new Employee
                {
                    No          = 222,
                    FirstName   = "CAC",
                    LastName    = "DDT",
                    MonthSalary = new MonthSalary
                    {
                        Basic = 5000f,
                        Bouns = 125.5f
                    },
                    Status       = EmployeeStatus.Normal,
                    LastModified = Timestamp.FromDateTime(DateTime.UtcNow)
                }
            };

            using var call = client.SaveAll();
            var requestStream  = call.RequestStream;
            var responseStream = call.ResponseStream;

            var responseTask = Task.Run(async() =>
            {
                while (await responseStream.MoveNext())
                {
                    Console.WriteLine($"Saved: {responseStream.Current.Employee}");
                }
            });

            foreach (var employee in employees)
            {
                await requestStream.WriteAsync(new EmployeeRequest
                {
                    Employee = employee
                });;
            }

            await requestStream.CompleteAsync();

            await responseTask;
        }
Ejemplo n.º 22
0
        public IActionResult DeleteConfirmed(int id)
        {
            var   client   = new EmployeeService.EmployeeServiceClient(channel);
            Empty response = client.Delete(new EmployeeId()
            {
                Id = id
            });

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 23
0
        private static async Task GetAllAsync(EmployeeService.EmployeeServiceClient client)
        {
            using var call = client.GetAll(new GetAllRequest());
            var responseStream = call.ResponseStream;

            while (await responseStream.MoveNext())
            {
                Console.WriteLine(responseStream.Current.Employee);
            }
        }
Ejemplo n.º 24
0
        protected void BtnGet_Click(object sender, EventArgs e)
        {
            int employeeId = Convert.ToInt32(TxtEmployeeID.Text);

            EmployeeService.EmployeeServiceClient client = new EmployeeService.EmployeeServiceClient();
            EmployeeService.Employee employee = client.GetEmployee(employeeId);

            TxtEmployeeName.Text = employee.Name;
            TxtEmployeeDateOfBirth.Text = employee.DateOfBirth.ToShortDateString();
        }
Ejemplo n.º 25
0
        static void Main(string[] args)
        {
            const int    Port = 50051;
            const string Host = "127.0.0.1";

            try
            {
                var creds = GetSslCredentials();

                var PcName         = Environment.MachineName;
                var channelOptions = new List <ChannelOption>
                {
                    // this will get rid of nds failure error
                    new ChannelOption(ChannelOptions.SslTargetNameOverride, PcName)
                };
                var channel = new Channel(Host, Port, creds, channelOptions);
                var client  = new EmployeeService.EmployeeServiceClient(channel);

                do
                {
                    Console.WriteLine("\n-----------------OPTIONS------------------");
                    Console.WriteLine("1. GetByBadgeNumber \t(UO)\n" +
                                      "2. GetAll \t(SS)\n" +
                                      "3. AddPhoto\t(CS)\n" +
                                      "4. SaveAll \t(DS)\n" +
                                      "- Type any other number to exit");
                    var input = Console.ReadLine().Trim();
                    switch (input)
                    {
                    case "1":
                        GetByBadgeNumber(client).Wait();
                        break;

                    case "2":
                        GetAll(client).Wait();
                        break;

                    case "3":
                        AddPhoto(client).Wait();
                        break;

                    case "4":
                        SaveAll(client).Wait();
                        break;

                    default:
                        return;
                    }
                } while (true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 26
0
        protected void BtnSave_Click(object sender, EventArgs e)
        {
            EmployeeService.EmployeeServiceClient client = new EmployeeService.EmployeeServiceClient();
            EmployeeService.Employee employee = new EmployeeService.Employee();

            employee.Id = Convert.ToInt32(TxtEmployeeID.Text);
            employee.Name = TxtEmployeeName.Text.ToString();
            employee.DateOfBirth = Convert.ToDateTime(TxtEmployeeDateOfBirth.Text);

            client.SetEmployee(employee);
        }
Ejemplo n.º 27
0
 public IActionResult Create(Employee employee)
 {
     if (ModelState.IsValid)
     {
         var client = new
                      EmployeeService.EmployeeServiceClient(channel);
         var createdEmployee = client.Insert(employee);
         return(RedirectToAction(nameof(Index)));
     }
     return(View(employee));
 }
Ejemplo n.º 28
0
        public static async Task GetEmployeeById(int id)
        {
            using var channel = GrpcChannel.ForAddress("https://localhost:5001");
            var client   = new EmployeeService.EmployeeServiceClient(channel);
            var employee = await client.GetByIdAsync(new GetByIdRequest
            {
                Id = id
            });

            Console.WriteLine($"Response messages: {employee}");
        }
Ejemplo n.º 29
0
        private static void testGRPC()
        {
            Channel channel = new Channel("127.0.0.1:50051", ChannelCredentials.Insecure);
            var     client  = new EmployeeService.EmployeeServiceClient(channel);
            var     reply   = client.GetEmployee(new EmployeeRequest {
                Id = 1
            });

            Console.WriteLine("Greeting: " + reply.Name);
            ListFeatures().Wait();
        }
Ejemplo n.º 30
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            EmployeeService.EmployeeServiceClient client = new EmployeeService.EmployeeServiceClient();
            EmployeeService.Employee employee = client.GetEmployee(Convert.ToInt32(TextBox1.Text));

            TextBox1.Text = employee.Id.ToString();
            TextBox5.Text = employee.Name.ToString();
            TextBox3.Text = employee.Gender.ToString();
            TextBox4.Text = employee.DateOfBirth.ToString("dd-MM-yyyy");

            Label1.Text = "Employee with ID = " + employee.Id.ToString() + " retrived";
        }
Ejemplo n.º 31
0
        protected void SaveEmployee()
        {
            Response4         = string.Empty; //清空前台显示
            using var channel = GrpcChannel.ForAddress(ServerAdderss);
            var client   = new EmployeeService.EmployeeServiceClient(channel);
            var newEmp   = GetNewEmployee(Request4);
            var response = client.SaveEmployee(new EmployeeRequest {
                Employee = newEmp
            });

            Response4 += $"New Employee “{response.Employee.Name}” is Saved";
        }
Ejemplo n.º 32
0
        public static async Task GetAllAsync(EmployeeService.EmployeeServiceClient client)
        {
            using var call = client.GetAll(new GetAllRequest());

            var responseSteam = call.ResponseStream;

            while (await responseSteam.MoveNext())
            {
                Log.Debug($"response message : {responseSteam.Current.Employee}");
                Console.WriteLine($"response message : {responseSteam.Current.Employee}");
            }
        }
Ejemplo n.º 33
0
        static async Task Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .WriteTo.Console()
                         .CreateLogger();

            Log.Information("Client starting...");

            using var channel = GrpcChannel.ForAddress("https://localhost:5001",
                                                       new GrpcChannelOptions
            {
                LoggerFactory = new SerilogLoggerFactory()
            });
            var client = new EmployeeService.EmployeeServiceClient(channel);

            //var option = int.Parse(args[0]);
            var option = 5;

            switch (option)
            {
            case 1:
                await GetByNoAsync(client);

                break;

            case 2:
                await GetAllAsync(client);

                break;

            case 3:
                await AddPhotoAsync(client);

                break;

            case 4:
                await SaveAsync(client);

                break;

            case 5:
                await SaveAllAsync(client);

                break;
            }

            Console.WriteLine("Press any key to exist.");
            Console.ReadKey();

            Log.CloseAndFlush();
        }
Ejemplo n.º 34
0
        public static async Task GetByNoAsync(EmployeeService.EmployeeServiceClient client)
        {
            var md = new Metadata {
                { "username", "dave" },
                { "role", "administrator" }
            };
            var response = await client.GetByNoAsync(new GetByNoRequest
            {
                No = 1994,
            }, md);

            Console.WriteLine($"Response messages : {response}");
        }
Ejemplo n.º 35
0
 public ActionResult Delete(int id)
 {
     try
     {
         EmployeeService.EmployeeServiceClient client = new EmployeeService.EmployeeServiceClient();
         client.DeleteEmployee(id);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Ejemplo n.º 36
0
        // server stream
        static async Task GetAll(EmployeeService.EmployeeServiceClient client)
        {
            Console.WriteLine($"GetAll - Server streaming sample");

            using (var call = client.GetAll(new GetAllRequest()))
            {
                var responserStream = call.ResponseStream;
                while (await responserStream.MoveNext())
                {
                    Console.WriteLine(responserStream.Current.Employee);
                }
            }
        }
Ejemplo n.º 37
0
        protected void Button2_Click(object sender, EventArgs e)
        {
            EmployeeService.EmployeeServiceClient client = new EmployeeService.EmployeeServiceClient();
            EmployeeService.Employee employee = new EmployeeService.Employee();

            employee.Id = Convert.ToInt32(TextBox1.Text);
            employee.Name = TextBox5.Text;
            employee.Gender = TextBox3.Text;
            employee.DateOfBirth = Convert.ToDateTime(TextBox4.Text);

            client.SaveEmployee(employee);
            Label1.Text = "Employee saved!";
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            EmployeeService.EmployeeServiceClient client = new EmployeeService.EmployeeServiceClient();
            //EmployeeService.Employee employee = new EmployeeService.Employee();
            EmployeeService.Employee employee = null;
            if ((EmployeeService.EmployeeType)Convert.ToInt32(ddlEmployeeType.SelectedValue) == EmployeeService.EmployeeType.FullTimeEmployee)
            {

                employee = new EmployeeService.FullTimeEmployee
                {
                    Id = Convert.ToInt32(txtID.Text),
                    Name = txtName.Text,
                    Gender = txtGender.Text,
                    DateOfBirth = Convert.ToDateTime(txtDateOfBirth.Text),
                    Type = EmployeeService.EmployeeType.FullTimeEmployee,
                    AnnualSalary = Convert.ToInt32(txtAnnualSalary.Text)

                };
                client.SaveEmployee(employee);
                lblMessage.Text = "Employee saved";
            }
            else if ((EmployeeService.EmployeeType)Convert.ToInt32(ddlEmployeeType.SelectedValue) == EmployeeService.EmployeeType.PartTimeEmployee)
            {
                employee = new EmployeeService.PartTimeEmployee
                {
                    Id = Convert.ToInt32(txtID.Text),
                    Name = txtName.Text,
                    Gender = txtGender.Text,
                    DateOfBirth = Convert.ToDateTime(txtDateOfBirth.Text),
                    Type = EmployeeService.EmployeeType.PartTimeEmployee,
                    Hourlypay = Convert.ToInt32(txtHourlyPay.Text),
                    HoursWorked = Convert.ToInt32(txtHoursWorked.Text)

                };
                client.SaveEmployee(employee);
                lblMessage.Text = "Employee saved";
            }
            else
            {
                lblMessage.Text = "Please select Employee Type";
            }
        }