コード例 #1
0
        private async Task PrintPackages(ListArgs listArgs, IEnumeratorAsync <IPackageSearchMetadata> asyncEnumerator)
        {
            bool hasPackages = false;

            if (asyncEnumerator != null)
            {
                if (listArgs.IsDetailed)
                {
                    /***********************************************
                    * Package-Name
                    *  1.0.0.2010
                    *  This is the package Description
                    *
                    * Package-Name-Two
                    *  2.0.0.2010
                    *  This is the second package Description
                    ***********************************************/
                    while (await asyncEnumerator.MoveNextAsync())
                    {
                        var p = asyncEnumerator.Current;
                        listArgs.PrintJustified(0, p.Identity.Id);
                        listArgs.PrintJustified(1, p.Identity.Version.ToFullString());
                        listArgs.PrintJustified(1, p.Description);
                        if (!string.IsNullOrEmpty(p.LicenseUrl?.OriginalString))
                        {
                            listArgs.PrintJustified(1,
                                                    string.Format(
                                                        CultureInfo.InvariantCulture,
                                                        listArgs.ListCommandLicenseUrl,
                                                        p.LicenseUrl.OriginalString));
                        }
                        Console.WriteLine();
                        hasPackages = true;
                    }
                }
                else
                {
                    /***********************************************
                    * Package-Name 1.0.0.2010
                    * Package-Name-Two 2.0.0.2010
                    ***********************************************/
                    while (await asyncEnumerator.MoveNextAsync())
                    {
                        var p = asyncEnumerator.Current;
                        listArgs.PrintJustified(0, p.Identity.Id + " " + p.Identity.Version.ToFullString());
                        hasPackages = true;
                    }
                }
            }
            if (!hasPackages)
            {
                Console.WriteLine(listArgs.ListCommandNoPackages);
            }
        }
コード例 #2
0
        private static async Task <TResult> SelectOptionalAsync <TItem, TSelect, TCarry, TResult>(IEnumeratorAsync <TItem> enumerable,
                                                                                                  TCarry carry, IEnumerableAsync <TSelect> selecteds, Func <TSelect, Task> selectSelection,
                                                                                                  Func <TItem, TCarry, Func <TSelect, TCarry, Task <TResult> >, Func <TCarry, Task <TResult> >, Task <TResult> > selection,
                                                                                                  Func <IEnumerableAsync <TSelect>, TCarry, TResult> aggregation)
        {
            if (!await enumerable.MoveNextAsync())
            {
                return(aggregation(selecteds, carry));
            }

            return(await selection(enumerable.Current, carry,
                                   async (selected, carryUpdated) =>
            {
                await selectSelection(selected);
                return await SelectOptionalAsync(enumerable, carryUpdated, selecteds, selectSelection,
                                                 selection,
                                                 aggregation);
            },
                                   async (carryUpdated) =>
            {
                return await SelectOptionalAsync(enumerable, carryUpdated, selecteds, selectSelection,
                                                 selection,
                                                 aggregation);
            }));
        }
コード例 #3
0
 public static async Task ForEachAsync <TSource>(this IEnumerableAsync <TSource> source, Func <TSource, Task> iterationAction, CancellationToken cancellationToken)
 {
     using (IEnumeratorAsync <TSource> en = source.GetEnumerator())
         while (await en.MoveNextAsync(cancellationToken))
         {
             await iterationAction(en.Current);
         }
 }
コード例 #4
0
            public async Task <bool> MoveNextAsync(CancellationToken cancellationToken)
            {
                bool result;

                while ((result = await _source.MoveNextAsync(cancellationToken)) && !_predicate(_source.Current))
                {
                    ;
                }
                return(result);
            }
コード例 #5
0
        public static async Task <List <T> > ToListAsync <T>(this IEnumeratorAsync <T> enumerator, CancellationToken cancellationToken = default(CancellationToken))
        {
            var list = new List <T>();

            while (await enumerator.MoveNextAsync(cancellationToken).ConfigureAwait(false))
            {
                list.Add(enumerator.Current);
            }

            return(list);
        }
コード例 #6
0
                public async Task <bool> MoveNextAsync(CancellationToken cancellationToken)
                {
                    if (!_initialized)
                    {
                        _data = await _dataProvider(cancellationToken);

                        _source      = _parserProvider(_data).GetEnumerator();
                        _initialized = true;
                    }

                    return(await _source.MoveNextAsync(cancellationToken));
                }
            private async Task <KeyValuePair <bool, TValue> > GetLockedValueAsync(TKey key)
            {
                dictionaryLock.WaitOne();
                try
                {
                    if (dictionary.ContainsKey(key))
                    {
                        return(dictionary[key].PairWithKey(true));
                    }

                    if (!isEnumerating)
                    {
                        return(default(TValue).PairWithKey(false));
                    }

                    while (true)
                    {
                        if (!await tryNextEnumerator.MoveNextAsync())
                        {
                            isEnumerating = false;
                            return(default(TValue).PairWithKey(false));
                        }

                        var element      = tryNextEnumerator.Current;
                        var elementKey   = this.keySelector(element);
                        var elementValue = this.valueSelector(element);
                        dictionary.Add(elementKey, elementValue);
                        if (!comparison(elementKey, key))
                        {
                            continue;
                        }

                        return(elementValue.PairWithKey(true));
                    }
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    dictionaryLock.Set();
                }
            }
コード例 #8
0
        public static IObservable <T> ToObservable <T>(this IEnumeratorAsync <T> enumeratorAsync)
        {
            var nextItem = Observable.Defer(() => enumeratorAsync.MoveNextAsync().ToObservable());

            return(nextItem.Repeat().TakeUntil(b => !b).Select(b => enumeratorAsync.Current));
        }
コード例 #9
0
 public Task <bool> MoveNextAsync(CancellationToken cancellationToken)
 => _source.MoveNextAsync(cancellationToken);
コード例 #10
0
 public static async Task <T> FirstOrDefaultAsync <T>(this IEnumerableAsync <T> source, CancellationToken cancellationToken)
 {
     using (IEnumeratorAsync <T> en = source.GetEnumerator())
         return(await en.MoveNextAsync(cancellationToken) ? en.Current : default(T));
 }