Beispiel #1
0
        public async Task <List <CipherView> > SearchCiphersAsync(string query, Func <CipherView, bool> filter = null,
                                                                  List <CipherView> ciphers = null, CancellationToken ct = default)
        {
            var results = new List <CipherView>();

            if (query != null)
            {
                query = query.Trim().ToLower();
            }
            if (query == string.Empty)
            {
                query = null;
            }
            if (ciphers == null)
            {
                ciphers = await _cipherService.GetAllDecryptedAsync();
            }

            ct.ThrowIfCancellationRequested();
            if (filter != null)
            {
                ciphers = ciphers.Where(filter).ToList();
            }

            ct.ThrowIfCancellationRequested();
            if (!IsSearchable(query))
            {
                return(ciphers);
            }

            return(SearchCiphersBasic(ciphers, query));
            // TODO: advanced searching with index
        }
Beispiel #2
0
        public async Task LoadItemsAsync(bool urlFilter = true, string searchFilter = null)
        {
            var combinedLogins = new List <CipherView>();

            if (urlFilter)
            {
                var logins = await _cipherService.GetAllDecryptedByUrlAsync(_context.UrlString);

                if (logins?.Item1 != null)
                {
                    combinedLogins.AddRange(logins.Item1);
                }
                if (logins?.Item2 != null)
                {
                    combinedLogins.AddRange(logins.Item2);
                }
            }
            else
            {
                var logins = await _cipherService.GetAllDecryptedAsync();

                combinedLogins.AddRange(logins);
            }

            _allItems = combinedLogins
                        .Where(c => c.Type == Bit.Core.Enums.CipherType.Login && !c.IsDeleted)
                        .Select(s => new CipherViewModel(s))
                        .ToList() ?? new List <CipherViewModel>();
            FilterResults(searchFilter, new CancellationToken());
        }
Beispiel #3
0
        public async Task ListItems()
        {
            var all = await _cipherService.GetAllDecryptedAsync();

            Console.WriteLine("Ciphers:");
            foreach (var c in all)
            {
                Console.WriteLine("  * {0} = {1}", c.Id, c.Name, c.Login?.Username, c.Login?.Password);
            }
        }
Beispiel #4
0
        public static async Task <List <FilledItem> > GetFillItemsAsync(Parser parser, ICipherService cipherService)
        {
            if (parser.FieldCollection.FillableForLogin)
            {
                var ciphers = await cipherService.GetAllDecryptedByUrlAsync(parser.Uri);

                if (ciphers.Item1.Any() || ciphers.Item2.Any())
                {
                    var allCiphers = ciphers.Item1.ToList();
                    allCiphers.AddRange(ciphers.Item2.ToList());
                    return(allCiphers.Select(c => new FilledItem(c)).ToList());
                }
            }
            else if (parser.FieldCollection.FillableForCard)
            {
                var ciphers = await cipherService.GetAllDecryptedAsync();

                return(ciphers.Where(c => c.Type == CipherType.Card).Select(c => new FilledItem(c)).ToList());
            }
            return(new List <FilledItem>());
        }