Ejemplo n.º 1
0
        private void btnComplete_Click(object sender, RoutedEventArgs e)
        {
            Cake cake = new Cake {
                CakeLayers = new CakeLayer[Board.Children.Count]
            };

            for (int i = 0; i < Board.Children.Count; ++i)
            {
                cake.CakeLayers[i] = ((UcCakeLayer)Board.Children[i]).Current;
            }

            UcClient client = null;

            foreach (UcClient c in OrdersTable.Children)
            {
                if (c.Current == cake)
                {
                    client = c;
                    break;
                }
            }
            if (client != null)
            {
                ++ApplicationData.HappyClients;
                ApplicationData.SumRating += client.Mood;
                ApplicationData.Income    += client.Current.CakeCost;
                OrdersTable.Children.Remove(client);
                Board.Children.Clear();
                bStatus.Background = Brushes.Chartreuse;
            }
            else
            {
                bStatus.Background = Brushes.Red;
            }
        }
Ejemplo n.º 2
0
        private async Task <UcClient> AddClient(int threadId)
        {
            UcClient client = new UcClient
            {
                Current   = new Cake().CreateCake(),
                tbOrderId = { Text = threadId.ToString() }
            };

            OrdersTable.Children.Add(client);

            return(client);
        }
Ejemplo n.º 3
0
        private void CreateClient(object state)
        {
            UcClient current = null;

            _sc.Send(async x => { current = await AddClient((int)state); }, null);
            while (current.Mood > 0)
            {
                Thread.Sleep(1000 * ApplicationData.Rnd.Next(1, 8));
                lock (_obj)
                {
                    _sc.Post(x => { current?.DecClientMood((int)state); }, null);
                }
            }
            Thread.CurrentThread.Abort();
        }