コード例 #1
0
ファイル: Program.cs プロジェクト: tanveeransari/Dumbekv
        private static void Main(string[] args)
        {
            if (args == null || args.Length < 1 || args[0] == null || args[0].Length == 0)
            {
                Console.WriteLine("Usage: Cashiers <filepath>");
                return;
            }

            if (!File.Exists(args[0]))
            {
                Console.WriteLine("ERROR: File {0} does not exist.", args[0]);
                return;
            }

            List<Customer> customerList = new List<Customer>();
            try
            {
                using (var fStream = File.OpenRead(args[0]))
                {
                    using (var strRdr = new StreamReader(fStream))
                    {
                        string lineOne = strRdr.ReadLine();
                        if (string.IsNullOrEmpty(lineOne)) return;
                        int numCashiers;
                        if (!int.TryParse(lineOne, out numCashiers)) return;

                        string custLine;
                        while ((custLine = strRdr.ReadLine()) != null)
                        {
                            Customer cust = CustomerFactory.CreateCustomer(custLine);
                            if (cust != null) customerList.Add(cust);
                        }

                        var store = new Store(numCashiers);
                        int finishTime = store.EnqueueCustomers(customerList);
                        Console.WriteLine("Finished at: t={0} minutes", finishTime);
                    }
                }
            }
            catch (IOException ex)
            {
                Console.WriteLine("Error reading {0} : {1} {2} {3}", args[0],
                    ex.Message, Environment.NewLine + "StackTrace:", ex.StackTrace);
            }
        }
コード例 #2
0
ファイル: StoreTests.cs プロジェクト: tanveeransari/Dumbekv
        private int ProcessTextInput(string inputText)
        {
            if (string.IsNullOrWhiteSpace(inputText))
            {
                return 0;
            }

            int numCashier;
            var customers = new List<Customer>();
            using (var s = new StringReader(inputText))
            {
                numCashier = int.Parse(s.ReadLine());
                string custLine;
                while ((custLine = s.ReadLine()) != null)
                {
                    var cust = CustomerFactory.CreateCustomer(custLine);
                    if (cust != null) customers.Add(cust);
                }
            }

            var store = new Store(numCashier);
            return store.EnqueueCustomers(customers);
        }
コード例 #3
0
ファイル: StoreTests.cs プロジェクト: tanveeransari/Dumbekv
 public void TestNoCustomers()
 {
     var store = new Store(4);
     int completionTime = store.EnqueueCustomers(new List<Customer>());
     Assert.AreEqual(0, completionTime);
 }