示例#1
0
        internal void Run()
        {
            Console.WriteLine("Type exit at any point to return to main menu.");

            mCommandStack = new Stack <List <CommandBase> >();
            mCommandStack.Push(new List <CommandBase>()
            {
                new CreateTaskCommand(this),
                new RenameTaskCommand(this),
                new UpdateDescriptionTaskCommand(this),
                new DeleteTaskCommand(this),
                new ChangeTaskTagsCommand(this),
                new ListTaskCommand(this),
                new MarkTaskCommand(this),
                new ClearTaskCommand(this),
                new ImportTaskCommand(this),
                new ExportTaskCommand(this),
                new ReorderTaskCommand(this),
                new RefreshTasksCommand(this),
                new BackCommand(this)
            });

            string          url             = @"http://localhost:8080/";
            StartConnection startConnection = new StartConnection(url, "ToDoHub", this);

            startConnection.Execute();

            while (mCommandStack.Count > 0)
            {
                var currentCommands = mCommandStack.Peek();

                Console.WriteLine("\n{0}:", string.Join(", ", currentCommands.Select(c => c.Name)));

                string userInput = Console.ReadLine().Trim();

                var matchingCommand = currentCommands.FirstOrDefault(command => string.Equals(command.Name, userInput, StringComparison.OrdinalIgnoreCase));
                if (Check.ExitCheck(userInput))
                {
                    break;
                }

                if (matchingCommand == null)
                {
                    Console.WriteLine("Command not recognised. Try again.");
                    continue;
                }

                matchingCommand.Execute();
            }
        }
示例#2
0
        public MainWindow()
        {
            string          url             = @"http://localhost:8080/";
            StartConnection startConnection = new StartConnection(url, "ToDoHub", this);

            startConnection.Execute();

            Tasks = new ObservableCollection <Task>();

            ViewableTasks        = new CollectionViewSource();
            ViewableTasks.Source = Tasks;
            ViewableTasks.SortDescriptions.Add(new SortDescription("SortOrder", ListSortDirection.Ascending));
            ViewableTasks.Filter += (s, e) =>
            {
                Task task = e.Item as Task;
                e.Accepted = task.IsViewable;
            };

            InitializeComponent();

            NAME_ATTRIBUTION        = (String)Application.Current.Resources["NAME_ATTRIBUTION"];
            DESCRIPTION_ATTRIBUTION = (String)Application.Current.Resources["DESCRIPTION_ATTRIBUTION"];
            MARKED_ATTRIBUTE        = (String)Application.Current.Resources["MARKED_ATTRIBUTE"];
            TAGS_ATTRIBUTE          = (String)Application.Current.Resources["TAGS_ATTRIBUTE"];
            #region Command Bindings
            CommandBinding Close           = new CommandBinding(ApplicationCommands.Close, ExitCommand_Executed, ExitCommand_CanExecute);
            CommandBinding Open            = new CommandBinding(ApplicationCommands.Open, OpenCommand_Executed, OpenCommand_CanExecute);
            CommandBinding Save            = new CommandBinding(ApplicationCommands.Save, SaveCommand_Executed, SaveCommand_CanExecute);
            CommandBinding Delete          = new CommandBinding(ApplicationCommands.Delete, DeleteTaskCommand_Executed, DeleteTaskCommand_CanExecute);
            CommandBinding MoveDown        = new CommandBinding(ComponentCommands.MoveDown, MoveDownCommand_Executed, MoveDownCommand_CanExecute);
            CommandBinding MoveUp          = new CommandBinding(ComponentCommands.MoveUp, MoveUpCommand_Executed, MoveUpCommand_CanExecute);
            CommandBinding New             = new CommandBinding(ApplicationCommands.New, NewTaskCommand_Executed, NewTaskCommand_CanExecute);
            CommandBinding Refresh         = new CommandBinding(NavigationCommands.Refresh, RefreshCommand_Executed, RefreshCommand_CanExecute);
            CommandBinding Clear_List      = new CommandBinding(Command.ClearList, ClearListCommand_Executed, ClearListCommand_CanExecute);
            CommandBinding View_Filtered   = new CommandBinding(Command.ViewFiltered, ViewFilteredCommand_Executed, ViewFilteredCommand_CanExecute);
            CommandBinding View_Completed  = new CommandBinding(Command.ViewCompleted, ViewCompletedCommand_Executed, ViewCompletedCommand_CanExecute);
            CommandBinding View_Unfinished = new CommandBinding(Command.ViewUnfinished, ViewUnfinishedCommand_Executed, ViewUnfinishedCommand_CanExecute);
            CommandBinding View_All        = new CommandBinding(Command.ViewAll, ViewAllCommand_Executed, ViewAllCommand_CanExecute);
            CommandBinding Cut             = new CommandBinding(ApplicationCommands.Cut, CutCommand_Executed, CutCommand_CanExecute);
            CommandBinding Copy            = new CommandBinding(ApplicationCommands.Copy, CopyCommand_Executed, CopyCommand_CanExecute);
            CommandBinding Paste           = new CommandBinding(ApplicationCommands.Paste, PasteCommand_Executed, PasteCommand_CanExecute);
            CommandBinding Connect         = new CommandBinding(Command.Connect, ConnectCommand_Executed, ConnectCommand_CanExecute);

            this.CommandBindings.Add(Close);
            this.CommandBindings.Add(Open);
            this.CommandBindings.Add(Save);
            this.CommandBindings.Add(Delete);
            this.CommandBindings.Add(MoveDown);
            this.CommandBindings.Add(MoveUp);
            this.CommandBindings.Add(New);
            this.CommandBindings.Add(Refresh);
            this.CommandBindings.Add(Clear_List);
            this.CommandBindings.Add(View_Filtered);
            this.CommandBindings.Add(View_Completed);
            this.CommandBindings.Add(View_Unfinished);
            this.CommandBindings.Add(View_All);
            this.CommandBindings.Add(Cut);
            this.CommandBindings.Add(Copy);
            this.CommandBindings.Add(Paste);
            this.CommandBindings.Add(Connect);
            #endregion
        }