private void NotifyPathToFileDependentCommands()
 {
     ApplicationService.RunOnUI(() =>
     {
         SavePoliciesCommand.RaiseCanExecuteChanged();
         CloseFileCommand.RaiseCanExecuteChanged();
         RefreshPolicyListCommand.RaiseCanExecuteChanged();
     });
 }
        public void Command()
        {
            var mockFileByOpen  = new MockCommand();
            var mockFileByClose = new MockCommand();

            ICommand commadOpen  = new OpenFileCommand(mockFileByOpen);
            ICommand commadClose = new CloseFileCommand(mockFileByClose);

            commadOpen.Execute();
            commadClose.Execute();

            Assert.IsTrue(mockFileByOpen.InvokedOpen);
            Assert.IsTrue(mockFileByClose.InvokedClose);

            Assert.IsFalse(mockFileByOpen.InvokedClose);
            Assert.IsFalse(mockFileByClose.InvokedOpen);
        }
        public static void InvokeCommand()
        {
            IAccessible file = new Archive();

            ICommand fileClose = new CloseFileCommand(file);
            ICommand fileOpen  = new OpenFileCommand(file);
            ICommand fileCopy  = new CopyFileCommand(file);
            ICommand filePaste = new PasteFileCommand(file);

            Access command = new Access(fileClose, fileOpen, fileCopy, filePaste);

            string [] orders = { "close", "open", "close", "close", "copy", "paste", "paste", "batata" };
            foreach (string ordem in orders)
            {
                switch (ordem)
                {
                case "open":
                    Console.Write("Comando " + ordem + ": ");
                    command.Open();
                    break;

                case "close":
                    Console.Write("Comando " + ordem + ": ");
                    command.Close();
                    break;

                case "copy":
                    Console.Write("Comando " + ordem + ": ");
                    command.Copy();
                    break;

                case "paste":
                    Console.Write("Comando " + ordem + ": ");
                    command.Paste();
                    break;

                default:
                    Console.WriteLine("Comando " + ordem + ": Comando Inválido");
                    break;
                }
            }

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            var fileSystemReceiver = FileSystemReceiverUtil.GetFileSystemReceiver();

            var openFileCommand = new OpenFileCommand(fileSystemReceiver);

            var closeFileCommand = new CloseFileCommand(fileSystemReceiver);

            var readFileCommand = new ReadFileCommand(fileSystemReceiver);

            var writeFileCommand = new WriteFileCommand(fileSystemReceiver);

            var invoker = new FileInvoker();

            invoker.Execute(openFileCommand);

            invoker.Execute(closeFileCommand);

            invoker.Execute(new ICommand[] { openFileCommand, readFileCommand, writeFileCommand, closeFileCommand });

            Console.Read();
        }
示例#5
0
        static void CommandTest()
        {
            //Creating the receiver object
            IFileSystemReceiver fs = FileSystemReceiverUtil.getUnderlyingFileSystem();

            //creating command and associating with receiver
            OpenFileCommand openFileCommand = new OpenFileCommand(fs);

            //Creating invoker and associating with Command
            FileInvoker file = new FileInvoker(openFileCommand);

            //perform action on invoker object
            file.execute();

            WriteFileCommand writeFileCommand = new WriteFileCommand(fs);

            file = new FileInvoker(writeFileCommand);
            file.execute();

            CloseFileCommand closeFileCommand = new CloseFileCommand(fs);

            file = new FileInvoker(closeFileCommand);
            file.execute();
        }