Exemplo n.º 1
0
        public int GiveChange(CopyMachine copyMachine)
        {
            var change = copyMachine.MoneyCount;

            copyMachine.MoneyCount = 0;
            return(change);
        }
Exemplo n.º 2
0
 public void ReturnRemain(CopyMachine context)
 {
     Console.WriteLine("Returning remain...");
     Console.WriteLine(context.Balance);
     context.Balance          = 0;
     context.SelectedDocument = null;
     context.State            = new InitialState();
 }
Exemplo n.º 3
0
            public override void PrintError(CopyMachine copyMachine)
            {
                ConsolePrintHelper.WriteLabel("Произошла ошибка: ");
                ConsolePrintHelper.WriteLineValue(copyMachine.Error);

                copyMachine.State = new ReturnDeliveryState();
                copyMachine.State.ReturnDelivery(copyMachine);
            }
Exemplo n.º 4
0
        public void EnterMoney(CopyMachine context)
        {
            Console.WriteLine("Enter money:");
            var amount = uint.Parse(Console.ReadLine());

            Console.WriteLine($"{amount} was deposited in the bill acceptor");
            context.Balance += amount;
            Console.WriteLine($"Current balance is {context.Balance}");
        }
 public override void ReturnDelivery(CopyMachine copyMachine)
 {
     if (copyMachine.Cash > 0)
     {
         ConsolePrintHelper.WriteLabel("Возьмите сдачу: ");
         ConsolePrintHelper.WriteLineValue(copyMachine.Cash.ToString());
         copyMachine.Cash = 0;
     }
     copyMachine.State = new GoodbyeState();
     copyMachine.State.SayGoodbye(copyMachine);
 }
Exemplo n.º 6
0
        static void Main()
        {
            var copyMachine = new CopyMachine();

            copyMachine.PutMoney(25);
            copyMachine.ChooseDevice("Flashcard");
            copyMachine.ChooseDocument("text1.doc");
            copyMachine.PrintDocument();
            copyMachine.ChooseDocument("text2.txt");
            copyMachine.PrintDocument();
            copyMachine.TakeMoney();
        }
Exemplo n.º 7
0
        public static void Main(string[] args)
        {
            var copyMachine = new CopyMachine();

            copyMachine.DepositMoney(8);
            copyMachine.SetStorageDevice(StorageDevice.flash);
            copyMachine.SetDocumentName("shpargalochka.txt");
            copyMachine.PrintDocument();
            copyMachine.DepositMoney(14);
            copyMachine.PrintDocument();
            copyMachine.SetDocumentName("kursach.docx");
            copyMachine.PrintDocument();
            copyMachine.GiveChange();
            //Exception here
            copyMachine.SetDocumentName("flash");
        }
Exemplo n.º 8
0
 public override void PrintSelectedDocument(CopyMachine context)
 {
     if (context.SelectedDocument == null)
     {
         context.State = new ErrorState();
         context.State.PrintSelectedDocument(context);
     }
     if (context.Balance < context.CopyCost)
     {
         throw new Exception("Insufficient funds on balance");
     }
     context.Balance -= context.CopyCost;
     Console.WriteLine("Printing document...");
     Console.WriteLine(context.SelectedDocument);
     Console.WriteLine($"Current balance is {context.Balance}");
 }
Exemplo n.º 9
0
        public static void Main(string[] args)
        {
            var copyMachine = new CopyMachine();

            copyMachine.SelectDevice();
            copyMachine.DepositMoney();
            copyMachine.PrintDocument();
            copyMachine.SelectDevice();
            copyMachine.DepositMoney();
            copyMachine.SelectDocument();
            copyMachine.DepositMoney();
            copyMachine.PrintDocument();
            copyMachine.DepositMoney();
            copyMachine.PickUpMoney();
            copyMachine.DepositMoney();
            copyMachine.PickUpMoney();
        }
Exemplo n.º 10
0
        public override void SelectDocument(CopyMachine context)
        {
            Console.WriteLine("Enter document name:");
            var name = Console.ReadLine();

            //TODO: File system operations
            //Example:
            var document = $"Title:\t{name}\nBody:\tdocument from USB device";
            var found    = true;

            if (!found)
            {
                throw new Exception($"Document {name} not found");
            }
            context.SelectedDocument = document;
            Console.WriteLine($"Selected document {name}");
            context.State = new USBPrintState();
        }
Exemplo n.º 11
0
        public override void SelectDevice(CopyMachine context)
        {
            Console.WriteLine("Enter input device (USB or WiFi):");
            if (!Enum.TryParse(Console.ReadLine(), true, out Device device))
            {
                throw new Exception("Wrong device name");
            }
            switch (device)
            {
            case Device.USB:
                context.State = new USBDeviceState();
                break;

            case Device.WiFi:
                context.State = new WiFiDeviceState();
                break;

            default:
                throw new Exception($"Selected unknown device {device}");
            }
            Console.WriteLine($"Selected device {device}");
        }
        public IHttpActionResult GetAllFlights()
        {
            IList <Flight> result = ((AnonymousUserFacade)Request.Properties["facade"]).GetAllFlights();

            IList <Flight> clonedResult = new List <Flight>();

            foreach (var item in result)
            {
                Flight clonedItem = CopyMachine.DeepCopy(item);

                clonedResult.Add(clonedItem);
            }

            //if (result.Count == 0)
            if (clonedResult.Count == 0)
            {
                return(StatusCode(HttpStatusCode.NoContent));
            }

            //return Ok(result);
            return(Ok(clonedResult));
        }
Exemplo n.º 13
0
        public void FileSystem()
        {
            var fs = new TextFileSystem(@"
f1
d1/f2
d1/f3
d1/d2/f4
d1/d2/d3/
", "", "");

            var rules = @"
f1 => FF
**/f* => FFF
.artifacts/core/** => .xxx
";

            var rs = RuleSet.Parse(rules);

            var copyMachine = new CopyMachine(fs, "", "");

            copyMachine.Copy(rs);

            var added = fs.CopiedFiles.ToString();
        }
Exemplo n.º 14
0
 public abstract void SelectDocument(CopyMachine copyMachine, int document);
Exemplo n.º 15
0
 public abstract void Print(CopyMachine copyMachine);
Exemplo n.º 16
0
 public override void PrintSelectedDocument(CopyMachine context)
 {
     throw new Exception("Document not selected");
 }
Exemplo n.º 17
0
 protected StateBase(CopyMachine copyMachine)
 {
     this.CopyMachine = copyMachine;
 }
Exemplo n.º 18
0
 public void SelectDevice(CopyMachine copyMachine, IDevice device)
 {
     copyMachine.SelectedDevice = device;
     copyMachine.State          = new SelectedDeviceState();
 }
Exemplo n.º 19
0
 public void AddMoney(CopyMachine copyMachine, int count)
 {
     copyMachine.MoneyCount += count;
 }
Exemplo n.º 20
0
 public override void PrintDocument(CopyMachine machine)
 {
     Console.WriteLine("Печать начата.");
     machine.State = new PickUpMoneyWaitingState();
 }
Exemplo n.º 21
0
 public SetDocumentState(CopyMachine copyMachine) : base(copyMachine)
 {
 }
Exemplo n.º 22
0
 public override void SelectDocument(CopyMachine machine)
 {
     Console.WriteLine("Документ выбран.");
     machine.State = new DocumentPrintWaitingState();
 }
Exemplo n.º 23
0
 public InitState(CopyMachine copyMachine) : base(copyMachine)
 {
 }
Exemplo n.º 24
0
 public override void PickUpMoney(CopyMachine machine)
 {
     Console.WriteLine("Сдача выдана.");
     machine.State = new DepositWaitingState();
 }
Exemplo n.º 25
0
 public override void SelectDocument(CopyMachine context)
 {
     context.State = new WiFiDeviceState();
     context.State.SelectDocument(context);
 }
Exemplo n.º 26
0
 public TakingChangeState(CopyMachine machine) : base(machine)
 {
 }
Exemplo n.º 27
0
 public override void SelectDevice(CopyMachine context)
 {
     throw new Exception("Device already selected");
 }
Exemplo n.º 28
0
 public WaitingMoneyState(CopyMachine machine) : base(machine)
 {
 }
Exemplo n.º 29
0
 public override void DepositMoney(CopyMachine machine)
 {
     Console.WriteLine("Деньги внесены.");
     machine.State = new DeviceSelectionWaitingState();
 }
Exemplo n.º 30
0
 public PrintSetupState(CopyMachine machine) : base(machine)
 {
 }