public PhonebookCommand ReadCommand(string line)
        {
            string commandType = line.Substring(0, line.IndexOf('(')).Trim();

            string commandArgs = line.Split('(', ')')[1].Trim();

            string[] args = commandArgs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < args.Length; i++)
            {
                args[i] = args[i].Trim();
            }

            Commands type;

            PhonebookCommand command = null;

            switch (commandType)
            {
            case "find": type = Commands.Find; command = new FindCommand(args); break;

            case "serialize": type = Commands.Serialize; command = new SerializeCommand(args); break;

            case "add": type = Commands.add; command = new AddCommand(args); break;

            default: type = Commands.Find; command = new FindCommand(args); break;
            }

            return(command);
        }
        /// <summary>
        /// Searches all items for us
        /// </summary>
        /// <param name="skip"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public Task <FindCommitResults> FindAllItemsAsync(int skip = 0, int limit = int.MaxValue)
        {
            var cmd = new FindCommand(this, null, skip, limit);

            controller.QueueCommand(cmd);
            return(cmd.GetTask());
        }
Exemplo n.º 3
0
        private void PrintCommandHelp(string commandName)
        {
            Command command;

            switch (commandName.ToLowerInvariant())
            {
            case "install":
                command = new InstallCommand();
                break;

            case "list":
                command = new ListCommand();
                break;

            case "find":
                command = new FindCommand();
                break;

            default:
                Console.WriteLine($"Unknown command '{commandName}'.{Environment.NewLine}");
                return;
            }

            command.Invoke(new string[] { "--help" });
        }
Exemplo n.º 4
0
        public IElement Find(string selector)
        {
            var command = new FindCommand(selector);
            var element = _performer.PerformAndReturn(command);

            return(element);
        }
 public void Configure(FindCommand find, ResolveByCommand resolveBy, string resolveQuery)
 {
     _configured  = false;
     _target      = null;
     _find        = find;
     _resolveBy   = resolveBy;
     _queryString = resolveQuery;
 }
 public void Configure(UnityEngine.Object target)
 {
     _configured  = true;
     _target      = target;
     _find        = FindCommand.Direct;
     _resolveBy   = ResolveByCommand.Nothing;
     _queryString = null;
 }
 public void Configure(UnityEngine.Object target, FindCommand find, ResolveByCommand resolveBy = ResolveByCommand.Nothing, string resolveQuery = null)
 {
     _configured  = true;
     _target      = target;
     _find        = find;
     _resolveBy   = resolveBy;
     _queryString = resolveQuery;
 }
Exemplo n.º 8
0
        public FluentSessionRecorder Find(string selector, out IElement element)
        {
            var command = new FindCommand(selector);

            element = _performer.PerformAndReturn(command);

            return(this);
        }
Exemplo n.º 9
0
        private static void FindFiles(BA2Archive archive, FindCommand cmd)
        {
            int counter = 1;

            foreach (string file in FindMatchingFiles(archive, cmd.Search))
            {
                Console.WriteLine($"{counter++}. {file}");
            }
        }
Exemplo n.º 10
0
        private string PerformFind(FindCommand command)
        {
            if (_storage.ContainsKey(command.Key))
            {
                return($"The element with key {command.Key} is in database");
            }

            return("No such element in database");
        }
Exemplo n.º 11
0
 Option <FindCommand> GetCommand()
 {
     if (!string.IsNullOrEmpty(Pattern))
     {
         return(FindCommand.Search(Pattern));
     }
     if (RunTimeInMs > 0)
     {
         return(FindCommand.RuntimeAtLeast(RunTimeInMs));
     }
     return(Option <FindCommand> .None);
 }
Exemplo n.º 12
0
        Func <LogListViewItem, bool> MakeSearchPredicate(FindCommand findCommand)
        {
            var predicate = findCommand.Match <Func <LogListViewItem, bool> >(
                search =>
            {
                var regex = new Regex(search.Pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled);
                return(item => regex.IsMatch(item.Message));
            },
                runtimeAtLeast => item => m_LogFormatProvider.GetTraceTimeInMs(item) >= runtimeAtLeast.Milliseconds
                );

            return(predicate);
        }
Exemplo n.º 13
0
        public UserVM()
        {
            questions = new ObservableCollection <QuestionDTO>();
            answers   = new ObservableCollection <ServiceReferenceAnswerOption.AnswerOptionDTO>();


            getQuestionscommacd = new GetQuestionsCommand(this);
            startComand         = new StartTestCommand(this);
            endComand           = new EndCommand(this);
            findComand          = new FindCommand(this);
            logStud             = new LogStudCommand(this);
            startPage           = new StartPageLogCommand(this);
        }
Exemplo n.º 14
0
        public void Initialize()
        {
#if DEBUG
            QueryText        = DEFAULT_QUERY;
            RootPathText     = DEFAULT_ROOT_PATH;
            FilterText       = DEFAULT_FILTER;
            RecursiveChecked = true;
#endif
            FindClicked     = new FindCommand(this);
            BrowseClicked   = new BrowseCommand(this);
            AdvancedClicked = new RelayCommand(RetrieveExtensions);
            OpenFileCommand = new RelayCommand(OpenFile);

            m_AuthToken = TabManager <FindTextViewModel> .Instance.ResolveActiveTabToken();
        }
Exemplo n.º 15
0
        public void DoFind()
        {
            Task.Run(() =>
            {
                LastMagicWords = MagicWords;

                var answer = _answers.FirstOrDefault(a => a.MagicWords == MagicWords.Trim());
                Ui(() =>
                {
                    if (answer == null)
                    {
                        AnswerText = "Answer Not Found";
                    }
                    else
                    {
                        AnswerText = FormatAnswer(answer);
                    }

                    FindCommand.RaiseCanExecuteChanged();
                });
            });
        }
Exemplo n.º 16
0
        static int Execute(ConsoleCommand cmd)
        {
            ICommand command = new NullCommand();

            switch (cmd.Name)
            {
            case null:
                return(0);

            case "exit":
                command = new ExitCommand();
                break;

            case "find":
                command = new FindCommand(cmd);
                break;

            case "route":
                command = new RouteCommand(cmd);
                break;

            case "multiroute":
                command = new MultiRouteCommand(cmd);
                break;

            case "stats":
                command = new StatsCommand();
                break;

            default:
                Console.WriteLine("Unrecognised command.");
                return(0);
            }

            return(command.Execute());
        }
Exemplo n.º 17
0
 public void SetUp()
 {
     _defaultCommand = new FindCommand(DefaultSelector);
 }
Exemplo n.º 18
0
 public int CountItems(FindCommand findCommand) => VisibleItems.Count(MakeSearchPredicate(findCommand));
Exemplo n.º 19
0
        public int ProcessSearch(FindCommand findCommand)
        {
            var predicate = MakeSearchPredicate(findCommand);

            return(HighlightItems(predicate));
        }
Exemplo n.º 20
0
        static void Main(string[] args)
        {
            PhoneBook <IEntity> book = new PhoneBook <IEntity>("Mad book");

            if (!File.Exists("../../book.txt"))
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("No file phonebook.txt found!");
            }
            else
            {
                PhonebookFileReader reader = new PhonebookFileReader("../../book.txt");

                List <IEntity> contacts;
                using (reader)
                {
                    contacts = reader.ReadRecords();
                }

                foreach (var person in contacts)
                {
                    Console.WriteLine(person);
                    var addCommand = new AddCommand(new string[]
                    {
                        person.Name,
                        person.CityName,
                        person.PhoneNumber
                    });

                    addCommand.Add(person, book);
                }

                PhonebookCommandFileReader commandReader = new PhonebookCommandFileReader("../../commands.txt");
                List <PhonebookCommand>    commands      = commandReader.GetCommands();

                foreach (var phonebookCommand in commands)
                {
                    Console.WriteLine($"\n\nCommand: {phonebookCommand}:");
                    for (int i = 0; i < phonebookCommand.Arguments.Length; i++)
                    {
                        Console.WriteLine($"\n - argument{i}: {phonebookCommand.Arguments[i]}");
                    }

                    if (phonebookCommand is SerializeCommand)
                    {
                        string name              = phonebookCommand.Arguments[0];
                        string fileName          = phonebookCommand.Arguments[1];
                        string serializationType = phonebookCommand.Arguments[2];

                        IDisposable writer = null;
                        ISerializator <List <IEntity> > serializator;


                        switch (((SerializeCommand)phonebookCommand).SerializationType)
                        {
                        case "json": serializator = new JsonSerializator <List <IEntity> >(); writer = new FileWriter(fileName); break;

                        case "xml": serializator = new XmlSerializator <List <IEntity> >(); writer = XmlWriter.Create(fileName); break;

                        default: serializator = new JsonSerializator <List <IEntity> >(); writer = new FileWriter(fileName); break;
                        }

                        var findCommand = new FindCommand(new string[] { name });

                        List <IEntity> personsFound = findCommand.FindAllEntities(name, book);

                        if (personsFound.Count > 0)
                        {
                            ((SerializeCommand)phonebookCommand).SerializeEntities(serializator, personsFound, writer);

                            // Deserialize test
                            IDisposable fileReader = null;

                            if (serializationType.ToLower() == "json")
                            {
                                fileReader = new FileReader(fileName);
                            }
                            else
                            {
                                fileReader = XmlReader.Create(fileName);
                            }

                            List <IEntity> newList = serializator.Deserialize(fileReader);

                            foreach (var person in newList)
                            {
                                Console.WriteLine($"Deserialized:\n -- Name {person.Name}, city: {person.CityName}, phone: {person.PhoneNumber}");
                            }
                        }
                        else
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine($"No person with name \"{name}\" found!");
                            Console.ForegroundColor = ConsoleColor.White;
                        }
                    }
                    else if (phonebookCommand is AddCommand)
                    {
                        var writer = new FileWriter("../../book.txt");
                        using (writer)
                        {
                            var entity =
                                new IEntity(
                                    phonebookCommand.Arguments[0].Trim(),
                                    phonebookCommand.Arguments[1].Trim(),
                                    phonebookCommand.Arguments[2].Trim()
                                    );
                            ((AddCommand)phonebookCommand).AddToFile(entity, writer, book);
                        }
                    }
                    else if (phonebookCommand is FindCommand)
                    {
                        IEntity entity = null;

                        if (phonebookCommand.Arguments.Length == 2)
                        {
                            entity = (phonebookCommand as FindCommand).FindEntity(phonebookCommand.Arguments[0], phonebookCommand.Arguments[1], book);
                        }
                        else
                        {
                            entity = (phonebookCommand as FindCommand).FindEntity(phonebookCommand.Arguments[0], book);
                        }

                        if (entity != null)
                        {
                            var consoleWriter = new ConsoleWriter();
                            Console.ForegroundColor = ConsoleColor.Green;
                            consoleWriter.WriteLine(String.Format($"{entity.Id} : {entity.Name}, {entity.CityName}, {entity.PhoneNumber}"));
                            Console.ForegroundColor = ConsoleColor.White;
                        }
                    }
                }
            }
        }
 public TriggerableTargetObject(UnityEngine.Object target, FindCommand find, ResolveByCommand resolveBy = ResolveByCommand.Nothing, string resolveQuery = null)
 {
     this.Configure(target, find, resolveBy, resolveQuery);
 }
 public TriggerableTargetObject(FindCommand find, ResolveByCommand resolveBy, string resolveQuery)
 {
     this.Configure(find, resolveBy, resolveQuery);
 }
 public TriggerableTargetObject(bool defaultTriggerArg, FindCommand find, ResolveByCommand resolve)
 {
     _configured = !defaultTriggerArg;
     _find       = find;
     _resolveBy  = resolve;
 }