コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TrackedProjectsViewModel" /> class.
        /// </summary>
        /// <param name="projects">The projects.</param>
        public TrackedProjectsViewModel(IEnumerable <TrackedProjectViewModel> projects)
        {
            Ensure.That(projects).IsNotNull();

            Projects = projects.ToArray();

            _filteredProjects = new CollectionViewSource
            {
                Source = Projects
            };

            _filteredProjects.Filter += (sender, e) =>
            {
                var project = (TrackedProjectViewModel)e.Item;

                e.Accepted = _matches?.Contains(project) ?? true;
            };

            FilteredProjects = _filteredProjects.View;

            _trie = new SuffixTrie <TrackedProjectViewModel>(3);

            foreach (var project in Projects)
            {
                _trie.Add(project.Name.ToLowerInvariant(), project);
            }
        }
コード例 #2
0
        private void BuildTrackerConnectionProgressChanged(object sender, BuildTrackerConnectionProgressEventArgs e)
        {
            if (ShouldExitHandler(e))
            {
                return;
            }

            foreach (var project in e.Projects)
            {
                var projectToUpdate = _projects.SingleOrDefault(p => p.Id == project.Id);

                if (projectToUpdate != null)
                {
                    projectToUpdate.TryUpdate(project.Name);
                }
                else
                {
                    _application.Dispatcher.Invoke(() =>
                    {
                        var projectToAdd = _projectFactory.Create(SettingsId, project.Id, project.Name);

                        var names = _projects.Select(p => p.Name).Concat(new[] { projectToAdd.Name }).OrderBy(name => name).ToArray();

                        var index = Array.IndexOf(names, projectToAdd.Name);

                        _projects.Insert(index, projectToAdd);
                    });
                }
            }

            var projectsToKeep   = e.Projects.Select(project => project.Id).ToArray();
            var projectsToRemove = _projects.Where(project => !projectsToKeep.Contains(project.Id)).ToArray();

            if (_projects.Any())
            {
                _application.Dispatcher.Invoke(() =>
                {
                    _projects.RemoveRange(projectsToRemove);
                });
            }

            _trie = new SuffixTrie <IProjectViewModel>(3);

            foreach (var project in _projects)
            {
                _trie.Add(project.Name.ToLowerInvariant(), project);
            }

            IsErrored = false;
            IsBusy    = false;

            NotifyOfPropertyChange(() => HasProjects);
            NotifyOfPropertyChange(() => HasNoProjects);
            NotifyOfPropertyChange(() => IsViewable);
        }
コード例 #3
0
    private static void FillTrie()
    {
        StreamReader reader = new StreamReader(filePath);

        using (reader)
        {
            //string[] words = reader.ReadToEnd().Split(' ');
            string[] words = { "koko", "kola", "mama", "kolan", "meso", "kolar", "merak", "kino", "kinoman", "m" };
            foreach (var word in words)
            {
                trie.Add(word);
            }
        }
        Console.WriteLine("Trie filled successfully.");
    }