Example #1
0
 static void AccountServiceRequest()
 {
     try
     {
         Channel      channel = new Channel("127.0.0.1:50051", ChannelCredentials.Insecure);
         var          client  = new AccountService.AccountServiceClient(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("AccountServiceRequest Terminated...");
     }
     catch (Exception ex)
     {
         Console.WriteLine($"Exception encountered: {ex}");
     }
 }
Example #2
0
        public static void Main()
        {
            try
            {
                Channel channel = new Channel("192.168.237.130:50051", ChannelCredentials.Insecure);
                var     client  = new AccountService.AccountServiceClient(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}");
            }
        }
        private static void RunAsClient(string[] args)
        {
            bool withArgs = RunningWithArguments(args);

            try
            {
                var hostName = ReadHostName(args);
                ReadPort(args);
                ShowAppHeader(args, false, hostName);

                var channel = new Channel($"{hostName}:{PORT}", ChannelCredentials.Insecure);
                var client  = new AccountService.AccountServiceClient(channel);

                var count    = 100;
                var runAgain = false;
                do
                {
                    ShowAppHeader(args, false);

                    if (withArgs)
                    {
                        if (args.Length >= 4)
                        {
                            if (!Int32.TryParse(args[4], out count))
                            {
                                count = 10;
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("How many iterations you want to perform?");
                        if (!Int32.TryParse(Console.ReadLine(), out count))
                        {
                            count = 10;
                        }
                    }

                    accClient = client;
                    perfCount = count;

                    NetworkThroughputBenchmark.Perform(new Action(new Program().RunBenchmark), perfCount);

                    if (!withArgs)
                    {
                        Console.WriteLine("Press [A] to run again...");
                        runAgain = (Console.ReadKey(intercept: true).Key == ConsoleKey.A);
                    }
                } while (runAgain);

                channel.ShutdownAsync().Wait();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Exception encountered: {ex}");
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey(intercept: true);
            }
        }
 public UserController(AccountService.AccountServiceClient client,
                       TokenProvider tokenProvider, ICache cache, IConfiguration config)
 {
     this.client        = client;
     this.tokenProvider = tokenProvider;
     this.cache         = cache;
     this.config        = config;
 }
 public bool IsLogin()
 {
     using ( AccountService.AccountServiceClient proxy = new AccountService.AccountServiceClient())
     {
         try
         {
             return proxy.IsLogin(Session);
         }
         catch (FaultException<HCSMSException> ex)
         {
             raiseError(ex);
             return false;
         }
         catch (Exception ex)
         {
             raiseError(ex);
             throw ex;
         }
     }
 }
Example #6
0
    public static void Test()
    {
        var channel = GrpcChannel.ForAddress("http://localhost:5265");
        var client  = new AccountService.AccountServiceClient(channel);

        var lifetime = new Duration
        {
            Seconds = 10000
        };

        var response = client.SignIn(new SignInRequest
        {
            UserId   = "test",
            Password = "******",
            Lifetime = lifetime
        });

        Console.WriteLine(response.AccessToken);
        Console.WriteLine(response.ExpiryDate);

        var createUserResponse = client.CreateUser(new User {
        });
    }
Example #7
0
        private void InitThread(object context)
        {
            var modelLevelThContext = (System.Runtime.Remoting.Contexts.Context)context;
            bool inited = false;

            #region Infinity try to connect then init and exit

            do
            {
                try
                {
                    using (var sClient = new AccountService.AccountServiceClient())
                    {
                        var getAccountsTask = sClient.GetAllAsync();
                        var getAccountsResTask = getAccountsTask.ContinueWith(res => 
                        {
                            stopCancellationTokenSource.Token.ThrowIfCancellationRequested();
                            if (res.Result.Error != null)
                                throw new Exception(res.Result.Error);
                            return res.Result.Values;
                        }, stopCancellationTokenSource.Token, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Current);

                        var getMarksTask = sClient.GetColumnMarksAsync();
                        var getMarksResTask = getMarksTask.ContinueWith(res =>
                        {
                            stopCancellationTokenSource.Token.ThrowIfCancellationRequested();
                            if (res.Result.Error != null)
                                throw new Exception(res.Result.Error);
                            return res.Result.Values;
                        }, stopCancellationTokenSource.Token, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Current);

                        var getImportQueueRecordStatesTask = sClient.GetImportQueueRecordStatesAsync();
                        var getImportQueueRecordStatesResTask = getImportQueueRecordStatesTask.ContinueWith(res =>
                        {
                            stopCancellationTokenSource.Token.ThrowIfCancellationRequested();
                            if (res.Result.Error != null)
                                throw new Exception(res.Result.Error);
                            return res.Result.Values;
                        }, stopCancellationTokenSource.Token, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Current);

                        var getColumnTypesTask = sClient.GetColumnTypesAsync();
                        var getColumnTypesResTask = getColumnTypesTask.ContinueWith(res =>
                        {
                            stopCancellationTokenSource.Token.ThrowIfCancellationRequested();
                            if (res.Result.Error != null)
                                throw new Exception(res.Result.Error);
                            return res.Result.Values;
                        }, stopCancellationTokenSource.Token, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Current);

                        Task.WaitAll(new Task[] { getAccountsTask, getMarksTask, getColumnTypesTask, getImportQueueRecordStatesTask }, stopCancellationTokenSource.Token);
                        Task.WaitAll(new Task[] { getAccountsResTask, getMarksResTask, getColumnTypesResTask, getImportQueueRecordStatesResTask }, stopCancellationTokenSource.Token);

                        modelLevelThContext.DoCallBack(() => RaiseAccountInitialize(getAccountsResTask.Result.ToArray()));
                        modelLevelThContext.DoCallBack(() => RaiseMarkInitialize(getMarksResTask.Result.ToArray()));
                        modelLevelThContext.DoCallBack(() => RaiseColumnTypesInitialize(getColumnTypesResTask.Result.ToArray()));
                        modelLevelThContext.DoCallBack(() => RaiseImportQueueRecordStateInitialize(getImportQueueRecordStatesResTask.Result.ToArray()));

                        inited = true;
                        SetError((string)null);
                    }
                }
                catch(ThreadAbortException ex)
                {
                    throw ex;
                }
                catch (Exception ex)
                {
                    SetError(ex);
                    Thread.Sleep(ConnectionTimeInterval);
                }
            } while (!inited);

            IsLoaded = true;

            #endregion
        }
        //check for user authentication
        private bool IsAuthorize(Session session)
        {
            using (AccountService.AccountServiceClient proxy = new AccountService.AccountServiceClient())
            {
                try
                {

                    return proxy.IsLogin(session);

                }
                catch (FaultException<HCSMSException> ex)
                {
                    raiseError(ex);
                    return false;
                }
                catch (Exception ex)
                {
                    raiseError(ex);
                    return false;
                }

            }
        }
        private static void RunAsClient(string[] args)
        {
            bool withArgs = RunningWithArguments(args);

            try
            {
                var hostName = ReadHostName(args);
                ReadPort(args);
                ShowAppHeader(args, false, hostName);

                var channel = new Channel($"{hostName}:{PORT}", ChannelCredentials.Insecure);
                var client  = new AccountService.AccountServiceClient(channel);

                var count    = 100;
                var runAgain = false;
                do
                {
                    ShowAppHeader(args, false);

                    if (withArgs)
                    {
                        if (args.Length >= 4)
                        {
                            if (!Int32.TryParse(args[4], out count))
                            {
                                count = 10;
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("How many iterations you want to perform?");
                        if (!Int32.TryParse(Console.ReadLine(), out count))
                        {
                            count = 10;
                        }
                    }

                    accClient = client;
                    perfCount = count;

                    BenchmarkDotNet.Running.BenchmarkRunner.Run <Program>();

                    //var sw = Stopwatch.StartNew();
                    //for (var x = 0; x < count; ++x)
                    //{
                    //    var empName = client.GetEmployeeName(new EmployeeNameRequest { EmpId = "1" });
                    //    Console.CursorTop = 6;
                    //    Console.CursorLeft = 0;
                    //    Console.WriteLine("Iteration count: {0,22:D8}", x + 1);
                    //}
                    //sw.Stop();
                    //Console.ForegroundColor = ConsoleColor.Yellow;
                    //Console.Write("Elapsed Milliseconds: ");
                    //Console.ForegroundColor = ConsoleColor.Green;
                    //Console.WriteLine(sw.ElapsedMilliseconds);
                    //Console.ResetColor();

                    if (!withArgs)
                    {
                        Console.WriteLine("Press [A] to run again...");
                        runAgain = (Console.ReadKey(intercept: true).Key == ConsoleKey.A);
                    }
                } while (runAgain);

                channel.ShutdownAsync().Wait();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Exception encountered: {ex}");
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey(intercept: true);
            }
        }
Example #10
0
        public void Login()
        {
            if (validate())
            {
                AccountService.AccountServiceClient proxy = new AccountService.AccountServiceClient();

                try
                {
                    Session = proxy.StartSession(account);

                }
                catch (FaultException<HCSMSException> ex)
                {
                    raiseError(ex);
                }
                catch (Exception ex)
                {
                    raiseError(ex);
                    throw ex;
                }

            }
            else
            {
                ProcessNotifyEvent(ValidateFail, new NotifyEventArgs("用户名或密码无效!"));
            }
        }