Beispiel #1
0
        public void GossipSpreadMeeting(Meeting newMeeting)
        {
            var clientNum  = Math.Min(this.GossipNumberOfClients, this.KnownClients.Count);
            var rand       = new Random();
            var clientDict = this.KnownClients.OrderBy(item => rand.Next()).ToList();

            if (newMeeting.invited.Count > 0)
            {
                clientDict = clientDict.Where(c => newMeeting.invited.Contains(c.Key)).ToList();
            }

            var clientList = clientDict.Select(c => c.Value).Take(clientNum).ToList();

            foreach (string client in clientList)
            {
                ClientInstance clientObj = (ClientInstance)Activator.GetObject(
                    typeof(ClientInstance),
                    client
                    );
                Thread thread = new Thread(() => clientObj.GossipAddMeeting(newMeeting));
                thread.Start();
            }
        }
Beispiel #2
0
        static void Main()
        {
            var endpointInstance = ClientInstance.Initialize().GetAwaiter().GetResult();
            var persistence      = new OrderPersistence();

            var orderProducer = new OrderProducer(endpointInstance, persistence);

            Console.WriteLine("Client initialized . . .");
            while (true)
            {
                var line = Console.ReadLine();

                if (line == null)
                {
                    continue;
                }
                if (line == "exit" || line == "q" || line == "quit")
                {
                    break;
                }
                if (line == "new")
                {
                    orderProducer.CreateOrderAsync().GetAwaiter().GetResult();
                }
                else if (line.Contains("add-item"))
                {
                    var commandItems = line.Split(' ');

                    var orderKey = int.Parse(commandItems[1]);

                    var orderId = persistence.OrderDictionary.FirstOrDefault(o => o.Key == orderKey).Value;

                    var quantity = int.Parse(commandItems[2]);
                    var price    = decimal.Parse(commandItems[3]);

                    orderProducer.CreateOrderItem(orderId, quantity, price).GetAwaiter().GetResult();
                }
                else if (line.Contains("place"))
                {
                    var commandItems = line.Split(' ');
                    var orderKey     = int.Parse(commandItems[1]);

                    var orderId = persistence.OrderDictionary.FirstOrDefault(o => o.Key == orderKey).Value;

                    orderProducer.PlaceOrder(orderId).GetAwaiter().GetResult();
                }
                else if (line.Contains("cancel"))
                {
                    var commandItems = line.Split(' ');

                    var orderKey = int.Parse(commandItems[1]);

                    var orderId = persistence.OrderDictionary.FirstOrDefault(o => o.Key == orderKey).Value;

                    orderProducer.CancelOrder(orderId).GetAwaiter().GetResult();
                }
                else if (line.Contains("new-customer"))
                {
                    var commandItems = line.Split(' ');

                    var customerId = Guid.Parse(commandItems[1]);

                    orderProducer.CreateCustomer(customerId).GetAwaiter().GetResult();
                }
                else if (line == "generate")
                {
                    orderProducer.GenerateTestEvents().GetAwaiter().GetResult();
                }
            }

            Console.WriteLine("Close client . . .");
            endpointInstance.Stop().GetAwaiter().GetResult();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            ClientInstance c = new ClientInstance();

            c.Start();
        }