Exemplo n.º 1
0
        public MainViewModel()
        {
            ClientConfiguration clientConfiguration = new ClientConfiguration();

            _proxy   = clientConfiguration.CreateProxy <IContactListProvider>("http://localhost:5000");
            Contacts = new ObservableCollection <Contact>();

            AddContactCommand = new RelayCommand(async() =>
            {
                try
                {
                    IsExecuting     = true;
                    Contact contact =
                        await
                        _proxy.AddContactAsync(new Contact {
                        Name = Name, Surname = Surname
                    }, CancellationToken.None);
                    Contacts.Add(contact);
                }
                finally
                {
                    IsExecuting = false;
                }
            }, () => !string.IsNullOrEmpty(Name) && !string.IsNullOrEmpty(Surname) && !IsExecuting);

            RemoveContactCommand = new RelayCommand(async() =>
            {
                try
                {
                    await _proxy.DeleteContactAsync(SelectedContact.Id, CancellationToken.None);
                    Contacts.Remove(SelectedContact);
                }
                finally
                {
                    IsExecuting = false;
                }
            }, () => SelectedContact != null && !IsExecuting);

            LoadContactsCommand = new RelayCommand(async() =>
            {
                try
                {
                    List <Contact> contacts = await _proxy.GetContactsAsync(CancellationToken.None);
                    Contacts.Clear();

                    foreach (Contact contact in contacts)
                    {
                        Contacts.Add(contact);
                    }
                }
                finally
                {
                    IsExecuting = false;
                }
            }, () => !IsExecuting);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            ClientConfiguration  configuration = new ClientConfiguration();
            IContactListProvider proxy         = configuration.CreateProxy <IContactListProvider>("http://localhost:5000");

            proxy.GetContactsAsync(CancellationToken.None).GetAwaiter().GetResult();

            for (int i = 0; i < 10; i++)
            {
                proxy.AddContactAsync(new Contact()
                {
                    Name = "Name_" + i, Surname = "Surname_" + i
                }, CancellationToken.None).GetAwaiter().GetResult();
                System.Console.WriteLine("Added new contact ... ");
            }

            System.Console.WriteLine("Contacts: {0}", proxy.GetContactsAsync(CancellationToken.None).GetAwaiter().GetResult().Count);
        }
Exemplo n.º 3
0
        private static async Task TestBoltAsync(ILogger <Program> logger, ISerializer serializer, CancellationToken cancellationToken)
        {
            // create Bolt proxy
            ClientConfiguration configuration = new ClientConfiguration()
            {
                Serializer = serializer
            };
            IDummyContract proxy = configuration.CreateProxy <IDummyContract>("http://localhost:5000");

            logger.LogInformation("Testing Bolt Proxy ... ");

            for (int i = 0; i < 10; i++)
            {
                try
                {
                    string payload = Guid.NewGuid().ToString();
                    string result  = await proxy.ExecuteAsync(payload);

                    if (result != payload)
                    {
                        throw new InvalidOperationException("Wrong data received.");
                    }
                }
                catch (Exception e)
                {
                    logger.LogInformation("Client: Error {0}", e.Message);
                    _result = 1;
                }

                logger.LogInformation("---------------------------------------------");

                try
                {
                    await Task.Delay(10, cancellationToken);
                }
                catch (OperationCanceledException)
                {
                    return;
                }
            }

            Console.WriteLine("Test finished. Application will now exit ... ");
        }
Exemplo n.º 4
0
        private static async Task TestBolt(ILogger <Program> logger, CancellationToken cancellationToken)
        {
            // create Bolt proxy
            ClientConfiguration configuration = new ClientConfiguration();
            IDummyContract      proxy         = configuration.CreateProxy <IDummyContract>("http://localhost:5000");

            logger.LogInformation("Testing Bolt Proxy ... ");

            for (int i = 0; i < 10; i++)
            {
                logger.LogInformation("Client: Sending {0}", i);

                // we can add timeout and CancellationToken to each Bolt call
                using (new RequestScope(TimeSpan.FromSeconds(5), cancellationToken))
                {
                    try
                    {
                        await proxy.ExecuteAsync(i.ToString(CultureInfo.InvariantCulture));
                    }
                    catch (OperationCanceledException)
                    {
                        // ok
                    }
                    catch (Exception e)
                    {
                        logger.LogInformation("Client: Error {0}", e.Message);
                    }
                }

                logger.LogInformation("Client: Received {0}", i);
                logger.LogInformation("--------------------------------------------");

                try
                {
                    await Task.Delay(10, cancellationToken);
                }
                catch (OperationCanceledException)
                {
                    return;
                }
            }
        }
Exemplo n.º 5
0
        public void GlobalSetup()
        {
            _person    = Person.Create(10);
            _large     = Enumerable.Repeat(_person, 100).ToList();
            _veryLarge = Enumerable.Repeat(_person, VeryLargeMethodParamters).ToList();

            _dateTime = DateTime.UtcNow;

            _runningServer = new TestServer(new WebHostBuilder().ConfigureLogging(ConfigureLog).Configure(Configure).ConfigureServices(ConfigureServices));

            ClientConfiguration = new ClientConfiguration();
            if (UseMessagePack)
            {
                ClientConfiguration.Serializer = new MessagePackSerializer();
            }

            HttpMessageHandler handler = _runningServer.CreateHandler();

            ClientConfiguration.HttpMessageHandler = handler;
            Proxy = ClientConfiguration.CreateProxy <IPerformanceContract>(new Uri("http://localhost"));
        }
Exemplo n.º 6
0
 protected virtual IDummyContract CreateChannel()
 {
     return(ClientConfiguration.CreateProxy <IDummyContract>(ServerUrl));
 }
Exemplo n.º 7
0
 private ITestContractAsync CreateChannel()
 {
     return(ClientConfiguration.CreateProxy <ITestContractAsync>(ServerUrl));
 }