예제 #1
0
        static void Main(string[] args)
        {
            /* Can use any RavenDb implementation
             * EmbeddableDocumentStore,
             * RavenDbDocumentStore,
             * DocumentStore
             */
            var ravenDbdocumentStore = new DocumentStore
            {
                Url             = "http://localhost:8080",
                DefaultDatabase = "Customers",
                //ConnectionStringName = "RavenDBDatabaseConnection"
            };
            var repository = new RavenDBcustomerRepository <Customer>(ravenDbdocumentStore);
            var queue      = new PersistenceCustomersQueue <Customer>(repository);
            var server     = new Server <Customer>();
            var barber     = new SleepingBarber <Customer>(queue, server);

            barber.CustomerServed += CustomerServed;
            barber.GoingToSleep   += BarberWentToSleep;
            for (int i = 0; i < 50; i++)
            {
                var name = $"Customer{i}";
                queue.Enqueue(new Customer {
                    Id = name, Name = name, DateCreate = DateTime.Now
                });
                Console.WriteLine($"{i} was added to database");
            }
            Console.ReadLine();
        }
        public void Run()
        {
            Console.WriteLine($"1. Dining Philosopher");
            Console.WriteLine($"2. Reader-Writer Lock");
            Console.WriteLine($"3. Producer-Consumer");
            Console.WriteLine($"4. Sleeping barber");
            Console.Write($"Enter choice: ");
            int choice = Int32.Parse(Console.ReadLine() ?? throw new InvalidOperationException());

            switch (choice)
            {
            case 1:
                DiningPhilosopher dp = new DiningPhilosopher();
                dp.Start();
                break;

            case 2:
                DataBase db = new DataBase();
                Reader   r1 = new Reader(1, db);
                Writer   w1 = new Writer(1, db);

                Task t1 = Task.Factory.StartNew(() => r1.Run());
                Task t2 = Task.Factory.StartNew(() => w1.Run());
                Task.WaitAll(t1, t2);

                break;

            case 3:

                Pipe     p  = new Pipe();
                Producer pr = new Producer(p);
                Consumer cn = new Consumer(p);
                t1 = Task.Factory.StartNew(() => pr.Run());
                t2 = Task.Factory.StartNew(() => cn.Run());
                Task.WaitAll(t1, t2);
                break;

            case 4:

                SleepingBarber sb = new SleepingBarber();
                sb.Run();

                break;

            default:
                throw new InvalidOperationException("No choice match found");
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            bool exitRequested = false;

            _queue          = new CustomersQueue <Customer>();
            _server         = new CustomerServer();
            _sleepingBarber = new SleepingBarber <Customer>(_queue, _server);
            _sleepingBarber.GoingToSleep += BarberWentToSleep;
            WriteLine("Enter customers range to add then press ENTER");
            WriteLine("Enter Q to Exit");

            while (!exitRequested)
            {
                var input = ReadLine();
                exitRequested = input.ToUpper() == "Q";
                AddCustomers(input);
            }
        }
예제 #4
0
 public void Setup()
 {
     _server         = Substitute.For <IServer <ICustomer> >();
     _customersQueue = Substitute.For <ICustomersQueue <ICustomer> >();
     _sleepingBarber = new SleepingBarber <ICustomer>(_customersQueue, _server);
 }